From 7ed1c9b8712982948fbe200326eb0bb556509f62 Mon Sep 17 00:00:00 2001 From: Christian Stewart Date: Thu, 1 Dec 2016 13:31:48 -0500 Subject: [PATCH] feat(ctl): add call to retreive a key --- ctl/ctl-service.pb.go | 125 ++++++++++++++++++++++++++++++++---------- ctl/ctl-service.proto | 9 +++ ctl/server.go | 16 ++++++ 3 files changed, 120 insertions(+), 30 deletions(-) diff --git a/ctl/ctl-service.pb.go b/ctl/ctl-service.pb.go index 7d2ca02..04057a7 100644 --- a/ctl/ctl-service.pb.go +++ b/ctl/ctl-service.pb.go @@ -17,6 +17,8 @@ It has these top-level messages: PutTransactionResponse GetGrantsRequest GetGrantsResponse + GetKeyRequest + GetKeyResponse */ package ctl @@ -169,6 +171,31 @@ func (m *GetGrantsResponse) GetGrants() []*data.SignedData { return nil } +type GetKeyRequest struct { + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` +} + +func (m *GetKeyRequest) Reset() { *m = GetKeyRequest{} } +func (m *GetKeyRequest) String() string { return proto.CompactTextString(m) } +func (*GetKeyRequest) ProtoMessage() {} +func (*GetKeyRequest) Descriptor() ([]byte, []int) { return fileDescriptorCtlService, []int{8} } + +type GetKeyResponse struct { + Transaction *tx.Transaction `protobuf:"bytes,1,opt,name=transaction" json:"transaction,omitempty"` +} + +func (m *GetKeyResponse) Reset() { *m = GetKeyResponse{} } +func (m *GetKeyResponse) String() string { return proto.CompactTextString(m) } +func (*GetKeyResponse) ProtoMessage() {} +func (*GetKeyResponse) Descriptor() ([]byte, []int) { return fileDescriptorCtlService, []int{9} } + +func (m *GetKeyResponse) GetTransaction() *tx.Transaction { + if m != nil { + return m.Transaction + } + return nil +} + func init() { proto.RegisterType((*PutGrantRequest)(nil), "ctl.PutGrantRequest") proto.RegisterType((*PutGrantResponse)(nil), "ctl.PutGrantResponse") @@ -178,6 +205,8 @@ func init() { proto.RegisterType((*PutTransactionResponse)(nil), "ctl.PutTransactionResponse") proto.RegisterType((*GetGrantsRequest)(nil), "ctl.GetGrantsRequest") proto.RegisterType((*GetGrantsResponse)(nil), "ctl.GetGrantsResponse") + proto.RegisterType((*GetKeyRequest)(nil), "ctl.GetKeyRequest") + proto.RegisterType((*GetKeyResponse)(nil), "ctl.GetKeyResponse") } // Reference imports to suppress errors if they are not otherwise used. @@ -195,6 +224,7 @@ type ControlServiceClient interface { BuildTransaction(ctx context.Context, in *BuildTransactionRequest, opts ...grpc.CallOption) (*BuildTransactionResponse, error) PutTransaction(ctx context.Context, in *PutTransactionRequest, opts ...grpc.CallOption) (*PutTransactionResponse, error) GetGrants(ctx context.Context, in *GetGrantsRequest, opts ...grpc.CallOption) (*GetGrantsResponse, error) + GetKey(ctx context.Context, in *GetKeyRequest, opts ...grpc.CallOption) (*GetKeyResponse, error) } type controlServiceClient struct { @@ -241,6 +271,15 @@ func (c *controlServiceClient) GetGrants(ctx context.Context, in *GetGrantsReque return out, nil } +func (c *controlServiceClient) GetKey(ctx context.Context, in *GetKeyRequest, opts ...grpc.CallOption) (*GetKeyResponse, error) { + out := new(GetKeyResponse) + err := grpc.Invoke(ctx, "/ctl.ControlService/GetKey", in, out, c.cc, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // Server API for ControlService service type ControlServiceServer interface { @@ -248,6 +287,7 @@ type ControlServiceServer interface { BuildTransaction(context.Context, *BuildTransactionRequest) (*BuildTransactionResponse, error) PutTransaction(context.Context, *PutTransactionRequest) (*PutTransactionResponse, error) GetGrants(context.Context, *GetGrantsRequest) (*GetGrantsResponse, error) + GetKey(context.Context, *GetKeyRequest) (*GetKeyResponse, error) } func RegisterControlServiceServer(s *grpc.Server, srv ControlServiceServer) { @@ -326,6 +366,24 @@ func _ControlService_GetGrants_Handler(srv interface{}, ctx context.Context, dec return interceptor(ctx, in, info, handler) } +func _ControlService_GetKey_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetKeyRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ControlServiceServer).GetKey(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/ctl.ControlService/GetKey", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ControlServiceServer).GetKey(ctx, req.(*GetKeyRequest)) + } + return interceptor(ctx, in, info, handler) +} + var _ControlService_serviceDesc = grpc.ServiceDesc{ ServiceName: "ctl.ControlService", HandlerType: (*ControlServiceServer)(nil), @@ -346,40 +404,47 @@ var _ControlService_serviceDesc = grpc.ServiceDesc{ MethodName: "GetGrants", Handler: _ControlService_GetGrants_Handler, }, + { + MethodName: "GetKey", + Handler: _ControlService_GetKey_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: fileDescriptorCtlService, } var fileDescriptorCtlService = []byte{ - // 460 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x94, 0x53, 0x5d, 0x6f, 0xd3, 0x30, - 0x14, 0xa5, 0x2d, 0x1a, 0xec, 0x16, 0xad, 0x99, 0xc5, 0x46, 0x15, 0x98, 0x84, 0xfc, 0x34, 0x21, - 0xe1, 0xb2, 0x22, 0x90, 0x90, 0xe0, 0x01, 0x98, 0x98, 0xc4, 0x5e, 0x4a, 0x86, 0xc4, 0xe3, 0x94, - 0x0f, 0x93, 0x59, 0x0b, 0x71, 0x88, 0x6f, 0xa2, 0x95, 0x7f, 0xc4, 0x03, 0xff, 0x11, 0xc7, 0x4e, - 0xda, 0x10, 0x1a, 0x15, 0x1e, 0x12, 0x59, 0xf7, 0x9e, 0x73, 0x7c, 0xcf, 0xb1, 0x0d, 0x2f, 0x63, - 0x81, 0x57, 0x45, 0xc0, 0x42, 0xf9, 0x6d, 0xf6, 0xb5, 0x50, 0x3c, 0x97, 0x81, 0x44, 0x11, 0xaa, - 0xd9, 0x75, 0x19, 0x4b, 0xa5, 0x44, 0x36, 0x0b, 0x31, 0xa9,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x8c, 0x5b, 0x61, 0xd6, 0xbe, 0x27, 0x0c, 0x6f, 0x58, 0x1b, 0xdd, 0xc6, 0x74, 0xcd, 0x0d, - 0xff, 0xc1, 0x9c, 0x76, 0x70, 0x47, 0xa4, 0xa5, 0x9f, 0x88, 0x68, 0x3a, 0xea, 0xc1, 0x37, 0x00, - 0xfa, 0x11, 0x0e, 0x74, 0xa0, 0x1b, 0x62, 0xf8, 0xff, 0x59, 0xe9, 0x14, 0x0e, 0xbb, 0x5a, 0xd6, - 0x38, 0x25, 0xe0, 0x9c, 0x71, 0x7b, 0x6c, 0xaa, 0xde, 0x80, 0xbe, 0x81, 0xfd, 0x56, 0xad, 0x4e, - 0xe8, 0x18, 0x76, 0xcc, 0x2d, 0xe8, 0x3f, 0xc6, 0xba, 0x3f, 0xff, 0x39, 0x84, 0xbd, 0xf7, 0x32, - 0xc5, 0x5c, 0x26, 0x17, 0xf6, 0x29, 0x90, 0x57, 0x70, 0xb7, 0xb9, 0x1c, 0xe4, 0x3e, 0xd3, 0x2f, - 0x82, 0x75, 0x6e, 0x9c, 0x7b, 0xd0, 0xa9, 0xd6, 0xe3, 0xdd, 0x22, 0x9f, 0xc0, 0xe9, 0x9e, 0x1a, - 0x79, 0x64, 0xc0, 0x3d, 0xd7, 0xc4, 0x3d, 0xea, 0xe9, 0xae, 0x24, 0xcf, 0x61, 0xef, 0xcf, 0x34, - 0x88, 0xdb, 0xec, 0xbe, 0x41, 0xee, 0xe1, 0xc6, 0xde, 0x4a, 0xec, 0x35, 0xec, 0xae, 0xc2, 0x22, - 0xd6, 0x45, 0x37, 0x50, 0xf7, 0xb0, 0x5b, 0x6e, 0xd8, 0xc1, 0x8e, 0x79, 0x82, 0xcf, 0x7f, 0x07, - 0x00, 0x00, 0xff, 0xff, 0xea, 0xde, 0xc7, 0x6f, 0x5e, 0x04, 0x00, 0x00, + // 499 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88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, 0x86, 0xad, 0x17, 0x8d, 0xa5, 0x17, 0x47, 0xd0, 0x75, 0x90, 0x1b, + 0x1b, 0x30, 0xfc, 0xdd, 0x84, 0xee, 0x91, 0x48, 0x31, 0x17, 0xc9, 0x99, 0x79, 0x72, 0xe4, 0x0d, + 0xdc, 0x75, 0x4b, 0x48, 0x1e, 0x06, 0xea, 0xe5, 0x05, 0xb5, 0xcd, 0xf6, 0x77, 0x6a, 0x51, 0x3b, + 0x86, 0x5b, 0xe4, 0x33, 0x78, 0xf5, 0xed, 0x20, 0x4f, 0x34, 0x78, 0xcd, 0x3a, 0xfa, 0x7b, 0x6b, + 0xb2, 0x8b, 0x92, 0xa7, 0xd0, 0xbd, 0x3e, 0x75, 0xe2, 0xbb, 0xdb, 0x57, 0x94, 0x7b, 0xbc, 0x32, + 0xb7, 0x28, 0xf6, 0x16, 0xb6, 0x16, 0xa6, 0x10, 0xa3, 0xa2, 0x6e, 0x9c, 0xbf, 0x5b, 0x0f, 0x2f, + 0xd8, 0x87, 0xd0, 0x36, 0x03, 0x27, 0xc4, 0x61, 0x96, 0x06, 0xf9, 0x0f, 0xae, 0xc5, 0x1c, 0x69, + 0xdc, 0xd6, 0xff, 0x0f, 0x87, 0x7f, 0x02, 0x00, 0x00, 0xff, 0xff, 0xe1, 0x4d, 0xa7, 0xd3, 0xfb, + 0x04, 0x00, 0x00, } diff --git a/ctl/ctl-service.proto b/ctl/ctl-service.proto index a834ef6..b86e1f6 100644 --- a/ctl/ctl-service.proto +++ b/ctl/ctl-service.proto @@ -40,9 +40,18 @@ message GetGrantsResponse { repeated data.SignedData grants = 1; } +message GetKeyRequest { + string key = 1; +} + +message GetKeyResponse { + tx.Transaction transaction = 1; +} + service ControlService { rpc PutGrant(PutGrantRequest) returns (PutGrantResponse) {} rpc BuildTransaction(BuildTransactionRequest) returns (BuildTransactionResponse) {} rpc PutTransaction(PutTransactionRequest) returns (PutTransactionResponse) {} rpc GetGrants(GetGrantsRequest) returns (GetGrantsResponse) {} + rpc GetKey(GetKeyRequest) returns (GetKeyResponse) {} } diff --git a/ctl/server.go b/ctl/server.go index 669e076..b50461e 100644 --- a/ctl/server.go +++ b/ctl/server.go @@ -7,6 +7,7 @@ import ( "time" log "github.com/Sirupsen/logrus" + "github.com/boltdb/bolt" "github.com/fuserobotics/kvgossip/data" "github.com/fuserobotics/kvgossip/db" "github.com/fuserobotics/kvgossip/grant" @@ -116,6 +117,21 @@ func (ct *CtlServer) PutTransaction(ctx context.Context, req *PutTransactionRequ return &PutTransactionResponse{}, nil } +func (ct *CtlServer) GetKey(ctx context.Context, req *GetKeyRequest) (*GetKeyResponse, error) { + if req.Key == "" { + return nil, errors.New("Must specify key.") + } + res := &GetKeyResponse{} + err := ct.DB.DB.View(func(tx *bolt.Tx) error { + res.Transaction = ct.DB.GetTransaction(tx, req.Key) + return nil + }) + if err != nil { + return nil, err + } + return res, nil +} + func (ct *CtlServer) Start(listen string) error { if ct.server != nil { return nil