-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from trisacrypto/sc-22231
Google secret manager storage
- Loading branch information
Showing
16 changed files
with
506 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package mock | ||
|
||
import "errors" | ||
|
||
var ( | ||
ErrNotConfigured = errors.New("mock function not configured") | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package mock | ||
|
||
import ( | ||
"context" | ||
|
||
"cloud.google.com/go/secretmanager/apiv1/secretmanagerpb" | ||
"github.com/googleapis/gax-go" | ||
"github.com/trisacrypto/courier/pkg/secrets" | ||
) | ||
|
||
// New returns a new secrets client mock. The On* functions can be used to configure | ||
// the mock behavior directly. Functions that are not configured will return an error. | ||
func New() (s *SecretManager) { | ||
s = &SecretManager{} | ||
s.Reset() | ||
return s | ||
} | ||
|
||
// Reset resets the state of the mock so all functions return an error. | ||
func (s *SecretManager) Reset() { | ||
s.OnCreateSecret = func(context.Context, *secretmanagerpb.CreateSecretRequest, ...gax.CallOption) (*secretmanagerpb.Secret, error) { | ||
return nil, ErrNotConfigured | ||
} | ||
s.OnGetSecretVersion = func(context.Context, *secretmanagerpb.GetSecretVersionRequest, ...gax.CallOption) (*secretmanagerpb.SecretVersion, error) { | ||
return nil, ErrNotConfigured | ||
} | ||
s.OnAddSecretVersion = func(context.Context, *secretmanagerpb.AddSecretVersionRequest, ...gax.CallOption) (*secretmanagerpb.SecretVersion, error) { | ||
return nil, ErrNotConfigured | ||
} | ||
s.OnAccessSecretVersion = func(context.Context, *secretmanagerpb.AccessSecretVersionRequest, ...gax.CallOption) (*secretmanagerpb.AccessSecretVersionResponse, error) { | ||
return nil, ErrNotConfigured | ||
} | ||
s.OnDeleteSecret = func(context.Context, *secretmanagerpb.DeleteSecretRequest, ...gax.CallOption) error { | ||
return ErrNotConfigured | ||
} | ||
} | ||
|
||
type SecretManager struct { | ||
OnCreateSecret func(context.Context, *secretmanagerpb.CreateSecretRequest, ...gax.CallOption) (*secretmanagerpb.Secret, error) | ||
OnGetSecretVersion func(context.Context, *secretmanagerpb.GetSecretVersionRequest, ...gax.CallOption) (*secretmanagerpb.SecretVersion, error) | ||
OnAddSecretVersion func(context.Context, *secretmanagerpb.AddSecretVersionRequest, ...gax.CallOption) (*secretmanagerpb.SecretVersion, error) | ||
OnAccessSecretVersion func(context.Context, *secretmanagerpb.AccessSecretVersionRequest, ...gax.CallOption) (*secretmanagerpb.AccessSecretVersionResponse, error) | ||
OnDeleteSecret func(context.Context, *secretmanagerpb.DeleteSecretRequest, ...gax.CallOption) error | ||
} | ||
|
||
var _ secrets.GRPCSecretClient = &SecretManager{} | ||
|
||
func (s *SecretManager) CreateSecret(ctx context.Context, req *secretmanagerpb.CreateSecretRequest, opts ...gax.CallOption) (*secretmanagerpb.Secret, error) { | ||
return s.OnCreateSecret(ctx, req, opts...) | ||
} | ||
|
||
func (s *SecretManager) GetSecretVersion(ctx context.Context, req *secretmanagerpb.GetSecretVersionRequest, opts ...gax.CallOption) (*secretmanagerpb.SecretVersion, error) { | ||
return s.OnGetSecretVersion(ctx, req, opts...) | ||
} | ||
|
||
func (s *SecretManager) AddSecretVersion(ctx context.Context, req *secretmanagerpb.AddSecretVersionRequest, opts ...gax.CallOption) (*secretmanagerpb.SecretVersion, error) { | ||
return s.OnAddSecretVersion(ctx, req, opts...) | ||
} | ||
|
||
func (s *SecretManager) AccessSecretVersion(ctx context.Context, req *secretmanagerpb.AccessSecretVersionRequest, opts ...gax.CallOption) (*secretmanagerpb.AccessSecretVersionResponse, error) { | ||
return s.OnAccessSecretVersion(ctx, req, opts...) | ||
} | ||
|
||
func (s *SecretManager) DeleteSecret(ctx context.Context, req *secretmanagerpb.DeleteSecretRequest, opts ...gax.CallOption) error { | ||
return s.OnDeleteSecret(ctx, req, opts...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package secrets | ||
|
||
// SecretsOption allows us to configure the secrets client when it is created. | ||
type SecretsOption func(s *GoogleSecrets) error | ||
|
||
func WithGRPCClient(client GRPCSecretClient) SecretsOption { | ||
return func(s *GoogleSecrets) error { | ||
s.client = client | ||
return nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package gcloud | ||
|
||
import "github.com/trisacrypto/courier/pkg/secrets" | ||
|
||
// StoreOption allows us to configure the store when it is created. | ||
type StoreOption func(s *Store) error | ||
|
||
func WithClient(client secrets.SecretManagerClient) StoreOption { | ||
return func(s *Store) error { | ||
s.client = client | ||
return nil | ||
} | ||
} |
Oops, something went wrong.