Skip to content

Commit

Permalink
fix: update access token secret key (#11)
Browse files Browse the repository at this point in the history
* fix: update access token secret key 'token'
  • Loading branch information
samirtahir91 authored Mar 31, 2024
1 parent 8dccd7e commit e22dfbf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions internal/controller/githubapp_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ 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)
}
}

// 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) {
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions internal/controller/githubapp_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,15 @@ 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
Eventually(func() string {
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))
})
})
Expand Down

0 comments on commit e22dfbf

Please sign in to comment.