From 7ee3bf3d1b18a5d8bef53dd74495b5c14b417635 Mon Sep 17 00:00:00 2001 From: Krishanx92 Date: Wed, 15 Nov 2023 08:42:19 +0530 Subject: [PATCH] Initial implementation for DP to CP --- .../wso2/discovery/service/apkmgt/apids.proto | 61 -- .../wso2/discovery/service/apkmgt/apids.pb.go | 866 +----------------- common-controller/internal/operator/PROJECT | 3 +- .../internal/operator/constant/constant.go | 1 + .../operator/controllers/dp/api_controller.go | 92 ++ management-server/cmd/main.go | 5 +- .../internal/backoffice/api_crud.go | 9 +- .../internal/config/default_config.go | 19 - .../internal/database/app_cache.go | 187 ---- management-server/internal/database/dao.go | 194 ---- .../internal/database/database.go | 80 -- .../internal/database/queries.go | 93 -- management-server/internal/xds/server.go | 68 +- 13 files changed, 154 insertions(+), 1524 deletions(-) create mode 100644 common-controller/internal/operator/controllers/dp/api_controller.go delete mode 100644 management-server/internal/database/app_cache.go delete mode 100644 management-server/internal/database/dao.go delete mode 100644 management-server/internal/database/database.go delete mode 100644 management-server/internal/database/queries.go diff --git a/adapter/api/proto/wso2/discovery/service/apkmgt/apids.proto b/adapter/api/proto/wso2/discovery/service/apkmgt/apids.proto index e53a525a3..1e0e0dee9 100644 --- a/adapter/api/proto/wso2/discovery/service/apkmgt/apids.proto +++ b/adapter/api/proto/wso2/discovery/service/apkmgt/apids.proto @@ -20,10 +20,6 @@ syntax = "proto3"; package discovery.service.apkmgt; option go_package = "github.com/wso2/apk/adapter/discovery/service/apkmgt"; -option java_package = "org.wso2.apk.enforcer.discovery.service.apkmgt"; -option java_outer_classname = "ApiDsProto"; -option java_multiple_files = false; -option java_generic_services = true; service APIService { rpc createAPI(API) returns (Response); @@ -32,66 +28,9 @@ service APIService { } message API { - string uuid = 1; - string provider = 2; string version = 3; string name = 4; string basePath = 5; - string type = 6; - string organizationId = 7; - string createdBy = 8; - string createdTime = 9; - string updatedBy = 10; - string updatedTime = 11; - string definition = 12; - repeated string transports = 13; - repeated Resource resources = 16; - CorsConfig corsConfig = 17; -} - -message CorsConfig { - bool corsConfigurationEnabled = 1; - repeated string accessControlAllowOrigins = 2; - bool accessControlAllowCredentials = 3; - repeated string accessControlAllowHeaders = 4; - repeated string accessControlAllowMethods = 5; -} - -message Resource { - string path = 1; - string verb = 2; - repeated Authentication authentications = 3; - repeated Scope scopes = 4; - OperationPolicies operationPolicies = 6; - repeated QueryParam queryParams = 7; - repeated string hostname = 8; -} - -message OperationPolicies {} - -message QueryParam { - string name = 1; - string value = 2; -} - -message Scope { - string name = 1; - string displayName = 2; - string description = 3; - repeated string bindings = 4; -} - -message Authentication { - string type = 1; - string iss = 2; - string aud = 3; - string jwksUri = 4; - repeated Credential credentialList = 5; -} - -message Credential { - string username = 1; - string password = 2; } message Response { diff --git a/adapter/pkg/discovery/api/wso2/discovery/service/apkmgt/apids.pb.go b/adapter/pkg/discovery/api/wso2/discovery/service/apkmgt/apids.pb.go index 72fcc2501..f7e5bb6b0 100644 --- a/adapter/pkg/discovery/api/wso2/discovery/service/apkmgt/apids.pb.go +++ b/adapter/pkg/discovery/api/wso2/discovery/service/apkmgt/apids.pb.go @@ -45,21 +45,9 @@ type API struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Uuid string `protobuf:"bytes,1,opt,name=uuid,proto3" json:"uuid,omitempty"` - Provider string `protobuf:"bytes,2,opt,name=provider,proto3" json:"provider,omitempty"` - Version string `protobuf:"bytes,3,opt,name=version,proto3" json:"version,omitempty"` - Name string `protobuf:"bytes,4,opt,name=name,proto3" json:"name,omitempty"` - BasePath string `protobuf:"bytes,5,opt,name=basePath,proto3" json:"basePath,omitempty"` - Type string `protobuf:"bytes,6,opt,name=type,proto3" json:"type,omitempty"` - OrganizationId string `protobuf:"bytes,7,opt,name=organizationId,proto3" json:"organizationId,omitempty"` - CreatedBy string `protobuf:"bytes,8,opt,name=createdBy,proto3" json:"createdBy,omitempty"` - CreatedTime string `protobuf:"bytes,9,opt,name=createdTime,proto3" json:"createdTime,omitempty"` - UpdatedBy string `protobuf:"bytes,10,opt,name=updatedBy,proto3" json:"updatedBy,omitempty"` - UpdatedTime string `protobuf:"bytes,11,opt,name=updatedTime,proto3" json:"updatedTime,omitempty"` - Definition string `protobuf:"bytes,12,opt,name=definition,proto3" json:"definition,omitempty"` - Transports []string `protobuf:"bytes,13,rep,name=transports,proto3" json:"transports,omitempty"` - Resources []*Resource `protobuf:"bytes,16,rep,name=resources,proto3" json:"resources,omitempty"` - CorsConfig *CorsConfig `protobuf:"bytes,17,opt,name=corsConfig,proto3" json:"corsConfig,omitempty"` + Version string `protobuf:"bytes,3,opt,name=version,proto3" json:"version,omitempty"` + Name string `protobuf:"bytes,4,opt,name=name,proto3" json:"name,omitempty"` + BasePath string `protobuf:"bytes,5,opt,name=basePath,proto3" json:"basePath,omitempty"` } func (x *API) Reset() { @@ -94,20 +82,6 @@ func (*API) Descriptor() ([]byte, []int) { return file_wso2_discovery_service_apkmgt_apids_proto_rawDescGZIP(), []int{0} } -func (x *API) GetUuid() string { - if x != nil { - return x.Uuid - } - return "" -} - -func (x *API) GetProvider() string { - if x != nil { - return x.Provider - } - return "" -} - func (x *API) GetVersion() string { if x != nil { return x.Version @@ -129,548 +103,6 @@ func (x *API) GetBasePath() string { return "" } -func (x *API) GetType() string { - if x != nil { - return x.Type - } - return "" -} - -func (x *API) GetOrganizationId() string { - if x != nil { - return x.OrganizationId - } - return "" -} - -func (x *API) GetCreatedBy() string { - if x != nil { - return x.CreatedBy - } - return "" -} - -func (x *API) GetCreatedTime() string { - if x != nil { - return x.CreatedTime - } - return "" -} - -func (x *API) GetUpdatedBy() string { - if x != nil { - return x.UpdatedBy - } - return "" -} - -func (x *API) GetUpdatedTime() string { - if x != nil { - return x.UpdatedTime - } - return "" -} - -func (x *API) GetDefinition() string { - if x != nil { - return x.Definition - } - return "" -} - -func (x *API) GetTransports() []string { - if x != nil { - return x.Transports - } - return nil -} - -func (x *API) GetResources() []*Resource { - if x != nil { - return x.Resources - } - return nil -} - -func (x *API) GetCorsConfig() *CorsConfig { - if x != nil { - return x.CorsConfig - } - return nil -} - -type CorsConfig struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - CorsConfigurationEnabled bool `protobuf:"varint,1,opt,name=corsConfigurationEnabled,proto3" json:"corsConfigurationEnabled,omitempty"` - AccessControlAllowOrigins []string `protobuf:"bytes,2,rep,name=accessControlAllowOrigins,proto3" json:"accessControlAllowOrigins,omitempty"` - AccessControlAllowCredentials bool `protobuf:"varint,3,opt,name=accessControlAllowCredentials,proto3" json:"accessControlAllowCredentials,omitempty"` - AccessControlAllowHeaders []string `protobuf:"bytes,4,rep,name=accessControlAllowHeaders,proto3" json:"accessControlAllowHeaders,omitempty"` - AccessControlAllowMethods []string `protobuf:"bytes,5,rep,name=accessControlAllowMethods,proto3" json:"accessControlAllowMethods,omitempty"` -} - -func (x *CorsConfig) Reset() { - *x = CorsConfig{} - if protoimpl.UnsafeEnabled { - mi := &file_wso2_discovery_service_apkmgt_apids_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *CorsConfig) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*CorsConfig) ProtoMessage() {} - -func (x *CorsConfig) ProtoReflect() protoreflect.Message { - mi := &file_wso2_discovery_service_apkmgt_apids_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 CorsConfig.ProtoReflect.Descriptor instead. -func (*CorsConfig) Descriptor() ([]byte, []int) { - return file_wso2_discovery_service_apkmgt_apids_proto_rawDescGZIP(), []int{1} -} - -func (x *CorsConfig) GetCorsConfigurationEnabled() bool { - if x != nil { - return x.CorsConfigurationEnabled - } - return false -} - -func (x *CorsConfig) GetAccessControlAllowOrigins() []string { - if x != nil { - return x.AccessControlAllowOrigins - } - return nil -} - -func (x *CorsConfig) GetAccessControlAllowCredentials() bool { - if x != nil { - return x.AccessControlAllowCredentials - } - return false -} - -func (x *CorsConfig) GetAccessControlAllowHeaders() []string { - if x != nil { - return x.AccessControlAllowHeaders - } - return nil -} - -func (x *CorsConfig) GetAccessControlAllowMethods() []string { - if x != nil { - return x.AccessControlAllowMethods - } - return nil -} - -type Resource struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Path string `protobuf:"bytes,1,opt,name=path,proto3" json:"path,omitempty"` - Verb string `protobuf:"bytes,2,opt,name=verb,proto3" json:"verb,omitempty"` - Authentications []*Authentication `protobuf:"bytes,3,rep,name=authentications,proto3" json:"authentications,omitempty"` - Scopes []*Scope `protobuf:"bytes,4,rep,name=scopes,proto3" json:"scopes,omitempty"` - OperationPolicies *OperationPolicies `protobuf:"bytes,6,opt,name=operationPolicies,proto3" json:"operationPolicies,omitempty"` - QueryParams []*QueryParam `protobuf:"bytes,7,rep,name=queryParams,proto3" json:"queryParams,omitempty"` - Hostname []string `protobuf:"bytes,8,rep,name=hostname,proto3" json:"hostname,omitempty"` -} - -func (x *Resource) Reset() { - *x = Resource{} - if protoimpl.UnsafeEnabled { - mi := &file_wso2_discovery_service_apkmgt_apids_proto_msgTypes[2] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Resource) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Resource) ProtoMessage() {} - -func (x *Resource) ProtoReflect() protoreflect.Message { - mi := &file_wso2_discovery_service_apkmgt_apids_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 Resource.ProtoReflect.Descriptor instead. -func (*Resource) Descriptor() ([]byte, []int) { - return file_wso2_discovery_service_apkmgt_apids_proto_rawDescGZIP(), []int{2} -} - -func (x *Resource) GetPath() string { - if x != nil { - return x.Path - } - return "" -} - -func (x *Resource) GetVerb() string { - if x != nil { - return x.Verb - } - return "" -} - -func (x *Resource) GetAuthentications() []*Authentication { - if x != nil { - return x.Authentications - } - return nil -} - -func (x *Resource) GetScopes() []*Scope { - if x != nil { - return x.Scopes - } - return nil -} - -func (x *Resource) GetOperationPolicies() *OperationPolicies { - if x != nil { - return x.OperationPolicies - } - return nil -} - -func (x *Resource) GetQueryParams() []*QueryParam { - if x != nil { - return x.QueryParams - } - return nil -} - -func (x *Resource) GetHostname() []string { - if x != nil { - return x.Hostname - } - return nil -} - -type OperationPolicies struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields -} - -func (x *OperationPolicies) Reset() { - *x = OperationPolicies{} - if protoimpl.UnsafeEnabled { - mi := &file_wso2_discovery_service_apkmgt_apids_proto_msgTypes[3] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *OperationPolicies) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*OperationPolicies) ProtoMessage() {} - -func (x *OperationPolicies) ProtoReflect() protoreflect.Message { - mi := &file_wso2_discovery_service_apkmgt_apids_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 OperationPolicies.ProtoReflect.Descriptor instead. -func (*OperationPolicies) Descriptor() ([]byte, []int) { - return file_wso2_discovery_service_apkmgt_apids_proto_rawDescGZIP(), []int{3} -} - -type QueryParam struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - Value string `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` -} - -func (x *QueryParam) Reset() { - *x = QueryParam{} - if protoimpl.UnsafeEnabled { - mi := &file_wso2_discovery_service_apkmgt_apids_proto_msgTypes[4] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *QueryParam) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*QueryParam) ProtoMessage() {} - -func (x *QueryParam) ProtoReflect() protoreflect.Message { - mi := &file_wso2_discovery_service_apkmgt_apids_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 QueryParam.ProtoReflect.Descriptor instead. -func (*QueryParam) Descriptor() ([]byte, []int) { - return file_wso2_discovery_service_apkmgt_apids_proto_rawDescGZIP(), []int{4} -} - -func (x *QueryParam) GetName() string { - if x != nil { - return x.Name - } - return "" -} - -func (x *QueryParam) GetValue() string { - if x != nil { - return x.Value - } - return "" -} - -type Scope struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - DisplayName string `protobuf:"bytes,2,opt,name=displayName,proto3" json:"displayName,omitempty"` - Description string `protobuf:"bytes,3,opt,name=description,proto3" json:"description,omitempty"` - Bindings []string `protobuf:"bytes,4,rep,name=bindings,proto3" json:"bindings,omitempty"` -} - -func (x *Scope) Reset() { - *x = Scope{} - if protoimpl.UnsafeEnabled { - mi := &file_wso2_discovery_service_apkmgt_apids_proto_msgTypes[5] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Scope) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Scope) ProtoMessage() {} - -func (x *Scope) ProtoReflect() protoreflect.Message { - mi := &file_wso2_discovery_service_apkmgt_apids_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 Scope.ProtoReflect.Descriptor instead. -func (*Scope) Descriptor() ([]byte, []int) { - return file_wso2_discovery_service_apkmgt_apids_proto_rawDescGZIP(), []int{5} -} - -func (x *Scope) GetName() string { - if x != nil { - return x.Name - } - return "" -} - -func (x *Scope) GetDisplayName() string { - if x != nil { - return x.DisplayName - } - return "" -} - -func (x *Scope) GetDescription() string { - if x != nil { - return x.Description - } - return "" -} - -func (x *Scope) GetBindings() []string { - if x != nil { - return x.Bindings - } - return nil -} - -type Authentication struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Type string `protobuf:"bytes,1,opt,name=type,proto3" json:"type,omitempty"` - Iss string `protobuf:"bytes,2,opt,name=iss,proto3" json:"iss,omitempty"` - Aud string `protobuf:"bytes,3,opt,name=aud,proto3" json:"aud,omitempty"` - JwksUri string `protobuf:"bytes,4,opt,name=jwksUri,proto3" json:"jwksUri,omitempty"` - CredentialList []*Credential `protobuf:"bytes,5,rep,name=credentialList,proto3" json:"credentialList,omitempty"` -} - -func (x *Authentication) Reset() { - *x = Authentication{} - if protoimpl.UnsafeEnabled { - mi := &file_wso2_discovery_service_apkmgt_apids_proto_msgTypes[6] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Authentication) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Authentication) ProtoMessage() {} - -func (x *Authentication) ProtoReflect() protoreflect.Message { - mi := &file_wso2_discovery_service_apkmgt_apids_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 Authentication.ProtoReflect.Descriptor instead. -func (*Authentication) Descriptor() ([]byte, []int) { - return file_wso2_discovery_service_apkmgt_apids_proto_rawDescGZIP(), []int{6} -} - -func (x *Authentication) GetType() string { - if x != nil { - return x.Type - } - return "" -} - -func (x *Authentication) GetIss() string { - if x != nil { - return x.Iss - } - return "" -} - -func (x *Authentication) GetAud() string { - if x != nil { - return x.Aud - } - return "" -} - -func (x *Authentication) GetJwksUri() string { - if x != nil { - return x.JwksUri - } - return "" -} - -func (x *Authentication) GetCredentialList() []*Credential { - if x != nil { - return x.CredentialList - } - return nil -} - -type Credential struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Username string `protobuf:"bytes,1,opt,name=username,proto3" json:"username,omitempty"` - Password string `protobuf:"bytes,2,opt,name=password,proto3" json:"password,omitempty"` -} - -func (x *Credential) Reset() { - *x = Credential{} - if protoimpl.UnsafeEnabled { - mi := &file_wso2_discovery_service_apkmgt_apids_proto_msgTypes[7] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Credential) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Credential) ProtoMessage() {} - -func (x *Credential) ProtoReflect() protoreflect.Message { - mi := &file_wso2_discovery_service_apkmgt_apids_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 Credential.ProtoReflect.Descriptor instead. -func (*Credential) Descriptor() ([]byte, []int) { - return file_wso2_discovery_service_apkmgt_apids_proto_rawDescGZIP(), []int{7} -} - -func (x *Credential) GetUsername() string { - if x != nil { - return x.Username - } - return "" -} - -func (x *Credential) GetPassword() string { - if x != nil { - return x.Password - } - return "" -} - type Response struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -682,7 +114,7 @@ type Response struct { func (x *Response) Reset() { *x = Response{} if protoimpl.UnsafeEnabled { - mi := &file_wso2_discovery_service_apkmgt_apids_proto_msgTypes[8] + mi := &file_wso2_discovery_service_apkmgt_apids_proto_msgTypes[1] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -695,7 +127,7 @@ func (x *Response) String() string { func (*Response) ProtoMessage() {} func (x *Response) ProtoReflect() protoreflect.Message { - mi := &file_wso2_discovery_service_apkmgt_apids_proto_msgTypes[8] + mi := &file_wso2_discovery_service_apkmgt_apids_proto_msgTypes[1] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -708,7 +140,7 @@ func (x *Response) ProtoReflect() protoreflect.Message { // Deprecated: Use Response.ProtoReflect.Descriptor instead. func (*Response) Descriptor() ([]byte, []int) { - return file_wso2_discovery_service_apkmgt_apids_proto_rawDescGZIP(), []int{8} + return file_wso2_discovery_service_apkmgt_apids_proto_rawDescGZIP(), []int{1} } func (x *Response) GetResult() bool { @@ -725,138 +157,34 @@ var file_wso2_discovery_service_apkmgt_apids_proto_rawDesc = []byte{ 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2f, 0x61, 0x70, 0x6b, 0x6d, 0x67, 0x74, 0x2f, 0x61, 0x70, 0x69, 0x64, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x18, 0x64, 0x69, 0x73, 0x63, 0x6f, 0x76, 0x65, 0x72, 0x79, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x61, - 0x70, 0x6b, 0x6d, 0x67, 0x74, 0x22, 0x83, 0x04, 0x0a, 0x03, 0x41, 0x50, 0x49, 0x12, 0x12, 0x0a, - 0x04, 0x75, 0x75, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x75, 0x75, 0x69, - 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x12, 0x18, 0x0a, - 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, - 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, - 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x62, - 0x61, 0x73, 0x65, 0x50, 0x61, 0x74, 0x68, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x62, - 0x61, 0x73, 0x65, 0x50, 0x61, 0x74, 0x68, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, - 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x26, 0x0a, 0x0e, 0x6f, - 0x72, 0x67, 0x61, 0x6e, 0x69, 0x7a, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x18, 0x07, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x0e, 0x6f, 0x72, 0x67, 0x61, 0x6e, 0x69, 0x7a, 0x61, 0x74, 0x69, 0x6f, - 0x6e, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x42, 0x79, - 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x42, - 0x79, 0x12, 0x20, 0x0a, 0x0b, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x54, 0x69, 0x6d, 0x65, - 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x54, - 0x69, 0x6d, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x42, 0x79, - 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x42, - 0x79, 0x12, 0x20, 0x0a, 0x0b, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x54, 0x69, 0x6d, 0x65, - 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x54, - 0x69, 0x6d, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x69, 0x74, 0x69, 0x6f, - 0x6e, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x69, 0x74, - 0x69, 0x6f, 0x6e, 0x12, 0x1e, 0x0a, 0x0a, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, - 0x73, 0x18, 0x0d, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0a, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, - 0x72, 0x74, 0x73, 0x12, 0x40, 0x0a, 0x09, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x73, - 0x18, 0x10, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x22, 0x2e, 0x64, 0x69, 0x73, 0x63, 0x6f, 0x76, 0x65, + 0x70, 0x6b, 0x6d, 0x67, 0x74, 0x22, 0x4f, 0x0a, 0x03, 0x41, 0x50, 0x49, 0x12, 0x18, 0x0a, 0x07, + 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x76, + 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x04, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x62, 0x61, + 0x73, 0x65, 0x50, 0x61, 0x74, 0x68, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x62, 0x61, + 0x73, 0x65, 0x50, 0x61, 0x74, 0x68, 0x22, 0x22, 0x0a, 0x08, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x08, 0x52, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x32, 0xfc, 0x01, 0x0a, 0x0a, 0x41, + 0x50, 0x49, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x4e, 0x0a, 0x09, 0x63, 0x72, 0x65, + 0x61, 0x74, 0x65, 0x41, 0x50, 0x49, 0x12, 0x1d, 0x2e, 0x64, 0x69, 0x73, 0x63, 0x6f, 0x76, 0x65, 0x72, 0x79, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x61, 0x70, 0x6b, 0x6d, 0x67, - 0x74, 0x2e, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x52, 0x09, 0x72, 0x65, 0x73, 0x6f, - 0x75, 0x72, 0x63, 0x65, 0x73, 0x12, 0x44, 0x0a, 0x0a, 0x63, 0x6f, 0x72, 0x73, 0x43, 0x6f, 0x6e, - 0x66, 0x69, 0x67, 0x18, 0x11, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x64, 0x69, 0x73, 0x63, - 0x6f, 0x76, 0x65, 0x72, 0x79, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x61, 0x70, - 0x6b, 0x6d, 0x67, 0x74, 0x2e, 0x43, 0x6f, 0x72, 0x73, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, - 0x0a, 0x63, 0x6f, 0x72, 0x73, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x22, 0xc8, 0x02, 0x0a, 0x0a, - 0x43, 0x6f, 0x72, 0x73, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x3a, 0x0a, 0x18, 0x63, 0x6f, - 0x72, 0x73, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x45, - 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x18, 0x63, 0x6f, - 0x72, 0x73, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x45, - 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x64, 0x12, 0x3c, 0x0a, 0x19, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, - 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x41, 0x6c, 0x6c, 0x6f, 0x77, 0x4f, 0x72, 0x69, 0x67, - 0x69, 0x6e, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x52, 0x19, 0x61, 0x63, 0x63, 0x65, 0x73, - 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x41, 0x6c, 0x6c, 0x6f, 0x77, 0x4f, 0x72, 0x69, - 0x67, 0x69, 0x6e, 0x73, 0x12, 0x44, 0x0a, 0x1d, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x43, 0x6f, - 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x41, 0x6c, 0x6c, 0x6f, 0x77, 0x43, 0x72, 0x65, 0x64, 0x65, 0x6e, - 0x74, 0x69, 0x61, 0x6c, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x1d, 0x61, 0x63, 0x63, - 0x65, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x41, 0x6c, 0x6c, 0x6f, 0x77, 0x43, - 0x72, 0x65, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x73, 0x12, 0x3c, 0x0a, 0x19, 0x61, 0x63, - 0x63, 0x65, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x41, 0x6c, 0x6c, 0x6f, 0x77, - 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x09, 0x52, 0x19, 0x61, - 0x63, 0x63, 0x65, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x41, 0x6c, 0x6c, 0x6f, - 0x77, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x12, 0x3c, 0x0a, 0x19, 0x61, 0x63, 0x63, 0x65, - 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x41, 0x6c, 0x6c, 0x6f, 0x77, 0x4d, 0x65, - 0x74, 0x68, 0x6f, 0x64, 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x09, 0x52, 0x19, 0x61, 0x63, 0x63, - 0x65, 0x73, 0x73, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x41, 0x6c, 0x6c, 0x6f, 0x77, 0x4d, - 0x65, 0x74, 0x68, 0x6f, 0x64, 0x73, 0x22, 0xfe, 0x02, 0x0a, 0x08, 0x52, 0x65, 0x73, 0x6f, 0x75, - 0x72, 0x63, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x61, 0x74, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x04, 0x70, 0x61, 0x74, 0x68, 0x12, 0x12, 0x0a, 0x04, 0x76, 0x65, 0x72, 0x62, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x76, 0x65, 0x72, 0x62, 0x12, 0x52, 0x0a, 0x0f, 0x61, - 0x75, 0x74, 0x68, 0x65, 0x6e, 0x74, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x03, - 0x20, 0x03, 0x28, 0x0b, 0x32, 0x28, 0x2e, 0x64, 0x69, 0x73, 0x63, 0x6f, 0x76, 0x65, 0x72, 0x79, - 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x61, 0x70, 0x6b, 0x6d, 0x67, 0x74, 0x2e, - 0x41, 0x75, 0x74, 0x68, 0x65, 0x6e, 0x74, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0f, - 0x61, 0x75, 0x74, 0x68, 0x65, 0x6e, 0x74, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, - 0x37, 0x0a, 0x06, 0x73, 0x63, 0x6f, 0x70, 0x65, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, - 0x1f, 0x2e, 0x64, 0x69, 0x73, 0x63, 0x6f, 0x76, 0x65, 0x72, 0x79, 0x2e, 0x73, 0x65, 0x72, 0x76, - 0x69, 0x63, 0x65, 0x2e, 0x61, 0x70, 0x6b, 0x6d, 0x67, 0x74, 0x2e, 0x53, 0x63, 0x6f, 0x70, 0x65, - 0x52, 0x06, 0x73, 0x63, 0x6f, 0x70, 0x65, 0x73, 0x12, 0x59, 0x0a, 0x11, 0x6f, 0x70, 0x65, 0x72, - 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x69, 0x65, 0x73, 0x18, 0x06, 0x20, - 0x01, 0x28, 0x0b, 0x32, 0x2b, 0x2e, 0x64, 0x69, 0x73, 0x63, 0x6f, 0x76, 0x65, 0x72, 0x79, 0x2e, - 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x61, 0x70, 0x6b, 0x6d, 0x67, 0x74, 0x2e, 0x4f, - 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x69, 0x65, 0x73, - 0x52, 0x11, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x50, 0x6f, 0x6c, 0x69, 0x63, - 0x69, 0x65, 0x73, 0x12, 0x46, 0x0a, 0x0b, 0x71, 0x75, 0x65, 0x72, 0x79, 0x50, 0x61, 0x72, 0x61, - 0x6d, 0x73, 0x18, 0x07, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x64, 0x69, 0x73, 0x63, 0x6f, - 0x76, 0x65, 0x72, 0x79, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x61, 0x70, 0x6b, - 0x6d, 0x67, 0x74, 0x2e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x52, 0x0b, - 0x71, 0x75, 0x65, 0x72, 0x79, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x68, - 0x6f, 0x73, 0x74, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x08, 0x20, 0x03, 0x28, 0x09, 0x52, 0x08, 0x68, - 0x6f, 0x73, 0x74, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x13, 0x0a, 0x11, 0x4f, 0x70, 0x65, 0x72, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x69, 0x65, 0x73, 0x22, 0x36, 0x0a, 0x0a, - 0x51, 0x75, 0x65, 0x72, 0x79, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, - 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x14, - 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, - 0x61, 0x6c, 0x75, 0x65, 0x22, 0x7b, 0x0a, 0x05, 0x53, 0x63, 0x6f, 0x70, 0x65, 0x12, 0x12, 0x0a, - 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, - 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x64, 0x69, 0x73, 0x70, 0x6c, 0x61, 0x79, 0x4e, 0x61, 0x6d, 0x65, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x64, 0x69, 0x73, 0x70, 0x6c, 0x61, 0x79, 0x4e, - 0x61, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, - 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, - 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x1a, 0x0a, 0x08, 0x62, 0x69, 0x6e, 0x64, 0x69, 0x6e, 0x67, - 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x09, 0x52, 0x08, 0x62, 0x69, 0x6e, 0x64, 0x69, 0x6e, 0x67, - 0x73, 0x22, 0xb0, 0x01, 0x0a, 0x0e, 0x41, 0x75, 0x74, 0x68, 0x65, 0x6e, 0x74, 0x69, 0x63, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x69, 0x73, 0x73, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x69, 0x73, 0x73, 0x12, 0x10, 0x0a, 0x03, 0x61, 0x75, - 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x61, 0x75, 0x64, 0x12, 0x18, 0x0a, 0x07, - 0x6a, 0x77, 0x6b, 0x73, 0x55, 0x72, 0x69, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6a, - 0x77, 0x6b, 0x73, 0x55, 0x72, 0x69, 0x12, 0x4c, 0x0a, 0x0e, 0x63, 0x72, 0x65, 0x64, 0x65, 0x6e, - 0x74, 0x69, 0x61, 0x6c, 0x4c, 0x69, 0x73, 0x74, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x24, - 0x2e, 0x64, 0x69, 0x73, 0x63, 0x6f, 0x76, 0x65, 0x72, 0x79, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, - 0x63, 0x65, 0x2e, 0x61, 0x70, 0x6b, 0x6d, 0x67, 0x74, 0x2e, 0x43, 0x72, 0x65, 0x64, 0x65, 0x6e, - 0x74, 0x69, 0x61, 0x6c, 0x52, 0x0e, 0x63, 0x72, 0x65, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, - 0x4c, 0x69, 0x73, 0x74, 0x22, 0x44, 0x0a, 0x0a, 0x43, 0x72, 0x65, 0x64, 0x65, 0x6e, 0x74, 0x69, - 0x61, 0x6c, 0x12, 0x1a, 0x0a, 0x08, 0x75, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x75, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1a, - 0x0a, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x22, 0x22, 0x0a, 0x08, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x32, 0xfc, - 0x01, 0x0a, 0x0a, 0x41, 0x50, 0x49, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x4e, 0x0a, - 0x09, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x41, 0x50, 0x49, 0x12, 0x1d, 0x2e, 0x64, 0x69, 0x73, - 0x63, 0x6f, 0x76, 0x65, 0x72, 0x79, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x61, - 0x70, 0x6b, 0x6d, 0x67, 0x74, 0x2e, 0x41, 0x50, 0x49, 0x1a, 0x22, 0x2e, 0x64, 0x69, 0x73, 0x63, - 0x6f, 0x76, 0x65, 0x72, 0x79, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x61, 0x70, - 0x6b, 0x6d, 0x67, 0x74, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x4e, 0x0a, - 0x09, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x41, 0x50, 0x49, 0x12, 0x1d, 0x2e, 0x64, 0x69, 0x73, - 0x63, 0x6f, 0x76, 0x65, 0x72, 0x79, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x61, - 0x70, 0x6b, 0x6d, 0x67, 0x74, 0x2e, 0x41, 0x50, 0x49, 0x1a, 0x22, 0x2e, 0x64, 0x69, 0x73, 0x63, - 0x6f, 0x76, 0x65, 0x72, 0x79, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x61, 0x70, - 0x6b, 0x6d, 0x67, 0x74, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x4e, 0x0a, - 0x09, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x41, 0x50, 0x49, 0x12, 0x1d, 0x2e, 0x64, 0x69, 0x73, - 0x63, 0x6f, 0x76, 0x65, 0x72, 0x79, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x61, - 0x70, 0x6b, 0x6d, 0x67, 0x74, 0x2e, 0x41, 0x50, 0x49, 0x1a, 0x22, 0x2e, 0x64, 0x69, 0x73, 0x63, - 0x6f, 0x76, 0x65, 0x72, 0x79, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x61, 0x70, - 0x6b, 0x6d, 0x67, 0x74, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x77, 0x0a, - 0x2e, 0x6f, 0x72, 0x67, 0x2e, 0x77, 0x73, 0x6f, 0x32, 0x2e, 0x61, 0x70, 0x6b, 0x2e, 0x65, 0x6e, - 0x66, 0x6f, 0x72, 0x63, 0x65, 0x72, 0x2e, 0x64, 0x69, 0x73, 0x63, 0x6f, 0x76, 0x65, 0x72, 0x79, - 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x61, 0x70, 0x6b, 0x6d, 0x67, 0x74, 0x42, - 0x0a, 0x41, 0x70, 0x69, 0x44, 0x73, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x00, 0x5a, 0x34, 0x67, - 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x77, 0x73, 0x6f, 0x32, 0x2f, 0x61, - 0x70, 0x6b, 0x2f, 0x61, 0x64, 0x61, 0x70, 0x74, 0x65, 0x72, 0x2f, 0x64, 0x69, 0x73, 0x63, 0x6f, - 0x76, 0x65, 0x72, 0x79, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2f, 0x61, 0x70, 0x6b, - 0x6d, 0x67, 0x74, 0x88, 0x01, 0x01, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x74, 0x2e, 0x41, 0x50, 0x49, 0x1a, 0x22, 0x2e, 0x64, 0x69, 0x73, 0x63, 0x6f, 0x76, 0x65, 0x72, + 0x79, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x61, 0x70, 0x6b, 0x6d, 0x67, 0x74, + 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x4e, 0x0a, 0x09, 0x75, 0x70, 0x64, + 0x61, 0x74, 0x65, 0x41, 0x50, 0x49, 0x12, 0x1d, 0x2e, 0x64, 0x69, 0x73, 0x63, 0x6f, 0x76, 0x65, + 0x72, 0x79, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x61, 0x70, 0x6b, 0x6d, 0x67, + 0x74, 0x2e, 0x41, 0x50, 0x49, 0x1a, 0x22, 0x2e, 0x64, 0x69, 0x73, 0x63, 0x6f, 0x76, 0x65, 0x72, + 0x79, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x61, 0x70, 0x6b, 0x6d, 0x67, 0x74, + 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x4e, 0x0a, 0x09, 0x64, 0x65, 0x6c, + 0x65, 0x74, 0x65, 0x41, 0x50, 0x49, 0x12, 0x1d, 0x2e, 0x64, 0x69, 0x73, 0x63, 0x6f, 0x76, 0x65, + 0x72, 0x79, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x61, 0x70, 0x6b, 0x6d, 0x67, + 0x74, 0x2e, 0x41, 0x50, 0x49, 0x1a, 0x22, 0x2e, 0x64, 0x69, 0x73, 0x63, 0x6f, 0x76, 0x65, 0x72, + 0x79, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x61, 0x70, 0x6b, 0x6d, 0x67, 0x74, + 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x36, 0x5a, 0x34, 0x67, 0x69, 0x74, + 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x77, 0x73, 0x6f, 0x32, 0x2f, 0x61, 0x70, 0x6b, + 0x2f, 0x61, 0x64, 0x61, 0x70, 0x74, 0x65, 0x72, 0x2f, 0x64, 0x69, 0x73, 0x63, 0x6f, 0x76, 0x65, + 0x72, 0x79, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2f, 0x61, 0x70, 0x6b, 0x6d, 0x67, + 0x74, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -871,37 +199,23 @@ func file_wso2_discovery_service_apkmgt_apids_proto_rawDescGZIP() []byte { return file_wso2_discovery_service_apkmgt_apids_proto_rawDescData } -var file_wso2_discovery_service_apkmgt_apids_proto_msgTypes = make([]protoimpl.MessageInfo, 9) +var file_wso2_discovery_service_apkmgt_apids_proto_msgTypes = make([]protoimpl.MessageInfo, 2) var file_wso2_discovery_service_apkmgt_apids_proto_goTypes = []interface{}{ - (*API)(nil), // 0: discovery.service.apkmgt.API - (*CorsConfig)(nil), // 1: discovery.service.apkmgt.CorsConfig - (*Resource)(nil), // 2: discovery.service.apkmgt.Resource - (*OperationPolicies)(nil), // 3: discovery.service.apkmgt.OperationPolicies - (*QueryParam)(nil), // 4: discovery.service.apkmgt.QueryParam - (*Scope)(nil), // 5: discovery.service.apkmgt.Scope - (*Authentication)(nil), // 6: discovery.service.apkmgt.Authentication - (*Credential)(nil), // 7: discovery.service.apkmgt.Credential - (*Response)(nil), // 8: discovery.service.apkmgt.Response + (*API)(nil), // 0: discovery.service.apkmgt.API + (*Response)(nil), // 1: discovery.service.apkmgt.Response } var file_wso2_discovery_service_apkmgt_apids_proto_depIdxs = []int32{ - 2, // 0: discovery.service.apkmgt.API.resources:type_name -> discovery.service.apkmgt.Resource - 1, // 1: discovery.service.apkmgt.API.corsConfig:type_name -> discovery.service.apkmgt.CorsConfig - 6, // 2: discovery.service.apkmgt.Resource.authentications:type_name -> discovery.service.apkmgt.Authentication - 5, // 3: discovery.service.apkmgt.Resource.scopes:type_name -> discovery.service.apkmgt.Scope - 3, // 4: discovery.service.apkmgt.Resource.operationPolicies:type_name -> discovery.service.apkmgt.OperationPolicies - 4, // 5: discovery.service.apkmgt.Resource.queryParams:type_name -> discovery.service.apkmgt.QueryParam - 7, // 6: discovery.service.apkmgt.Authentication.credentialList:type_name -> discovery.service.apkmgt.Credential - 0, // 7: discovery.service.apkmgt.APIService.createAPI:input_type -> discovery.service.apkmgt.API - 0, // 8: discovery.service.apkmgt.APIService.updateAPI:input_type -> discovery.service.apkmgt.API - 0, // 9: discovery.service.apkmgt.APIService.deleteAPI:input_type -> discovery.service.apkmgt.API - 8, // 10: discovery.service.apkmgt.APIService.createAPI:output_type -> discovery.service.apkmgt.Response - 8, // 11: discovery.service.apkmgt.APIService.updateAPI:output_type -> discovery.service.apkmgt.Response - 8, // 12: discovery.service.apkmgt.APIService.deleteAPI:output_type -> discovery.service.apkmgt.Response - 10, // [10:13] is the sub-list for method output_type - 7, // [7:10] is the sub-list for method input_type - 7, // [7:7] is the sub-list for extension type_name - 7, // [7:7] is the sub-list for extension extendee - 0, // [0:7] is the sub-list for field type_name + 0, // 0: discovery.service.apkmgt.APIService.createAPI:input_type -> discovery.service.apkmgt.API + 0, // 1: discovery.service.apkmgt.APIService.updateAPI:input_type -> discovery.service.apkmgt.API + 0, // 2: discovery.service.apkmgt.APIService.deleteAPI:input_type -> discovery.service.apkmgt.API + 1, // 3: discovery.service.apkmgt.APIService.createAPI:output_type -> discovery.service.apkmgt.Response + 1, // 4: discovery.service.apkmgt.APIService.updateAPI:output_type -> discovery.service.apkmgt.Response + 1, // 5: discovery.service.apkmgt.APIService.deleteAPI:output_type -> discovery.service.apkmgt.Response + 3, // [3:6] is the sub-list for method output_type + 0, // [0:3] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name } func init() { file_wso2_discovery_service_apkmgt_apids_proto_init() } @@ -923,90 +237,6 @@ func file_wso2_discovery_service_apkmgt_apids_proto_init() { } } file_wso2_discovery_service_apkmgt_apids_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*CorsConfig); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_wso2_discovery_service_apkmgt_apids_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Resource); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_wso2_discovery_service_apkmgt_apids_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*OperationPolicies); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_wso2_discovery_service_apkmgt_apids_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*QueryParam); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_wso2_discovery_service_apkmgt_apids_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Scope); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_wso2_discovery_service_apkmgt_apids_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Authentication); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_wso2_discovery_service_apkmgt_apids_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Credential); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_wso2_discovery_service_apkmgt_apids_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*Response); i { case 0: return &v.state @@ -1025,7 +255,7 @@ func file_wso2_discovery_service_apkmgt_apids_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_wso2_discovery_service_apkmgt_apids_proto_rawDesc, NumEnums: 0, - NumMessages: 9, + NumMessages: 2, NumExtensions: 0, NumServices: 1, }, diff --git a/common-controller/internal/operator/PROJECT b/common-controller/internal/operator/PROJECT index aa5912bad..82f35e31f 100644 --- a/common-controller/internal/operator/PROJECT +++ b/common-controller/internal/operator/PROJECT @@ -4,7 +4,7 @@ # More info: https://book.kubebuilder.io/reference/project-config.html domain: wso2.com layout: -- go.kubebuilder.io/v4 +- go.kubebuilder.io/v3 multigroup: true projectName: operator repo: github.com/wso2/apk/common-controller/internal/operator @@ -21,6 +21,7 @@ resources: - api: crdVersion: v1 namespaced: true + controller: true domain: wso2.com group: dp kind: API diff --git a/common-controller/internal/operator/constant/constant.go b/common-controller/internal/operator/constant/constant.go index cb2e18985..df8ad4140 100644 --- a/common-controller/internal/operator/constant/constant.go +++ b/common-controller/internal/operator/constant/constant.go @@ -19,6 +19,7 @@ package constants // Controller related constants const ( + APIController string = "APIController" RatelimitController string = "RatelimitController" ApplicationController string = "ApplicationController" SubscriptionController string = "SubscriptionController" diff --git a/common-controller/internal/operator/controllers/dp/api_controller.go b/common-controller/internal/operator/controllers/dp/api_controller.go new file mode 100644 index 000000000..772e6597a --- /dev/null +++ b/common-controller/internal/operator/controllers/dp/api_controller.go @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package dp + +import ( + "context" + + "github.com/wso2/apk/adapter/pkg/logging" + loggers "github.com/wso2/apk/common-controller/internal/loggers" + dpv1alpha2 "github.com/wso2/apk/common-controller/internal/operator/apis/dp/v1alpha2" + constants "github.com/wso2/apk/common-controller/internal/operator/constant" + "github.com/wso2/apk/common-controller/internal/utils" + "k8s.io/apimachinery/pkg/runtime" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/controller" + "sigs.k8s.io/controller-runtime/pkg/handler" + "sigs.k8s.io/controller-runtime/pkg/log" + "sigs.k8s.io/controller-runtime/pkg/manager" + "sigs.k8s.io/controller-runtime/pkg/predicate" + "sigs.k8s.io/controller-runtime/pkg/source" +) + +// APIReconciler reconciles a API object +type APIReconciler struct { + client client.Client + Scheme *runtime.Scheme +} + +// NewApplicationController creates a new Application controller instance +func NewAPIController(mgr manager.Manager) error { + r := &APIReconciler{ + client: mgr.GetClient(), + } + c, err := controller.New(constants.APIController, mgr, controller.Options{Reconciler: r}) + if err != nil { + loggers.LoggerAPKOperator.ErrorC(logging.PrintError(logging.Error2606, logging.BLOCKER, "Error creating API controller: %v", err.Error())) + return err + } + + if err := c.Watch(source.Kind(mgr.GetCache(), &dpv1alpha2.API{}), &handler.EnqueueRequestForObject{}, + predicate.NewPredicateFuncs(utils.FilterByNamespaces([]string{utils.GetOperatorPodNamespace()}))); err != nil { + loggers.LoggerAPKOperator.ErrorC(logging.PrintError(logging.Error2607, logging.BLOCKER, "Error watching API resources: %v", err.Error())) + return err + } + + loggers.LoggerAPKOperator.Debug("API Controller successfully started. Watching API Objects...") + return nil +} + +//+kubebuilder:rbac:groups=dp.wso2.com,resources=apis,verbs=get;list;watch;create;update;patch;delete +//+kubebuilder:rbac:groups=dp.wso2.com,resources=apis/status,verbs=get;update;patch +//+kubebuilder:rbac:groups=dp.wso2.com,resources=apis/finalizers,verbs=update + +// Reconcile is part of the main kubernetes reconciliation loop which aims to +// move the current state of the cluster closer to the desired state. +// TODO(user): Modify the Reconcile function to compare the state specified by +// the API object against the actual cluster state, and then +// perform operations to make the cluster state reflect the state specified by +// the user. +// +// For more details, check Reconcile and its Result here: +// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.14.4/pkg/reconcile +func (r *APIReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { + _ = log.FromContext(ctx) + + // TODO(user): your logic here + + return ctrl.Result{}, nil +} + +// SetupWithManager sets up the controller with the Manager. +func (r *APIReconciler) SetupWithManager(mgr ctrl.Manager) error { + return ctrl.NewControllerManagedBy(mgr). + For(&dpv1alpha2.API{}). + Complete(r) +} diff --git a/management-server/cmd/main.go b/management-server/cmd/main.go index 9b10a9e5b..2637c0464 100644 --- a/management-server/cmd/main.go +++ b/management-server/cmd/main.go @@ -21,7 +21,6 @@ import ( "os" "os/signal" - "github.com/wso2/apk/management-server/internal/database" server "github.com/wso2/apk/management-server/internal/grpc-server" "github.com/wso2/apk/management-server/internal/logger" "github.com/wso2/apk/management-server/internal/notification" @@ -33,9 +32,7 @@ func main() { logger.LoggerServer.Info("Starting Management server ...") sig := make(chan os.Signal, 1) signal.Notify(sig, os.Interrupt) - // connect to the postgres database - database.ConnectToDB() - defer database.CloseDBConn() + go xds.InitAPKMgtServer() go synchronizer.ProcessApplicationEvents() diff --git a/management-server/internal/backoffice/api_crud.go b/management-server/internal/backoffice/api_crud.go index aca27c6b8..b83b00bfb 100644 --- a/management-server/internal/backoffice/api_crud.go +++ b/management-server/internal/backoffice/api_crud.go @@ -53,13 +53,10 @@ func getBackOfficeURL() string { func composeRequestBody(api *apiProtos.API) requestData { request := new(requestData) - request.APIProperties.ID = api.Uuid request.APIProperties.Name = api.Name request.APIProperties.Context = api.BasePath request.APIProperties.Version = api.Version - request.APIProperties.Provider = api.Provider - request.APIProperties.OrganizationID = api.OrganizationId - json.Unmarshal([]byte(api.Definition), &request.Definition) + //json.Unmarshal([]byte(api.Definition), &request.Definition) return *request } @@ -78,7 +75,7 @@ func CreateAPI(api *apiProtos.API) error { func UpdateAPI(api *apiProtos.API) error { putBody, _ := json.Marshal(composeRequestBody(api)) requestBody := bytes.NewBuffer(putBody) - putRequest, err := http.NewRequest(http.MethodPut, fmt.Sprintf("%s/%s", getBackOfficeURL(), api.Uuid), requestBody) + putRequest, err := http.NewRequest(http.MethodPut, fmt.Sprintf("%s", getBackOfficeURL()), requestBody) if err != nil { return err } @@ -100,7 +97,7 @@ func UpdateAPI(api *apiProtos.API) error { // DeleteAPI deletes an API by invoking backoffice service func DeleteAPI(api *apiProtos.API) error { - deleteRequest, err := http.NewRequest(http.MethodDelete, fmt.Sprintf("%s/%s", getBackOfficeURL(), api.Uuid), nil) + deleteRequest, err := http.NewRequest(http.MethodDelete, fmt.Sprintf("%s", getBackOfficeURL()), nil) _, err = backOfficeClient.Do(deleteRequest) if err != nil { return err diff --git a/management-server/internal/config/default_config.go b/management-server/internal/config/default_config.go index 9e740ad25..a3120ffb4 100644 --- a/management-server/internal/config/default_config.go +++ b/management-server/internal/config/default_config.go @@ -25,25 +25,6 @@ var defaultConfig = &Config{ GRPCPort: 8765, NotificationPort: 8766, }, - Database: database{ - Name: "WSO2AM_DB", - Username: "wso2carbon", - Password: "wso2carbon", - Host: "wso2apk-db-service", - Port: 5432, - PoolOptions: dbPool{ - PoolMaxConns: 4, - PoolMinConns: 0, - PoolMaxConnLifetime: "1h", - PoolMaxConnIdleTime: "1h", - PoolHealthCheckPeriod: "1m", - PoolMaxConnLifetimeJitter: "1s", - }, - DbCache: dbCache{ - CleanupInterval: "1h", - TTL: "1h", - }, - }, BackOffice: backOffice{ Host: "localhost", Port: 9443, diff --git a/management-server/internal/database/app_cache.go b/management-server/internal/database/app_cache.go deleted file mode 100644 index 43c13d4f6..000000000 --- a/management-server/internal/database/app_cache.go +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Copyright (c) 2022, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 LLC. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package database - -import ( - "errors" - "sync" - "time" - - apkmgt "github.com/wso2/apk/adapter/pkg/discovery/api/wso2/discovery/apkmgt" - "github.com/wso2/apk/management-server/internal/config" - "github.com/wso2/apk/management-server/internal/logger" -) - -// CachedApplication is an application with an expiry timestamp -type CachedApplication struct { - application *apkmgt.Application - expireAtTimestamp int64 -} - -// ApplicationLocalCache is data holder for cached applications -type ApplicationLocalCache struct { - stop chan struct{} - - wg sync.WaitGroup - mu sync.RWMutex - apps map[string]CachedApplication -} - -var cleanupInterval time.Duration -var ttl time.Duration - -func init() { - conf := config.ReadConfigs() - cleanupInterval, _ = time.ParseDuration(conf.Database.DbCache.CleanupInterval) - ttl, _ = time.ParseDuration(conf.Database.DbCache.TTL) - DbCache = NewApplicationLocalCache(cleanupInterval) -} - -// NewApplicationLocalCache creates an application local cache -func NewApplicationLocalCache(cleanupInterval time.Duration) *ApplicationLocalCache { - lc := &ApplicationLocalCache{ - apps: make(map[string]CachedApplication), - stop: make(chan struct{}), - } - - lc.wg.Add(1) - go func(cleanupInterval time.Duration) { - defer lc.wg.Done() - lc.cleanupLoop(cleanupInterval) - }(cleanupInterval) - return lc -} - -func (lc *ApplicationLocalCache) cleanupLoop(interval time.Duration) { - t := time.NewTicker(interval) - defer t.Stop() - - for { - select { - case <-lc.stop: - return - case <-t.C: - lc.mu.Lock() - for uid, cu := range lc.apps { - if cu.expireAtTimestamp <= time.Now().Unix() { - delete(lc.apps, uid) - } - } - lc.mu.Unlock() - } - } -} - -func (lc *ApplicationLocalCache) stopCleanup() { - close(lc.stop) - lc.wg.Wait() -} - -// Update updates the expiry timestamp of an existing application in the cache -func (lc *ApplicationLocalCache) Update(u *apkmgt.Application, expireAtTimestamp int64) { - lc.mu.Lock() - defer lc.mu.Unlock() - - lc.apps[u.Uuid] = CachedApplication{ - application: u, - expireAtTimestamp: expireAtTimestamp, - } - logger.LoggerDatabase.Infof("Cache updated successfully.. cache: %v", lc.apps) -} - -// UpdateSubscriptionInApplication updates the subscription of an application in the cache -func (lc *ApplicationLocalCache) UpdateSubscriptionInApplication(appUUID string, s *apkmgt.Subscription) error { - if app, ok := lc.apps[appUUID]; ok { - for i, sub := range app.application.Subscriptions { - if sub.Uuid == s.Uuid { - lc.apps[appUUID].application.Subscriptions[i] = s - return nil - } - } - app.expireAtTimestamp = time.Now().Unix() + ttl.Microseconds() - } else { - return ErrApplicationNotInCache - } - return ErrSubscriptionNotInAppCache -} - -// AddSubscriptionForApplication adds a subscription to an application in the cache -func (lc *ApplicationLocalCache) AddSubscriptionForApplication(appUUID string, s *apkmgt.Subscription) error { - if app, ok := lc.apps[appUUID]; ok { - app.application.Subscriptions = append(app.application.Subscriptions, s) - app.expireAtTimestamp = time.Now().Unix() + ttl.Microseconds() - return nil - } - return ErrApplicationNotInCache -} - -// DeleteSubscriptionFromApplication deletes a subscription from an application in the cache -func (lc *ApplicationLocalCache) DeleteSubscriptionFromApplication(appUUID, subUUID string) error { - if app, ok := lc.apps[appUUID]; ok { - for i, sub := range app.application.Subscriptions { - if sub.Uuid == subUUID { - app.application.Subscriptions[i] = app.application.Subscriptions[len(app.application.Subscriptions)-1] - app.application.Subscriptions = app.application.Subscriptions[:len(app.application.Subscriptions)-1] - return nil - } - } - app.expireAtTimestamp = time.Now().Unix() + ttl.Microseconds() - } else { - return ErrApplicationNotInCache - } - return ErrSubscriptionNotInAppCache -} - -var ( - // ErrApplicationNotInCache is the error returned when application is not present in the cache - ErrApplicationNotInCache = errors.New("unable to find application in cache") - // ErrSubscriptionNotInAppCache is the error returned when subscription is not present in the cache - ErrSubscriptionNotInAppCache = errors.New("unable to find subscription in application cache") -) - -// Read returns an applicaiton found in the in the cache with the given application id -func (lc *ApplicationLocalCache) Read(id string) (*apkmgt.Application, error) { - lc.mu.RLock() - defer lc.mu.RUnlock() - - cu, ok := lc.apps[id] - if !ok { - return &apkmgt.Application{}, ErrApplicationNotInCache - } - - return cu.application, nil -} - -// ReadAll returns all the applications in the cache -func (lc *ApplicationLocalCache) ReadAll() ([]*apkmgt.Application, error) { - var apps []*apkmgt.Application - - for _, app := range lc.apps { - apps = append(apps, app.application) - } - return apps, nil -} - -// Delete deletes an applicaton in the cache using the given id -func (lc *ApplicationLocalCache) Delete(id string) { - lc.mu.Lock() - defer lc.mu.Unlock() - - delete(lc.apps, id) -} diff --git a/management-server/internal/database/dao.go b/management-server/internal/database/dao.go deleted file mode 100644 index b2ac5a0cc..000000000 --- a/management-server/internal/database/dao.go +++ /dev/null @@ -1,194 +0,0 @@ -/* - * Copyright (c) 2022, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package database - -import ( - "encoding/json" - "fmt" - "time" - - apkmgt "github.com/wso2/apk/adapter/pkg/discovery/api/wso2/discovery/apkmgt" - apiProtos "github.com/wso2/apk/adapter/pkg/discovery/api/wso2/discovery/service/apkmgt" - "github.com/wso2/apk/adapter/pkg/logging" - "github.com/wso2/apk/management-server/internal/logger" -) - -// DbCache is a pointer to an ApplicationLocalCache -var DbCache *ApplicationLocalCache - -func init() { - DbCache = NewApplicationLocalCache(cleanupInterval) -} - -type artifact struct { - APIName string `json:"apiName"` - ID string `json:"id"` - Context string `json:"context"` - Version string `json:"version"` - ProviderName string `json:"providerName"` - Status string `json:"status"` -} - -// GetApplicationByUUID retrives an application using uuid and returns it -func GetApplicationByUUID(uuid string) (*apkmgt.Application, error) { - rows, _ := ExecDBQuery(queryGetApplicationByUUID, uuid) - rows.Next() - values, err := rows.Values() - if err != nil { - return nil, err - } - subs, _ := getSubscriptionsForApplication(uuid) - keys, _ := getConsumerKeysForApplication(uuid) - application := &apkmgt.Application{ - Uuid: values[0].(string), - Name: values[1].(string), - Owner: "", //ToDo : Check how to get Owner from db - Attributes: nil, //ToDo : check the values for Attributes - Subscriber: "", - Organization: values[3].(string), - Subscriptions: subs, - ConsumerKeys: keys, - } - DbCache.Update(application, time.Now().Unix()+ttl.Microseconds()) - return application, nil -} - -// GetCachedApplicationByUUID returns the Application details from the cache. -// If the application is not available in the cache, it will fetch the application from DB. -func GetCachedApplicationByUUID(uuid string) (*apkmgt.Application, error) { - if app, ok := DbCache.Read(uuid); ok == nil { - return app, nil - } - return GetApplicationByUUID(uuid) -} - -// getSubscriptionsForApplication returns all subscriptions from DB, for a given application. -func getSubscriptionsForApplication(appUUID string) ([]*apkmgt.Subscription, error) { - rows, _ := ExecDBQuery(queryGetAllSubscriptionsForApplication, appUUID) - var subs []*apkmgt.Subscription - for rows.Next() { - values, err := rows.Values() - if err != nil { - return nil, err - } - subs = append(subs, &apkmgt.Subscription{ - Uuid: values[0].(string), - ApiUuid: values[1].(string), - PolicyId: "", - SubscriptionStatus: values[3].(string), - Organization: values[4].(string), - CreatedBy: values[5].(string), - }) - } - return subs, nil -} - -// getConsumerKeysForApplication returns all Consumer Keys from DB, for a given application. -func getConsumerKeysForApplication(appUUID string) ([]*apkmgt.ConsumerKey, error) { - rows, _ := ExecDBQuery(queryConsumerKeysForApplication, appUUID) - var keys []*apkmgt.ConsumerKey - for rows.Next() { - values, err := rows.Values() - if err != nil { - return nil, err - } - keys = append(keys, &apkmgt.ConsumerKey{ - Key: values[0].(string), - KeyManager: values[1].(string), - }) - } - return keys, nil -} - -// GetSubscriptionByUUID returns the Application details from the DB for a given subscription UUID. -func GetSubscriptionByUUID(subUUID string) (*apkmgt.Subscription, error) { - rows, _ := ExecDBQuery(querySubscriptionByUUID, subUUID) - rows.Next() - values, err := rows.Values() - if err != nil { - return nil, err - } - return &apkmgt.Subscription{ - Uuid: values[0].(string), - ApiUuid: values[1].(string), - PolicyId: "", - SubscriptionStatus: values[2].(string), - Organization: values[3].(string), - CreatedBy: values[4].(string), - }, nil -} - -// CreateAPI creates an API in the DB -func CreateAPI(api *apiProtos.API) error { - _, err := ExecDBQuery(queryCreateAPI, &api.Uuid, &api.Name, &api.Provider, - &api.Version, &api.BasePath, &api.OrganizationId, &api.CreatedBy, time.Now(), &api.Type, marshalArtifact(api), "PUBLISHED") - - if err != nil { - logger.LoggerDatabase.ErrorC(logging.ErrorDetails{ - Message: fmt.Sprintf("Error creating API %q, Error: %v", api.Uuid, err.Error()), - Severity: logging.CRITICAL, - ErrorCode: 1201, - }) - return err - } - return nil -} - -// UpdateAPI updates the given API in the DB -func UpdateAPI(api *apiProtos.API) error { - _, err := ExecDBQuery(queryUpdateAPI, &api.Uuid, &api.Name, &api.Provider, - &api.Version, &api.BasePath, &api.OrganizationId, &api.UpdatedBy, time.Now(), &api.Type, marshalArtifact(api), "PUBLISHED") - if err != nil { - logger.LoggerDatabase.ErrorC(logging.ErrorDetails{ - Message: fmt.Sprintf("Error updating API %q, Error: %v", api.Uuid, err.Error()), - Severity: logging.CRITICAL, - ErrorCode: 1202, - }) - return err - } - return nil -} - -// DeleteAPI deletes the given API in the DB -func DeleteAPI(api *apiProtos.API) error { - _, err := ExecDBQuery(queryDeleteAPI, api.Uuid) - if err != nil { - logger.LoggerDatabase.ErrorC(logging.ErrorDetails{ - Message: fmt.Sprintf("Error deleting API %q, Error: %v", api.Uuid, err.Error()), - Severity: logging.CRITICAL, - ErrorCode: 1203, - }) - return err - } - return nil -} - -func marshalArtifact(api *apiProtos.API) string { - artifact := &artifact{APIName: api.Name, - ID: api.Uuid, - Context: api.BasePath, - Version: api.Version, - ProviderName: api.Provider, - Status: "PUBLISHED", - } - jsonString, err := json.Marshal(artifact) - if err != nil { - return "{}" - } - return string(jsonString) -} diff --git a/management-server/internal/database/database.go b/management-server/internal/database/database.go deleted file mode 100644 index af4a1c98c..000000000 --- a/management-server/internal/database/database.go +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2022, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package database - -import ( - "context" - "fmt" - - "github.com/jackc/pgx/v5" - "github.com/jackc/pgx/v5/pgxpool" - "github.com/wso2/apk/adapter/pkg/logging" - "github.com/wso2/apk/management-server/internal/config" - "github.com/wso2/apk/management-server/internal/logger" -) - -var dbPool *pgxpool.Pool - -// ConnectToDB creates the DB connection -func ConnectToDB() { - conf := config.ReadConfigs() - var err error - connString := fmt.Sprintf("postgresql://%s:%s@%s:%d/%s?pool_max_conns=%d&pool_min_conns=%d&"+ - "pool_max_conn_lifetime=%s&pool_max_conn_idle_time=%s&pool_health_check_period=%s&pool_max_conn_lifetime_jitter=%s", - conf.Database.Username, - conf.Database.Password, - conf.Database.Host, - conf.Database.Port, - conf.Database.Name, - conf.Database.PoolOptions.PoolMaxConns, - conf.Database.PoolOptions.PoolMinConns, - conf.Database.PoolOptions.PoolMaxConnLifetime, - conf.Database.PoolOptions.PoolMaxConnIdleTime, - conf.Database.PoolOptions.PoolHealthCheckPeriod, - conf.Database.PoolOptions.PoolMaxConnLifetimeJitter) - dbPool, err = pgxpool.New(context.Background(), connString) - if err != nil { - logger.LoggerDatabase.ErrorC(logging.ErrorDetails{ - Message: fmt.Sprintf("Unable to connect to database: %v", err.Error()), - Severity: logging.CRITICAL, - ErrorCode: 1100, - }) - } -} - -// ExecDBQuery executes a given database query with the arguments provided -func ExecDBQuery(query string, args ...interface{}) (pgx.Rows, error) { - rows, err := dbPool.Query(context.Background(), query, args...) - if err != nil { - return nil, err - } - return rows, nil -} - -// IsAliveConn checks whether the DB connections pool is alive -func IsAliveConn(ctx context.Context) (isAlive bool) { - if err := dbPool.Ping(ctx); err != nil { - return true - } - return isAlive -} - -// CloseDBConn closes the DB connections pool -func CloseDBConn() { - dbPool.Close() -} diff --git a/management-server/internal/database/queries.go b/management-server/internal/database/queries.go deleted file mode 100644 index 3c2b4cbed..000000000 --- a/management-server/internal/database/queries.go +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (c) 2022, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package database - -const ( - queryGetApplicationByUUID string = " SELECT " + - " APP.UUID," + - " APP.NAME," + - " APP.SUBSCRIBER_ID," + - " APP.ORGANIZATION ORGANIZATION," + - " SUB.USER_ID " + - " FROM " + - " SUBSCRIBER SUB," + - " APPLICATION APP " + - " WHERE " + - " APP.UUID = $1 " + - " AND APP.SUBSCRIBER_ID = SUB.SUBSCRIBER_ID" - - queryGetAllSubscriptionsForApplication string = "select " + - " SUB.uuid as UUID, " + - " API.api_uuid as API_UUID, " + - " API.api_version as API_VERSION, " + - " SUB.sub_status as SUB_STATUS, " + - " APP.organization as ORGANIZATION, " + - " SUB.created_by as CREATED_BY " + - " FROM " + - " APPLICATION APP, SUBSCRIPTION SUB, API API " + - " where 1 = 1 " + - " AND APP.application_id = SUB.application_id " + - " AND SUB.api_id = API.api_id " + - " AND APP.uuid = $1" - - queryConsumerKeysForApplication string = "select " + - " APPKEY.consumer_key, " + - " APPKEY.key_manager " + - " from " + - " application_key_mapping APPKEY, " + - " application APP " + - " where 1=1 " + - " AND APP.application_id = APPKEY.application_id " + - " AND APP.UUID = $1" - - querySubscriptionByUUID string = "select " + - " SUB.uuid, " + - " API.api_uuid, " + - " SUB.sub_status, " + - " API.organization, " + - " SUB.created_by " + - " from " + - " subscription SUB, " + - " api API " + - " where 1=1 " + - " AND SUB.api_id = API.api_id " + - " AND SUB.uuid = $1" - - queryCreateAPI string = "INSERT INTO API " + - "(API_UUID, API_NAME, API_PROVIDER, API_VERSION," + - "CONTEXT, ORGANIZATION, CREATED_BY, CREATED_TIME, API_TYPE, ARTIFACT, STATUS)" + - " VALUES " + "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)" - - queryDeleteAPI string = "DELETE FROM API" + - " WHERE " + - "API_UUID = $1" - - queryUpdateAPI string = "UPDATE API SET " + - "API_NAME = $2, " + - "API_PROVIDER = $3, " + - "API_VERSION = $4, " + - "CONTEXT = $5, " + - "ORGANIZATION = $6, " + - "UPDATED_BY = $7, " + - "UPDATED_TIME = $8, " + - "API_TYPE = $9, " + - "ARTIFACT = $10, " + - "STATUS = $11" + - " WHERE " + - "API_UUID = $1" -) diff --git a/management-server/internal/xds/server.go b/management-server/internal/xds/server.go index bf602ea08..23e26688f 100644 --- a/management-server/internal/xds/server.go +++ b/management-server/internal/xds/server.go @@ -27,8 +27,6 @@ import ( "sync" "time" - "github.com/wso2/apk/management-server/internal/database" - corev3 "github.com/envoyproxy/go-control-plane/envoy/config/core/v3" "github.com/envoyproxy/go-control-plane/pkg/cache/types" sub_service "github.com/wso2/apk/adapter/pkg/discovery/api/wso2/discovery/service/subscription" @@ -107,13 +105,13 @@ func AddSingleApplication(label string, application internal_types.ApplicationEv // } // } convertedApplication := &internal_application.Application{ - Uuid: application.UUID, - Name: application.Name, + Uuid: application.UUID, + Name: application.Name, // Policy: application.Policy, - Owner: application.Owner, + Owner: application.Owner, // Organization: application.Organization, // Keys: appKeys, - Attributes: application.Attributes, + Attributes: application.Attributes, } logger.LoggerXds.Debugf("Converted Application: %v", convertedApplication) @@ -180,58 +178,6 @@ func RemoveApplication(label, appUUID string) { logger.LoggerXds.Errorf("Application : %s is not found within snapshot for label %s", appUUID, label) } -// AddMultipleApplications adds the applications specified in applicationEventArray to the xds cache -// This will ideally be used to populate all applications in the startup of the mgt server. -func AddMultipleApplications(applicationEventArray []*internal_types.ApplicationEvent) { - snapshotMap := make(map[string]*wso2_cache.Snapshot) - version := rand.Intn(maxRandomInt) - - for _, event := range applicationEventArray { - label := event.Label - appUUID := event.UUID - - application, err := database.GetApplicationByUUID(appUUID) - if err != nil { - logger.LoggerDatabase.ErrorC(logging.ErrorDetails{ - Message: fmt.Sprintf("Error retrieving application for uuid : %s from database error: %v, "+ - "hence skipping add to xdx cache", appUUID, err), - Severity: logging.MINOR, - ErrorCode: 1101, - }) - continue - } - - snapshotEntry, snapshotFound := snapshotMap[label] - var newSnapshot wso2_cache.Snapshot - - if !snapshotFound { - newSnapshot, _ = wso2_cache.NewSnapshot(fmt.Sprint(version), map[wso2_resource.Type][]types.Resource{ - wso2_resource.ApplicationType: {application}, - }) - snapshotEntry = &newSnapshot - snapshotMap[label] = &newSnapshot - } else { - // error occurs if no snapshot is under the provided label - resourceMap := snapshotEntry.GetResourcesAndTTL(wso2_resource.ApplicationType) - resourceMap[appUUID] = types.ResourceWithTTL{ - Resource: application, - } - appResources := convertResourceMapToArray(resourceMap) - newSnapshot, _ = wso2_cache.NewSnapshot(fmt.Sprint(version), map[wso2_resource.Type][]types.Resource{ - wso2_resource.ApplicationType: appResources, - }) - snapshotMap[label] = &newSnapshot - } - } - applicationCacheMutex.Lock() - defer applicationCacheMutex.Unlock() - for label, snapshotEntry := range snapshotMap { - applicationCache.SetSnapshot(context.Background(), label, *snapshotEntry) - introducedLabels[label] = true - logger.LoggerXds.Infof("Application Snaphsot is updated for label %s with the version %d.", label, version) - } -} - func convertResourceMapToArray(resourceMap map[string]types.ResourceWithTTL) []types.Resource { var appResources []types.Resource for _, res := range resourceMap { @@ -326,12 +272,12 @@ func InitAPKMgtServer() { // AddSingleSubscription will update the Subscription specified by the UUID to the xds cache func AddSingleSubscription(label string, subscription internal_types.SubscriptionEvent) { convertedSubscription := &internal_application.Subscription{ - Uuid: subscription.UUID, + Uuid: subscription.UUID, // ApplicationRef: subscription.ApplicationRef, // ApiRef: subscription.APIRef, - SubStatus: subscription.SubStatus, + SubStatus: subscription.SubStatus, // PolicyId: subscription.PolicyID, - Organization: subscription.Organization, + Organization: subscription.Organization, // Subscriber: subscription.Subscriber, // Timetamp: subscription.TimeStamp, }