Skip to content

Commit 2bdaf94

Browse files
authored
Merge pull request #68 from ovotech/remove-pointless-acc-string
Remove unnecessary 'account' string that's obtained out-of-band
2 parents f3d3935 + 485f16f commit 2bdaf94

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ jobs:
103103
command: |
104104
export GO111MODULE=on
105105
go mod download
106-
go test ./...
106+
go test ./... -v
107107
108108
workflows:
109109
version: 2

pkg/rotate/rotatekeys.go

+16-16
Original file line numberDiff line numberDiff line change
@@ -101,29 +101,29 @@ func Rotate(account, provider, project string, c config.Config) (err error) {
101101
return
102102
}
103103
var rc []rotationCandidate
104-
if rc, err = rotationCandidates(account, providerKeys, c.AccountKeyLocations,
104+
if rc, err = rotationCandidates(providerKeys, c.AccountKeyLocations,
105105
c.Credentials, c.DefaultRotationAgeThresholdMins); err != nil {
106106
return
107107
}
108108
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)
110110
}
111111

112112
//rotatekey creates a new key for the rotation candidate, updates its key locations,
113113
// 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) {
115115
key := rotationCandidate.key
116116
keyProvider := key.Provider.Provider
117117
var newKeyID string
118118
var newKey string
119-
if newKeyID, newKey, err = createKey(account, key, keyProvider); err != nil {
119+
if newKeyID, newKey, err = createKey(key, keyProvider); err != nil {
120120
return
121121
}
122122
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 {
124124
return
125125
}
126-
return deleteKey(account, key, keyProvider)
126+
return deleteKey(key, keyProvider)
127127
}
128128

129129
//rotationAgeThreshold calculates the key age rotation threshold based on config values
@@ -137,17 +137,17 @@ func rotationAgeThreshold(keyLocation config.KeyLocations, defaultRotationAgeThr
137137

138138
//rotateKeys iterates over the rotation candidates, invoking the func that actually
139139
// 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) {
141141
for _, rc := range rotationCandidates {
142142
key := rc.key
143143
logger.Infow("Rotation process started",
144144
"keyProvider", key.Provider.Provider,
145-
"account", account,
145+
"account", key.FullAccount,
146146
"keyID", key.ID,
147147
"keyAge", fmt.Sprintf("%f", key.Age),
148148
"keyAgeThreshold", strconv.Itoa(rc.rotationThresholdMins))
149149

150-
if err = rotateKey(account, rc, creds); err != nil {
150+
if err = rotateKey(rc, creds); err != nil {
151151
return
152152
}
153153
}
@@ -158,7 +158,7 @@ func rotateKeys(account string, rotationCandidates []rotationCandidate, creds cr
158158
//rotatekeys runs through the end to end process of rotating a slice of keys:
159159
//filter down to subset of target keys, generate new key for each, update the
160160
//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,
162162
creds cred.Credentials, defaultRotationAgeThresholdMins int) (rotationCandidates []rotationCandidate, err error) {
163163
processedItems := make([]string, 0)
164164
for _, key := range accountKeys {
@@ -171,14 +171,14 @@ func rotationCandidates(account string, accountKeys []keys.Key, keyLoc []config.
171171

172172
if contains(processedItems, key.FullAccount) {
173173
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)
175175
continue
176176
}
177177

178178
rotationThresholdMins := rotationAgeThreshold(locations, defaultRotationAgeThresholdMins)
179179
if float64(rotationThresholdMins) > key.Age {
180180
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)
182182
continue
183183
}
184184

@@ -192,26 +192,26 @@ func rotationCandidates(account string, accountKeys []keys.Key, keyLoc []config.
192192
}
193193

194194
//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) {
196196
if newKeyID, newKey, err = keys.CreateKey(key); err != nil {
197197
logger.Error(err)
198198
return
199199
}
200200
logger.Infow("New key created",
201201
"keyProvider", keyProvider,
202-
"account", account,
202+
"account", key.FullAccount,
203203
"keyID", newKeyID)
204204
return
205205
}
206206

207207
//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) {
209209
if err = keys.DeleteKey(key); err != nil {
210210
return
211211
}
212212
logger.Infow("Old key deleted",
213213
"keyProvider", keyProvider,
214-
"account", account,
214+
"account", key.FullAccount,
215215
"keyID", key.ID)
216216
return
217217
}

0 commit comments

Comments
 (0)