From e22dfbf8feb4dc351567db0de198083d6ddc48e9 Mon Sep 17 00:00:00 2001 From: samirtahir91 <30797145+samirtahir91@users.noreply.github.com> Date: Sun, 31 Mar 2024 07:25:57 +0100 Subject: [PATCH] fix: update access token secret key (#11) * fix: update access token secret key 'token' --- internal/controller/githubapp_controller.go | 8 ++++---- internal/controller/githubapp_controller_test.go | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/controller/githubapp_controller.go b/internal/controller/githubapp_controller.go index c87f6a5..6477e86 100644 --- a/internal/controller/githubapp_controller.go +++ b/internal/controller/githubapp_controller.go @@ -122,7 +122,7 @@ func (r *GithubAppReconciler) checkExpiryAndUpdateAccessToken(ctx context.Contex } // Check if there are additional keys in the existing secret's data besides accessToken for key := range accessTokenSecret.Data { - if key != "accessToken" { + if key != "token" { log.Log.Info("Removing invalid key in access token secret", "Key", key) return r.generateOrUpdateAccessToken(ctx, githubApp) } @@ -130,7 +130,7 @@ func (r *GithubAppReconciler) checkExpiryAndUpdateAccessToken(ctx context.Contex // Check if the accessToken field exists and is not empty var accessToken string - accessToken = string(accessTokenSecret.Data["accessToken"]) + accessToken = string(accessTokenSecret.Data["token"]) // Check if the access token is a valid github token via gh api auth if !isAccessTokenValid(ctx, accessToken, req) { @@ -272,7 +272,7 @@ func (r *GithubAppReconciler) generateOrUpdateAccessToken(ctx context.Context, g Namespace: githubApp.Namespace, }, StringData: map[string]string{ - "accessToken": accessToken, + "token": accessToken, }, } accessTokenSecretKey := client.ObjectKey{ @@ -326,7 +326,7 @@ func (r *GithubAppReconciler) generateOrUpdateAccessToken(ctx context.Context, g delete(existingSecret.Data, k) } existingSecret.StringData = map[string]string{ - "accessToken": accessToken, + "token": accessToken, } if err := r.Update(ctx, existingSecret); err != nil { l.Error(err, "Failed to update existing Secret") diff --git a/internal/controller/githubapp_controller_test.go b/internal/controller/githubapp_controller_test.go index 52c8d3f..0426ae2 100644 --- a/internal/controller/githubapp_controller_test.go +++ b/internal/controller/githubapp_controller_test.go @@ -138,7 +138,7 @@ var _ = Describe("GithubApp controller", func() { } accessTokenSecret := &corev1.Secret{} Expect(k8sClient.Get(ctx, accessTokenSecretKey, accessTokenSecret)).To(Succeed()) - accessTokenSecret.Data["accessToken"] = []byte(dummyAccessToken) + accessTokenSecret.Data["token"] = []byte(dummyAccessToken) Expect(k8sClient.Update(ctx, accessTokenSecret)).To(Succeed()) // Wait for the accessToken to be updated @@ -146,7 +146,7 @@ var _ = Describe("GithubApp controller", func() { updatedSecret := &corev1.Secret{} err := k8sClient.Get(ctx, accessTokenSecretKey, updatedSecret) Expect(err).To(Succeed()) - return string(updatedSecret.Data["accessToken"]) + return string(updatedSecret.Data["token"]) }, "60s", "5s").ShouldNot(Equal(dummyAccessToken)) }) })