Skip to content

Commit

Permalink
fix: environment variable app secret (#432)
Browse files Browse the repository at this point in the history
fix: environment variable app secret

when testing locally the cert file option was used. When using this in
Kubernetes, I realized this wasn't working as expected.

New tests were added to ensure that this is working properly. This was
tested Kubernetes and works as expected.

Signed-off-by: Karl Haworth <karl.haworth@aa.com>
  • Loading branch information
karlhaworth authored Aug 1, 2024
1 parent 172b575 commit 077bb0a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion pkg/ghtransport/ghtransport.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"fmt"
"net/http"
"os"

kms "cloud.google.com/go/kms/apiv1"
"github.com/bradleyfalzon/ghinstallation/v2"
Expand All @@ -17,7 +18,7 @@ import (
func New(ctx context.Context, env *envConfig.EnvConfig, kmsClient *kms.KeyManagementClient) (*ghinstallation.AppsTransport, error) {
switch {
case env.AppSecretCertificateEnvVar != "":
atr, err := ghinstallation.NewAppsTransport(http.DefaultTransport, env.AppID, []byte(env.AppSecretCertificateEnvVar))
atr, err := ghinstallation.NewAppsTransport(http.DefaultTransport, env.AppID, []byte(os.Getenv(env.AppSecretCertificateEnvVar)))

if err != nil {
return nil, err
Expand Down
4 changes: 3 additions & 1 deletion pkg/ghtransport/ghtransport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@ func TestGCPKMS(t *testing.T) {
func TestCertEnvVar(t *testing.T) {
ctx := context.Background()

t.Setenv("GITHUB_APP_SECRET", generateTestCertificateString())

testConfig := &envconfig.EnvConfig{
Port: 8080,
Domain: "example.com",
AppID: 123456,
EventingIngress: "https://event.ingress.uri",
AppSecretCertificateEnvVar: generateTestCertificateString(),
AppSecretCertificateEnvVar: "GITHUB_APP_SECRET",
Metrics: true,
}

Expand Down

0 comments on commit 077bb0a

Please sign in to comment.