get.porter.sh/porter@v1.3.0/pkg/signing/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/signing/plugins"
     8  	"get.porter.sh/porter/pkg/signing/plugins/proto"
     9  )
    10  
    11  var _ plugins.SigningProtocol = &GClient{}
    12  
    13  // GClient is a gRPC implementation of the signing client.
    14  type GClient struct {
    15  	client proto.SigningProtocolClient
    16  }
    17  
    18  func NewClient(client proto.SigningProtocolClient) *GClient {
    19  	return &GClient{client}
    20  }
    21  
    22  func (m *GClient) Sign(ctx context.Context, ref string) error {
    23  	req := &proto.SignRequest{
    24  		Ref: ref,
    25  	}
    26  
    27  	_, err := m.client.Sign(ctx, req)
    28  	if err != nil {
    29  		return err
    30  	}
    31  	return nil
    32  }
    33  
    34  func (m *GClient) Verify(ctx context.Context, ref string) error {
    35  	req := &proto.VerifyRequest{
    36  		Ref: ref,
    37  	}
    38  	_, err := m.client.Verify(ctx, req)
    39  	return err
    40  }
    41  
    42  func (m *GClient) Connect(ctx context.Context) error {
    43  	req := &proto.ConnectRequest{}
    44  	_, err := m.client.Connect(ctx, req)
    45  	return err
    46  }
    47  
    48  // GServer is a gRPC wrapper around a SecretsProtocol plugin
    49  type GServer struct {
    50  	c    *portercontext.Context
    51  	impl plugins.SigningProtocol
    52  	proto.UnsafeSigningProtocolServer
    53  }
    54  
    55  func NewServer(c *portercontext.Context, impl plugins.SigningProtocol) *GServer {
    56  	return &GServer{c: c, impl: impl}
    57  }
    58  
    59  func (m *GServer) Sign(ctx context.Context, request *proto.SignRequest) (*proto.SignResponse, error) {
    60  	err := m.impl.Sign(ctx, request.Ref)
    61  	if err != nil {
    62  		return nil, err
    63  	}
    64  	return &proto.SignResponse{}, nil
    65  }
    66  
    67  func (m *GServer) Verify(ctx context.Context, request *proto.VerifyRequest) (*proto.VerifyResponse, error) {
    68  	err := m.impl.Verify(ctx, request.Ref)
    69  	if err != nil {
    70  		return nil, err
    71  	}
    72  	return &proto.VerifyResponse{}, nil
    73  }
    74  
    75  func (m *GServer) Connect(ctx context.Context, request *proto.ConnectRequest) (*proto.ConnectResponse, error) {
    76  	err := m.impl.Connect(ctx)
    77  	if err != nil {
    78  		return nil, err
    79  	}
    80  	return &proto.ConnectResponse{}, nil
    81  }