@@ -101,29 +101,29 @@ func Rotate(account, provider, project string, c config.Config) (err error) {
101
101
return
102
102
}
103
103
var rc []rotationCandidate
104
- if rc , err = rotationCandidates (account , providerKeys , c .AccountKeyLocations ,
104
+ if rc , err = rotationCandidates (providerKeys , c .AccountKeyLocations ,
105
105
c .Credentials , c .DefaultRotationAgeThresholdMins ); err != nil {
106
106
return
107
107
}
108
108
logger .Infof ("Finalised %d keys that are candidates for rotation" , len (rc ))
109
- return rotateKeys (account , rc , c .Credentials )
109
+ return rotateKeys (rc , c .Credentials )
110
110
}
111
111
112
112
//rotatekey creates a new key for the rotation candidate, updates its key locations,
113
113
// and deletes the old key iff the key location update is successful
114
- func rotateKey (account string , rotationCandidate rotationCandidate , creds cred.Credentials ) (err error ) {
114
+ func rotateKey (rotationCandidate rotationCandidate , creds cred.Credentials ) (err error ) {
115
115
key := rotationCandidate .key
116
116
keyProvider := key .Provider .Provider
117
117
var newKeyID string
118
118
var newKey string
119
- if newKeyID , newKey , err = createKey (account , key , keyProvider ); err != nil {
119
+ if newKeyID , newKey , err = createKey (key , keyProvider ); err != nil {
120
120
return
121
121
}
122
122
keyWrapper := location.KeyWrapper {Key : newKey , KeyID : newKeyID , KeyProvider : keyProvider }
123
- if err = updateKeyLocation (account , rotationCandidate .keyLocation , keyWrapper , creds ); err != nil {
123
+ if err = updateKeyLocation (key . FullAccount , rotationCandidate .keyLocation , keyWrapper , creds ); err != nil {
124
124
return
125
125
}
126
- return deleteKey (account , key , keyProvider )
126
+ return deleteKey (key , keyProvider )
127
127
}
128
128
129
129
//rotationAgeThreshold calculates the key age rotation threshold based on config values
@@ -137,17 +137,17 @@ func rotationAgeThreshold(keyLocation config.KeyLocations, defaultRotationAgeThr
137
137
138
138
//rotateKeys iterates over the rotation candidates, invoking the func that actually
139
139
// performs the rotation
140
- func rotateKeys (account string , rotationCandidates []rotationCandidate , creds cred.Credentials ) (err error ) {
140
+ func rotateKeys (rotationCandidates []rotationCandidate , creds cred.Credentials ) (err error ) {
141
141
for _ , rc := range rotationCandidates {
142
142
key := rc .key
143
143
logger .Infow ("Rotation process started" ,
144
144
"keyProvider" , key .Provider .Provider ,
145
- "account" , account ,
145
+ "account" , key . FullAccount ,
146
146
"keyID" , key .ID ,
147
147
"keyAge" , fmt .Sprintf ("%f" , key .Age ),
148
148
"keyAgeThreshold" , strconv .Itoa (rc .rotationThresholdMins ))
149
149
150
- if err = rotateKey (account , rc , creds ); err != nil {
150
+ if err = rotateKey (rc , creds ); err != nil {
151
151
return
152
152
}
153
153
}
@@ -158,7 +158,7 @@ func rotateKeys(account string, rotationCandidates []rotationCandidate, creds cr
158
158
//rotatekeys runs through the end to end process of rotating a slice of keys:
159
159
//filter down to subset of target keys, generate new key for each, update the
160
160
//key's locations and finally delete the existing/old key
161
- func rotationCandidates (account string , accountKeys []keys.Key , keyLoc []config.KeyLocations ,
161
+ func rotationCandidates (accountKeys []keys.Key , keyLoc []config.KeyLocations ,
162
162
creds cred.Credentials , defaultRotationAgeThresholdMins int ) (rotationCandidates []rotationCandidate , err error ) {
163
163
processedItems := make ([]string , 0 )
164
164
for _ , key := range accountKeys {
@@ -171,14 +171,14 @@ func rotationCandidates(account string, accountKeys []keys.Key, keyLoc []config.
171
171
172
172
if contains (processedItems , key .FullAccount ) {
173
173
logger .Infof ("Skipping SA: %s, key: %s as a key for this account has already been added as a candidate for rotation" ,
174
- account , key .ID )
174
+ key . FullAccount , key .ID )
175
175
continue
176
176
}
177
177
178
178
rotationThresholdMins := rotationAgeThreshold (locations , defaultRotationAgeThresholdMins )
179
179
if float64 (rotationThresholdMins ) > key .Age {
180
180
logger .Infof ("Skipping SA: %s, key: %s as it's only %f minutes old (threshold: %d mins)" ,
181
- account , key .ID , key .Age , rotationThresholdMins )
181
+ key . FullAccount , key .ID , key .Age , rotationThresholdMins )
182
182
continue
183
183
}
184
184
@@ -192,26 +192,26 @@ func rotationCandidates(account string, accountKeys []keys.Key, keyLoc []config.
192
192
}
193
193
194
194
//createKey creates a new key with the provider specified
195
- func createKey (account string , key keys.Key , keyProvider string ) (newKeyID , newKey string , err error ) {
195
+ func createKey (key keys.Key , keyProvider string ) (newKeyID , newKey string , err error ) {
196
196
if newKeyID , newKey , err = keys .CreateKey (key ); err != nil {
197
197
logger .Error (err )
198
198
return
199
199
}
200
200
logger .Infow ("New key created" ,
201
201
"keyProvider" , keyProvider ,
202
- "account" , account ,
202
+ "account" , key . FullAccount ,
203
203
"keyID" , newKeyID )
204
204
return
205
205
}
206
206
207
207
//deletekey deletes the key
208
- func deleteKey (account string , key keys.Key , keyProvider string ) (err error ) {
208
+ func deleteKey (key keys.Key , keyProvider string ) (err error ) {
209
209
if err = keys .DeleteKey (key ); err != nil {
210
210
return
211
211
}
212
212
logger .Infow ("Old key deleted" ,
213
213
"keyProvider" , keyProvider ,
214
- "account" , account ,
214
+ "account" , key . FullAccount ,
215
215
"keyID" , key .ID )
216
216
return
217
217
}
0 commit comments