Skip to content

Commit

Permalink
fix: apply context to GenerateRSA
Browse files Browse the repository at this point in the history
  • Loading branch information
plyr4 committed May 30, 2024
1 parent 5e88941 commit 0699f60
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/vela-server/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func setupTokenManager(c *cli.Context, db database.Interface) (*token.Manager, e
}

// generate a new RSA key pair
err := tm.GenerateRSA(db)
err := tm.GenerateRSA(c.Context, db)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/token/generate_rsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

// GenerateRSA creates an RSA key pair and sets it in the token manager and saves the JWK in the database.
func (tm *Manager) GenerateRSA(db database.Interface) error {
func (tm *Manager) GenerateRSA(ctx context.Context, db database.Interface) error {
// generate key pair
privateRSAKey, err := rsa.GenerateKey(rand.Reader, 2048)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/token/mint.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,14 @@ func (tm *Manager) MintIDToken(ctx context.Context, mto *MintTokenOpts, db datab
tk := jwt.NewWithClaims(jwt.SigningMethodRS256, claims)

// verify key is active in the database before signing
_, err = db.GetActiveJWK(context.TODO(), tm.RSAKeySet.KID)
_, err = db.GetActiveJWK(ctx, tm.RSAKeySet.KID)
if err != nil {
if !errors.Is(err, gorm.ErrRecordNotFound) {
return "", fmt.Errorf("unable to get active public key: %w", err)
}

// generate a new RSA key pair if previous key is inactive (rotated)
err = tm.GenerateRSA(db)
err = tm.GenerateRSA(ctx, db)
if err != nil {
return "", fmt.Errorf("unable to generate RSA key pair: %w", err)
}
Expand Down

0 comments on commit 0699f60

Please sign in to comment.