Skip to content

Commit

Permalink
chore(lint): minor improvements (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
thevilledev committed Jul 5, 2023
1 parent 8090629 commit 25db59c
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ linters:
- exhaustive
- gocyclo
- gomnd
- errorlint
- nlreturn
- forcetypeassert
- godox
- godot

linters-settings:
govet:
Expand Down
1 change: 0 additions & 1 deletion pkg/client/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ type Token struct {
Name string `json:"name"`
Type string `json:"type"`
Origin string `json:"origin"`
// TODO scopes
}

type DeleteAuthTokenRequest struct {
Expand Down
4 changes: 4 additions & 0 deletions pkg/client/token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import (
)

func TestCreateDeleteToken(t *testing.T) {
t.Parallel()

recordHelper(t, "auth_token", func(ctx context.Context, t *testing.T, rec *recorder.Recorder, c *Client) {
t.Helper()

require.NotNil(t, c.httpClient)
pfx := "vault-plugin-secrets-vercel-fixtures-token"
ts := time.Now().UnixNano()
Expand Down
2 changes: 0 additions & 2 deletions pkg/plugin/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@ Vercel Secrets backend is a secrets backend for dynamically managing Vercel toke
`
)

// backend wraps the backend framework and adds a map for storing key value pairs
type backend struct {
*framework.Backend
}

var _ logical.Factory = Factory

// Factory configures and returns the backend
func Factory(ctx context.Context, conf *logical.BackendConfig) (logical.Backend, error) {
b := newBackend()

Expand Down
9 changes: 6 additions & 3 deletions pkg/plugin/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,14 @@ func newTestBackend(t *testing.T) (*backend, logical.Storage) {
config := logical.TestBackendConfig()
config.StorageView = new(logical.InmemStorage)
config.Logger = hclog.NewNullLogger()
b, err := Factory(context.Background(), config)
br, err := Factory(context.Background(), config)
require.NoError(t, err)
require.NotNil(t, b)
require.NotNil(t, br)

return b.(*backend), config.StorageView
b, ok := br.(*backend)
require.Equal(t, ok, true)

return b, config.StorageView
}

func TestBackend_Config(t *testing.T) {
Expand Down
3 changes: 3 additions & 0 deletions pkg/plugin/path_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func (b *backend) pathConfigWrite(ctx context.Context, req *logical.Request,
config.APIKey, ok = v.(string)
if !ok {
b.Logger().Trace("type assertion failed: %+v", v)

return nil, errTypeAssertionFailed
}
}
Expand All @@ -97,6 +98,7 @@ func (b *backend) pathConfigWrite(ctx context.Context, req *logical.Request,
config.BaseURL, ok = v.(string)
if !ok {
b.Logger().Trace("type assertion failed: %+v", v)

return nil, errTypeAssertionFailed
}
}
Expand All @@ -105,6 +107,7 @@ func (b *backend) pathConfigWrite(ctx context.Context, req *logical.Request,
v, ta := vr.(int)
if !ta {
b.Logger().Trace("type assertion failed: %+v", v)

return nil, errTypeAssertionFailed
}

Expand Down
1 change: 1 addition & 0 deletions pkg/plugin/path_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func (b *backend) pathTokenWrite(ctx context.Context, req *logical.Request,
v, ta := vr.(int)
if !ta {
b.Logger().Trace("type assertion failed: %+v", v)

return nil, errTypeAssertionFailed
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/plugin/revoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ func (b *backend) Revoke(ctx context.Context, req *logical.Request, _ *framework
ks, ok := k.(string)
if !ok {
b.Logger().Trace("type assertion failed: %+v", ks)

return nil, errTypeAssertionFailed
}

_, err = svc.DeleteAuthToken(ctx, ks)
if err != nil {
b.Logger().Error("token delete failed: %s", err)
return nil, fmt.Errorf("failed to delete token: %s", err)

return nil, fmt.Errorf("failed to delete token: %w", err)
}

return &logical.Response{}, nil
Expand Down
1 change: 1 addition & 0 deletions pkg/service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/stretchr/testify/require"
)

//nolint:paralleltest
func TestIntegration_Token(t *testing.T) {
if os.Getenv("ACC_TEST") == "" {
t.Skip("test skipped as ACC_TEST environment variable is not set")
Expand Down

0 comments on commit 25db59c

Please sign in to comment.