Skip to content

Commit 644d3d3

Browse files
authored
Add b64 decode config option to circle contexts (#336)
The option to base64 decode was added to the CircleCI location but not the CircleCIContext location. This adds the same configuration option to the context based location.
1 parent c96ce68 commit 644d3d3

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

pkg/location/circlecicontext.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
package location
22

33
import (
4+
"encoding/base64"
45
"github.com/ovotech/cloud-key-rotator/pkg/cred"
56

67
"github.com/CircleCI-Public/circleci-cli/api"
78
)
89

910
// CircleCIContext type
1011
type CircleCIContext struct {
11-
ContextID string
12-
KeyIDEnvVar string
13-
KeyEnvVar string
12+
ContextID string
13+
KeyIDEnvVar string
14+
KeyEnvVar string
15+
Base64Decode bool
1416
}
1517

1618
func (circleContext CircleCIContext) Write(serviceAccountName string, keyWrapper KeyWrapper, creds cred.Credentials) (updated UpdatedLocation, err error) {
@@ -25,6 +27,16 @@ func (circleContext CircleCIContext) Write(serviceAccountName string, keyWrapper
2527

2628
provider := keyWrapper.KeyProvider
2729
contextID := circleContext.ContextID
30+
key := keyWrapper.Key
31+
// if configured, base64 decode the key (GCP return encoded keys)
32+
if circle.Base64Decode {
33+
var keyb []byte
34+
keyb, err = base64.StdEncoding.DecodeString(key)
35+
if err != nil {
36+
return
37+
}
38+
key = string(keyb)
39+
}
2840

2941
var keyEnvVar string
3042
var idValue bool
@@ -44,7 +56,7 @@ func (circleContext CircleCIContext) Write(serviceAccountName string, keyWrapper
4456
}
4557
}
4658

47-
if err = updateCircleCIContext(contextID, keyEnvVar, keyWrapper.Key, gqlclient); err != nil {
59+
if err = updateCircleCIContext(contextID, keyEnvVar, key, gqlclient); err != nil {
4860
return
4961
}
5062

0 commit comments

Comments
 (0)