Skip to content

Commit

Permalink
modified auth files for linting
Browse files Browse the repository at this point in the history
  • Loading branch information
pacificcode committed Jan 14, 2025
1 parent fd28da8 commit 8d4947b
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 22 deletions.
5 changes: 1 addition & 4 deletions auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -51,7 +49,6 @@ func New(config Config) (*authorization, error) {
}
ath.sess = sess
ath.getCallerIdentity = ath.getCallerIdentityRequest

}

ath.config = config
Expand Down
2 changes: 1 addition & 1 deletion auth/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
9 changes: 4 additions & 5 deletions auth/aws_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package auth

import (
"errors"
"io"
"net/http"
"reflect"
Expand All @@ -11,7 +12,6 @@ import (
)

func TestGetSTSHeaderAndBody(t *testing.T) {

testCases := []struct {
name string
getCallerIdentity func() *request.Request
Expand All @@ -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},
}

Expand All @@ -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)
}

Expand All @@ -43,7 +44,5 @@ func TestGetSTSHeaderAndBody(t *testing.T) {
if !reflect.DeepEqual(body, tt.expectedBody) {
t.Error("unexpected body", body)
}

}

}
6 changes: 5 additions & 1 deletion auth/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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:]

Expand Down
2 changes: 0 additions & 2 deletions example/aws/auth_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 0 additions & 2 deletions example/client/client_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 1 addition & 3 deletions vault/client_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//go:build integration

package vault

import "testing"
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions vault/role_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//go:build integration

package vault

import "testing"
Expand All @@ -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
Expand All @@ -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
}
}
2 changes: 1 addition & 1 deletion vault/secret_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//go:build integration

package vault

import (
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion vault/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions vault/vault_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//go:build integration

package vault

import (
Expand Down

0 comments on commit 8d4947b

Please sign in to comment.