Skip to content
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
27 changes: 20 additions & 7 deletions internal/credentials/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,6 @@ type Reader interface {
ReadCredentials(ctx context.Context, secretName string, credentials any) error
}

type Role int64

const (
RoleReader Role = iota
RoleWriter
)

var ErrNotFound = errors.New("credentials not found")
var ErrValidation = errors.New("credentials validation error")

Expand Down Expand Up @@ -78,3 +71,23 @@ func (a *APICreds) Validate() error {
}
return nil
}

type Role int64

const (
RoleUnknown Role = iota
RoleReader
RoleWriter
)

// Implement string interface for Role
func (r Role) String() string {
switch r {
case RoleReader:
return "reader"
case RoleWriter:
return "writer"
default:
return "unknown"
}
}
2 changes: 1 addition & 1 deletion internal/credentials/vault/keyval.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func validateWriterClient(kv *vault.KVv2, pathPrefix string) error {
return err
}

if err := kv.DeleteMetadata(ctx, healthCheckSecret); err != nil {
if err := kv.DeleteMetadata(ctx, keyPath); err != nil {
return fmt.Errorf("deleting health check secret: %w", err)
}

Expand Down
7 changes: 5 additions & 2 deletions internal/credentials/vault/keyval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,24 @@ func (s *testSuite) TestNewManager() {
connection string
token string
path string
prefix string
expectedError bool
role credentials.Role
}{
{name: "missing token", connection: s.connectionString, expectedError: true},
{name: "missing address", token: defaultToken, expectedError: true},
{name: "invalid address reader", token: defaultToken, connection: "http://non-existing:5000", expectedError: true, role: credentials.RoleReader},
{name: "invalid address writer", token: defaultToken, connection: "http://non-existing:5000", expectedError: true},
{name: "invalid mount path", token: defaultToken, connection: s.connectionString, path: "non-existing", expectedError: true, role: credentials.RoleWriter},
{name: "invalid mount path", token: defaultToken, connection: s.connectionString, path: "non-existing", expectedError: true},
{name: "valid connection reader", connection: s.connectionString, token: defaultToken, role: credentials.RoleReader},
{name: "valid connection reader with prefix", connection: s.connectionString, token: defaultToken, role: credentials.RoleReader, prefix: "prefix"},
{name: "valid connection", connection: s.connectionString, token: defaultToken},
{name: "valid connection with prefix", connection: s.connectionString, token: defaultToken, prefix: "prefix"},
}

for _, tc := range testCases {
s.Run(tc.name, func() {
opts := &vault.NewManagerOpts{AuthToken: tc.token, Address: tc.connection, MountPath: tc.path, Role: tc.role}
opts := &vault.NewManagerOpts{AuthToken: tc.token, Address: tc.connection, MountPath: tc.path, Role: tc.role, SecretPrefix: tc.prefix}
_, err := vault.NewManager(opts)
if tc.expectedError {
assert.Error(err)
Expand Down