Skip to content

Commit

Permalink
Fix calls to fmt Errorf with no interpolation (#187)
Browse files Browse the repository at this point in the history
## 🎫 Ticket

https://jira.cms.gov/browse/BCDA-8373

## 🛠 Changes

Convert various fmt.Errorf statements to either require the
interpolation or to errors.New. Both versions should return a string as
an error.

## ℹ️ Context

The build was failing on golangci-lint checks.

<!-- If any of the following security implications apply, this PR must
not be merged without Stephen Walter's approval. Explain in this section
and add @SJWalter11 as a reviewer.
  - Adds a new software dependency or dependencies.
  - Modifies or invalidates one or more of our security controls.
  - Stores or transmits data that was not stored or transmitted before.
- Requires additional review of security implications for other reasons.
-->

## 🧪 Validation

Linting and testing were run to verify no breaking changes.
  • Loading branch information
carlpartridge authored Sep 23, 2024
1 parent 41ec7e6 commit ad8a9aa
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
3 changes: 1 addition & 2 deletions ssas/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ func ListGroups(ctx context.Context) (list GroupList, err error) {
func UpdateGroup(ctx context.Context, id string, gd GroupData) (Group, error) {
g, err := GetGroupByID(ctx, id)
if err != nil {
errString := fmt.Sprintf("record not found for id=%s", id)
err := fmt.Errorf(errString)
err := fmt.Errorf("record not found for id=%s", id)
return Group{}, err
}
gd.GroupID = g.Data.GroupID
Expand Down
10 changes: 5 additions & 5 deletions ssas/service/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,25 +58,25 @@ func ChooseSigningKey(signingKeyPath, signingKey string) (*rsa.PrivateKey, error
if err != nil {
msg := fmt.Sprintf("bad signing key; path %s; %v", signingKeyPath, err)
ssas.Logger.Error(msg)
error = fmt.Errorf(msg)
error = errors.New(msg)
}
key = sk
} else if signingKey != "" && signingKeyPath == "" {
sk, err := ssas.ReadPrivateKey([]byte(signingKey))
if err != nil {
msg := fmt.Sprintf("bad inline signing key; %v", err)
ssas.Logger.Error(msg)
error = fmt.Errorf(msg)
error = errors.New(msg)
}
key = sk
} else if signingKey == "" && signingKeyPath == "" {
msg := "inline key and path are both empty strings"
ssas.Logger.Error(msg)
error = fmt.Errorf(msg)
error = errors.New(msg)
} else {
msg := "inline key or path must be set, but not both"
ssas.Logger.Error(msg)
error = fmt.Errorf(msg)
error = errors.New(msg)
}

return key, error
Expand Down Expand Up @@ -481,7 +481,7 @@ func (s *Server) CheckRequiredClaims(claims *CommonClaims, requiredTokenType str
}

if requiredTokenType != claims.TokenType {
return fmt.Errorf(fmt.Sprintf("wrong token type: %s; required type: %s", claims.TokenType, requiredTokenType))
return fmt.Errorf("wrong token type: %s; required type: %s", claims.TokenType, requiredTokenType)
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion ssas/service/tokenblacklist.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (t *Blacklist) BlacklistToken(ctx context.Context, tokenID string, blacklis
entryDate := time.Now()
expirationDate := entryDate.Add(blacklistExpiration)
if _, err := ssas.CreateBlacklistEntry(ctx, tokenID, entryDate, expirationDate); err != nil {
return fmt.Errorf(fmt.Sprintf("unable to blacklist token id %s: %s", tokenID, err.Error()))
return fmt.Errorf("unable to blacklist token id %s: %s", tokenID, err.Error())
}

// Add to cache only after token is blacklisted in database
Expand Down
2 changes: 1 addition & 1 deletion ssas/systems.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func (system *System) RevokeSecret(ctx context.Context, systemID string) error {

err = system.deactivateSecrets(ctx)
if err != nil {
return fmt.Errorf("unable to revoke credentials for clientID " + system.ClientID)
return fmt.Errorf("unable to revoke credentials for clientID %s", system.ClientID)
}
return nil
}
Expand Down

0 comments on commit ad8a9aa

Please sign in to comment.