Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
-- cspSecretName in place of ApiToken in policy.yml
-- Secret Data initialized while creation

Signed-off-by: harshsharma071988 <[email protected]>
  • Loading branch information
harshsharma071988 committed Mar 1, 2023
1 parent 1ded538 commit b75bea0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/config/samples/policy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 3 additions & 2 deletions src/lib/cspauth/csp_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
Expand Down Expand Up @@ -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.")
Expand Down

0 comments on commit b75bea0

Please sign in to comment.