From f4f0b799bc279f5b5178112cd91ba09eb1a7e4ae Mon Sep 17 00:00:00 2001 From: Kamil Samigullin Date: Thu, 27 Sep 2018 20:08:51 +0300 Subject: [PATCH] fix #26: use protected storage; issue #10: update grpc layer; issue #28: update swagger; issue #12: add new commands --- cmd/ctl.go | 13 +- cmd/grpc_helper.go | 17 +- env/client/guard.swagger.json | 66 +++- pkg/storage/protected.go | 35 +- pkg/storage/query/license.go | 8 + pkg/transport/grpc/contract.go | 11 +- pkg/transport/grpc/license.pb.go | 468 +++++++++++++++++++-------- pkg/transport/grpc/license.pb.gw.go | 176 ++++++++-- pkg/transport/grpc/license.proto | 53 ++- pkg/transport/grpc/license.proxy.go | 32 +- pkg/transport/grpc/license_server.go | 38 ++- pkg/transport/grpc/proxy.go | 7 + 12 files changed, 689 insertions(+), 235 deletions(-) create mode 100644 pkg/transport/grpc/proxy.go diff --git a/cmd/ctl.go b/cmd/ctl.go index 7ebd6f6..d043d3e 100644 --- a/cmd/ctl.go +++ b/cmd/ctl.go @@ -18,9 +18,14 @@ const ( var ( // License TODO issue#docs - License = &cobra.Command{Use: "license", Short: "Guard License"} - extendLicense = &cobra.Command{Use: "extend", Short: "Extend user license", RunE: communicate} - readLicense = &cobra.Command{Use: "read", Short: "Read user license", RunE: communicate} + License = &cobra.Command{Use: "license", Short: "Guard License"} + createLicense = &cobra.Command{Use: "create", Short: "Create user license", RunE: communicate} + readLicense = &cobra.Command{Use: "read", Short: "Read user license", RunE: communicate} + updateLicense = &cobra.Command{Use: "update", Short: "Update user license", RunE: communicate} + deleteLicense = &cobra.Command{Use: "delete", Short: "Delete user license", RunE: communicate} + + // --- + registerLicense = &cobra.Command{Use: "register", Short: "Register user license", RunE: communicate} ) @@ -53,5 +58,5 @@ func init() { return nil }, ) - License.AddCommand(extendLicense, readLicense, registerLicense) + License.AddCommand(createLicense, readLicense, updateLicense, deleteLicense, registerLicense) } diff --git a/cmd/grpc_helper.go b/cmd/grpc_helper.go index 4053eb4..45a8fa5 100644 --- a/cmd/grpc_helper.go +++ b/cmd/grpc_helper.go @@ -24,8 +24,13 @@ var entities factory func init() { entities = factory{ - readLicense: {"License": func() pb.Proxy { return pb.ReadLicenseRequestProxy{} }}, - extendLicense: {"License": func() pb.Proxy { return pb.ExtendLicenseRequestProxy{} }}, + createLicense: {"License": func() pb.Proxy { return pb.CreateLicenseRequestProxy{} }}, + readLicense: {"License": func() pb.Proxy { return pb.ReadLicenseRequestProxy{} }}, + updateLicense: {"License": func() pb.Proxy { return pb.UpdateLicenseRequestProxy{} }}, + deleteLicense: {"License": func() pb.Proxy { return pb.DeleteLicenseRequestProxy{} }}, + + // --- + registerLicense: {"License": func() pb.Proxy { return pb.RegisterLicenseRequestProxy{} }}, } } @@ -116,10 +121,14 @@ func call(cnf config.GRPCConfig, entity pb.Proxy) (interface{}, error) { middleware.AuthHeader, strings.Concat(middleware.AuthScheme, " ", string(cnf.Token))) switch request := entity.Convert().(type) { + case *pb.CreateLicenseRequest: + return client.Create(ctx, request) case *pb.ReadLicenseRequest: return client.Read(ctx, request) - case *pb.ExtendLicenseRequest: - return client.Extend(ctx, request) + case *pb.UpdateLicenseRequest: + return client.Update(ctx, request) + case *pb.DeleteLicenseRequest: + return client.Delete(ctx, request) case *pb.RegisterLicenseRequest: return client.Register(ctx, request) default: diff --git a/env/client/guard.swagger.json b/env/client/guard.swagger.json index 4196ba6..757f4d9 100644 --- a/env/client/guard.swagger.json +++ b/env/client/guard.swagger.json @@ -1,7 +1,7 @@ { "swagger": "2.0", "info": { - "title": "Access Guard as a Service", + "title": "Access Control as a Service", "version": "dev", "contact": { "name": "Guard project of Hugs Platform", @@ -20,14 +20,14 @@ "application/json" ], "paths": { - "/api/v1/license/extend": { - "put": { - "operationId": "Extend", + "/api/v1/license": { + "post": { + "operationId": "Create", "responses": { "200": { "description": "", "schema": { - "$ref": "#/definitions/grpcExtendLicenseResponse" + "$ref": "#/definitions/grpcCreateLicenseResponse" } } }, @@ -52,7 +52,7 @@ ] } }, - "/api/v1/license/{id}": { + "/api/v1/license/{number}": { "get": { "operationId": "Read", "responses": { @@ -65,7 +65,51 @@ }, "parameters": [ { - "name": "id", + "name": "number", + "in": "path", + "required": true, + "type": "string" + } + ], + "tags": [ + "License" + ] + }, + "delete": { + "operationId": "Delete", + "responses": { + "200": { + "description": "", + "schema": { + "$ref": "#/definitions/grpcDeleteLicenseResponse" + } + } + }, + "parameters": [ + { + "name": "number", + "in": "path", + "required": true, + "type": "string" + } + ], + "tags": [ + "License" + ] + }, + "put": { + "operationId": "Update", + "responses": { + "200": { + "description": "", + "schema": { + "$ref": "#/definitions/grpcUpdateLicenseResponse" + } + } + }, + "parameters": [ + { + "name": "number", "in": "path", "required": true, "type": "string" @@ -78,7 +122,10 @@ } }, "definitions": { - "grpcExtendLicenseResponse": { + "grpcCreateLicenseResponse": { + "type": "object" + }, + "grpcDeleteLicenseResponse": { "type": "object" }, "grpcReadLicenseResponse": { @@ -86,6 +133,9 @@ }, "grpcRegisterLicenseResponse": { "type": "object" + }, + "grpcUpdateLicenseResponse": { + "type": "object" } } } diff --git a/pkg/storage/protected.go b/pkg/storage/protected.go index e6e785c..71cdf98 100644 --- a/pkg/storage/protected.go +++ b/pkg/storage/protected.go @@ -111,38 +111,7 @@ func (storage *Storage) DeleteLicense(ctx context.Context, id domain.Token, data // --- -// ExtendLicense TODO issue#docs -func (storage *Storage) ExtendLicense(ctx context.Context, id domain.Token, data query.UpdateLicense) (repository.License, error) { - var license repository.License - - conn, closer, err := storage.connection(ctx) - if err != nil { - return license, err - } - defer closer() - - _, err = storage.exec.UserManager(ctx, conn).AccessToken(id) - if err != nil { - return license, err - } - - return license, nil -} - // RegisterLicense TODO issue#docs -func (storage *Storage) RegisterLicense(ctx context.Context, id domain.Token, data query.CreateLicense) (repository.License, error) { - var license repository.License - - conn, closer, err := storage.connection(ctx) - if err != nil { - return license, err - } - defer closer() - - _, err = storage.exec.UserManager(ctx, conn).AccessToken(id) - if err != nil { - return license, err - } - - return license, nil +func (storage *Storage) RegisterLicense(ctx context.Context, id domain.Token, data query.RegisterLicense) (repository.License, error) { + return storage.CreateLicense(ctx, id, query.CreateLicense{Number: &data.Number, Contract: data.Contract}) } diff --git a/pkg/storage/query/license.go b/pkg/storage/query/license.go index 184188f..b82f2d8 100644 --- a/pkg/storage/query/license.go +++ b/pkg/storage/query/license.go @@ -23,3 +23,11 @@ type UpdateLicense struct { Number domain.ID Contract domain.Contract } + +// --- + +// RegisterLicense TODO issue#docs +type RegisterLicense struct { + Number domain.ID + Contract domain.Contract +} diff --git a/pkg/transport/grpc/contract.go b/pkg/transport/grpc/contract.go index 0952edc..0a29767 100644 --- a/pkg/transport/grpc/contract.go +++ b/pkg/transport/grpc/contract.go @@ -11,10 +11,17 @@ import ( // ProtectedStorage TODO issue#docs type ProtectedStorage interface { - // ExtendLicense TODO issue#docs - ExtendLicense(context.Context, domain.Token, query.ExtendLicense) (repository.License, error) + // CreateLicense TODO issue#docs + CreateLicense(context.Context, domain.Token, query.CreateLicense) (repository.License, error) // ReadLicense TODO issue#docs ReadLicense(context.Context, domain.Token, query.ReadLicense) (repository.License, error) + // UpdateLicense TODO issue#docs + UpdateLicense(context.Context, domain.Token, query.UpdateLicense) (repository.License, error) + // DeleteLicense TODO issue#docs + DeleteLicense(context.Context, domain.Token, query.DeleteLicense) (repository.License, error) + + // --- + // RegisterLicense TODO issue#docs RegisterLicense(context.Context, domain.Token, query.RegisterLicense) (repository.License, error) } diff --git a/pkg/transport/grpc/license.pb.go b/pkg/transport/grpc/license.pb.go index 2393a5c..f42ec0e 100644 --- a/pkg/transport/grpc/license.pb.go +++ b/pkg/transport/grpc/license.pb.go @@ -25,8 +25,76 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package +type CreateLicenseRequest struct { + Number string `protobuf:"bytes,1,opt,name=number,proto3" json:"number,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *CreateLicenseRequest) Reset() { *m = CreateLicenseRequest{} } +func (m *CreateLicenseRequest) String() string { return proto.CompactTextString(m) } +func (*CreateLicenseRequest) ProtoMessage() {} +func (*CreateLicenseRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_090c1f856632b222, []int{0} +} +func (m *CreateLicenseRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_CreateLicenseRequest.Unmarshal(m, b) +} +func (m *CreateLicenseRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_CreateLicenseRequest.Marshal(b, m, deterministic) +} +func (m *CreateLicenseRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_CreateLicenseRequest.Merge(m, src) +} +func (m *CreateLicenseRequest) XXX_Size() int { + return xxx_messageInfo_CreateLicenseRequest.Size(m) +} +func (m *CreateLicenseRequest) XXX_DiscardUnknown() { + xxx_messageInfo_CreateLicenseRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_CreateLicenseRequest proto.InternalMessageInfo + +func (m *CreateLicenseRequest) GetNumber() string { + if m != nil { + return m.Number + } + return "" +} + +type CreateLicenseResponse struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *CreateLicenseResponse) Reset() { *m = CreateLicenseResponse{} } +func (m *CreateLicenseResponse) String() string { return proto.CompactTextString(m) } +func (*CreateLicenseResponse) ProtoMessage() {} +func (*CreateLicenseResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_090c1f856632b222, []int{1} +} +func (m *CreateLicenseResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_CreateLicenseResponse.Unmarshal(m, b) +} +func (m *CreateLicenseResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_CreateLicenseResponse.Marshal(b, m, deterministic) +} +func (m *CreateLicenseResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_CreateLicenseResponse.Merge(m, src) +} +func (m *CreateLicenseResponse) XXX_Size() int { + return xxx_messageInfo_CreateLicenseResponse.Size(m) +} +func (m *CreateLicenseResponse) XXX_DiscardUnknown() { + xxx_messageInfo_CreateLicenseResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_CreateLicenseResponse proto.InternalMessageInfo + type ReadLicenseRequest struct { - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + Number string `protobuf:"bytes,1,opt,name=number,proto3" json:"number,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -36,7 +104,7 @@ func (m *ReadLicenseRequest) Reset() { *m = ReadLicenseRequest{} } func (m *ReadLicenseRequest) String() string { return proto.CompactTextString(m) } func (*ReadLicenseRequest) ProtoMessage() {} func (*ReadLicenseRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_090c1f856632b222, []int{0} + return fileDescriptor_090c1f856632b222, []int{2} } func (m *ReadLicenseRequest) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_ReadLicenseRequest.Unmarshal(m, b) @@ -56,9 +124,9 @@ func (m *ReadLicenseRequest) XXX_DiscardUnknown() { var xxx_messageInfo_ReadLicenseRequest proto.InternalMessageInfo -func (m *ReadLicenseRequest) GetId() string { +func (m *ReadLicenseRequest) GetNumber() string { if m != nil { - return m.Id + return m.Number } return "" } @@ -73,7 +141,7 @@ func (m *ReadLicenseResponse) Reset() { *m = ReadLicenseResponse{} } func (m *ReadLicenseResponse) String() string { return proto.CompactTextString(m) } func (*ReadLicenseResponse) ProtoMessage() {} func (*ReadLicenseResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_090c1f856632b222, []int{1} + return fileDescriptor_090c1f856632b222, []int{3} } func (m *ReadLicenseResponse) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_ReadLicenseResponse.Unmarshal(m, b) @@ -93,6 +161,142 @@ func (m *ReadLicenseResponse) XXX_DiscardUnknown() { var xxx_messageInfo_ReadLicenseResponse proto.InternalMessageInfo +type UpdateLicenseRequest struct { + Number string `protobuf:"bytes,1,opt,name=number,proto3" json:"number,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *UpdateLicenseRequest) Reset() { *m = UpdateLicenseRequest{} } +func (m *UpdateLicenseRequest) String() string { return proto.CompactTextString(m) } +func (*UpdateLicenseRequest) ProtoMessage() {} +func (*UpdateLicenseRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_090c1f856632b222, []int{4} +} +func (m *UpdateLicenseRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_UpdateLicenseRequest.Unmarshal(m, b) +} +func (m *UpdateLicenseRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_UpdateLicenseRequest.Marshal(b, m, deterministic) +} +func (m *UpdateLicenseRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_UpdateLicenseRequest.Merge(m, src) +} +func (m *UpdateLicenseRequest) XXX_Size() int { + return xxx_messageInfo_UpdateLicenseRequest.Size(m) +} +func (m *UpdateLicenseRequest) XXX_DiscardUnknown() { + xxx_messageInfo_UpdateLicenseRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_UpdateLicenseRequest proto.InternalMessageInfo + +func (m *UpdateLicenseRequest) GetNumber() string { + if m != nil { + return m.Number + } + return "" +} + +type UpdateLicenseResponse struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *UpdateLicenseResponse) Reset() { *m = UpdateLicenseResponse{} } +func (m *UpdateLicenseResponse) String() string { return proto.CompactTextString(m) } +func (*UpdateLicenseResponse) ProtoMessage() {} +func (*UpdateLicenseResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_090c1f856632b222, []int{5} +} +func (m *UpdateLicenseResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_UpdateLicenseResponse.Unmarshal(m, b) +} +func (m *UpdateLicenseResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_UpdateLicenseResponse.Marshal(b, m, deterministic) +} +func (m *UpdateLicenseResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_UpdateLicenseResponse.Merge(m, src) +} +func (m *UpdateLicenseResponse) XXX_Size() int { + return xxx_messageInfo_UpdateLicenseResponse.Size(m) +} +func (m *UpdateLicenseResponse) XXX_DiscardUnknown() { + xxx_messageInfo_UpdateLicenseResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_UpdateLicenseResponse proto.InternalMessageInfo + +type DeleteLicenseRequest struct { + Number string `protobuf:"bytes,1,opt,name=number,proto3" json:"number,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *DeleteLicenseRequest) Reset() { *m = DeleteLicenseRequest{} } +func (m *DeleteLicenseRequest) String() string { return proto.CompactTextString(m) } +func (*DeleteLicenseRequest) ProtoMessage() {} +func (*DeleteLicenseRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_090c1f856632b222, []int{6} +} +func (m *DeleteLicenseRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_DeleteLicenseRequest.Unmarshal(m, b) +} +func (m *DeleteLicenseRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_DeleteLicenseRequest.Marshal(b, m, deterministic) +} +func (m *DeleteLicenseRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_DeleteLicenseRequest.Merge(m, src) +} +func (m *DeleteLicenseRequest) XXX_Size() int { + return xxx_messageInfo_DeleteLicenseRequest.Size(m) +} +func (m *DeleteLicenseRequest) XXX_DiscardUnknown() { + xxx_messageInfo_DeleteLicenseRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_DeleteLicenseRequest proto.InternalMessageInfo + +func (m *DeleteLicenseRequest) GetNumber() string { + if m != nil { + return m.Number + } + return "" +} + +type DeleteLicenseResponse struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *DeleteLicenseResponse) Reset() { *m = DeleteLicenseResponse{} } +func (m *DeleteLicenseResponse) String() string { return proto.CompactTextString(m) } +func (*DeleteLicenseResponse) ProtoMessage() {} +func (*DeleteLicenseResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_090c1f856632b222, []int{7} +} +func (m *DeleteLicenseResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_DeleteLicenseResponse.Unmarshal(m, b) +} +func (m *DeleteLicenseResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_DeleteLicenseResponse.Marshal(b, m, deterministic) +} +func (m *DeleteLicenseResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_DeleteLicenseResponse.Merge(m, src) +} +func (m *DeleteLicenseResponse) XXX_Size() int { + return xxx_messageInfo_DeleteLicenseResponse.Size(m) +} +func (m *DeleteLicenseResponse) XXX_DiscardUnknown() { + xxx_messageInfo_DeleteLicenseResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_DeleteLicenseResponse proto.InternalMessageInfo + type RegisterLicenseRequest struct { Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` @@ -104,7 +308,7 @@ func (m *RegisterLicenseRequest) Reset() { *m = RegisterLicenseRequest{} func (m *RegisterLicenseRequest) String() string { return proto.CompactTextString(m) } func (*RegisterLicenseRequest) ProtoMessage() {} func (*RegisterLicenseRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_090c1f856632b222, []int{2} + return fileDescriptor_090c1f856632b222, []int{8} } func (m *RegisterLicenseRequest) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_RegisterLicenseRequest.Unmarshal(m, b) @@ -141,7 +345,7 @@ func (m *RegisterLicenseResponse) Reset() { *m = RegisterLicenseResponse func (m *RegisterLicenseResponse) String() string { return proto.CompactTextString(m) } func (*RegisterLicenseResponse) ProtoMessage() {} func (*RegisterLicenseResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_090c1f856632b222, []int{3} + return fileDescriptor_090c1f856632b222, []int{9} } func (m *RegisterLicenseResponse) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_RegisterLicenseResponse.Unmarshal(m, b) @@ -161,81 +365,17 @@ func (m *RegisterLicenseResponse) XXX_DiscardUnknown() { var xxx_messageInfo_RegisterLicenseResponse proto.InternalMessageInfo -type ExtendLicenseRequest struct { - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *ExtendLicenseRequest) Reset() { *m = ExtendLicenseRequest{} } -func (m *ExtendLicenseRequest) String() string { return proto.CompactTextString(m) } -func (*ExtendLicenseRequest) ProtoMessage() {} -func (*ExtendLicenseRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_090c1f856632b222, []int{4} -} -func (m *ExtendLicenseRequest) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_ExtendLicenseRequest.Unmarshal(m, b) -} -func (m *ExtendLicenseRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_ExtendLicenseRequest.Marshal(b, m, deterministic) -} -func (m *ExtendLicenseRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_ExtendLicenseRequest.Merge(m, src) -} -func (m *ExtendLicenseRequest) XXX_Size() int { - return xxx_messageInfo_ExtendLicenseRequest.Size(m) -} -func (m *ExtendLicenseRequest) XXX_DiscardUnknown() { - xxx_messageInfo_ExtendLicenseRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_ExtendLicenseRequest proto.InternalMessageInfo - -func (m *ExtendLicenseRequest) GetId() string { - if m != nil { - return m.Id - } - return "" -} - -type ExtendLicenseResponse struct { - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *ExtendLicenseResponse) Reset() { *m = ExtendLicenseResponse{} } -func (m *ExtendLicenseResponse) String() string { return proto.CompactTextString(m) } -func (*ExtendLicenseResponse) ProtoMessage() {} -func (*ExtendLicenseResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_090c1f856632b222, []int{5} -} -func (m *ExtendLicenseResponse) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_ExtendLicenseResponse.Unmarshal(m, b) -} -func (m *ExtendLicenseResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_ExtendLicenseResponse.Marshal(b, m, deterministic) -} -func (m *ExtendLicenseResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_ExtendLicenseResponse.Merge(m, src) -} -func (m *ExtendLicenseResponse) XXX_Size() int { - return xxx_messageInfo_ExtendLicenseResponse.Size(m) -} -func (m *ExtendLicenseResponse) XXX_DiscardUnknown() { - xxx_messageInfo_ExtendLicenseResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_ExtendLicenseResponse proto.InternalMessageInfo - func init() { + proto.RegisterType((*CreateLicenseRequest)(nil), "grpc.CreateLicenseRequest") + proto.RegisterType((*CreateLicenseResponse)(nil), "grpc.CreateLicenseResponse") proto.RegisterType((*ReadLicenseRequest)(nil), "grpc.ReadLicenseRequest") proto.RegisterType((*ReadLicenseResponse)(nil), "grpc.ReadLicenseResponse") + proto.RegisterType((*UpdateLicenseRequest)(nil), "grpc.UpdateLicenseRequest") + proto.RegisterType((*UpdateLicenseResponse)(nil), "grpc.UpdateLicenseResponse") + proto.RegisterType((*DeleteLicenseRequest)(nil), "grpc.DeleteLicenseRequest") + proto.RegisterType((*DeleteLicenseResponse)(nil), "grpc.DeleteLicenseResponse") proto.RegisterType((*RegisterLicenseRequest)(nil), "grpc.RegisterLicenseRequest") proto.RegisterType((*RegisterLicenseResponse)(nil), "grpc.RegisterLicenseResponse") - proto.RegisterType((*ExtendLicenseRequest)(nil), "grpc.ExtendLicenseRequest") - proto.RegisterType((*ExtendLicenseResponse)(nil), "grpc.ExtendLicenseResponse") } // Reference imports to suppress errors if they are not otherwise used. @@ -250,9 +390,11 @@ const _ = grpc.SupportPackageIsVersion4 // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type LicenseClient interface { + Create(ctx context.Context, in *CreateLicenseRequest, opts ...grpc.CallOption) (*CreateLicenseResponse, error) Read(ctx context.Context, in *ReadLicenseRequest, opts ...grpc.CallOption) (*ReadLicenseResponse, error) + Update(ctx context.Context, in *UpdateLicenseRequest, opts ...grpc.CallOption) (*UpdateLicenseResponse, error) + Delete(ctx context.Context, in *DeleteLicenseRequest, opts ...grpc.CallOption) (*DeleteLicenseResponse, error) Register(ctx context.Context, in *RegisterLicenseRequest, opts ...grpc.CallOption) (*RegisterLicenseResponse, error) - Extend(ctx context.Context, in *ExtendLicenseRequest, opts ...grpc.CallOption) (*ExtendLicenseResponse, error) } type licenseClient struct { @@ -263,6 +405,15 @@ func NewLicenseClient(cc *grpc.ClientConn) LicenseClient { return &licenseClient{cc} } +func (c *licenseClient) Create(ctx context.Context, in *CreateLicenseRequest, opts ...grpc.CallOption) (*CreateLicenseResponse, error) { + out := new(CreateLicenseResponse) + err := c.cc.Invoke(ctx, "/grpc.License/Create", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + func (c *licenseClient) Read(ctx context.Context, in *ReadLicenseRequest, opts ...grpc.CallOption) (*ReadLicenseResponse, error) { out := new(ReadLicenseResponse) err := c.cc.Invoke(ctx, "/grpc.License/Read", in, out, opts...) @@ -272,18 +423,27 @@ func (c *licenseClient) Read(ctx context.Context, in *ReadLicenseRequest, opts . return out, nil } -func (c *licenseClient) Register(ctx context.Context, in *RegisterLicenseRequest, opts ...grpc.CallOption) (*RegisterLicenseResponse, error) { - out := new(RegisterLicenseResponse) - err := c.cc.Invoke(ctx, "/grpc.License/Register", in, out, opts...) +func (c *licenseClient) Update(ctx context.Context, in *UpdateLicenseRequest, opts ...grpc.CallOption) (*UpdateLicenseResponse, error) { + out := new(UpdateLicenseResponse) + err := c.cc.Invoke(ctx, "/grpc.License/Update", in, out, opts...) if err != nil { return nil, err } return out, nil } -func (c *licenseClient) Extend(ctx context.Context, in *ExtendLicenseRequest, opts ...grpc.CallOption) (*ExtendLicenseResponse, error) { - out := new(ExtendLicenseResponse) - err := c.cc.Invoke(ctx, "/grpc.License/Extend", in, out, opts...) +func (c *licenseClient) Delete(ctx context.Context, in *DeleteLicenseRequest, opts ...grpc.CallOption) (*DeleteLicenseResponse, error) { + out := new(DeleteLicenseResponse) + err := c.cc.Invoke(ctx, "/grpc.License/Delete", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *licenseClient) Register(ctx context.Context, in *RegisterLicenseRequest, opts ...grpc.CallOption) (*RegisterLicenseResponse, error) { + out := new(RegisterLicenseResponse) + err := c.cc.Invoke(ctx, "/grpc.License/Register", in, out, opts...) if err != nil { return nil, err } @@ -292,15 +452,35 @@ func (c *licenseClient) Extend(ctx context.Context, in *ExtendLicenseRequest, op // LicenseServer is the server API for License service. type LicenseServer interface { + Create(context.Context, *CreateLicenseRequest) (*CreateLicenseResponse, error) Read(context.Context, *ReadLicenseRequest) (*ReadLicenseResponse, error) + Update(context.Context, *UpdateLicenseRequest) (*UpdateLicenseResponse, error) + Delete(context.Context, *DeleteLicenseRequest) (*DeleteLicenseResponse, error) Register(context.Context, *RegisterLicenseRequest) (*RegisterLicenseResponse, error) - Extend(context.Context, *ExtendLicenseRequest) (*ExtendLicenseResponse, error) } func RegisterLicenseServer(s *grpc.Server, srv LicenseServer) { s.RegisterService(&_License_serviceDesc, srv) } +func _License_Create_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CreateLicenseRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(LicenseServer).Create(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/grpc.License/Create", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(LicenseServer).Create(ctx, req.(*CreateLicenseRequest)) + } + return interceptor(ctx, in, info, handler) +} + func _License_Read_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(ReadLicenseRequest) if err := dec(in); err != nil { @@ -319,38 +499,56 @@ func _License_Read_Handler(srv interface{}, ctx context.Context, dec func(interf return interceptor(ctx, in, info, handler) } -func _License_Register_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(RegisterLicenseRequest) +func _License_Update_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(UpdateLicenseRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(LicenseServer).Register(ctx, in) + return srv.(LicenseServer).Update(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/grpc.License/Register", + FullMethod: "/grpc.License/Update", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(LicenseServer).Register(ctx, req.(*RegisterLicenseRequest)) + return srv.(LicenseServer).Update(ctx, req.(*UpdateLicenseRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _License_Delete_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(DeleteLicenseRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(LicenseServer).Delete(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/grpc.License/Delete", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(LicenseServer).Delete(ctx, req.(*DeleteLicenseRequest)) } return interceptor(ctx, in, info, handler) } -func _License_Extend_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(ExtendLicenseRequest) +func _License_Register_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(RegisterLicenseRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(LicenseServer).Extend(ctx, in) + return srv.(LicenseServer).Register(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/grpc.License/Extend", + FullMethod: "/grpc.License/Register", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(LicenseServer).Extend(ctx, req.(*ExtendLicenseRequest)) + return srv.(LicenseServer).Register(ctx, req.(*RegisterLicenseRequest)) } return interceptor(ctx, in, info, handler) } @@ -359,17 +557,25 @@ var _License_serviceDesc = grpc.ServiceDesc{ ServiceName: "grpc.License", HandlerType: (*LicenseServer)(nil), Methods: []grpc.MethodDesc{ + { + MethodName: "Create", + Handler: _License_Create_Handler, + }, { MethodName: "Read", Handler: _License_Read_Handler, }, { - MethodName: "Register", - Handler: _License_Register_Handler, + MethodName: "Update", + Handler: _License_Update_Handler, + }, + { + MethodName: "Delete", + Handler: _License_Delete_Handler, }, { - MethodName: "Extend", - Handler: _License_Extend_Handler, + MethodName: "Register", + Handler: _License_Register_Handler, }, }, Streams: []grpc.StreamDesc{}, @@ -379,34 +585,38 @@ var _License_serviceDesc = grpc.ServiceDesc{ func init() { proto.RegisterFile("license.proto", fileDescriptor_090c1f856632b222) } var fileDescriptor_090c1f856632b222 = []byte{ - // 451 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x93, 0x41, 0x6f, 0xd3, 0x30, - 0x14, 0xc7, 0x69,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0x31, 0x95, 0x96, - 0x7e, 0x8c, 0xb9, 0x1b, 0x6b, 0x33, 0xc1, 0xf4, 0xca, 0xb9, 0xd4, 0x9e, 0x31, 0x26, 0x95, 0xbb, - 0x9a, 0x8e, 0x02, 0xa1, 0x27, 0xec, 0x9a, 0x4f, 0x54, 0x6c, 0xaf, 0x99, 0x5c, 0x7e, 0x4a, 0x9e, - 0xaa, 0x64, 0xac, 0xdf, 0x68, 0xe1, 0x74, 0xcc, 0x47, 0x81, 0x36, 0xb2, 0xb7, 0x15, 0x41, 0x36, - 0xda, 0x29, 0xfe, 0xb8, 0xa3, 0xff, 0x01, 0x00, 0x00, 0xff, 0xff, 0x2f, 0x86, 0x88, 0xfa, 0xd4, - 0x03, 0x00, 0x00, + // 522 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xc4, 0x94, 0xcf, 0x6f, 0xd3, 0x30, + 0x14, 0xc7, 0x69, 0x3b, 0x15, 0xb0, 0x84, 0x00, 0xc3, 0x68, 0x97, 0x0d, 0x64, 0xe5, 0x84, 0x10, + 0x69, 0x58, 0xb7, 0xc3, 0xb6, 0x13, 0xe9, 0xf8, 0x31, 0x09, 0x0e, 0xa8, 0xc0, 0x85, 0xaa, 0x07, + 0xd7, 0x79, 0xf5, 0xcc, 0xd2, 0x38, 0xd8, 0x6e, 0x41, 0x9b, 0x82, 0x10, 0x47, 0x8e, 0xe5, 0x4f, + 0xe3, 0x5f, 0xe0, 0x9f, 0xe0, 0x86, 0xda, 0x38, 0x13, 0x4d, 0x33, 0x6e, 0x53, 0x4f, 0x71, 0x6c, + 0xbf, 0xf7, 0xfd, 0xe4, 0xbd, 0xef, 0x0b, 0xba, 0x11, 0x09, 0x06, 0xb1, 0x86, 0x56, 0xa2, 0xa4, + 0x91, 0x78, 0x8d, 0xab, 0x84, 0x39, 0x5b, 0x5c, 0x4a, 0x1e, 0x81, 0x4f, 0x13, 0xe1,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b4, 0x98, 0x1c, 0xf9, 0x27, 0x74, 0x24, + 0x22, 0x7d, 0xe2, 0xf3, 0x59, 0xa8, 0x73, 0x4b, 0xc4, 0x43, 0xf9, 0x54, 0x32, 0x23, 0x23, 0x3a, + 0x68, 0x49, 0xc5, 0xdb, 0xb5, 0x10, 0x26, 0x83, 0xfa, 0xfc, 0x1f, 0xbc, 0xf3, 0x37, 0x00, 0x00, + 0xff, 0xff, 0x39, 0x4a, 0x27, 0x03, 0xe6, 0x05, 0x00, 0x00, } diff --git a/pkg/transport/grpc/license.pb.gw.go b/pkg/transport/grpc/license.pb.gw.go index 260e7eb..28c1c2b 100644 --- a/pkg/transport/grpc/license.pb.gw.go +++ b/pkg/transport/grpc/license.pb.gw.go @@ -28,6 +28,23 @@ var _ status.Status var _ = runtime.String var _ = utilities.NewDoubleArray +var ( + filter_License_Create_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_License_Create_0(ctx context.Context, marshaler runtime.Marshaler, client LicenseClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq CreateLicenseRequest + var metadata runtime.ServerMetadata + + if err := runtime.PopulateQueryParameters(&protoReq, req.URL.Query(), filter_License_Create_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.Create(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + func request_License_Read_0(ctx context.Context, marshaler runtime.Marshaler, client LicenseClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq ReadLicenseRequest var metadata runtime.ServerMetadata @@ -39,15 +56,15 @@ func request_License_Read_0(ctx context.Context, marshaler runtime.Marshaler, cl _ = err ) - val, ok = pathParams["id"] + val, ok = pathParams["number"] if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "number") } - protoReq.Id, err = runtime.String(val) + protoReq.Number, err = runtime.String(val) if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "number", err) } msg, err := client.Read(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) @@ -55,36 +72,73 @@ func request_License_Read_0(ctx context.Context, marshaler runtime.Marshaler, cl } -var ( - filter_License_Register_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} -) +func request_License_Update_0(ctx context.Context, marshaler runtime.Marshaler, client LicenseClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq UpdateLicenseRequest + var metadata runtime.ServerMetadata -func request_License_Register_0(ctx context.Context, marshaler runtime.Marshaler, client LicenseClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq RegisterLicenseRequest + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["number"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "number") + } + + protoReq.Number, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "number", err) + } + + msg, err := client.Update(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func request_License_Delete_0(ctx context.Context, marshaler runtime.Marshaler, client LicenseClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq DeleteLicenseRequest var metadata runtime.ServerMetadata - if err := runtime.PopulateQueryParameters(&protoReq, req.URL.Query(), filter_License_Register_0); err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["number"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "number") } - msg, err := client.Register(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + protoReq.Number, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "number", err) + } + + msg, err := client.Delete(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err } var ( - filter_License_Extend_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} + filter_License_Register_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} ) -func request_License_Extend_0(ctx context.Context, marshaler runtime.Marshaler, client LicenseClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq ExtendLicenseRequest +func request_License_Register_0(ctx context.Context, marshaler runtime.Marshaler, client LicenseClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq RegisterLicenseRequest var metadata runtime.ServerMetadata - if err := runtime.PopulateQueryParameters(&protoReq, req.URL.Query(), filter_License_Extend_0); err != nil { + if err := runtime.PopulateQueryParameters(&protoReq, req.URL.Query(), filter_License_Register_0); err != nil { return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } - msg, err := client.Extend(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + msg, err := client.Register(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err } @@ -127,6 +181,35 @@ func RegisterLicenseHandler(ctx context.Context, mux *runtime.ServeMux, conn *gr // "LicenseClient" to call the correct interceptors. func RegisterLicenseHandlerClient(ctx context.Context, mux *runtime.ServeMux, client LicenseClient) error { + mux.Handle("POST", pattern_License_Create_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + if cn, ok := w.(http.CloseNotifier); ok { + go func(done <-chan struct{}, closed <-chan bool) { + select { + case <-done: + case <-closed: + cancel() + } + }(ctx.Done(), cn.CloseNotify()) + } + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_License_Create_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_License_Create_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + mux.Handle("GET", pattern_License_Read_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() @@ -156,7 +239,7 @@ func RegisterLicenseHandlerClient(ctx context.Context, mux *runtime.ServeMux, cl }) - mux.Handle("POST", pattern_License_Register_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("PUT", pattern_License_Update_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() if cn, ok := w.(http.CloseNotifier); ok { @@ -174,18 +257,18 @@ func RegisterLicenseHandlerClient(ctx context.Context, mux *runtime.ServeMux, cl runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_License_Register_0(rctx, inboundMarshaler, client, req, pathParams) + resp, md, err := request_License_Update_0(rctx, inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_License_Register_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_License_Update_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) - mux.Handle("PUT", pattern_License_Extend_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("DELETE", pattern_License_Delete_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() if cn, ok := w.(http.CloseNotifier); ok { @@ -203,14 +286,43 @@ func RegisterLicenseHandlerClient(ctx context.Context, mux *runtime.ServeMux, cl runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_License_Extend_0(rctx, inboundMarshaler, client, req, pathParams) + resp, md, err := request_License_Delete_0(rctx, inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_License_Extend_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_License_Delete_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("POST", pattern_License_Register_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + if cn, ok := w.(http.CloseNotifier); ok { + go func(done <-chan struct{}, closed <-chan bool) { + select { + case <-done: + case <-closed: + cancel() + } + }(ctx.Done(), cn.CloseNotify()) + } + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_License_Register_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_License_Register_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -218,17 +330,25 @@ func RegisterLicenseHandlerClient(ctx context.Context, mux *runtime.ServeMux, cl } var ( - pattern_License_Read_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"api", "v1", "license", "id"}, "")) + pattern_License_Create_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"api", "v1", "license"}, "")) - pattern_License_Register_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"api", "v1", "license", "register"}, "")) + pattern_License_Read_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"api", "v1", "license", "number"}, "")) - pattern_License_Extend_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"api", "v1", "license", "extend"}, "")) + pattern_License_Update_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"api", "v1", "license", "number"}, "")) + + pattern_License_Delete_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"api", "v1", "license", "number"}, "")) + + pattern_License_Register_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"api", "v1", "license", "register"}, "")) ) var ( + forward_License_Create_0 = runtime.ForwardResponseMessage + forward_License_Read_0 = runtime.ForwardResponseMessage - forward_License_Register_0 = runtime.ForwardResponseMessage + forward_License_Update_0 = runtime.ForwardResponseMessage + + forward_License_Delete_0 = runtime.ForwardResponseMessage - forward_License_Extend_0 = runtime.ForwardResponseMessage + forward_License_Register_0 = runtime.ForwardResponseMessage ) diff --git a/pkg/transport/grpc/license.proto b/pkg/transport/grpc/license.proto index f8a3da2..106e9aa 100644 --- a/pkg/transport/grpc/license.proto +++ b/pkg/transport/grpc/license.proto @@ -7,7 +7,7 @@ import "protoc-gen-swagger/options/annotations.proto"; option (grpc.gateway.protoc_gen_swagger.options.openapiv2_swagger) = { info: { - title: "Access Guard as a Service"; + title: "Access Control as a Service"; version: "dev"; contact: { name: "Guard project of Hugs Platform"; @@ -17,44 +17,73 @@ option (grpc.gateway.protoc_gen_swagger.options.openapiv2_swagger) = { }; }; +message CreateLicenseRequest { + option (grpc.gateway.protoc_gen_swagger.options.openapiv2_schema) = {}; + + string number = 1 [(grpc.gateway.protoc_gen_swagger.options.openapiv2_field) = {pattern: "[0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}"}]; +} + +message CreateLicenseResponse {} + message ReadLicenseRequest { option (grpc.gateway.protoc_gen_swagger.options.openapiv2_schema) = {}; - string id = 1 [(grpc.gateway.protoc_gen_swagger.options.openapiv2_field) = {pattern: "[0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}"}]; + string number = 1 [(grpc.gateway.protoc_gen_swagger.options.openapiv2_field) = {pattern: "[0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}"}]; } message ReadLicenseResponse {} -message RegisterLicenseRequest { +message UpdateLicenseRequest { option (grpc.gateway.protoc_gen_swagger.options.openapiv2_schema) = {}; - string id = 1 [(grpc.gateway.protoc_gen_swagger.options.openapiv2_field) = {pattern: "[0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}"}]; + string number = 1 [(grpc.gateway.protoc_gen_swagger.options.openapiv2_field) = {pattern: "[0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}"}]; } -message RegisterLicenseResponse {} +message UpdateLicenseResponse {} + +message DeleteLicenseRequest { + option (grpc.gateway.protoc_gen_swagger.options.openapiv2_schema) = {}; + + string number = 1 [(grpc.gateway.protoc_gen_swagger.options.openapiv2_field) = {pattern: "[0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}"}]; +} + +message DeleteLicenseResponse {} -message ExtendLicenseRequest { +message RegisterLicenseRequest { option (grpc.gateway.protoc_gen_swagger.options.openapiv2_schema) = {}; string id = 1 [(grpc.gateway.protoc_gen_swagger.options.openapiv2_field) = {pattern: "[0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}"}]; } -message ExtendLicenseResponse {} +message RegisterLicenseResponse {} service License { + rpc Create (CreateLicenseRequest) returns (CreateLicenseResponse) { + option (google.api.http) = { + post: "/api/v1/license" + }; + } rpc Read (ReadLicenseRequest) returns (ReadLicenseResponse) { option (google.api.http) = { - get: "/api/v1/license/{id}" + get: "/api/v1/license/{number}" }; } - rpc Register (RegisterLicenseRequest) returns (RegisterLicenseResponse) { + rpc Update (UpdateLicenseRequest) returns (UpdateLicenseResponse) { option (google.api.http) = { - post: "/api/v1/license/register" + put: "/api/v1/license/{number}" }; } - rpc Extend (ExtendLicenseRequest) returns (ExtendLicenseResponse) { + rpc Delete (DeleteLicenseRequest) returns (DeleteLicenseResponse) { option (google.api.http) = { - put: "/api/v1/license/extend" + delete: "/api/v1/license/{number}" + }; + } + + // --- + + rpc Register (RegisterLicenseRequest) returns (RegisterLicenseResponse) { + option (google.api.http) = { + post: "/api/v1/license/register" }; } } diff --git a/pkg/transport/grpc/license.proxy.go b/pkg/transport/grpc/license.proxy.go index 415556d..1565393 100644 --- a/pkg/transport/grpc/license.proxy.go +++ b/pkg/transport/grpc/license.proxy.go @@ -1,17 +1,11 @@ package grpc -// Proxy TODO issue#docs -type Proxy interface { - // Convert TODO issue#docs - Convert() interface{} -} - -// ExtendLicenseRequestProxy TODO issue#docs -type ExtendLicenseRequestProxy struct{} +// CreateLicenseRequestProxy TODO issue#docs +type CreateLicenseRequestProxy struct{} // Convert TODO issue#docs -func (proxy ExtendLicenseRequestProxy) Convert() interface{} { - return &ExtendLicenseRequest{} +func (proxy CreateLicenseRequestProxy) Convert() interface{} { + return &CreateLicenseRequest{} } // ReadLicenseRequestProxy TODO issue#docs @@ -22,6 +16,24 @@ func (proxy ReadLicenseRequestProxy) Convert() interface{} { return &ReadLicenseRequest{} } +// UpdateLicenseRequestProxy TODO issue#docs +type UpdateLicenseRequestProxy struct{} + +// Convert TODO issue#docs +func (proxy UpdateLicenseRequestProxy) Convert() interface{} { + return &UpdateLicenseRequest{} +} + +// DeleteLicenseRequestProxy TODO issue#docs +type DeleteLicenseRequestProxy struct{} + +// Convert TODO issue#docs +func (proxy DeleteLicenseRequestProxy) Convert() interface{} { + return &DeleteLicenseRequest{} +} + +// --- + // RegisterLicenseRequestProxy TODO issue#docs type RegisterLicenseRequestProxy struct{} diff --git a/pkg/transport/grpc/license_server.go b/pkg/transport/grpc/license_server.go index c0c7130..8e7fe34 100644 --- a/pkg/transport/grpc/license_server.go +++ b/pkg/transport/grpc/license_server.go @@ -19,17 +19,17 @@ type licenseServer struct { storage ProtectedStorage } -// Extend TODO issue#docs -func (server *licenseServer) Extend(ctx context.Context, req *ExtendLicenseRequest) (*ExtendLicenseResponse, error) { +// Create TODO issue#docs +func (server *licenseServer) Create(ctx context.Context, req *CreateLicenseRequest) (*CreateLicenseResponse, error) { token, authErr := middleware.TokenExtractor(ctx) if authErr != nil { return nil, authErr } - if _, err := server.storage.ExtendLicense(ctx, token, query.ExtendLicense{}); err != nil { + if _, err := server.storage.CreateLicense(ctx, token, query.CreateLicense{}); err != nil { return nil, status.Errorf(codes.Unauthenticated, "token: %s; something happen: %v", token, err) } - log.Printf("LicenseServer.Extend was called with token %q\n", token) - return &ExtendLicenseResponse{}, nil + log.Printf("LicenseServer.Create was called with token %q\n", token) + return &CreateLicenseResponse{}, nil } // Read TODO issue#docs @@ -45,6 +45,34 @@ func (server *licenseServer) Read(ctx context.Context, req *ReadLicenseRequest) return &ReadLicenseResponse{}, nil } +// Update TODO issue#docs +func (server *licenseServer) Update(ctx context.Context, req *UpdateLicenseRequest) (*UpdateLicenseResponse, error) { + token, authErr := middleware.TokenExtractor(ctx) + if authErr != nil { + return nil, authErr + } + if _, err := server.storage.UpdateLicense(ctx, token, query.UpdateLicense{}); err != nil { + return nil, status.Errorf(codes.Unauthenticated, "token: %s; something happen: %v", token, err) + } + log.Printf("LicenseServer.Update was called with token %q\n", token) + return &UpdateLicenseResponse{}, nil +} + +// Delete TODO issue#docs +func (server *licenseServer) Delete(ctx context.Context, req *DeleteLicenseRequest) (*DeleteLicenseResponse, error) { + token, authErr := middleware.TokenExtractor(ctx) + if authErr != nil { + return nil, authErr + } + if _, err := server.storage.DeleteLicense(ctx, token, query.DeleteLicense{}); err != nil { + return nil, status.Errorf(codes.Unauthenticated, "token: %s; something happen: %v", token, err) + } + log.Printf("LicenseServer.Update was called with token %q\n", token) + return &DeleteLicenseResponse{}, nil +} + +// --- + // Register TODO issue#docs func (server *licenseServer) Register(ctx context.Context, req *RegisterLicenseRequest) (*RegisterLicenseResponse, error) { token, authErr := middleware.TokenExtractor(ctx) diff --git a/pkg/transport/grpc/proxy.go b/pkg/transport/grpc/proxy.go new file mode 100644 index 0000000..57c4cab --- /dev/null +++ b/pkg/transport/grpc/proxy.go @@ -0,0 +1,7 @@ +package grpc + +// Proxy TODO issue#docs +type Proxy interface { + // Convert TODO issue#docs + Convert() interface{} +}