From 5150cabbbe335bc38e1ae966a8caedd61d8170bc Mon Sep 17 00:00:00 2001 From: Daniele Ferru Date: Thu, 15 Jan 2026 00:00:31 +0100 Subject: [PATCH] reverting check when generating token for Connection --- apps/provisioning/pkg/connection/github/connection.go | 8 +++----- .../provisioning/pkg/connection/github/connection_test.go | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/apps/provisioning/pkg/connection/github/connection.go b/apps/provisioning/pkg/connection/github/connection.go index 53a465bea2b..26e524c2314 100644 --- a/apps/provisioning/pkg/connection/github/connection.go +++ b/apps/provisioning/pkg/connection/github/connection.go @@ -60,11 +60,9 @@ func (c *Connection) Mutate(_ context.Context) error { c.obj.Spec.URL = fmt.Sprintf("%s/%s", githubInstallationURL, c.obj.Spec.GitHub.InstallationID) - // Generate token only if one of the following cases are true - // - The object is being created now (generation == 0) - // - The token is not there - // - A new Private key is being submitted - if c.obj.Generation == 0 || c.secrets.Token.IsZero() || !c.obj.Secure.PrivateKey.Create.IsZero() { + // Generate JWT token if a new private key is being provided. + // Same as for the spec.Github, if such a field is required, Validation will take care of that. + if !c.obj.Secure.PrivateKey.Create.IsZero() { token, err := generateToken(c.obj.Spec.GitHub.AppID, c.secrets.PrivateKey) if err != nil { return fmt.Errorf("failed to generate JWT token: %w", err) diff --git a/apps/provisioning/pkg/connection/github/connection_test.go b/apps/provisioning/pkg/connection/github/connection_test.go index bd8794edae3..de34c6c8909 100644 --- a/apps/provisioning/pkg/connection/github/connection_test.go +++ b/apps/provisioning/pkg/connection/github/connection_test.go @@ -107,7 +107,7 @@ func TestConnection_Mutate(t *testing.T) { }, }, { - name: "should not generate JWT token when token is already there", + name: "should not generate JWT token when no new private key is provided", connection: &provisioning.Connection{ ObjectMeta: metav1.ObjectMeta{Name: "test-connection", Generation: 1}, Spec: provisioning.ConnectionSpec{