From b75bea04f19f780da43905857b34ee6be7e55f63 Mon Sep 17 00:00:00 2001 From: harshsharma071988 Date: Wed, 1 Mar 2023 16:38:39 +0530 Subject: [PATCH] Minor fixes -- cspSecretName in place of ApiToken in policy.yml -- Secret Data initialized while creation Signed-off-by: harshsharma071988 --- src/config/samples/policy.yaml | 2 +- src/lib/cspauth/csp_auth.go | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/config/samples/policy.yaml b/src/config/samples/policy.yaml index 0970ad73..32085098 100644 --- a/src/config/samples/policy.yaml +++ b/src/config/samples/policy.yaml @@ -61,7 +61,7 @@ spec: enabled: true clusterId: "65a03970-c53a-4ba1-8d1f-42c9f95d2761" url: "https://api.int.app-catalog.vmware.com/catalog-governor/v1" - apiToken: "n6yDMkMEghPUYJDGsn39I_GYNnPh4Vi-LnaH2URjpgwcXbFIVYzMU-n8LRzTJGKO" + cspSecretName: "csp-secret" baselines: - kind: "vulnerability" baseline: "High" diff --git a/src/lib/cspauth/csp_auth.go b/src/lib/cspauth/csp_auth.go index f591e77e..09f92414 100644 --- a/src/lib/cspauth/csp_auth.go +++ b/src/lib/cspauth/csp_auth.go @@ -74,7 +74,8 @@ func (a *CspAuth) refreshToken(ctx context.Context, clientSet kubernetes.Interfa expiresIn := time.Duration(math.Min(float64(cspAuthResponse.ExpiresIn), tokenMaxAgeSeconds)) * time.Second formattedExpiration := now.Add(expiresIn).Format(time.Layout) - log.Infof("Refreshed access token for governor: %s which expires in %s", cspAuthResponse.AccessToken, formattedExpiration) + log.Infof("Refreshed access token for governor which expires in %s", formattedExpiration) + accessTokenSecret.Data = make(map[string][]byte, 0) accessTokenSecret.Data[governorAccessTokenKey] = []byte(cspAuthResponse.AccessToken) accessTokenSecret.Data[governorTokenExpiresIn] = []byte(formattedExpiration) _, err = clientSet.CoreV1().Secrets(cspSecretNamespace).Update(ctx, accessTokenSecret, v1.UpdateOptions{}) @@ -104,7 +105,7 @@ func getOrCreateSecretForAccessToken(clientSet kubernetes.Interface, ctx context secret = &v12.Secret{} secret.Name = accessTokenSecretName secret.Namespace = ns - secret.Data = map[string][]byte{} + secret.Data = make(map[string][]byte, 0) secret, err = clientSet.CoreV1().Secrets(ns).Create(ctx, secret, v1.CreateOptions{}) if err != nil { log.Error(err, "Failed to create secret for storing access token.")