From e69c5e8b08fd2aa9dc746df46e953571508c99cc Mon Sep 17 00:00:00 2001 From: Madhur Shrimal Date: Fri, 17 Jan 2025 11:36:00 -0800 Subject: [PATCH] feat: add api key and admin API (#7) * feat: add api key and admin API * admin bindings * change admin input to g1 public key * update admin api --- build.rs | 3 +- pkg/api/v1/admin.pb.go | 699 +++++++++++++++++++++++++++++++++ pkg/api/v1/admin.pb.gw.go | 395 +++++++++++++++++++ pkg/api/v1/admin_grpc.pb.go | 220 +++++++++++ pkg/api/v1/key_manager.pb.go | 149 ++++--- proto/admin.proto | 52 +++ proto/key_manager.proto | 5 + src/generated/admin.v1.rs | 563 ++++++++++++++++++++++++++ src/generated/keymanager.v1.rs | 6 + swagger/grpc.swagger.yaml | 138 ++++++- 10 files changed, 2164 insertions(+), 66 deletions(-) create mode 100644 pkg/api/v1/admin.pb.go create mode 100644 pkg/api/v1/admin.pb.gw.go create mode 100644 pkg/api/v1/admin_grpc.pb.go create mode 100644 proto/admin.proto create mode 100644 src/generated/admin.v1.rs diff --git a/build.rs b/build.rs index a59ef3d..c8445d2 100644 --- a/build.rs +++ b/build.rs @@ -3,7 +3,8 @@ use std::path::PathBuf; fn main() -> Result<(), Box> { let proto_files = vec![ "proto/key_manager.proto", - "proto/signer.proto" + "proto/signer.proto", + "proto/admin.proto" ]; let proto_include_dirs = vec![ diff --git a/pkg/api/v1/admin.pb.go b/pkg/api/v1/admin.pb.go new file mode 100644 index 0000000..fdcac10 --- /dev/null +++ b/pkg/api/v1/admin.pb.go @@ -0,0 +1,699 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.34.1 +// protoc (unknown) +// source: admin.proto + +package v1 + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type LockKeyRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + PublicKeyG1 string `protobuf:"bytes,1,opt,name=public_key_g1,json=publicKeyG1,proto3" json:"public_key_g1,omitempty"` +} + +func (x *LockKeyRequest) Reset() { + *x = LockKeyRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_admin_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *LockKeyRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*LockKeyRequest) ProtoMessage() {} + +func (x *LockKeyRequest) ProtoReflect() protoreflect.Message { + mi := &file_admin_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use LockKeyRequest.ProtoReflect.Descriptor instead. +func (*LockKeyRequest) Descriptor() ([]byte, []int) { + return file_admin_proto_rawDescGZIP(), []int{0} +} + +func (x *LockKeyRequest) GetPublicKeyG1() string { + if x != nil { + return x.PublicKeyG1 + } + return "" +} + +type LockKeyResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *LockKeyResponse) Reset() { + *x = LockKeyResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_admin_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *LockKeyResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*LockKeyResponse) ProtoMessage() {} + +func (x *LockKeyResponse) ProtoReflect() protoreflect.Message { + mi := &file_admin_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use LockKeyResponse.ProtoReflect.Descriptor instead. +func (*LockKeyResponse) Descriptor() ([]byte, []int) { + return file_admin_proto_rawDescGZIP(), []int{1} +} + +type UnlockKeyRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + PublicKeyG1 string `protobuf:"bytes,1,opt,name=public_key_g1,json=publicKeyG1,proto3" json:"public_key_g1,omitempty"` +} + +func (x *UnlockKeyRequest) Reset() { + *x = UnlockKeyRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_admin_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UnlockKeyRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UnlockKeyRequest) ProtoMessage() {} + +func (x *UnlockKeyRequest) ProtoReflect() protoreflect.Message { + mi := &file_admin_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UnlockKeyRequest.ProtoReflect.Descriptor instead. +func (*UnlockKeyRequest) Descriptor() ([]byte, []int) { + return file_admin_proto_rawDescGZIP(), []int{2} +} + +func (x *UnlockKeyRequest) GetPublicKeyG1() string { + if x != nil { + return x.PublicKeyG1 + } + return "" +} + +type UnlockKeyResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *UnlockKeyResponse) Reset() { + *x = UnlockKeyResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_admin_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UnlockKeyResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UnlockKeyResponse) ProtoMessage() {} + +func (x *UnlockKeyResponse) ProtoReflect() protoreflect.Message { + mi := &file_admin_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UnlockKeyResponse.ProtoReflect.Descriptor instead. +func (*UnlockKeyResponse) Descriptor() ([]byte, []int) { + return file_admin_proto_rawDescGZIP(), []int{3} +} + +type GenerateNewApiKeyRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + PublicKeyG1 string `protobuf:"bytes,1,opt,name=public_key_g1,json=publicKeyG1,proto3" json:"public_key_g1,omitempty"` +} + +func (x *GenerateNewApiKeyRequest) Reset() { + *x = GenerateNewApiKeyRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_admin_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GenerateNewApiKeyRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GenerateNewApiKeyRequest) ProtoMessage() {} + +func (x *GenerateNewApiKeyRequest) ProtoReflect() protoreflect.Message { + mi := &file_admin_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GenerateNewApiKeyRequest.ProtoReflect.Descriptor instead. +func (*GenerateNewApiKeyRequest) Descriptor() ([]byte, []int) { + return file_admin_proto_rawDescGZIP(), []int{4} +} + +func (x *GenerateNewApiKeyRequest) GetPublicKeyG1() string { + if x != nil { + return x.PublicKeyG1 + } + return "" +} + +type GenerateNewApiKeyResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + PublicKeyG1 string `protobuf:"bytes,1,opt,name=public_key_g1,json=publicKeyG1,proto3" json:"public_key_g1,omitempty"` + ApiKey string `protobuf:"bytes,2,opt,name=api_key,json=apiKey,proto3" json:"api_key,omitempty"` +} + +func (x *GenerateNewApiKeyResponse) Reset() { + *x = GenerateNewApiKeyResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_admin_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GenerateNewApiKeyResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GenerateNewApiKeyResponse) ProtoMessage() {} + +func (x *GenerateNewApiKeyResponse) ProtoReflect() protoreflect.Message { + mi := &file_admin_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GenerateNewApiKeyResponse.ProtoReflect.Descriptor instead. +func (*GenerateNewApiKeyResponse) Descriptor() ([]byte, []int) { + return file_admin_proto_rawDescGZIP(), []int{5} +} + +func (x *GenerateNewApiKeyResponse) GetPublicKeyG1() string { + if x != nil { + return x.PublicKeyG1 + } + return "" +} + +func (x *GenerateNewApiKeyResponse) GetApiKey() string { + if x != nil { + return x.ApiKey + } + return "" +} + +type KeyMetadata struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + PublicKeyG1 string `protobuf:"bytes,1,opt,name=public_key_g1,json=publicKeyG1,proto3" json:"public_key_g1,omitempty"` + PublicKeyG2 string `protobuf:"bytes,2,opt,name=public_key_g2,json=publicKeyG2,proto3" json:"public_key_g2,omitempty"` + Locked bool `protobuf:"varint,3,opt,name=locked,proto3" json:"locked,omitempty"` + CreatedAt string `protobuf:"bytes,4,opt,name=created_at,json=createdAt,proto3" json:"created_at,omitempty"` + UpdatedAt string `protobuf:"bytes,5,opt,name=updated_at,json=updatedAt,proto3" json:"updated_at,omitempty"` +} + +func (x *KeyMetadata) Reset() { + *x = KeyMetadata{} + if protoimpl.UnsafeEnabled { + mi := &file_admin_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *KeyMetadata) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*KeyMetadata) ProtoMessage() {} + +func (x *KeyMetadata) ProtoReflect() protoreflect.Message { + mi := &file_admin_proto_msgTypes[6] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use KeyMetadata.ProtoReflect.Descriptor instead. +func (*KeyMetadata) Descriptor() ([]byte, []int) { + return file_admin_proto_rawDescGZIP(), []int{6} +} + +func (x *KeyMetadata) GetPublicKeyG1() string { + if x != nil { + return x.PublicKeyG1 + } + return "" +} + +func (x *KeyMetadata) GetPublicKeyG2() string { + if x != nil { + return x.PublicKeyG2 + } + return "" +} + +func (x *KeyMetadata) GetLocked() bool { + if x != nil { + return x.Locked + } + return false +} + +func (x *KeyMetadata) GetCreatedAt() string { + if x != nil { + return x.CreatedAt + } + return "" +} + +func (x *KeyMetadata) GetUpdatedAt() string { + if x != nil { + return x.UpdatedAt + } + return "" +} + +type ListAllKeysRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *ListAllKeysRequest) Reset() { + *x = ListAllKeysRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_admin_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ListAllKeysRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ListAllKeysRequest) ProtoMessage() {} + +func (x *ListAllKeysRequest) ProtoReflect() protoreflect.Message { + mi := &file_admin_proto_msgTypes[7] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ListAllKeysRequest.ProtoReflect.Descriptor instead. +func (*ListAllKeysRequest) Descriptor() ([]byte, []int) { + return file_admin_proto_rawDescGZIP(), []int{7} +} + +type ListAllKeysResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Keys []*KeyMetadata `protobuf:"bytes,1,rep,name=keys,proto3" json:"keys,omitempty"` +} + +func (x *ListAllKeysResponse) Reset() { + *x = ListAllKeysResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_admin_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ListAllKeysResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ListAllKeysResponse) ProtoMessage() {} + +func (x *ListAllKeysResponse) ProtoReflect() protoreflect.Message { + mi := &file_admin_proto_msgTypes[8] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ListAllKeysResponse.ProtoReflect.Descriptor instead. +func (*ListAllKeysResponse) Descriptor() ([]byte, []int) { + return file_admin_proto_rawDescGZIP(), []int{8} +} + +func (x *ListAllKeysResponse) GetKeys() []*KeyMetadata { + if x != nil { + return x.Keys + } + return nil +} + +var File_admin_proto protoreflect.FileDescriptor + +var file_admin_proto_rawDesc = []byte{ + 0x0a, 0x0b, 0x61, 0x64, 0x6d, 0x69, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x08, 0x61, + 0x64, 0x6d, 0x69, 0x6e, 0x2e, 0x76, 0x31, 0x22, 0x34, 0x0a, 0x0e, 0x4c, 0x6f, 0x63, 0x6b, 0x4b, + 0x65, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x22, 0x0a, 0x0d, 0x70, 0x75, 0x62, + 0x6c, 0x69, 0x63, 0x5f, 0x6b, 0x65, 0x79, 0x5f, 0x67, 0x31, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0b, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x4b, 0x65, 0x79, 0x47, 0x31, 0x22, 0x11, 0x0a, + 0x0f, 0x4c, 0x6f, 0x63, 0x6b, 0x4b, 0x65, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x22, 0x36, 0x0a, 0x10, 0x55, 0x6e, 0x6c, 0x6f, 0x63, 0x6b, 0x4b, 0x65, 0x79, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x12, 0x22, 0x0a, 0x0d, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x5f, 0x6b, + 0x65, 0x79, 0x5f, 0x67, 0x31, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x70, 0x75, 0x62, + 0x6c, 0x69, 0x63, 0x4b, 0x65, 0x79, 0x47, 0x31, 0x22, 0x13, 0x0a, 0x11, 0x55, 0x6e, 0x6c, 0x6f, + 0x63, 0x6b, 0x4b, 0x65, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x3e, 0x0a, + 0x18, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x4e, 0x65, 0x77, 0x41, 0x70, 0x69, 0x4b, + 0x65, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x22, 0x0a, 0x0d, 0x70, 0x75, 0x62, + 0x6c, 0x69, 0x63, 0x5f, 0x6b, 0x65, 0x79, 0x5f, 0x67, 0x31, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0b, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x4b, 0x65, 0x79, 0x47, 0x31, 0x22, 0x58, 0x0a, + 0x19, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x4e, 0x65, 0x77, 0x41, 0x70, 0x69, 0x4b, + 0x65, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x22, 0x0a, 0x0d, 0x70, 0x75, + 0x62, 0x6c, 0x69, 0x63, 0x5f, 0x6b, 0x65, 0x79, 0x5f, 0x67, 0x31, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0b, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x4b, 0x65, 0x79, 0x47, 0x31, 0x12, 0x17, + 0x0a, 0x07, 0x61, 0x70, 0x69, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x06, 0x61, 0x70, 0x69, 0x4b, 0x65, 0x79, 0x22, 0xab, 0x01, 0x0a, 0x0b, 0x4b, 0x65, 0x79, 0x4d, + 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x22, 0x0a, 0x0d, 0x70, 0x75, 0x62, 0x6c, 0x69, + 0x63, 0x5f, 0x6b, 0x65, 0x79, 0x5f, 0x67, 0x31, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, + 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x4b, 0x65, 0x79, 0x47, 0x31, 0x12, 0x22, 0x0a, 0x0d, 0x70, + 0x75, 0x62, 0x6c, 0x69, 0x63, 0x5f, 0x6b, 0x65, 0x79, 0x5f, 0x67, 0x32, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0b, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x4b, 0x65, 0x79, 0x47, 0x32, 0x12, + 0x16, 0x0a, 0x06, 0x6c, 0x6f, 0x63, 0x6b, 0x65, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, + 0x06, 0x6c, 0x6f, 0x63, 0x6b, 0x65, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, + 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x63, 0x72, 0x65, + 0x61, 0x74, 0x65, 0x64, 0x41, 0x74, 0x12, 0x1d, 0x0a, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, + 0x64, 0x5f, 0x61, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x75, 0x70, 0x64, 0x61, + 0x74, 0x65, 0x64, 0x41, 0x74, 0x22, 0x14, 0x0a, 0x12, 0x4c, 0x69, 0x73, 0x74, 0x41, 0x6c, 0x6c, + 0x4b, 0x65, 0x79, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x40, 0x0a, 0x13, 0x4c, + 0x69, 0x73, 0x74, 0x41, 0x6c, 0x6c, 0x4b, 0x65, 0x79, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x12, 0x29, 0x0a, 0x04, 0x6b, 0x65, 0x79, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, + 0x32, 0x15, 0x2e, 0x61, 0x64, 0x6d, 0x69, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x4b, 0x65, 0x79, 0x4d, + 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x52, 0x04, 0x6b, 0x65, 0x79, 0x73, 0x32, 0xbf, 0x02, + 0x0a, 0x05, 0x41, 0x64, 0x6d, 0x69, 0x6e, 0x12, 0x40, 0x0a, 0x07, 0x4c, 0x6f, 0x63, 0x6b, 0x4b, + 0x65, 0x79, 0x12, 0x18, 0x2e, 0x61, 0x64, 0x6d, 0x69, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x6f, + 0x63, 0x6b, 0x4b, 0x65, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x61, + 0x64, 0x6d, 0x69, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x6f, 0x63, 0x6b, 0x4b, 0x65, 0x79, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x46, 0x0a, 0x09, 0x55, 0x6e, 0x6c, + 0x6f, 0x63, 0x6b, 0x4b, 0x65, 0x79, 0x12, 0x1a, 0x2e, 0x61, 0x64, 0x6d, 0x69, 0x6e, 0x2e, 0x76, + 0x31, 0x2e, 0x55, 0x6e, 0x6c, 0x6f, 0x63, 0x6b, 0x4b, 0x65, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x61, 0x64, 0x6d, 0x69, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x6e, + 0x6c, 0x6f, 0x63, 0x6b, 0x4b, 0x65, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, + 0x00, 0x12, 0x5e, 0x0a, 0x11, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x4e, 0x65, 0x77, + 0x41, 0x70, 0x69, 0x4b, 0x65, 0x79, 0x12, 0x22, 0x2e, 0x61, 0x64, 0x6d, 0x69, 0x6e, 0x2e, 0x76, + 0x31, 0x2e, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x4e, 0x65, 0x77, 0x41, 0x70, 0x69, + 0x4b, 0x65, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x23, 0x2e, 0x61, 0x64, 0x6d, + 0x69, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x4e, 0x65, + 0x77, 0x41, 0x70, 0x69, 0x4b, 0x65, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, + 0x00, 0x12, 0x4c, 0x0a, 0x0b, 0x4c, 0x69, 0x73, 0x74, 0x41, 0x6c, 0x6c, 0x4b, 0x65, 0x79, 0x73, + 0x12, 0x1c, 0x2e, 0x61, 0x64, 0x6d, 0x69, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74, + 0x41, 0x6c, 0x6c, 0x4b, 0x65, 0x79, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, + 0x2e, 0x61, 0x64, 0x6d, 0x69, 0x6e, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x41, 0x6c, + 0x6c, 0x4b, 0x65, 0x79, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, + 0x2e, 0x5a, 0x2c, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6c, 0x61, + 0x79, 0x72, 0x2d, 0x6c, 0x61, 0x62, 0x73, 0x2f, 0x63, 0x65, 0x72, 0x62, 0x65, 0x72, 0x75, 0x73, + 0x2d, 0x61, 0x70, 0x69, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x62, + 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_admin_proto_rawDescOnce sync.Once + file_admin_proto_rawDescData = file_admin_proto_rawDesc +) + +func file_admin_proto_rawDescGZIP() []byte { + file_admin_proto_rawDescOnce.Do(func() { + file_admin_proto_rawDescData = protoimpl.X.CompressGZIP(file_admin_proto_rawDescData) + }) + return file_admin_proto_rawDescData +} + +var file_admin_proto_msgTypes = make([]protoimpl.MessageInfo, 9) +var file_admin_proto_goTypes = []interface{}{ + (*LockKeyRequest)(nil), // 0: admin.v1.LockKeyRequest + (*LockKeyResponse)(nil), // 1: admin.v1.LockKeyResponse + (*UnlockKeyRequest)(nil), // 2: admin.v1.UnlockKeyRequest + (*UnlockKeyResponse)(nil), // 3: admin.v1.UnlockKeyResponse + (*GenerateNewApiKeyRequest)(nil), // 4: admin.v1.GenerateNewApiKeyRequest + (*GenerateNewApiKeyResponse)(nil), // 5: admin.v1.GenerateNewApiKeyResponse + (*KeyMetadata)(nil), // 6: admin.v1.KeyMetadata + (*ListAllKeysRequest)(nil), // 7: admin.v1.ListAllKeysRequest + (*ListAllKeysResponse)(nil), // 8: admin.v1.ListAllKeysResponse +} +var file_admin_proto_depIdxs = []int32{ + 6, // 0: admin.v1.ListAllKeysResponse.keys:type_name -> admin.v1.KeyMetadata + 0, // 1: admin.v1.Admin.LockKey:input_type -> admin.v1.LockKeyRequest + 2, // 2: admin.v1.Admin.UnlockKey:input_type -> admin.v1.UnlockKeyRequest + 4, // 3: admin.v1.Admin.GenerateNewApiKey:input_type -> admin.v1.GenerateNewApiKeyRequest + 7, // 4: admin.v1.Admin.ListAllKeys:input_type -> admin.v1.ListAllKeysRequest + 1, // 5: admin.v1.Admin.LockKey:output_type -> admin.v1.LockKeyResponse + 3, // 6: admin.v1.Admin.UnlockKey:output_type -> admin.v1.UnlockKeyResponse + 5, // 7: admin.v1.Admin.GenerateNewApiKey:output_type -> admin.v1.GenerateNewApiKeyResponse + 8, // 8: admin.v1.Admin.ListAllKeys:output_type -> admin.v1.ListAllKeysResponse + 5, // [5:9] is the sub-list for method output_type + 1, // [1:5] is the sub-list for method input_type + 1, // [1:1] is the sub-list for extension type_name + 1, // [1:1] is the sub-list for extension extendee + 0, // [0:1] is the sub-list for field type_name +} + +func init() { file_admin_proto_init() } +func file_admin_proto_init() { + if File_admin_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_admin_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*LockKeyRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_admin_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*LockKeyResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_admin_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*UnlockKeyRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_admin_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*UnlockKeyResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_admin_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GenerateNewApiKeyRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_admin_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GenerateNewApiKeyResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_admin_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*KeyMetadata); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_admin_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ListAllKeysRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_admin_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ListAllKeysResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_admin_proto_rawDesc, + NumEnums: 0, + NumMessages: 9, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_admin_proto_goTypes, + DependencyIndexes: file_admin_proto_depIdxs, + MessageInfos: file_admin_proto_msgTypes, + }.Build() + File_admin_proto = out.File + file_admin_proto_rawDesc = nil + file_admin_proto_goTypes = nil + file_admin_proto_depIdxs = nil +} diff --git a/pkg/api/v1/admin.pb.gw.go b/pkg/api/v1/admin.pb.gw.go new file mode 100644 index 0000000..f4039f2 --- /dev/null +++ b/pkg/api/v1/admin.pb.gw.go @@ -0,0 +1,395 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: admin.proto + +/* +Package v1 is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package v1 + +import ( + "context" + "io" + "net/http" + + "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" + "github.com/grpc-ecosystem/grpc-gateway/v2/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" + "google.golang.org/protobuf/proto" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = metadata.Join + +func request_Admin_LockKey_0(ctx context.Context, marshaler runtime.Marshaler, client AdminClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq LockKeyRequest + var metadata runtime.ServerMetadata + + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.LockKey(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Admin_LockKey_0(ctx context.Context, marshaler runtime.Marshaler, server AdminServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq LockKeyRequest + var metadata runtime.ServerMetadata + + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.LockKey(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Admin_UnlockKey_0(ctx context.Context, marshaler runtime.Marshaler, client AdminClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq UnlockKeyRequest + var metadata runtime.ServerMetadata + + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.UnlockKey(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Admin_UnlockKey_0(ctx context.Context, marshaler runtime.Marshaler, server AdminServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq UnlockKeyRequest + var metadata runtime.ServerMetadata + + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.UnlockKey(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Admin_GenerateNewApiKey_0(ctx context.Context, marshaler runtime.Marshaler, client AdminClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq GenerateNewApiKeyRequest + var metadata runtime.ServerMetadata + + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.GenerateNewApiKey(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Admin_GenerateNewApiKey_0(ctx context.Context, marshaler runtime.Marshaler, server AdminServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq GenerateNewApiKeyRequest + var metadata runtime.ServerMetadata + + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.GenerateNewApiKey(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Admin_ListAllKeys_0(ctx context.Context, marshaler runtime.Marshaler, client AdminClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ListAllKeysRequest + var metadata runtime.ServerMetadata + + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.ListAllKeys(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Admin_ListAllKeys_0(ctx context.Context, marshaler runtime.Marshaler, server AdminServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ListAllKeysRequest + var metadata runtime.ServerMetadata + + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.ListAllKeys(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterAdminHandlerServer registers the http handlers for service Admin to "mux". +// UnaryRPC :call AdminServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterAdminHandlerFromEndpoint instead. +// GRPC interceptors will not work for this type of registration. To use interceptors, you must use the "runtime.WithMiddlewares" option in the "runtime.NewServeMux" call. +func RegisterAdminHandlerServer(ctx context.Context, mux *runtime.ServeMux, server AdminServer) error { + + mux.Handle("POST", pattern_Admin_LockKey_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/admin.v1.Admin/LockKey", runtime.WithHTTPPathPattern("/admin.v1.Admin/LockKey")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Admin_LockKey_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_Admin_LockKey_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("POST", pattern_Admin_UnlockKey_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/admin.v1.Admin/UnlockKey", runtime.WithHTTPPathPattern("/admin.v1.Admin/UnlockKey")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Admin_UnlockKey_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_Admin_UnlockKey_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("POST", pattern_Admin_GenerateNewApiKey_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/admin.v1.Admin/GenerateNewApiKey", runtime.WithHTTPPathPattern("/admin.v1.Admin/GenerateNewApiKey")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Admin_GenerateNewApiKey_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_Admin_GenerateNewApiKey_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("POST", pattern_Admin_ListAllKeys_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/admin.v1.Admin/ListAllKeys", runtime.WithHTTPPathPattern("/admin.v1.Admin/ListAllKeys")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Admin_ListAllKeys_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_Admin_ListAllKeys_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterAdminHandlerFromEndpoint is same as RegisterAdminHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterAdminHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.NewClient(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Errorf("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Errorf("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterAdminHandler(ctx, mux, conn) +} + +// RegisterAdminHandler registers the http handlers for service Admin to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterAdminHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterAdminHandlerClient(ctx, mux, NewAdminClient(conn)) +} + +// RegisterAdminHandlerClient registers the http handlers for service Admin +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "AdminClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "AdminClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "AdminClient" to call the correct interceptors. This client ignores the HTTP middlewares. +func RegisterAdminHandlerClient(ctx context.Context, mux *runtime.ServeMux, client AdminClient) error { + + mux.Handle("POST", pattern_Admin_LockKey_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/admin.v1.Admin/LockKey", runtime.WithHTTPPathPattern("/admin.v1.Admin/LockKey")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Admin_LockKey_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_Admin_LockKey_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("POST", pattern_Admin_UnlockKey_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/admin.v1.Admin/UnlockKey", runtime.WithHTTPPathPattern("/admin.v1.Admin/UnlockKey")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Admin_UnlockKey_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_Admin_UnlockKey_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("POST", pattern_Admin_GenerateNewApiKey_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/admin.v1.Admin/GenerateNewApiKey", runtime.WithHTTPPathPattern("/admin.v1.Admin/GenerateNewApiKey")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Admin_GenerateNewApiKey_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_Admin_GenerateNewApiKey_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("POST", pattern_Admin_ListAllKeys_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/admin.v1.Admin/ListAllKeys", runtime.WithHTTPPathPattern("/admin.v1.Admin/ListAllKeys")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Admin_ListAllKeys_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_Admin_ListAllKeys_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Admin_LockKey_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"admin.v1.Admin", "LockKey"}, "")) + + pattern_Admin_UnlockKey_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"admin.v1.Admin", "UnlockKey"}, "")) + + pattern_Admin_GenerateNewApiKey_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"admin.v1.Admin", "GenerateNewApiKey"}, "")) + + pattern_Admin_ListAllKeys_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"admin.v1.Admin", "ListAllKeys"}, "")) +) + +var ( + forward_Admin_LockKey_0 = runtime.ForwardResponseMessage + + forward_Admin_UnlockKey_0 = runtime.ForwardResponseMessage + + forward_Admin_GenerateNewApiKey_0 = runtime.ForwardResponseMessage + + forward_Admin_ListAllKeys_0 = runtime.ForwardResponseMessage +) diff --git a/pkg/api/v1/admin_grpc.pb.go b/pkg/api/v1/admin_grpc.pb.go new file mode 100644 index 0000000..0129cce --- /dev/null +++ b/pkg/api/v1/admin_grpc.pb.go @@ -0,0 +1,220 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.3.0 +// - protoc (unknown) +// source: admin.proto + +package v1 + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.32.0 or later. +const _ = grpc.SupportPackageIsVersion7 + +const ( + Admin_LockKey_FullMethodName = "/admin.v1.Admin/LockKey" + Admin_UnlockKey_FullMethodName = "/admin.v1.Admin/UnlockKey" + Admin_GenerateNewApiKey_FullMethodName = "/admin.v1.Admin/GenerateNewApiKey" + Admin_ListAllKeys_FullMethodName = "/admin.v1.Admin/ListAllKeys" +) + +// AdminClient is the client API for Admin service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type AdminClient interface { + LockKey(ctx context.Context, in *LockKeyRequest, opts ...grpc.CallOption) (*LockKeyResponse, error) + UnlockKey(ctx context.Context, in *UnlockKeyRequest, opts ...grpc.CallOption) (*UnlockKeyResponse, error) + GenerateNewApiKey(ctx context.Context, in *GenerateNewApiKeyRequest, opts ...grpc.CallOption) (*GenerateNewApiKeyResponse, error) + ListAllKeys(ctx context.Context, in *ListAllKeysRequest, opts ...grpc.CallOption) (*ListAllKeysResponse, error) +} + +type adminClient struct { + cc grpc.ClientConnInterface +} + +func NewAdminClient(cc grpc.ClientConnInterface) AdminClient { + return &adminClient{cc} +} + +func (c *adminClient) LockKey(ctx context.Context, in *LockKeyRequest, opts ...grpc.CallOption) (*LockKeyResponse, error) { + out := new(LockKeyResponse) + err := c.cc.Invoke(ctx, Admin_LockKey_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *adminClient) UnlockKey(ctx context.Context, in *UnlockKeyRequest, opts ...grpc.CallOption) (*UnlockKeyResponse, error) { + out := new(UnlockKeyResponse) + err := c.cc.Invoke(ctx, Admin_UnlockKey_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *adminClient) GenerateNewApiKey(ctx context.Context, in *GenerateNewApiKeyRequest, opts ...grpc.CallOption) (*GenerateNewApiKeyResponse, error) { + out := new(GenerateNewApiKeyResponse) + err := c.cc.Invoke(ctx, Admin_GenerateNewApiKey_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *adminClient) ListAllKeys(ctx context.Context, in *ListAllKeysRequest, opts ...grpc.CallOption) (*ListAllKeysResponse, error) { + out := new(ListAllKeysResponse) + err := c.cc.Invoke(ctx, Admin_ListAllKeys_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// AdminServer is the server API for Admin service. +// All implementations must embed UnimplementedAdminServer +// for forward compatibility +type AdminServer interface { + LockKey(context.Context, *LockKeyRequest) (*LockKeyResponse, error) + UnlockKey(context.Context, *UnlockKeyRequest) (*UnlockKeyResponse, error) + GenerateNewApiKey(context.Context, *GenerateNewApiKeyRequest) (*GenerateNewApiKeyResponse, error) + ListAllKeys(context.Context, *ListAllKeysRequest) (*ListAllKeysResponse, error) + mustEmbedUnimplementedAdminServer() +} + +// UnimplementedAdminServer must be embedded to have forward compatible implementations. +type UnimplementedAdminServer struct { +} + +func (UnimplementedAdminServer) LockKey(context.Context, *LockKeyRequest) (*LockKeyResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method LockKey not implemented") +} +func (UnimplementedAdminServer) UnlockKey(context.Context, *UnlockKeyRequest) (*UnlockKeyResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UnlockKey not implemented") +} +func (UnimplementedAdminServer) GenerateNewApiKey(context.Context, *GenerateNewApiKeyRequest) (*GenerateNewApiKeyResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GenerateNewApiKey not implemented") +} +func (UnimplementedAdminServer) ListAllKeys(context.Context, *ListAllKeysRequest) (*ListAllKeysResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ListAllKeys not implemented") +} +func (UnimplementedAdminServer) mustEmbedUnimplementedAdminServer() {} + +// UnsafeAdminServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to AdminServer will +// result in compilation errors. +type UnsafeAdminServer interface { + mustEmbedUnimplementedAdminServer() +} + +func RegisterAdminServer(s grpc.ServiceRegistrar, srv AdminServer) { + s.RegisterService(&Admin_ServiceDesc, srv) +} + +func _Admin_LockKey_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(LockKeyRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AdminServer).LockKey(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Admin_LockKey_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AdminServer).LockKey(ctx, req.(*LockKeyRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Admin_UnlockKey_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(UnlockKeyRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AdminServer).UnlockKey(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Admin_UnlockKey_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AdminServer).UnlockKey(ctx, req.(*UnlockKeyRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Admin_GenerateNewApiKey_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GenerateNewApiKeyRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AdminServer).GenerateNewApiKey(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Admin_GenerateNewApiKey_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AdminServer).GenerateNewApiKey(ctx, req.(*GenerateNewApiKeyRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Admin_ListAllKeys_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ListAllKeysRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AdminServer).ListAllKeys(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Admin_ListAllKeys_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AdminServer).ListAllKeys(ctx, req.(*ListAllKeysRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// Admin_ServiceDesc is the grpc.ServiceDesc for Admin service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var Admin_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "admin.v1.Admin", + HandlerType: (*AdminServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "LockKey", + Handler: _Admin_LockKey_Handler, + }, + { + MethodName: "UnlockKey", + Handler: _Admin_UnlockKey_Handler, + }, + { + MethodName: "GenerateNewApiKey", + Handler: _Admin_GenerateNewApiKey_Handler, + }, + { + MethodName: "ListAllKeys", + Handler: _Admin_ListAllKeys_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "admin.proto", +} diff --git a/pkg/api/v1/key_manager.pb.go b/pkg/api/v1/key_manager.pb.go index b108a9c..905d8d1 100644 --- a/pkg/api/v1/key_manager.pb.go +++ b/pkg/api/v1/key_manager.pb.go @@ -82,6 +82,8 @@ type GenerateKeyPairResponse struct { Mnemonic string `protobuf:"bytes,3,opt,name=mnemonic,proto3" json:"mnemonic,omitempty"` // G2 Public key hex of the generated keypair PublicKeyG2 string `protobuf:"bytes,4,opt,name=public_key_g2,json=publicKeyG2,proto3" json:"public_key_g2,omitempty"` + // API key associated with the keypair + ApiKey string `protobuf:"bytes,5,opt,name=api_key,json=apiKey,proto3" json:"api_key,omitempty"` } func (x *GenerateKeyPairResponse) Reset() { @@ -144,6 +146,13 @@ func (x *GenerateKeyPairResponse) GetPublicKeyG2() string { return "" } +func (x *GenerateKeyPairResponse) GetApiKey() string { + if x != nil { + return x.ApiKey + } + return "" +} + type ImportKeyRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -219,6 +228,8 @@ type ImportKeyResponse struct { PublicKeyG1 string `protobuf:"bytes,1,opt,name=public_key_g1,json=publicKeyG1,proto3" json:"public_key_g1,omitempty"` // G2 Public key hex of the imported keypair PublicKeyG2 string `protobuf:"bytes,2,opt,name=public_key_g2,json=publicKeyG2,proto3" json:"public_key_g2,omitempty"` + // API key associated with the keypair + ApiKey string `protobuf:"bytes,3,opt,name=api_key,json=apiKey,proto3" json:"api_key,omitempty"` } func (x *ImportKeyResponse) Reset() { @@ -267,6 +278,13 @@ func (x *ImportKeyResponse) GetPublicKeyG2() string { return "" } +func (x *ImportKeyResponse) GetApiKey() string { + if x != nil { + return x.ApiKey + } + return "" +} + type PublicKey struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -541,7 +559,7 @@ var file_key_manager_proto_rawDesc = []byte{ 0x76, 0x31, 0x22, 0x34, 0x0a, 0x16, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x4b, 0x65, 0x79, 0x50, 0x61, 0x69, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, - 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x22, 0x9e, 0x01, 0x0a, 0x17, 0x47, 0x65, 0x6e, + 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x22, 0xb7, 0x01, 0x0a, 0x17, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x4b, 0x65, 0x79, 0x50, 0x61, 0x69, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x22, 0x0a, 0x0d, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x5f, 0x6b, 0x65, 0x79, 0x5f, 0x67, 0x31, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x70, 0x75, 0x62, @@ -551,72 +569,75 @@ var file_key_manager_proto_rawDesc = []byte{ 0x6d, 0x6f, 0x6e, 0x69, 0x63, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x6d, 0x6e, 0x65, 0x6d, 0x6f, 0x6e, 0x69, 0x63, 0x12, 0x22, 0x0a, 0x0d, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x5f, 0x6b, 0x65, 0x79, 0x5f, 0x67, 0x32, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x70, 0x75, - 0x62, 0x6c, 0x69, 0x63, 0x4b, 0x65, 0x79, 0x47, 0x32, 0x22, 0x6b, 0x0a, 0x10, 0x49, 0x6d, 0x70, - 0x6f, 0x72, 0x74, 0x4b, 0x65, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1f, 0x0a, - 0x0b, 0x70, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x0a, 0x70, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x4b, 0x65, 0x79, 0x12, 0x1a, - 0x0a, 0x08, 0x6d, 0x6e, 0x65, 0x6d, 0x6f, 0x6e, 0x69, 0x63, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x08, 0x6d, 0x6e, 0x65, 0x6d, 0x6f, 0x6e, 0x69, 0x63, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, - 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x61, - 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x22, 0x5b, 0x0a, 0x11, 0x49, 0x6d, 0x70, 0x6f, 0x72, 0x74, - 0x4b, 0x65, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x22, 0x0a, 0x0d, 0x70, - 0x75, 0x62, 0x6c, 0x69, 0x63, 0x5f, 0x6b, 0x65, 0x79, 0x5f, 0x67, 0x31, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x0b, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x4b, 0x65, 0x79, 0x47, 0x31, 0x12, - 0x22, 0x0a, 0x0d, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x5f, 0x6b, 0x65, 0x79, 0x5f, 0x67, 0x32, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x4b, 0x65, - 0x79, 0x47, 0x32, 0x22, 0x53, 0x0a, 0x09, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x4b, 0x65, 0x79, - 0x12, 0x22, 0x0a, 0x0d, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x5f, 0x6b, 0x65, 0x79, 0x5f, 0x67, - 0x31, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x4b, - 0x65, 0x79, 0x47, 0x31, 0x12, 0x22, 0x0a, 0x0d, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x5f, 0x6b, - 0x65, 0x79, 0x5f, 0x67, 0x32, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x70, 0x75, 0x62, - 0x6c, 0x69, 0x63, 0x4b, 0x65, 0x79, 0x47, 0x32, 0x22, 0x11, 0x0a, 0x0f, 0x4c, 0x69, 0x73, 0x74, - 0x4b, 0x65, 0x79, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x4d, 0x0a, 0x10, 0x4c, - 0x69, 0x73, 0x74, 0x4b, 0x65, 0x79, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, - 0x39, 0x0a, 0x0b, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x5f, 0x6b, 0x65, 0x79, 0x73, 0x18, 0x01, - 0x20, 0x03, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x6b, 0x65, 0x79, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, - 0x72, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x4b, 0x65, 0x79, 0x52, 0x0a, - 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x4b, 0x65, 0x79, 0x73, 0x22, 0x3b, 0x0a, 0x15, 0x47, 0x65, - 0x74, 0x4b, 0x65, 0x79, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x12, 0x22, 0x0a, 0x0d, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x5f, 0x6b, 0x65, - 0x79, 0x5f, 0x67, 0x31, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x70, 0x75, 0x62, 0x6c, - 0x69, 0x63, 0x4b, 0x65, 0x79, 0x47, 0x31, 0x22, 0x9e, 0x01, 0x0a, 0x16, 0x47, 0x65, 0x74, 0x4b, - 0x65, 0x79, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x12, 0x22, 0x0a, 0x0d, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x5f, 0x6b, 0x65, 0x79, + 0x62, 0x6c, 0x69, 0x63, 0x4b, 0x65, 0x79, 0x47, 0x32, 0x12, 0x17, 0x0a, 0x07, 0x61, 0x70, 0x69, + 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x61, 0x70, 0x69, 0x4b, + 0x65, 0x79, 0x22, 0x6b, 0x0a, 0x10, 0x49, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x4b, 0x65, 0x79, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1f, 0x0a, 0x0b, 0x70, 0x72, 0x69, 0x76, 0x61, 0x74, + 0x65, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x70, 0x72, 0x69, + 0x76, 0x61, 0x74, 0x65, 0x4b, 0x65, 0x79, 0x12, 0x1a, 0x0a, 0x08, 0x6d, 0x6e, 0x65, 0x6d, 0x6f, + 0x6e, 0x69, 0x63, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x6d, 0x6e, 0x65, 0x6d, 0x6f, + 0x6e, 0x69, 0x63, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x18, + 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x22, + 0x74, 0x0a, 0x11, 0x49, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x4b, 0x65, 0x79, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x22, 0x0a, 0x0d, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x5f, 0x6b, + 0x65, 0x79, 0x5f, 0x67, 0x31, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x70, 0x75, 0x62, + 0x6c, 0x69, 0x63, 0x4b, 0x65, 0x79, 0x47, 0x31, 0x12, 0x22, 0x0a, 0x0d, 0x70, 0x75, 0x62, 0x6c, + 0x69, 0x63, 0x5f, 0x6b, 0x65, 0x79, 0x5f, 0x67, 0x32, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0b, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x4b, 0x65, 0x79, 0x47, 0x32, 0x12, 0x17, 0x0a, 0x07, + 0x61, 0x70, 0x69, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x61, + 0x70, 0x69, 0x4b, 0x65, 0x79, 0x22, 0x53, 0x0a, 0x09, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x4b, + 0x65, 0x79, 0x12, 0x22, 0x0a, 0x0d, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x5f, 0x6b, 0x65, 0x79, 0x5f, 0x67, 0x31, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x4b, 0x65, 0x79, 0x47, 0x31, 0x12, 0x22, 0x0a, 0x0d, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x5f, 0x6b, 0x65, 0x79, 0x5f, 0x67, 0x32, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x70, - 0x75, 0x62, 0x6c, 0x69, 0x63, 0x4b, 0x65, 0x79, 0x47, 0x32, 0x12, 0x1d, 0x0a, 0x0a, 0x63, 0x72, - 0x65, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, - 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x41, 0x74, 0x12, 0x1d, 0x0a, 0x0a, 0x75, 0x70, 0x64, - 0x61, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x75, - 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x41, 0x74, 0x32, 0xf2, 0x02, 0x0a, 0x0a, 0x4b, 0x65, 0x79, - 0x4d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x72, 0x12, 0x62, 0x0a, 0x0f, 0x47, 0x65, 0x6e, 0x65, 0x72, - 0x61, 0x74, 0x65, 0x4b, 0x65, 0x79, 0x50, 0x61, 0x69, 0x72, 0x12, 0x25, 0x2e, 0x6b, 0x65, 0x79, - 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x6e, 0x65, 0x72, - 0x61, 0x74, 0x65, 0x4b, 0x65, 0x79, 0x50, 0x61, 0x69, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x1a, 0x26, 0x2e, 0x6b, 0x65, 0x79, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x72, 0x2e, 0x76, - 0x31, 0x2e, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x4b, 0x65, 0x79, 0x50, 0x61, 0x69, - 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x50, 0x0a, 0x09, 0x49, - 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x4b, 0x65, 0x79, 0x12, 0x1f, 0x2e, 0x6b, 0x65, 0x79, 0x6d, 0x61, - 0x6e, 0x61, 0x67, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x2e, 0x49, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x4b, - 0x65, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x20, 0x2e, 0x6b, 0x65, 0x79, 0x6d, - 0x61, 0x6e, 0x61, 0x67, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x2e, 0x49, 0x6d, 0x70, 0x6f, 0x72, 0x74, - 0x4b, 0x65, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x4d, 0x0a, - 0x08, 0x4c, 0x69, 0x73, 0x74, 0x4b, 0x65, 0x79, 0x73, 0x12, 0x1e, 0x2e, 0x6b, 0x65, 0x79, 0x6d, - 0x61, 0x6e, 0x61, 0x67, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x4b, 0x65, - 0x79, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x6b, 0x65, 0x79, 0x6d, - 0x61, 0x6e, 0x61, 0x67, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x4b, 0x65, - 0x79, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x5f, 0x0a, 0x0e, - 0x47, 0x65, 0x74, 0x4b, 0x65, 0x79, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x24, - 0x2e, 0x6b, 0x65, 0x79, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x2e, 0x47, - 0x65, 0x74, 0x4b, 0x65, 0x79, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x1a, 0x25, 0x2e, 0x6b, 0x65, 0x79, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, - 0x72, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x4b, 0x65, 0x79, 0x4d, 0x65, 0x74, 0x61, 0x64, - 0x61, 0x74, 0x61, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x2e, 0x5a, - 0x2c, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6c, 0x61, 0x79, 0x72, - 0x2d, 0x6c, 0x61, 0x62, 0x73, 0x2f, 0x63, 0x65, 0x72, 0x62, 0x65, 0x72, 0x75, 0x73, 0x2d, 0x61, - 0x70, 0x69, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x62, 0x06, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x75, 0x62, 0x6c, 0x69, 0x63, 0x4b, 0x65, 0x79, 0x47, 0x32, 0x22, 0x11, 0x0a, 0x0f, 0x4c, 0x69, + 0x73, 0x74, 0x4b, 0x65, 0x79, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x4d, 0x0a, + 0x10, 0x4c, 0x69, 0x73, 0x74, 0x4b, 0x65, 0x79, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x12, 0x39, 0x0a, 0x0b, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x5f, 0x6b, 0x65, 0x79, 0x73, + 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x6b, 0x65, 0x79, 0x6d, 0x61, 0x6e, 0x61, + 0x67, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x4b, 0x65, 0x79, + 0x52, 0x0a, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x4b, 0x65, 0x79, 0x73, 0x22, 0x3b, 0x0a, 0x15, + 0x47, 0x65, 0x74, 0x4b, 0x65, 0x79, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x22, 0x0a, 0x0d, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x5f, + 0x6b, 0x65, 0x79, 0x5f, 0x67, 0x31, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x70, 0x75, + 0x62, 0x6c, 0x69, 0x63, 0x4b, 0x65, 0x79, 0x47, 0x31, 0x22, 0x9e, 0x01, 0x0a, 0x16, 0x47, 0x65, + 0x74, 0x4b, 0x65, 0x79, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x22, 0x0a, 0x0d, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x5f, 0x6b, + 0x65, 0x79, 0x5f, 0x67, 0x31, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x70, 0x75, 0x62, + 0x6c, 0x69, 0x63, 0x4b, 0x65, 0x79, 0x47, 0x31, 0x12, 0x22, 0x0a, 0x0d, 0x70, 0x75, 0x62, 0x6c, + 0x69, 0x63, 0x5f, 0x6b, 0x65, 0x79, 0x5f, 0x67, 0x32, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0b, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x4b, 0x65, 0x79, 0x47, 0x32, 0x12, 0x1d, 0x0a, 0x0a, + 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, + 0x52, 0x09, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x41, 0x74, 0x12, 0x1d, 0x0a, 0x0a, 0x75, + 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, + 0x09, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x41, 0x74, 0x32, 0xf2, 0x02, 0x0a, 0x0a, 0x4b, + 0x65, 0x79, 0x4d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x72, 0x12, 0x62, 0x0a, 0x0f, 0x47, 0x65, 0x6e, + 0x65, 0x72, 0x61, 0x74, 0x65, 0x4b, 0x65, 0x79, 0x50, 0x61, 0x69, 0x72, 0x12, 0x25, 0x2e, 0x6b, + 0x65, 0x79, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x6e, + 0x65, 0x72, 0x61, 0x74, 0x65, 0x4b, 0x65, 0x79, 0x50, 0x61, 0x69, 0x72, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x1a, 0x26, 0x2e, 0x6b, 0x65, 0x79, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x72, + 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x4b, 0x65, 0x79, 0x50, + 0x61, 0x69, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x50, 0x0a, + 0x09, 0x49, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x4b, 0x65, 0x79, 0x12, 0x1f, 0x2e, 0x6b, 0x65, 0x79, + 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x2e, 0x49, 0x6d, 0x70, 0x6f, 0x72, + 0x74, 0x4b, 0x65, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x20, 0x2e, 0x6b, 0x65, + 0x79, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x2e, 0x49, 0x6d, 0x70, 0x6f, + 0x72, 0x74, 0x4b, 0x65, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, + 0x4d, 0x0a, 0x08, 0x4c, 0x69, 0x73, 0x74, 0x4b, 0x65, 0x79, 0x73, 0x12, 0x1e, 0x2e, 0x6b, 0x65, + 0x79, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74, + 0x4b, 0x65, 0x79, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x6b, 0x65, + 0x79, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x2e, 0x4c, 0x69, 0x73, 0x74, + 0x4b, 0x65, 0x79, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x5f, + 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x4b, 0x65, 0x79, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, + 0x12, 0x24, 0x2e, 0x6b, 0x65, 0x79, 0x6d, 0x61, 0x6e, 0x61, 0x67, 0x65, 0x72, 0x2e, 0x76, 0x31, + 0x2e, 0x47, 0x65, 0x74, 0x4b, 0x65, 0x79, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x25, 0x2e, 0x6b, 0x65, 0x79, 0x6d, 0x61, 0x6e, 0x61, + 0x67, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x4b, 0x65, 0x79, 0x4d, 0x65, 0x74, + 0x61, 0x64, 0x61, 0x74, 0x61, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, + 0x2e, 0x5a, 0x2c, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6c, 0x61, + 0x79, 0x72, 0x2d, 0x6c, 0x61, 0x62, 0x73, 0x2f, 0x63, 0x65, 0x72, 0x62, 0x65, 0x72, 0x75, 0x73, + 0x2d, 0x61, 0x70, 0x69, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x31, 0x62, + 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/proto/admin.proto b/proto/admin.proto new file mode 100644 index 0000000..8459bb9 --- /dev/null +++ b/proto/admin.proto @@ -0,0 +1,52 @@ +syntax = "proto3"; + +package admin.v1; + +option go_package = "github.com/layr-labs/cerberus-api/pkg/api/v1"; + +service Admin { + rpc LockKey(LockKeyRequest) returns (LockKeyResponse) {} + rpc UnlockKey(UnlockKeyRequest) returns (UnlockKeyResponse) {} + rpc GenerateNewApiKey(GenerateNewApiKeyRequest) returns (GenerateNewApiKeyResponse) {} + rpc ListAllKeys(ListAllKeysRequest) returns (ListAllKeysResponse) {} +} + +message LockKeyRequest { + string public_key_g1 = 1; +} + +message LockKeyResponse { +} + +message UnlockKeyRequest { + string public_key_g1 = 1; +} + +message UnlockKeyResponse { +} + +message GenerateNewApiKeyRequest { + string public_key_g1 = 1; +} + +message GenerateNewApiKeyResponse { + string public_key_g1 = 1; + + string api_key = 2; +} + +message KeyMetadata { + string public_key_g1 = 1; + string public_key_g2 = 2; + bool locked = 3; + string created_at = 4; + string updated_at = 5; +} + +message ListAllKeysRequest { +} + +message ListAllKeysResponse { + repeated KeyMetadata keys = 1; +} + diff --git a/proto/key_manager.proto b/proto/key_manager.proto index 1b602c3..96d44d5 100644 --- a/proto/key_manager.proto +++ b/proto/key_manager.proto @@ -30,6 +30,9 @@ message GenerateKeyPairResponse { // G2 Public key hex of the generated keypair string public_key_g2 = 4; + + // API key associated with the keypair + string api_key = 5; } message ImportKeyRequest { @@ -48,6 +51,8 @@ message ImportKeyResponse { string public_key_g1 = 1; // G2 Public key hex of the imported keypair string public_key_g2 = 2; + // API key associated with the keypair + string api_key = 3; } message PublicKey { diff --git a/src/generated/admin.v1.rs b/src/generated/admin.v1.rs new file mode 100644 index 0000000..8f9bbcd --- /dev/null +++ b/src/generated/admin.v1.rs @@ -0,0 +1,563 @@ +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct LockKeyRequest { + #[prost(string, tag = "1")] + pub public_key_g1: ::prost::alloc::string::String, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct LockKeyResponse {} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct UnlockKeyRequest { + #[prost(string, tag = "1")] + pub public_key_g1: ::prost::alloc::string::String, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct UnlockKeyResponse {} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct GenerateNewApiKeyRequest { + #[prost(string, tag = "1")] + pub public_key_g1: ::prost::alloc::string::String, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct GenerateNewApiKeyResponse { + #[prost(string, tag = "1")] + pub public_key_g1: ::prost::alloc::string::String, + #[prost(string, tag = "2")] + pub api_key: ::prost::alloc::string::String, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct KeyMetadata { + #[prost(string, tag = "1")] + pub public_key_g1: ::prost::alloc::string::String, + #[prost(string, tag = "2")] + pub public_key_g2: ::prost::alloc::string::String, + #[prost(bool, tag = "3")] + pub locked: bool, + #[prost(string, tag = "4")] + pub created_at: ::prost::alloc::string::String, + #[prost(string, tag = "5")] + pub updated_at: ::prost::alloc::string::String, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct ListAllKeysRequest {} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct ListAllKeysResponse { + #[prost(message, repeated, tag = "1")] + pub keys: ::prost::alloc::vec::Vec, +} +/// Generated client implementations. +pub mod admin_client { + #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)] + use tonic::codegen::*; + use tonic::codegen::http::Uri; + #[derive(Debug, Clone)] + pub struct AdminClient { + inner: tonic::client::Grpc, + } + impl AdminClient { + /// Attempt to create a new client by connecting to a given endpoint. + pub async fn connect(dst: D) -> Result + where + D: TryInto, + D::Error: Into, + { + let conn = tonic::transport::Endpoint::new(dst)?.connect().await?; + Ok(Self::new(conn)) + } + } + impl AdminClient + where + T: tonic::client::GrpcService, + T::Error: Into, + T::ResponseBody: Body + Send + 'static, + ::Error: Into + Send, + { + pub fn new(inner: T) -> Self { + let inner = tonic::client::Grpc::new(inner); + Self { inner } + } + pub fn with_origin(inner: T, origin: Uri) -> Self { + let inner = tonic::client::Grpc::with_origin(inner, origin); + Self { inner } + } + pub fn with_interceptor( + inner: T, + interceptor: F, + ) -> AdminClient> + where + F: tonic::service::Interceptor, + T::ResponseBody: Default, + T: tonic::codegen::Service< + http::Request, + Response = http::Response< + >::ResponseBody, + >, + >, + , + >>::Error: Into + Send + Sync, + { + AdminClient::new(InterceptedService::new(inner, interceptor)) + } + /// Compress requests with the given encoding. + /// + /// This requires the server to support it otherwise it might respond with an + /// error. + #[must_use] + pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self { + self.inner = self.inner.send_compressed(encoding); + self + } + /// Enable decompressing responses. + #[must_use] + pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self { + self.inner = self.inner.accept_compressed(encoding); + self + } + /// Limits the maximum size of a decoded message. + /// + /// Default: `4MB` + #[must_use] + pub fn max_decoding_message_size(mut self, limit: usize) -> Self { + self.inner = self.inner.max_decoding_message_size(limit); + self + } + /// Limits the maximum size of an encoded message. + /// + /// Default: `usize::MAX` + #[must_use] + pub fn max_encoding_message_size(mut self, limit: usize) -> Self { + self.inner = self.inner.max_encoding_message_size(limit); + self + } + pub async fn lock_key( + &mut self, + request: impl tonic::IntoRequest, + ) -> std::result::Result< + tonic::Response, + tonic::Status, + > { + self.inner + .ready() + .await + .map_err(|e| { + tonic::Status::new( + tonic::Code::Unknown, + format!("Service was not ready: {}", e.into()), + ) + })?; + let codec = tonic::codec::ProstCodec::default(); + let path = http::uri::PathAndQuery::from_static("/admin.v1.Admin/LockKey"); + let mut req = request.into_request(); + req.extensions_mut().insert(GrpcMethod::new("admin.v1.Admin", "LockKey")); + self.inner.unary(req, path, codec).await + } + pub async fn unlock_key( + &mut self, + request: impl tonic::IntoRequest, + ) -> std::result::Result< + tonic::Response, + tonic::Status, + > { + self.inner + .ready() + .await + .map_err(|e| { + tonic::Status::new( + tonic::Code::Unknown, + format!("Service was not ready: {}", e.into()), + ) + })?; + let codec = tonic::codec::ProstCodec::default(); + let path = http::uri::PathAndQuery::from_static("/admin.v1.Admin/UnlockKey"); + let mut req = request.into_request(); + req.extensions_mut().insert(GrpcMethod::new("admin.v1.Admin", "UnlockKey")); + self.inner.unary(req, path, codec).await + } + pub async fn generate_new_api_key( + &mut self, + request: impl tonic::IntoRequest, + ) -> std::result::Result< + tonic::Response, + tonic::Status, + > { + self.inner + .ready() + .await + .map_err(|e| { + tonic::Status::new( + tonic::Code::Unknown, + format!("Service was not ready: {}", e.into()), + ) + })?; + let codec = tonic::codec::ProstCodec::default(); + let path = http::uri::PathAndQuery::from_static( + "/admin.v1.Admin/GenerateNewApiKey", + ); + let mut req = request.into_request(); + req.extensions_mut() + .insert(GrpcMethod::new("admin.v1.Admin", "GenerateNewApiKey")); + self.inner.unary(req, path, codec).await + } + pub async fn list_all_keys( + &mut self, + request: impl tonic::IntoRequest, + ) -> std::result::Result< + tonic::Response, + tonic::Status, + > { + self.inner + .ready() + .await + .map_err(|e| { + tonic::Status::new( + tonic::Code::Unknown, + format!("Service was not ready: {}", e.into()), + ) + })?; + let codec = tonic::codec::ProstCodec::default(); + let path = http::uri::PathAndQuery::from_static( + "/admin.v1.Admin/ListAllKeys", + ); + let mut req = request.into_request(); + req.extensions_mut() + .insert(GrpcMethod::new("admin.v1.Admin", "ListAllKeys")); + self.inner.unary(req, path, codec).await + } + } +} +/// Generated server implementations. +pub mod admin_server { + #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)] + use tonic::codegen::*; + /// Generated trait containing gRPC methods that should be implemented for use with AdminServer. + #[async_trait] + pub trait Admin: Send + Sync + 'static { + async fn lock_key( + &self, + request: tonic::Request, + ) -> std::result::Result, tonic::Status>; + async fn unlock_key( + &self, + request: tonic::Request, + ) -> std::result::Result< + tonic::Response, + tonic::Status, + >; + async fn generate_new_api_key( + &self, + request: tonic::Request, + ) -> std::result::Result< + tonic::Response, + tonic::Status, + >; + async fn list_all_keys( + &self, + request: tonic::Request, + ) -> std::result::Result< + tonic::Response, + tonic::Status, + >; + } + #[derive(Debug)] + pub struct AdminServer { + inner: _Inner, + accept_compression_encodings: EnabledCompressionEncodings, + send_compression_encodings: EnabledCompressionEncodings, + max_decoding_message_size: Option, + max_encoding_message_size: Option, + } + struct _Inner(Arc); + impl AdminServer { + pub fn new(inner: T) -> Self { + Self::from_arc(Arc::new(inner)) + } + pub fn from_arc(inner: Arc) -> Self { + let inner = _Inner(inner); + Self { + inner, + accept_compression_encodings: Default::default(), + send_compression_encodings: Default::default(), + max_decoding_message_size: None, + max_encoding_message_size: None, + } + } + pub fn with_interceptor( + inner: T, + interceptor: F, + ) -> InterceptedService + where + F: tonic::service::Interceptor, + { + InterceptedService::new(Self::new(inner), interceptor) + } + /// Enable decompressing requests with the given encoding. + #[must_use] + pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self { + self.accept_compression_encodings.enable(encoding); + self + } + /// Compress responses with the given encoding, if the client supports it. + #[must_use] + pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self { + self.send_compression_encodings.enable(encoding); + self + } + /// Limits the maximum size of a decoded message. + /// + /// Default: `4MB` + #[must_use] + pub fn max_decoding_message_size(mut self, limit: usize) -> Self { + self.max_decoding_message_size = Some(limit); + self + } + /// Limits the maximum size of an encoded message. + /// + /// Default: `usize::MAX` + #[must_use] + pub fn max_encoding_message_size(mut self, limit: usize) -> Self { + self.max_encoding_message_size = Some(limit); + self + } + } + impl tonic::codegen::Service> for AdminServer + where + T: Admin, + B: Body + Send + 'static, + B::Error: Into + Send + 'static, + { + type Response = http::Response; + type Error = std::convert::Infallible; + type Future = BoxFuture; + fn poll_ready( + &mut self, + _cx: &mut Context<'_>, + ) -> Poll> { + Poll::Ready(Ok(())) + } + fn call(&mut self, req: http::Request) -> Self::Future { + let inner = self.inner.clone(); + match req.uri().path() { + "/admin.v1.Admin/LockKey" => { + #[allow(non_camel_case_types)] + struct LockKeySvc(pub Arc); + impl tonic::server::UnaryService + for LockKeySvc { + type Response = super::LockKeyResponse; + type Future = BoxFuture< + tonic::Response, + tonic::Status, + >; + fn call( + &mut self, + request: tonic::Request, + ) -> Self::Future { + let inner = Arc::clone(&self.0); + let fut = async move { (*inner).lock_key(request).await }; + Box::pin(fut) + } + } + let accept_compression_encodings = self.accept_compression_encodings; + let send_compression_encodings = self.send_compression_encodings; + let max_decoding_message_size = self.max_decoding_message_size; + let max_encoding_message_size = self.max_encoding_message_size; + let inner = self.inner.clone(); + let fut = async move { + let inner = inner.0; + let method = LockKeySvc(inner); + let codec = tonic::codec::ProstCodec::default(); + let mut grpc = tonic::server::Grpc::new(codec) + .apply_compression_config( + accept_compression_encodings, + send_compression_encodings, + ) + .apply_max_message_size_config( + max_decoding_message_size, + max_encoding_message_size, + ); + let res = grpc.unary(method, req).await; + Ok(res) + }; + Box::pin(fut) + } + "/admin.v1.Admin/UnlockKey" => { + #[allow(non_camel_case_types)] + struct UnlockKeySvc(pub Arc); + impl tonic::server::UnaryService + for UnlockKeySvc { + type Response = super::UnlockKeyResponse; + type Future = BoxFuture< + tonic::Response, + tonic::Status, + >; + fn call( + &mut self, + request: tonic::Request, + ) -> Self::Future { + let inner = Arc::clone(&self.0); + let fut = async move { (*inner).unlock_key(request).await }; + Box::pin(fut) + } + } + let accept_compression_encodings = self.accept_compression_encodings; + let send_compression_encodings = self.send_compression_encodings; + let max_decoding_message_size = self.max_decoding_message_size; + let max_encoding_message_size = self.max_encoding_message_size; + let inner = self.inner.clone(); + let fut = async move { + let inner = inner.0; + let method = UnlockKeySvc(inner); + let codec = tonic::codec::ProstCodec::default(); + let mut grpc = tonic::server::Grpc::new(codec) + .apply_compression_config( + accept_compression_encodings, + send_compression_encodings, + ) + .apply_max_message_size_config( + max_decoding_message_size, + max_encoding_message_size, + ); + let res = grpc.unary(method, req).await; + Ok(res) + }; + Box::pin(fut) + } + "/admin.v1.Admin/GenerateNewApiKey" => { + #[allow(non_camel_case_types)] + struct GenerateNewApiKeySvc(pub Arc); + impl< + T: Admin, + > tonic::server::UnaryService + for GenerateNewApiKeySvc { + type Response = super::GenerateNewApiKeyResponse; + type Future = BoxFuture< + tonic::Response, + tonic::Status, + >; + fn call( + &mut self, + request: tonic::Request, + ) -> Self::Future { + let inner = Arc::clone(&self.0); + let fut = async move { + (*inner).generate_new_api_key(request).await + }; + Box::pin(fut) + } + } + let accept_compression_encodings = self.accept_compression_encodings; + let send_compression_encodings = self.send_compression_encodings; + let max_decoding_message_size = self.max_decoding_message_size; + let max_encoding_message_size = self.max_encoding_message_size; + let inner = self.inner.clone(); + let fut = async move { + let inner = inner.0; + let method = GenerateNewApiKeySvc(inner); + let codec = tonic::codec::ProstCodec::default(); + let mut grpc = tonic::server::Grpc::new(codec) + .apply_compression_config( + accept_compression_encodings, + send_compression_encodings, + ) + .apply_max_message_size_config( + max_decoding_message_size, + max_encoding_message_size, + ); + let res = grpc.unary(method, req).await; + Ok(res) + }; + Box::pin(fut) + } + "/admin.v1.Admin/ListAllKeys" => { + #[allow(non_camel_case_types)] + struct ListAllKeysSvc(pub Arc); + impl tonic::server::UnaryService + for ListAllKeysSvc { + type Response = super::ListAllKeysResponse; + type Future = BoxFuture< + tonic::Response, + tonic::Status, + >; + fn call( + &mut self, + request: tonic::Request, + ) -> Self::Future { + let inner = Arc::clone(&self.0); + let fut = async move { + (*inner).list_all_keys(request).await + }; + Box::pin(fut) + } + } + let accept_compression_encodings = self.accept_compression_encodings; + let send_compression_encodings = self.send_compression_encodings; + let max_decoding_message_size = self.max_decoding_message_size; + let max_encoding_message_size = self.max_encoding_message_size; + let inner = self.inner.clone(); + let fut = async move { + let inner = inner.0; + let method = ListAllKeysSvc(inner); + let codec = tonic::codec::ProstCodec::default(); + let mut grpc = tonic::server::Grpc::new(codec) + .apply_compression_config( + accept_compression_encodings, + send_compression_encodings, + ) + .apply_max_message_size_config( + max_decoding_message_size, + max_encoding_message_size, + ); + let res = grpc.unary(method, req).await; + Ok(res) + }; + Box::pin(fut) + } + _ => { + Box::pin(async move { + Ok( + http::Response::builder() + .status(200) + .header("grpc-status", "12") + .header("content-type", "application/grpc") + .body(empty_body()) + .unwrap(), + ) + }) + } + } + } + } + impl Clone for AdminServer { + fn clone(&self) -> Self { + let inner = self.inner.clone(); + Self { + inner, + accept_compression_encodings: self.accept_compression_encodings, + send_compression_encodings: self.send_compression_encodings, + max_decoding_message_size: self.max_decoding_message_size, + max_encoding_message_size: self.max_encoding_message_size, + } + } + } + impl Clone for _Inner { + fn clone(&self) -> Self { + Self(Arc::clone(&self.0)) + } + } + impl std::fmt::Debug for _Inner { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{:?}", self.0) + } + } + impl tonic::server::NamedService for AdminServer { + const NAME: &'static str = "admin.v1.Admin"; + } +} diff --git a/src/generated/keymanager.v1.rs b/src/generated/keymanager.v1.rs index 56b74de..c390c8f 100644 --- a/src/generated/keymanager.v1.rs +++ b/src/generated/keymanager.v1.rs @@ -21,6 +21,9 @@ pub struct GenerateKeyPairResponse { /// G2 Public key hex of the generated keypair #[prost(string, tag = "4")] pub public_key_g2: ::prost::alloc::string::String, + /// API key associated with the keypair + #[prost(string, tag = "5")] + pub api_key: ::prost::alloc::string::String, } #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] @@ -44,6 +47,9 @@ pub struct ImportKeyResponse { /// G2 Public key hex of the imported keypair #[prost(string, tag = "2")] pub public_key_g2: ::prost::alloc::string::String, + /// API key associated with the keypair + #[prost(string, tag = "3")] + pub api_key: ::prost::alloc::string::String, } #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] diff --git a/swagger/grpc.swagger.yaml b/swagger/grpc.swagger.yaml index 1b14322..607c3ad 100644 --- a/swagger/grpc.swagger.yaml +++ b/swagger/grpc.swagger.yaml @@ -1,8 +1,9 @@ swagger: "2.0" info: - title: key_manager.proto + title: admin.proto version: version not set tags: + - name: Admin - name: KeyManager - name: Signer consumes: @@ -10,6 +11,86 @@ consumes: produces: - application/json paths: + /admin.v1.Admin/GenerateNewApiKey: + post: + operationId: Admin_GenerateNewApiKey + responses: + "200": + description: A successful response. + schema: + $ref: '#/definitions/v1GenerateNewApiKeyResponse' + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/rpcStatus' + parameters: + - name: body + in: body + required: true + schema: + $ref: '#/definitions/v1GenerateNewApiKeyRequest' + tags: + - Admin + /admin.v1.Admin/ListAllKeys: + post: + operationId: Admin_ListAllKeys + responses: + "200": + description: A successful response. + schema: + $ref: '#/definitions/v1ListAllKeysResponse' + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/rpcStatus' + parameters: + - name: body + in: body + required: true + schema: + $ref: '#/definitions/v1ListAllKeysRequest' + tags: + - Admin + /admin.v1.Admin/LockKey: + post: + operationId: Admin_LockKey + responses: + "200": + description: A successful response. + schema: + $ref: '#/definitions/v1LockKeyResponse' + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/rpcStatus' + parameters: + - name: body + in: body + required: true + schema: + $ref: '#/definitions/v1LockKeyRequest' + tags: + - Admin + /admin.v1.Admin/UnlockKey: + post: + operationId: Admin_UnlockKey + responses: + "200": + description: A successful response. + schema: + $ref: '#/definitions/v1UnlockKeyResponse' + default: + description: An unexpected error response. + schema: + $ref: '#/definitions/rpcStatus' + parameters: + - name: body + in: body + required: true + schema: + $ref: '#/definitions/v1UnlockKeyRequest' + tags: + - Admin /keymanager.v1.KeyManager/GenerateKeyPair: post: operationId: KeyManager_GenerateKeyPair @@ -173,6 +254,21 @@ definitions: publicKeyG2: type: string title: G2 Public key hex of the generated keypair + apiKey: + type: string + title: API key associated with the keypair + v1GenerateNewApiKeyRequest: + type: object + properties: + publicKeyG1: + type: string + v1GenerateNewApiKeyResponse: + type: object + properties: + publicKeyG1: + type: string + apiKey: + type: string v1GetKeyMetadataRequest: type: object properties: @@ -217,6 +313,32 @@ definitions: publicKeyG2: type: string title: G2 Public key hex of the imported keypair + apiKey: + type: string + title: API key associated with the keypair + v1KeyMetadata: + type: object + properties: + publicKeyG1: + type: string + publicKeyG2: + type: string + locked: + type: boolean + createdAt: + type: string + updatedAt: + type: string + v1ListAllKeysRequest: + type: object + v1ListAllKeysResponse: + type: object + properties: + keys: + type: array + items: + type: object + $ref: '#/definitions/v1KeyMetadata' v1ListKeysRequest: type: object v1ListKeysResponse: @@ -228,6 +350,13 @@ definitions: type: object $ref: '#/definitions/v1PublicKey' title: List of public keys + v1LockKeyRequest: + type: object + properties: + publicKeyG1: + type: string + v1LockKeyResponse: + type: object v1PublicKey: type: object properties: @@ -279,3 +408,10 @@ definitions: type: string format: byte title: Signature of the data + v1UnlockKeyRequest: + type: object + properties: + publicKeyG1: + type: string + v1UnlockKeyResponse: + type: object