get.porter.sh/porter@v1.3.0/pkg/secrets/pluginstore/grpc.go (about) 1 package pluginstore 2 3 import ( 4 "context" 5 6 "get.porter.sh/porter/pkg/portercontext" 7 "get.porter.sh/porter/pkg/secrets/plugins" 8 "get.porter.sh/porter/pkg/secrets/plugins/proto" 9 ) 10 11 var _ plugins.SecretsProtocol = &GClient{} 12 13 // GClient is a gRPC implementation of the storage client. 14 type GClient struct { 15 client proto.SecretsProtocolClient 16 } 17 18 func NewClient(client proto.SecretsProtocolClient) *GClient { 19 return &GClient{client} 20 } 21 22 func (m *GClient) Resolve(ctx context.Context, keyName string, keyValue string) (string, error) { 23 req := &proto.ResolveRequest{ 24 KeyName: keyName, 25 KeyValue: keyValue, 26 } 27 28 resp, err := m.client.Resolve(ctx, req) 29 if err != nil { 30 return "", err 31 } 32 return resp.Value, nil 33 } 34 35 func (m *GClient) Create(ctx context.Context, keyName string, keyValue string, value string) error { 36 req := &proto.CreateRequest{ 37 KeyName: keyName, 38 KeyValue: keyValue, 39 Value: value, 40 } 41 _, err := m.client.Create(ctx, req) 42 return err 43 } 44 45 // GServer is a gRPC wrapper around a SecretsProtocol plugin 46 type GServer struct { 47 c *portercontext.Context 48 impl plugins.SecretsProtocol 49 proto.UnsafeSecretsProtocolServer 50 } 51 52 func NewServer(c *portercontext.Context, impl plugins.SecretsProtocol) *GServer { 53 return &GServer{c: c, impl: impl} 54 } 55 56 func (m *GServer) Resolve(ctx context.Context, request *proto.ResolveRequest) (*proto.ResolveResponse, error) { 57 value, err := m.impl.Resolve(ctx, request.KeyName, request.KeyValue) 58 if err != nil { 59 return nil, err 60 } 61 return &proto.ResolveResponse{Value: value}, nil 62 } 63 64 func (m *GServer) Create(ctx context.Context, request *proto.CreateRequest) (*proto.CreateResponse, error) { 65 err := m.impl.Create(ctx, request.KeyName, request.KeyValue, request.Value) 66 if err != nil { 67 return nil, err 68 } 69 return &proto.CreateResponse{}, nil 70 }