Skip to content

Commit

Permalink
B64 encode gcp credentials for credentials sync
Browse files Browse the repository at this point in the history
Signed-off-by: Danil Grigorev <danil.grigorev@suse.com>
  • Loading branch information
Danil-Grigorev authored and furkatgofurov7 committed May 13, 2024
1 parent 2c99afb commit 354df4c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/sync/secret_mapper_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ var (
{to: "VSPHERE_USERNAME", from: Raw{source: "vmwarevsphere-username"}},
},
"gcp": {
{to: "GCP_B64ENCODED_CREDENTIALS", from: Raw{source: "googlecredentialConfig-authEncodedJson"}},
{to: "GCP_B64ENCODED_CREDENTIALS", from: B64{source: "googlecredentialConfig-authEncodedJson"}},
},
"digitalocean": {
{to: "DIGITALOCEAN_ACCESS_TOKEN", from: Raw{source: "digitaloceancredentialConfig-accessToken"}},
Expand Down
22 changes: 22 additions & 0 deletions internal/sync/secret_mapper_sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,28 @@ var _ = Describe("SecretMapperSync get", func() {
}))
}).Should(Succeed())
})

It("converts GCP credentials with double B64 encode", func() {
capiProvider.Spec.Name = "gcp"
rancherSecret.Annotations[sync.DriverNameAnnotation] = "gcp"
rancherSecret.Data = map[string][]byte{
"googlecredentialConfig-authEncodedJson": []byte("test"),
}
Expect(testEnv.Client.Create(ctx, rancherSecret)).ToNot(HaveOccurred())

Eventually(ctx, func(g Gomega) {
syncer := sync.NewSecretMapperSync(ctx, testEnv, capiProvider).(*sync.SecretMapperSync)
g.Expect(syncer.Get(ctx)).ToNot(HaveOccurred())
g.Expect(syncer.Sync(context.Background())).ToNot(HaveOccurred())
g.Expect(conditions.Get(syncer.Source, turtlesv1.RancherCredentialsSecretCondition)).ToNot(BeNil())
g.Expect(conditions.IsTrue(syncer.Source, turtlesv1.RancherCredentialsSecretCondition)).To(BeTrue())

g.Expect(syncer.Secret.StringData).To(Equal(map[string]string{
"GCP_B64ENCODED_CREDENTIALS": "dGVzdA==",
}))
}).Should(Succeed())
})

It("provider requirements digitalocean", func() {
capiProvider.Spec.Name = "digitalocean"
rancherSecret.Annotations[sync.DriverNameAnnotation] = "digitalocean"
Expand Down

0 comments on commit 354df4c

Please sign in to comment.