mirror of https://github.com/dapr/go-sdk.git
36 lines
697 B
Go
36 lines
697 B
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
|
|
pb "github.com/dapr/go-sdk/dapr/proto/runtime/v1"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
// GetSecret gets secret by key from specified store
|
|
func (c *Client) GetSecret(ctx context.Context, store, key string, meta map[string]string) (out map[string]string, err error) {
|
|
if store == "" {
|
|
return nil, errors.New("nil store")
|
|
}
|
|
if key == "" {
|
|
return nil, errors.New("nil key")
|
|
}
|
|
|
|
req := &pb.GetSecretRequest{
|
|
Key: key,
|
|
StoreName: store,
|
|
Metadata: meta,
|
|
}
|
|
|
|
resp, err := c.protoClient.GetSecret(authContext(ctx), req)
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "error invoking service")
|
|
}
|
|
|
|
if resp != nil {
|
|
out = resp.GetData()
|
|
}
|
|
|
|
return
|
|
}
|