Skip to content

Commit

Permalink
Use a pointer (*time.Time) instead of a variadic param
Browse files Browse the repository at this point in the history
  • Loading branch information
pawanpinjarkar committed Sep 16, 2024
1 parent f96b34d commit a3806ae
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions pkg/asset/agent/gencrypto/auth_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ func TestParseExpirationFromToken(t *testing.T) {
assert.NotEmpty(t, privateKey)
assert.NoError(t, err)

tokenNoExp, err := generateToken(privateKey)
tokenNoExp, err := generateToken(privateKey, nil)
assert.NotEmpty(t, tokenNoExp)
assert.NoError(t, err)

expiry := time.Now().UTC().Add(30 * time.Second)
tokenWithExp, err := generateToken(privateKey, expiry)
tokenWithExp, err := generateToken(privateKey, &expiry)
assert.NotEmpty(t, tokenWithExp)
assert.NoError(t, err)

Expand Down
10 changes: 5 additions & 5 deletions pkg/asset/agent/gencrypto/authconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (a *AuthConfig) Generate(_ context.Context, dependencies asset.Parents) err
switch agentWorkflow.Workflow {
case workflow.AgentWorkflowTypeInstall:
// Auth tokens do not expire
token, err := generateToken(privateKey)
token, err := generateToken(privateKey, nil)
if err != nil {
return err
}
Expand All @@ -81,7 +81,7 @@ func (a *AuthConfig) Generate(_ context.Context, dependencies asset.Parents) err
// Auth tokens expires after 48 hours
expiry := time.Now().UTC().Add(48 * time.Hour)
a.AgentAuthTokenExpiry = expiry.Format(time.RFC3339)
token, err := generateToken(privateKey, expiry)
token, err := generateToken(privateKey, &expiry)
if err != nil {
return err
}
Expand Down Expand Up @@ -147,13 +147,13 @@ func keyPairPEM() (string, string, error) {
}

// generateToken returns a JWT token based on the private key.
func generateToken(privateKkeyPem string, expiry ...time.Time) (string, error) {
func generateToken(privateKkeyPem string, expiry *time.Time) (string, error) {
// Create the JWT claims
claims := jwt.MapClaims{}

// Set the expiry time if provided
if len(expiry) > 0 {
claims["exp"] = expiry[0].Unix()
if expiry != nil {
claims["exp"] = expiry.Unix()
}

// Create the token using the ES256 signing method and the claims
Expand Down

0 comments on commit a3806ae

Please sign in to comment.