diff --git a/auth/auth.go b/auth/auth.go index 2a6ef86..e2ef788 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -17,9 +17,7 @@ const ( AZURE ) -var ( - errAwsSession = errors.New("failed to create aws session") -) +var errAwsSession = errors.New("failed to create aws session") type Config struct { Profile string @@ -51,7 +49,6 @@ func New(config Config) (*authorization, error) { } ath.sess = sess ath.getCallerIdentity = ath.getCallerIdentityRequest - } ath.config = config diff --git a/auth/aws.go b/auth/aws.go index 62c776b..7a04f1e 100644 --- a/auth/aws.go +++ b/auth/aws.go @@ -26,6 +26,6 @@ func (a *authorization) GetSTSHeaderAndBody() (string, string, error) { func (a *authorization) getCallerIdentityRequest() *request.Request { r, _ := sts.New(a.sess).GetCallerIdentityRequest(nil) - r.Sign() + _ = r.Sign() return r } diff --git a/auth/aws_test.go b/auth/aws_test.go index 1761a66..8050277 100644 --- a/auth/aws_test.go +++ b/auth/aws_test.go @@ -1,6 +1,7 @@ package auth import ( + "errors" "io" "net/http" "reflect" @@ -11,7 +12,6 @@ import ( ) func TestGetSTSHeaderAndBody(t *testing.T) { - testCases := []struct { name string getCallerIdentity func() *request.Request @@ -22,7 +22,8 @@ func TestGetSTSHeaderAndBody(t *testing.T) { {"good Response", func() *request.Request { return &request.Request{HTTPRequest: &http.Request{ Header: http.Header{}, - Body: io.NopCloser(strings.NewReader("Test data"))}} + Body: io.NopCloser(strings.NewReader("Test data")), + }} }, "e30=", "VGVzdCBkYXRh", nil}, } @@ -32,7 +33,7 @@ func TestGetSTSHeaderAndBody(t *testing.T) { header, body, err := ath.GetSTSHeaderAndBody() - if err != tt.expectedError { + if !errors.Is(err, tt.expectedError) { t.Error("unexpected err", err) } @@ -43,7 +44,5 @@ func TestGetSTSHeaderAndBody(t *testing.T) { if !reflect.DeepEqual(body, tt.expectedBody) { t.Error("unexpected body", body) } - } - } diff --git a/auth/azure.go b/auth/azure.go index 69a6be2..e48ba65 100644 --- a/auth/azure.go +++ b/auth/azure.go @@ -21,6 +21,10 @@ const ( FederatedAzure = AuthType("azure") ) +var ( + ErrInvalidToken = errors.New("received invalid bearer token") +) + // authTypeToGrantType maps authentication type to grant type which will be sent to DSV. var authTypeToGrantType = map[AuthType]string{ FederatedAzure: "azure", @@ -44,7 +48,7 @@ func (a *authorization) BuildAzureParams() (*requestBody, error) { qualifiedBearer := r.Header.Get("Authorization") lenPrefix := len("Bearer ") if len(qualifiedBearer) < lenPrefix { - return nil, errors.New("received invalid bearer token") + return nil, ErrInvalidToken } bearer := qualifiedBearer[lenPrefix:] diff --git a/example/aws/auth_aws.go b/example/aws/auth_aws.go index ae22936..b030a97 100644 --- a/example/aws/auth_aws.go +++ b/example/aws/auth_aws.go @@ -14,13 +14,11 @@ func main() { Tenant: os.Getenv("DSV_TENANT"), Provider: auth.AWS, }) - if err != nil { log.Fatalf("failed to configure vault: %v", err) } secret, err := dsv.Secret("your secret path") - if err != nil { log.Fatalf("failed to fetch secret: %v", err) } diff --git a/example/client/client_auth.go b/example/client/client_auth.go index cf5d9dd..e238989 100644 --- a/example/client/client_auth.go +++ b/example/client/client_auth.go @@ -17,13 +17,11 @@ func main() { Tenant: os.Getenv("DSV_TENANT"), TLD: os.Getenv("DSV_TLD"), }) - if err != nil { log.Fatalf("failed to configure vault: %v", err) } secret, err := dsv.Secret("your secret path") - if err != nil { log.Fatalf("failed to fetch secret: %v", err) } diff --git a/vault/client_test.go b/vault/client_test.go index 6aed600..c5626a3 100644 --- a/vault/client_test.go +++ b/vault/client_test.go @@ -1,4 +1,5 @@ //go:build integration + package vault import "testing" @@ -9,7 +10,6 @@ func TestClient(t *testing.T) { t.Run("TestNewClient", func(t *testing.T) { client := &Client{clientResource: clientResource{RoleName: roleName}} err := dsv.New(client) - if err != nil { t.Errorf("calling clients.New(\"%s\"): %s", roleName, err) return @@ -23,7 +23,6 @@ func TestClient(t *testing.T) { }) t.Run("TestGetClient", func(t *testing.T) { client, err := dsv.Client(config.Credentials.ClientID) - if err != nil { t.Errorf("calling clients.Client(\"%s\"): %s", ID, err) return @@ -36,7 +35,6 @@ func TestClient(t *testing.T) { }) t.Run("TestDeleteClient", func(t *testing.T) { client, err := dsv.Client(ID) - if err != nil { t.Errorf("calling clients.Client(\"%s\"): %s", ID, err) return diff --git a/vault/role_test.go b/vault/role_test.go index 5e633d8..d2b711c 100644 --- a/vault/role_test.go +++ b/vault/role_test.go @@ -1,4 +1,5 @@ //go:build integration + package vault import "testing" @@ -8,7 +9,6 @@ const roleName = "test-role" // TestRole tests Role func TestRole(t *testing.T) { role, err := dsv.Role(roleName) - if err != nil { t.Errorf("calling roles.Role(\"%s\"): %s", roleName, err) return @@ -26,7 +26,7 @@ func TestNonexistentRole(t *testing.T) { _, err := dsv.Role(roleName) if err == nil { - t.Errorf("role '%s' exists but but it should not", roleName) + t.Errorf("role '%s' exists but it should not", roleName) return } } diff --git a/vault/secret_test.go b/vault/secret_test.go index 65145d2..a09360f 100644 --- a/vault/secret_test.go +++ b/vault/secret_test.go @@ -1,4 +1,5 @@ //go:build integration + package vault import ( @@ -19,7 +20,6 @@ func TestSecret(t *testing.T) { defer cleanup() secret, err := dsv.Secret(path) - if err != nil { t.Fatalf("Secret for path=%s: %s", path, err) return diff --git a/vault/vault.go b/vault/vault.go index a5e9790..30b0132 100644 --- a/vault/vault.go +++ b/vault/vault.go @@ -235,7 +235,7 @@ func (v Vault) getAccessToken() (string, error) { } ok := v.setCacheAccessToken(resp.AccessToken, resp.ExpiresIn) if !ok { - return "", fmt.Errorf("unable to cache access token") + return "", errors.New("unable to cache access token") } return resp.AccessToken, nil } diff --git a/vault/vault_test.go b/vault/vault_test.go index 1c03151..fd1aa08 100644 --- a/vault/vault_test.go +++ b/vault/vault_test.go @@ -1,4 +1,5 @@ //go:build integration + package vault import (