Skip to content

Commit

Permalink
adds bulk secret (dapr#126)
Browse files Browse the repository at this point in the history
* adds bulk secret

* spelling
  • Loading branch information
mchmarny authored Dec 15, 2020
1 parent d14116b commit f2b03d2
Show file tree
Hide file tree
Showing 7 changed files with 676 additions and 388 deletions.
5 changes: 4 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,12 @@ type Client interface {
// PublishEventfromCustomContent serializes an struct and pubishes its contents as data (JSON) onto topic in specific pubsub component.
PublishEventfromCustomContent(ctx context.Context, pubsubName, topicName string, data interface{}) error

// GetSecret retreaves preconfigred secret from specified store using key.
// GetSecret retrieves preconfigred secret from specified store using key.
GetSecret(ctx context.Context, storeName, key string, meta map[string]string) (data map[string]string, err error)

// GetBulkSecret retrieves all preconfigred secrets for this application.
GetBulkSecret(ctx context.Context, storeName string, meta map[string]string) (data map[string]string, err error)

// SaveState saves the raw data into store using default state options.
SaveState(ctx context.Context, storeName, key string, data []byte) error

Expand Down
8 changes: 8 additions & 0 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,14 @@ func (s *testDaprServer) GetSecret(ctx context.Context, req *pb.GetSecretRequest
}, nil
}

func (s *testDaprServer) GetBulkSecret(ctx context.Context, req *pb.GetBulkSecretRequest) (*pb.GetBulkSecretResponse, error) {
d := make(map[string]string)
d["test"] = "value"
return &pb.GetBulkSecretResponse{
Data: d,
}, nil
}

func (s *testDaprServer) InvokeActor(context.Context, *pb.InvokeActorRequest) (*pb.InvokeActorResponse, error) {
return nil, errors.New("actors not implemented in go SDK")
}
Expand Down
25 changes: 24 additions & 1 deletion client/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/pkg/errors"
)

// GetSecret retreaves preconfigred secret from specified store using key.
// GetSecret retrieves preconfigred secret from specified store using key.
func (c *GRPCClient) GetSecret(ctx context.Context, storeName, key string, meta map[string]string) (data map[string]string, err error) {
if storeName == "" {
return nil, errors.New("nil storeName")
Expand All @@ -33,3 +33,26 @@ func (c *GRPCClient) GetSecret(ctx context.Context, storeName, key string, meta

return
}

// GetBulkSecret retrieves all preconfigred secrets for this application.
func (c *GRPCClient) GetBulkSecret(ctx context.Context, storeName string, meta map[string]string) (data map[string]string, err error) {
if storeName == "" {
return nil, errors.New("nil storeName")
}

req := &pb.GetBulkSecretRequest{
StoreName: storeName,
Metadata: meta,
}

resp, err := c.protoClient.GetBulkSecret(c.withAuthToken(ctx), req)
if err != nil {
return nil, errors.Wrap(err, "error invoking service")
}

if resp != nil {
data = resp.GetData()
}

return
}
23 changes: 23 additions & 0 deletions client/secret_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,26 @@ func TestGetSecret(t *testing.T) {
assert.NotNil(t, out)
})
}

func TestGetBulkSecret(t *testing.T) {
ctx := context.Background()

t.Run("without store", func(t *testing.T) {
out, err := testClient.GetBulkSecret(ctx, "", nil)
assert.Error(t, err)
assert.Nil(t, out)
})

t.Run("without meta", func(t *testing.T) {
out, err := testClient.GetBulkSecret(ctx, "store", nil)
assert.Nil(t, err)
assert.NotNil(t, out)
})

t.Run("with meta", func(t *testing.T) {
in := map[string]string{"k1": "v1", "k2": "v2"}
out, err := testClient.GetBulkSecret(ctx, "store", in)
assert.Nil(t, err)
assert.NotNil(t, out)
})
}
6 changes: 3 additions & 3 deletions client/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func (c *GRPCClient) SaveBulkState(ctx context.Context, storeName string, items

}

// GetBulkState retreaves state for multiple keys from specific store.
// GetBulkState retrieves state for multiple keys from specific store.
func (c *GRPCClient) GetBulkState(ctx context.Context, storeName string, keys []string, meta map[string]string, parallelism int32) ([]*BulkStateItem, error) {
if storeName == "" {
return nil, errors.New("nil store")
Expand Down Expand Up @@ -263,12 +263,12 @@ func (c *GRPCClient) GetBulkState(ctx context.Context, storeName string, keys []
return items, nil
}

// GetState retreaves state from specific store using default consistency option.
// GetState retrieves state from specific store using default consistency option.
func (c *GRPCClient) GetState(ctx context.Context, storeName, key string) (item *StateItem, err error) {
return c.GetStateWithConsistency(ctx, storeName, key, nil, StateConsistencyStrong)
}

// GetStateWithConsistency retreaves state from specific store using provided state consistency.
// GetStateWithConsistency retrieves state from specific store using provided state consistency.
func (c *GRPCClient) GetStateWithConsistency(ctx context.Context, storeName, key string, meta map[string]string, sc StateConsistency) (item *StateItem, err error) {
if err := hasRequiredStateArgs(storeName, key); err != nil {
return nil, errors.Wrap(err, "missing required arguments")
Expand Down
Loading

0 comments on commit f2b03d2

Please sign in to comment.