Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes lint error issues and golangci deprecated configurations #515

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ run:

linters:
disable:
- deadcode
- varcheck
- unused
enable:
- gosec
Expand Down
5 changes: 3 additions & 2 deletions pkg/endpoint/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"crypto/rsa"
"crypto/x509"
"encoding/pem"
"errors"
"fmt"
"log"
"net"
Expand Down Expand Up @@ -337,7 +338,7 @@ func (p *Policy) ValidateCertificateRequest(request *certificate.Request) error
}
}
if !keyValid {
return fmt.Errorf(keyError)
return errors.New(keyError)
}
}

Expand All @@ -361,7 +362,7 @@ func (p *Policy) ValidateCertificateRequest(request *certificate.Request) error

if len(p.AllowedKeyConfigurations) > 0 {
if !checkKey(request.KeyType, request.KeyLength, request.KeyCurve.String(), p.AllowedKeyConfigurations) {
return fmt.Errorf(keyError)
return errors.New(keyError)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/pemUtil.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func X509EncryptPEMBlock(rand io.Reader, blockType string, data, password []byte
}
iv := make([]byte, ciph.blockSize)
if _, err := io.ReadFull(rand, iv); err != nil {
return nil, fmt.Errorf("x509: cannot generate IV: " + err.Error())
return nil, fmt.Errorf("x509: cannot generate IV: %s", err.Error())
}
// The salt is the first 8 bytes of the initialization vector,
// matching the key derivation in DecryptPEMBlock.
Expand Down
5 changes: 3 additions & 2 deletions pkg/venafi/cloud/cloudUtil.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cloud

import (
"encoding/json"
"errors"
"fmt"
"net/http"
"regexp"
Expand All @@ -27,7 +28,7 @@ func parseCertificateInfo(httpStatusCode int, httpStatus string, body []byte) (*
for _, e := range respErrors {
respError += fmt.Sprintf("Error Code: %d Error: %s\n", e.Code, e.Message)
}
return nil, fmt.Errorf(respError)
return nil, errors.New(respError)
}
}
return nil, fmt.Errorf("unexpected status code on Venafi Cloud certificate search. Status: %s", httpStatus)
Expand All @@ -51,7 +52,7 @@ func parseDEKInfo(httpStatusCode int, httpStatus string, body []byte) (*EdgeEncr
for _, e := range respErrors {
respError += fmt.Sprintf("Error Code: %d Error: %s\n", e.Code, e.Message)
}
return nil, fmt.Errorf(respError)
return nil, errors.New(respError)
}
}
return nil, fmt.Errorf("unexpected status code on VaaS retrieving DEK's info. Status. Status: %s", httpStatus)
Expand Down
5 changes: 3 additions & 2 deletions pkg/venafi/cloud/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"encoding/base64"
"encoding/json"
"encoding/pem"
"errors"
"fmt"
"io"
"log"
Expand Down Expand Up @@ -1045,7 +1046,7 @@ func (c *Connector) getCertificateStatus(requestID string) (certStatus *certific
for _, e := range respErrors {
respError += fmt.Sprintf("Error Code: %d Error: %s\n", e.Code, e.Message)
}
return nil, fmt.Errorf(respError)
return nil, errors.New(respError)
}

return nil, fmt.Errorf("unexpected status code on Venafi Cloud certificate search. Status: %d", statusCode)
Expand Down Expand Up @@ -1297,7 +1298,7 @@ func (c *Connector) getCertificate(certificateId string) (*managedCertificate, e
for _, e := range respErrors {
respError += fmt.Sprintf("Error Code: %d Error: %s\n", e.Code, e.Message)
}
return nil, fmt.Errorf(respError)
return nil, errors.New(respError)
}
}
return nil, fmt.Errorf("unexpected status code on Venafi Cloud certificate search. Status: %d", statusCode)
Expand Down
3 changes: 2 additions & 1 deletion pkg/venafi/cloud/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package cloud

import (
"encoding/json"
"errors"
"fmt"
"log"
"math"
Expand Down Expand Up @@ -138,7 +139,7 @@ func ParseCertificateSearchResponse(httpStatusCode int, body []byte) (searchResu
for _, e := range respErrors {
respError += fmt.Sprintf("Error Code: %d Error: %s\n", e.Code, e.Message)
}
return nil, fmt.Errorf(respError)
return nil, errors.New(respError)
}
}
return nil, fmt.Errorf("unexpected status code on Venafi Cloud certificate search. Status: %d", httpStatusCode)
Expand Down
7 changes: 4 additions & 3 deletions pkg/venafi/firefly/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package firefly
import (
"context"
"crypto/x509"
"errors"
"fmt"
"net/http"
"net/url"
Expand Down Expand Up @@ -89,7 +90,7 @@ func (c *Connector) Authenticate(auth *endpoint.Authentication) error {
if auth == nil {
msg := "failed to authenticate: no credentials provided"
zap.L().Error(msg, fieldPlatform)
return fmt.Errorf(msg)
return errors.New(msg)
}

if auth.AccessToken == "" {
Expand Down Expand Up @@ -121,7 +122,7 @@ func (c *Connector) Authorize(auth *endpoint.Authentication) (token *oauth2.Toke
if auth == nil {
msg := "failed to authenticate: missing credentials"
zap.L().Error(msg, fieldPlatform)
return nil, fmt.Errorf(msg)
return nil, errors.New(msg)
}

successMsg := "successfully authorized to OAuth2 server"
Expand Down Expand Up @@ -198,7 +199,7 @@ func (c *Connector) Authorize(auth *endpoint.Authentication) (token *oauth2.Toke

errMsg := "authorization failed: cannot determine the authorization flow required for the credentials provided"
zap.L().Error(errMsg, fieldPlatform)
return token, fmt.Errorf(errMsg)
return token, errors.New(errMsg)
}

// SynchronousRequestCertificate It's not supported yet in VaaS
Expand Down
12 changes: 6 additions & 6 deletions pkg/venafi/tpp/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (c *Connector) Ping() (err error) {
return
}
if statusCode != http.StatusOK {
err = fmt.Errorf(status)
err = errors.New(status)
}
return
}
Expand Down Expand Up @@ -847,7 +847,7 @@ func (c *Connector) ResetCertificate(req *certificate.Request, restart bool) (er
}

if strings.HasSuffix(decodedResetResponse.Error, "does not exist or you do not have sufficient rights to the object.") {
return &ErrCertNotFound{fmt.Errorf(decodedResetResponse.Error)}
return &ErrCertNotFound{errors.New(decodedResetResponse.Error)}
}

return fmt.Errorf("while resetting: %s", decodedResetResponse.Error)
Expand Down Expand Up @@ -890,7 +890,7 @@ func (c *Connector) GetPolicy(name string) (*policy.PolicySpecification, error)
}

if checkPolicyResponse.Error != "" {
return nil, fmt.Errorf(checkPolicyResponse.Error)
return nil, errors.New(checkPolicyResponse.Error)
}

log.Println("Building policy")
Expand Down Expand Up @@ -972,7 +972,7 @@ func PolicyExist(policyName string, c *Connector) (bool, error) {
} else if (response.Error != "") && (response.Result == 400) {
return false, nil
} else {
return false, fmt.Errorf(response.Error)
return false, errors.New(response.Error)
}

}
Expand Down Expand Up @@ -1994,7 +1994,7 @@ func createPolicyAttribute(c *Connector, at string, av []string, n string, l boo
}

if response.Error != "" {
err = fmt.Errorf(response.Error)
err = errors.New(response.Error)
return statusCode, statusText, body, err
}

Expand Down Expand Up @@ -2158,7 +2158,7 @@ func resetTPPAttribute(c *Connector, at, zone string) error {
}

if response.Error != "" {
err = fmt.Errorf(response.Error)
err = errors.New(response.Error)
return err
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/venafi/tpp/sshCertUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package tpp

import (
"encoding/json"
"errors"
"fmt"
"log"
"net/http"
Expand Down Expand Up @@ -319,7 +320,7 @@ func GetAvailableSshTemplates(c *Connector) ([]certificate.SshAvaliableTemplate,
}
case http.StatusNotFound:
// Return NotFound as this API method is unavailable in SSH Protect versions prior 21.4.0
return nil, fmt.Errorf(status)
return nil, errors.New(status)
default:
return nil, fmt.Errorf("error while retriving avaliable SSH templates, error body:%s, status:%s and status code:%v", string(body), status, statusCode)
}
Expand Down