diff --git a/api/external/infra_proxy/infra_proxy.swagger.json b/api/external/infra_proxy/infra_proxy.swagger.json index aeccd8467dc..2a61a2220e9 100644 --- a/api/external/infra_proxy/infra_proxy.swagger.json +++ b/api/external/infra_proxy/infra_proxy.swagger.json @@ -4015,12 +4015,9 @@ "chef.automate.api.infra_proxy.response.GetInfraServerOrgs": { "type": "object", "properties": { - "orgs": { - "type": "array", - "items": { - "$ref": "#/definitions/chef.automate.api.infra_proxy.response.Org" - }, - "title": "Chef organization list from chef server" + "migration_id": { + "type": "string", + "title": "id of organisation migration" } } }, diff --git a/api/external/infra_proxy/response/orgs.pb.go b/api/external/infra_proxy/response/orgs.pb.go index 702756d69ff..cf3b2797767 100644 --- a/api/external/infra_proxy/response/orgs.pb.go +++ b/api/external/infra_proxy/response/orgs.pb.go @@ -265,8 +265,8 @@ type GetInfraServerOrgs struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - // Chef organization list from chef server - Orgs []*Org `protobuf:"bytes,1,rep,name=orgs,proto3" json:"orgs,omitempty"` + // id of organisation migration + MigrationId string `protobuf:"bytes,1,opt,name=migration_id,json=migrationId,proto3" json:"migration_id,omitempty"` } func (x *GetInfraServerOrgs) Reset() { @@ -301,11 +301,11 @@ func (*GetInfraServerOrgs) Descriptor() ([]byte, []int) { return file_external_infra_proxy_response_orgs_proto_rawDescGZIP(), []int{5} } -func (x *GetInfraServerOrgs) GetOrgs() []*Org { +func (x *GetInfraServerOrgs) GetMigrationId() string { if x != nil { - return x.Orgs + return x.MigrationId } - return nil + return "" } type Org struct { @@ -480,33 +480,31 @@ var file_external_infra_proxy_response_orgs_proto_rawDesc = []byte{ 0x6f, 0x72, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x2b, 0x2e, 0x63, 0x68, 0x65, 0x66, 0x2e, 0x61, 0x75, 0x74, 0x6f, 0x6d, 0x61, 0x74, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x5f, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2e, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x2e, 0x4f, 0x72, 0x67, 0x52, 0x03, 0x6f, 0x72, 0x67, 0x22, 0x55, 0x0a, 0x12, 0x47, + 0x73, 0x65, 0x2e, 0x4f, 0x72, 0x67, 0x52, 0x03, 0x6f, 0x72, 0x67, 0x22, 0x37, 0x0a, 0x12, 0x47, 0x65, 0x74, 0x49, 0x6e, 0x66, 0x72, 0x61, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x4f, 0x72, 0x67, - 0x73, 0x12, 0x3f, 0x0a, 0x04, 0x6f, 0x72, 0x67, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, - 0x2b, 0x2e, 0x63, 0x68, 0x65, 0x66, 0x2e, 0x61, 0x75, 0x74, 0x6f, 0x6d, 0x61, 0x74, 0x65, 0x2e, - 0x61, 0x70, 0x69, 0x2e, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x5f, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2e, - 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x4f, 0x72, 0x67, 0x52, 0x04, 0x6f, 0x72, - 0x67, 0x73, 0x22, 0xa6, 0x01, 0x0a, 0x03, 0x4f, 0x72, 0x67, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, - 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1d, - 0x0a, 0x0a, 0x61, 0x64, 0x6d, 0x69, 0x6e, 0x5f, 0x75, 0x73, 0x65, 0x72, 0x18, 0x03, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x09, 0x61, 0x64, 0x6d, 0x69, 0x6e, 0x55, 0x73, 0x65, 0x72, 0x12, 0x23, 0x0a, - 0x0d, 0x63, 0x72, 0x65, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x5f, 0x69, 0x64, 0x18, 0x04, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x63, 0x72, 0x65, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, - 0x49, 0x64, 0x12, 0x1b, 0x0a, 0x09, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, - 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x49, 0x64, 0x12, - 0x1a, 0x0a, 0x08, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x73, 0x18, 0x06, 0x20, 0x03, 0x28, - 0x09, 0x52, 0x08, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x73, 0x22, 0x51, 0x0a, 0x10, 0x52, - 0x65, 0x73, 0x65, 0x74, 0x4f, 0x72, 0x67, 0x41, 0x64, 0x6d, 0x69, 0x6e, 0x4b, 0x65, 0x79, 0x12, - 0x3d, 0x0a, 0x03, 0x6f, 0x72, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x2b, 0x2e, 0x63, - 0x68, 0x65, 0x66, 0x2e, 0x61, 0x75, 0x74, 0x6f, 0x6d, 0x61, 0x74, 0x65, 0x2e, 0x61, 0x70, 0x69, - 0x2e, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x5f, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2e, 0x72, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x4f, 0x72, 0x67, 0x52, 0x03, 0x6f, 0x72, 0x67, 0x42, 0x3c, - 0x5a, 0x3a, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x68, 0x65, - 0x66, 0x2f, 0x61, 0x75, 0x74, 0x6f, 0x6d, 0x61, 0x74, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x65, - 0x78, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x5f, 0x70, 0x72, - 0x6f, 0x78, 0x79, 0x2f, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x62, 0x06, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x33, + 0x73, 0x12, 0x21, 0x0a, 0x0c, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x69, + 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x49, 0x64, 0x22, 0xa6, 0x01, 0x0a, 0x03, 0x4f, 0x72, 0x67, 0x12, 0x0e, 0x0a, 0x02, + 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, + 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, + 0x12, 0x1d, 0x0a, 0x0a, 0x61, 0x64, 0x6d, 0x69, 0x6e, 0x5f, 0x75, 0x73, 0x65, 0x72, 0x18, 0x03, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x61, 0x64, 0x6d, 0x69, 0x6e, 0x55, 0x73, 0x65, 0x72, 0x12, + 0x23, 0x0a, 0x0d, 0x63, 0x72, 0x65, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x5f, 0x69, 0x64, + 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x63, 0x72, 0x65, 0x64, 0x65, 0x6e, 0x74, 0x69, + 0x61, 0x6c, 0x49, 0x64, 0x12, 0x1b, 0x0a, 0x09, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x5f, 0x69, + 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x49, + 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x73, 0x18, 0x06, 0x20, + 0x03, 0x28, 0x09, 0x52, 0x08, 0x70, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x73, 0x22, 0x51, 0x0a, + 0x10, 0x52, 0x65, 0x73, 0x65, 0x74, 0x4f, 0x72, 0x67, 0x41, 0x64, 0x6d, 0x69, 0x6e, 0x4b, 0x65, + 0x79, 0x12, 0x3d, 0x0a, 0x03, 0x6f, 0x72, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x2b, + 0x2e, 0x63, 0x68, 0x65, 0x66, 0x2e, 0x61, 0x75, 0x74, 0x6f, 0x6d, 0x61, 0x74, 0x65, 0x2e, 0x61, + 0x70, 0x69, 0x2e, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x5f, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2e, 0x72, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x4f, 0x72, 0x67, 0x52, 0x03, 0x6f, 0x72, 0x67, + 0x42, 0x3c, 0x5a, 0x3a, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, + 0x68, 0x65, 0x66, 0x2f, 0x61, 0x75, 0x74, 0x6f, 0x6d, 0x61, 0x74, 0x65, 0x2f, 0x61, 0x70, 0x69, + 0x2f, 0x65, 0x78, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x5f, + 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2f, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x62, 0x06, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -538,13 +536,12 @@ var file_external_infra_proxy_response_orgs_proto_depIdxs = []int32{ 6, // 2: chef.automate.api.infra_proxy.response.UpdateOrg.org:type_name -> chef.automate.api.infra_proxy.response.Org 6, // 3: chef.automate.api.infra_proxy.response.GetOrgs.orgs:type_name -> chef.automate.api.infra_proxy.response.Org 6, // 4: chef.automate.api.infra_proxy.response.GetOrg.org:type_name -> chef.automate.api.infra_proxy.response.Org - 6, // 5: chef.automate.api.infra_proxy.response.GetInfraServerOrgs.orgs:type_name -> chef.automate.api.infra_proxy.response.Org - 6, // 6: chef.automate.api.infra_proxy.response.ResetOrgAdminKey.org:type_name -> chef.automate.api.infra_proxy.response.Org - 7, // [7:7] is the sub-list for method output_type - 7, // [7:7] 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 + 6, // 5: chef.automate.api.infra_proxy.response.ResetOrgAdminKey.org:type_name -> chef.automate.api.infra_proxy.response.Org + 6, // [6:6] is the sub-list for method output_type + 6, // [6:6] is the sub-list for method input_type + 6, // [6:6] is the sub-list for extension type_name + 6, // [6:6] is the sub-list for extension extendee + 0, // [0:6] is the sub-list for field type_name } func init() { file_external_infra_proxy_response_orgs_proto_init() } diff --git a/api/external/infra_proxy/response/orgs.proto b/api/external/infra_proxy/response/orgs.proto index 0818c81489b..50359c283ce 100644 --- a/api/external/infra_proxy/response/orgs.proto +++ b/api/external/infra_proxy/response/orgs.proto @@ -29,8 +29,8 @@ message GetOrg { } message GetInfraServerOrgs { - // Chef organization list from chef server - repeated Org orgs = 1; + // id of organisation migration + string migration_id = 1; } message Org { diff --git a/api/interservice/infra_proxy/response/orgs.pb.go b/api/interservice/infra_proxy/response/orgs.pb.go index 97c017e30d3..67e48d6f08e 100644 --- a/api/interservice/infra_proxy/response/orgs.pb.go +++ b/api/interservice/infra_proxy/response/orgs.pb.go @@ -265,8 +265,8 @@ type GetInfraServerOrgs struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - // Chef organization list from chef server - Orgs []*Org `protobuf:"bytes,1,rep,name=orgs,proto3" json:"orgs,omitempty" toml:"orgs,omitempty" mapstructure:"orgs,omitempty"` + // id of organisation migration + MigrationId string `protobuf:"bytes,1,opt,name=migration_id,json=migrationId,proto3" json:"migration_id,omitempty" toml:"migration_id,omitempty" mapstructure:"migration_id,omitempty"` } func (x *GetInfraServerOrgs) Reset() { @@ -301,11 +301,11 @@ func (*GetInfraServerOrgs) Descriptor() ([]byte, []int) { return file_interservice_infra_proxy_response_orgs_proto_rawDescGZIP(), []int{5} } -func (x *GetInfraServerOrgs) GetOrgs() []*Org { +func (x *GetInfraServerOrgs) GetMigrationId() string { if x != nil { - return x.Orgs + return x.MigrationId } - return nil + return "" } type Org struct { @@ -482,33 +482,31 @@ var file_interservice_infra_proxy_response_orgs_proto_rawDesc = []byte{ 0x68, 0x65, 0x66, 0x2e, 0x61, 0x75, 0x74, 0x6f, 0x6d, 0x61, 0x74, 0x65, 0x2e, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x5f, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2e, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x4f, 0x72, 0x67, 0x52, 0x03, 0x6f, 0x72, - 0x67, 0x22, 0x58, 0x0a, 0x12, 0x47, 0x65, 0x74, 0x49, 0x6e, 0x66, 0x72, 0x61, 0x53, 0x65, 0x72, - 0x76, 0x65, 0x72, 0x4f, 0x72, 0x67, 0x73, 0x12, 0x42, 0x0a, 0x04, 0x6f, 0x72, 0x67, 0x73, 0x18, - 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2e, 0x2e, 0x63, 0x68, 0x65, 0x66, 0x2e, 0x61, 0x75, 0x74, - 0x6f, 0x6d, 0x61, 0x74, 0x65, 0x2e, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x69, 0x6e, 0x66, - 0x72, 0x61, 0x5f, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2e, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x2e, 0x4f, 0x72, 0x67, 0x52, 0x04, 0x6f, 0x72, 0x67, 0x73, 0x22, 0xa6, 0x01, 0x0a, 0x03, - 0x4f, 0x72, 0x67, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1d, 0x0a, 0x0a, 0x61, 0x64, 0x6d, 0x69, 0x6e, - 0x5f, 0x75, 0x73, 0x65, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x61, 0x64, 0x6d, - 0x69, 0x6e, 0x55, 0x73, 0x65, 0x72, 0x12, 0x23, 0x0a, 0x0d, 0x63, 0x72, 0x65, 0x64, 0x65, 0x6e, - 0x74, 0x69, 0x61, 0x6c, 0x5f, 0x69, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x63, - 0x72, 0x65, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x49, 0x64, 0x12, 0x1b, 0x0a, 0x09, 0x73, - 0x65, 0x72, 0x76, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, - 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x72, 0x6f, 0x6a, - 0x65, 0x63, 0x74, 0x73, 0x18, 0x06, 0x20, 0x03, 0x28, 0x09, 0x52, 0x08, 0x70, 0x72, 0x6f, 0x6a, - 0x65, 0x63, 0x74, 0x73, 0x22, 0x54, 0x0a, 0x10, 0x52, 0x65, 0x73, 0x65, 0x74, 0x4f, 0x72, 0x67, - 0x41, 0x64, 0x6d, 0x69, 0x6e, 0x4b, 0x65, 0x79, 0x12, 0x40, 0x0a, 0x03, 0x6f, 0x72, 0x67, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x2e, 0x2e, 0x63, 0x68, 0x65, 0x66, 0x2e, 0x61, 0x75, 0x74, - 0x6f, 0x6d, 0x61, 0x74, 0x65, 0x2e, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x69, 0x6e, 0x66, - 0x72, 0x61, 0x5f, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2e, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x2e, 0x4f, 0x72, 0x67, 0x52, 0x03, 0x6f, 0x72, 0x67, 0x42, 0x40, 0x5a, 0x3e, 0x67, 0x69, - 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x68, 0x65, 0x66, 0x2f, 0x61, 0x75, - 0x74, 0x6f, 0x6d, 0x61, 0x74, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, - 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2f, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x5f, 0x70, 0x72, - 0x6f, 0x78, 0x79, 0x2f, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x62, 0x06, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x33, + 0x67, 0x22, 0x37, 0x0a, 0x12, 0x47, 0x65, 0x74, 0x49, 0x6e, 0x66, 0x72, 0x61, 0x53, 0x65, 0x72, + 0x76, 0x65, 0x72, 0x4f, 0x72, 0x67, 0x73, 0x12, 0x21, 0x0a, 0x0c, 0x6d, 0x69, 0x67, 0x72, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6d, + 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x22, 0xa6, 0x01, 0x0a, 0x03, 0x4f, + 0x72, 0x67, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, + 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1d, 0x0a, 0x0a, 0x61, 0x64, 0x6d, 0x69, 0x6e, 0x5f, + 0x75, 0x73, 0x65, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x61, 0x64, 0x6d, 0x69, + 0x6e, 0x55, 0x73, 0x65, 0x72, 0x12, 0x23, 0x0a, 0x0d, 0x63, 0x72, 0x65, 0x64, 0x65, 0x6e, 0x74, + 0x69, 0x61, 0x6c, 0x5f, 0x69, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x63, 0x72, + 0x65, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x49, 0x64, 0x12, 0x1b, 0x0a, 0x09, 0x73, 0x65, + 0x72, 0x76, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x73, + 0x65, 0x72, 0x76, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x72, 0x6f, 0x6a, 0x65, + 0x63, 0x74, 0x73, 0x18, 0x06, 0x20, 0x03, 0x28, 0x09, 0x52, 0x08, 0x70, 0x72, 0x6f, 0x6a, 0x65, + 0x63, 0x74, 0x73, 0x22, 0x54, 0x0a, 0x10, 0x52, 0x65, 0x73, 0x65, 0x74, 0x4f, 0x72, 0x67, 0x41, + 0x64, 0x6d, 0x69, 0x6e, 0x4b, 0x65, 0x79, 0x12, 0x40, 0x0a, 0x03, 0x6f, 0x72, 0x67, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x2e, 0x2e, 0x63, 0x68, 0x65, 0x66, 0x2e, 0x61, 0x75, 0x74, 0x6f, + 0x6d, 0x61, 0x74, 0x65, 0x2e, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x69, 0x6e, 0x66, 0x72, + 0x61, 0x5f, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2e, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x2e, 0x4f, 0x72, 0x67, 0x52, 0x03, 0x6f, 0x72, 0x67, 0x42, 0x40, 0x5a, 0x3e, 0x67, 0x69, 0x74, + 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x68, 0x65, 0x66, 0x2f, 0x61, 0x75, 0x74, + 0x6f, 0x6d, 0x61, 0x74, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x73, + 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2f, 0x69, 0x6e, 0x66, 0x72, 0x61, 0x5f, 0x70, 0x72, 0x6f, + 0x78, 0x79, 0x2f, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x33, } var ( @@ -540,13 +538,12 @@ var file_interservice_infra_proxy_response_orgs_proto_depIdxs = []int32{ 6, // 2: chef.automate.domain.infra_proxy.response.UpdateOrg.org:type_name -> chef.automate.domain.infra_proxy.response.Org 6, // 3: chef.automate.domain.infra_proxy.response.GetOrgs.orgs:type_name -> chef.automate.domain.infra_proxy.response.Org 6, // 4: chef.automate.domain.infra_proxy.response.GetOrg.org:type_name -> chef.automate.domain.infra_proxy.response.Org - 6, // 5: chef.automate.domain.infra_proxy.response.GetInfraServerOrgs.orgs:type_name -> chef.automate.domain.infra_proxy.response.Org - 6, // 6: chef.automate.domain.infra_proxy.response.ResetOrgAdminKey.org:type_name -> chef.automate.domain.infra_proxy.response.Org - 7, // [7:7] is the sub-list for method output_type - 7, // [7:7] 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 + 6, // 5: chef.automate.domain.infra_proxy.response.ResetOrgAdminKey.org:type_name -> chef.automate.domain.infra_proxy.response.Org + 6, // [6:6] is the sub-list for method output_type + 6, // [6:6] is the sub-list for method input_type + 6, // [6:6] is the sub-list for extension type_name + 6, // [6:6] is the sub-list for extension extendee + 0, // [0:6] is the sub-list for field type_name } func init() { file_interservice_infra_proxy_response_orgs_proto_init() } diff --git a/api/interservice/infra_proxy/response/orgs.proto b/api/interservice/infra_proxy/response/orgs.proto index 3cb0703fd92..444a570d324 100644 --- a/api/interservice/infra_proxy/response/orgs.proto +++ b/api/interservice/infra_proxy/response/orgs.proto @@ -29,8 +29,8 @@ message GetOrg { } message GetInfraServerOrgs { - // Chef organization list from chef server - repeated Org orgs = 1; + // id of organisation migration + string migration_id = 1; } message Org { diff --git a/components/automate-gateway/api/infra_proxy.pb.swagger.go b/components/automate-gateway/api/infra_proxy.pb.swagger.go index e14cbce2828..2af6b23c551 100644 --- a/components/automate-gateway/api/infra_proxy.pb.swagger.go +++ b/components/automate-gateway/api/infra_proxy.pb.swagger.go @@ -4018,12 +4018,9 @@ func init() { "chef.automate.api.infra_proxy.response.GetInfraServerOrgs": { "type": "object", "properties": { - "orgs": { - "type": "array", - "items": { - "$ref": "#/definitions/chef.automate.api.infra_proxy.response.Org" - }, - "title": "Chef organization list from chef server" + "migration_id": { + "type": "string", + "title": "id of organisation migration" } } }, diff --git a/components/automate-gateway/handler/infra_proxy/orgs.go b/components/automate-gateway/handler/infra_proxy/orgs.go index a8fed1e5496..81e3eb4fec3 100644 --- a/components/automate-gateway/handler/infra_proxy/orgs.go +++ b/components/automate-gateway/handler/infra_proxy/orgs.go @@ -118,7 +118,7 @@ func (c *InfraProxyServer) GetInfraServerOrgs(ctx context.Context, r *gwreq.GetI return nil, err } return &gwres.GetInfraServerOrgs{ - Orgs: fromUpstreamOrgs(res.Orgs), + MigrationId: res.MigrationId, }, nil } func fromUpstreamOrg(t *infra_res.Org) *gwres.Org { diff --git a/components/infra-proxy-service/constants/constants.go b/components/infra-proxy-service/constants/constants.go index fc7fc4556c8..cbcddd2b2f0 100644 --- a/components/infra-proxy-service/constants/constants.go +++ b/components/infra-proxy-service/constants/constants.go @@ -1,6 +1,48 @@ package constants +// MigrationPhase: enum of migration phases +type MigrationPhase int64 + +// Migration phases id should be between 100 & 5000 +const ( + StartMigration = 100 + CompleteMigration = 5000 +) + +// MigrationStatus: enum of migration status +type MigrationStatus int64 + // IAM default project ID const ( UnassignedProjectID = "(unassigned)" ) + +const ( + StartFileUpload MigrationPhase = iota + 1000 + CompleteFileUpload + FailedFileUpload + StartUnzip + ComplteUnzip + FailedUnzip + StartZipParsing + CompleteZipParsing + FailedZipParsing + StartOrgMigration + CompleteOrgMigration + FailedOrgMigration + StartUserMigration + CompleteUserMigration + FailedUserMigration + StartAssciation + CompleteAssciation + FailedAssciation + StartPermissionMigration + CompletePermissionMigration + FailedPermissionMigration +) + +const ( + InProgress MigrationStatus = iota + 100 + Completed + Failed +) diff --git a/components/infra-proxy-service/server/migration.go b/components/infra-proxy-service/server/migration.go new file mode 100644 index 00000000000..5e37dbf09b4 --- /dev/null +++ b/components/infra-proxy-service/server/migration.go @@ -0,0 +1,38 @@ +package server + +import ( + "context" + "errors" + + secrets "github.com/chef/automate/api/external/secrets" + "github.com/chef/automate/components/infra-proxy-service/service" +) + +var IsMigrationAlreadyRunning bool + +func setMigrationStatus(status bool) { + IsMigrationAlreadyRunning = status +} + +// getChefClient: creates the chef client +func (s *Server) getChefClient(ctx context.Context, serverId string) (*ChefClient, error) { + // Get the credential ID from servers table + server, err := s.service.Storage.GetServer(ctx, serverId) + if err != nil { + return nil, service.ParseStorageError(err, serverId, "server") + } + if server.CredentialID == "" { + return nil, errors.New("webui key is not available with server") + } + // Get web ui key from secrets service + secret, err := s.service.Secrets.Read(ctx, &secrets.Id{Id: server.CredentialID}) + if err != nil { + return nil, err + } + + c, err := s.createChefServerClient(ctx, serverId, GetAdminKeyFrom(secret), "pivotal", true) + if err != nil { + return nil, err + } + return c, nil +} diff --git a/components/infra-proxy-service/server/orgs.go b/components/infra-proxy-service/server/orgs.go index b3de9e594fa..cf42c41dcd9 100644 --- a/components/infra-proxy-service/server/orgs.go +++ b/components/infra-proxy-service/server/orgs.go @@ -11,6 +11,7 @@ import ( "github.com/chef/automate/components/infra-proxy-service/service" "github.com/chef/automate/components/infra-proxy-service/storage" "github.com/chef/automate/components/infra-proxy-service/validation" + "github.com/gofrs/uuid" ) // CreateOrg creates a new org @@ -214,42 +215,61 @@ func (s *Server) ResetOrgAdminKey(ctx context.Context, req *request.ResetOrgAdmi //GetInfraServerOrgs: Fetches the list of automate infra server organisations from the chef server and save it into the automate back end DB func (s *Server) GetInfraServerOrgs(ctx context.Context, req *request.GetInfraServerOrgs) (*response.GetInfraServerOrgs, error) { - // Get the credential ID from servers table - server, err := s.service.Storage.GetServer(ctx, req.ServerId) - if err != nil { - return nil, service.ParseStorageError(err, *req, "server") - } - if server.CredentialID == "" { - return nil, errors.New("webui key is not available with server") + // Check whether any migration is in progress or not + if IsMigrationAlreadyRunning { + return nil, errors.New("Migration is already in process") } - // Get web ui key from secrets service - secret, err := s.service.Secrets.Read(ctx, &secrets.Id{Id: server.CredentialID}) + + // Get chef client + client, err := s.getChefClient(ctx, req.ServerId) if err != nil { return nil, err } - // Get organization list from chef server - c, err := s.createChefServerClient(ctx, req.ServerId, GetAdminKeyFrom(secret), "pivotal", true) + + setMigrationStatus(true) + defer setMigrationStatus(false) + + //Store the status in migration table as in progress + migration, err := s.service.Migration.StartMigration(ctx, uuid.Must(uuid.NewV4()).String(), req.ServerId) + migration, err = s.service.Migration.StartOrgMigration(ctx, uuid.Must(uuid.NewV4()).String(), req.ServerId) if err != nil { return nil, err } + + // Get and save orgs in goroutine + go s.getInfraServerOrgs(client, req.ServerId, migration) + + return &response.GetInfraServerOrgs{ + MigrationId: migration.ID, + }, nil +} + +func (s *Server) getInfraServerOrgs(c *ChefClient, serverId string, migration storage.Migration) { + //var migrationStatus string + var totalSucceeded, totalSkipped, totalFailed int64 + + defer func() { + _, _ = s.service.Migration.CompleteOrgMigration(context.Background(), migration.MigrationID, serverId, totalSucceeded, totalSkipped, totalFailed) + }() + + // Get organisation list from chef server orgsList, err := c.client.Organizations.List() if err != nil { - return nil, ParseAPIError(err) + //migrationStatus = "Failed" + return } // Save organisations in backend DB - orgs := []storage.Org{} for key := range orgsList { - org, err := s.service.Storage.StoreOrg(ctx, key, key, "", "", req.ServerId, nil) + _, err := s.service.Storage.StoreOrg(context.Background(), key, key, "", "", serverId, nil) if err != nil { - return nil, service.ParseStorageError(err, *req, "org") + totalFailed++ + continue } - orgs = append(orgs, org) + totalSucceeded++ } - - return &response.GetInfraServerOrgs{ - Orgs: fromStorageToListOrgs(orgs), - }, nil + //migrationStatus = "Completed" + return } // Create a response.Org from a storage.Org diff --git a/components/infra-proxy-service/service/service.go b/components/infra-proxy-service/service/service.go index cc2580087e3..b017ece5246 100644 --- a/components/infra-proxy-service/service/service.go +++ b/components/infra-proxy-service/service/service.go @@ -21,21 +21,22 @@ type Service struct { Logger logger.Logger ConnFactory *secureconn.Factory Storage storage.Storage + Migration storage.MigrationStorage Secrets secrets.SecretsServiceClient } // Start returns an instance of Service that connects to a postgres storage backend. func Start(l logger.Logger, migrationsConfig migration.Config, connFactory *secureconn.Factory, secretsClient secrets.SecretsServiceClient, authzClient authz.AuthorizationServiceClient) (*Service, error) { - p, err := postgres.New(l, migrationsConfig, authzClient) + p, pObj, err := postgres.New(l, migrationsConfig, authzClient) if err != nil { return nil, err } - return &Service{ Logger: l, ConnFactory: connFactory, Storage: p, + Migration: pObj, Secrets: secretsClient, }, nil } diff --git a/components/infra-proxy-service/storage/postgres/migration/sql/07_migration.down.sql b/components/infra-proxy-service/storage/postgres/migration/sql/07_migration.down.sql index e14d9c12fcb..2c4d81fba2d 100644 --- a/components/infra-proxy-service/storage/postgres/migration/sql/07_migration.down.sql +++ b/components/infra-proxy-service/storage/postgres/migration/sql/07_migration.down.sql @@ -6,3 +6,9 @@ DROP TABLE IF EXISTS migration_type; -- drop table migration_status DROP TABLE IF EXISTS migration_status; + +-- drop function insert_migration +DROP FUNCTION IF EXISTS insert_migration; + +-- drop type migration_records +DROP TYPE IF EXISTS migration_records; diff --git a/components/infra-proxy-service/storage/postgres/migration/sql/07_migration.up.sql b/components/infra-proxy-service/storage/postgres/migration/sql/07_migration.up.sql index eeda0041384..814796af0af 100644 --- a/components/infra-proxy-service/storage/postgres/migration/sql/07_migration.up.sql +++ b/components/infra-proxy-service/storage/postgres/migration/sql/07_migration.up.sql @@ -1,36 +1,100 @@ --create table migration_type CREATE TABLE IF NOT EXISTS migration_type ( - id TEXT PRIMARY KEY, + id int PRIMARY KEY, type TEXT NOT NULL DEFAULT '' ); --create table migration_status CREATE TABLE IF NOT EXISTS migration_status ( - id TEXT PRIMARY KEY, + id int PRIMARY KEY, status_message TEXT NOT NULL DEFAULT 'In Progress' ); --create table migration CREATE TABLE IF NOT EXISTS migration ( - id TEXT PRIMARY KEY, - type_id TEXT NOT NULL references migration_type(id) ON DELETE RESTRICT, - status_id TEXT NOT NULL references migration_status(id) ON DELETE RESTRICT, - server_id TEXT NOT NULL references servers(id) ON DELETE RESTRICT, - total_succeeded int, - total_skipped int, - total_failed int, - created_at TIMESTAMPTZ NOT NULL, - updated_at TIMESTAMPTZ NOT NULL + id SERIAL PRIMARY KEY, + migration_id TEXT NOT NULL, + server_id TEXT NOT NULL references servers(id) ON DELETE RESTRICT, + type_id int NOT NULL references migration_type(id) ON DELETE RESTRICT, + status_id int NOT NULL references migration_status(id) ON DELETE RESTRICT, + total_succeeded int NOT NULL DEFAULT 0, + total_skipped int NOT NULL DEFAULT 0, + total_failed int NOT NULL DEFAULT 0, + message TEXT NOT NULL DEFAULT '', + updated_timestamp TIMESTAMPTZ NOT NULL DEFAULT now() ); CREATE INDEX IF NOT EXISTS migration_server_id_index ON migration (server_id); +CREATE INDEX IF NOT EXISTS migration_migration_id_index ON migration (migration_id); -- Insert rows into migration_type -INSERT INTO migration_type (id,type) -VALUES (md5(RANDOM()::TEXT),'user'), - (md5(RANDOM()::TEXT),'org'); +INSERT INTO migration_type VALUES + (100,'Migration started'), + (1000,'Upload of zip file started'), + (1001,'Upload of zip file completed'), + (1002,'Upload of zip file failed'), + (1003,'Unzip of file started'), + (1004,'Unzip of file completed'), + (1005,'Unzip of file failed'), + (1006,'Parsing of zip file started'), + (1007,'Parsing of zip file completed'), + (1008,'Parsing of zip file failed'), + (1009,'Migration of organization started'), + (1010,'Migration of organization completed'), + (1011,'Migration of organization failed'), + (1012,'Migration of users started'), + (1013,'Migration of users completed'), + (1014,'Migration of users failed'), + (1015,'Association of users to orgs started'), + (1016,'Association of users to orgs completed'), + (1017,'Association of users to orgs failed'), + (1018,'Migrating user permissions started'), + (1019,'Migrating user permissions completed'), + (1020,'Migrating user permissions failed'), + (5000,'Migration Completed') +; -- Insert rows into migration_status -INSERT INTO migration_status(id,status_message) -VALUES (md5(RANDOM()::TEXT),'In Progress'), - (md5(RANDOM()::TEXT),'Completed'), - (md5(RANDOM()::TEXT),'Failed'); +INSERT INTO migration_status VALUES + (100,'In Progress'), + (101,'Completed'), + (102,'Failed') +; + +-- Created type migration_records +CREATE TYPE migration_records AS ( + id TEXT, + migration_id TEXT, + server_id TEXT, + type_id int, + status_id int, + total_succeeded int, + total_skipped int, + total_failed int, + message TEXT, + updated_timestamp TIMESTAMPTZ +); + +-- Insert entry into migration table +CREATE OR REPLACE FUNCTION insert_migration(migrationId TEXT, serverId TEXT, typeId int, statusId int, totalSucceeded int, totalSkipped int, totalFailed int, msg TEXT) +RETURNS json AS +$$ +DECLARE result_record migration_records; +BEGIN + INSERT INTO migration ( + migration_id, server_id, + type_id, status_id, + total_succeeded, total_skipped, total_failed, + message, updated_timestamp) + VALUES (migrationId, serverId, typeId, statusId, totalSucceeded, totalSkipped, totalFailed, msg, now()) + RETURNING id, migration_id, server_id,type_id, status_id, total_succeeded, total_skipped, total_failed, message, updated_timestamp + INTO + result_record.id,result_record.migration_id,result_record.server_id, + result_record.type_id,result_record.status_id, + result_record.total_succeeded,result_record.total_skipped,result_record.total_failed, + result_record.message,result_record.updated_timestamp; + + RETURN row_to_json(result_record); + +END; +$$ +LANGUAGE plpgsql; diff --git a/components/infra-proxy-service/storage/postgres/migrations.go b/components/infra-proxy-service/storage/postgres/migrations.go new file mode 100644 index 00000000000..631491b9205 --- /dev/null +++ b/components/infra-proxy-service/storage/postgres/migrations.go @@ -0,0 +1,145 @@ +package postgres + +import ( + "context" + "encoding/json" + + "github.com/chef/automate/components/infra-proxy-service/constants" + "github.com/chef/automate/components/infra-proxy-service/storage" +) + +// StartMigration Insert a migration entry to the DB for migration started +func (p *postgres) StartMigration(ctx context.Context, migrationId, serverId string) (storage.Migration, error) { + return p.insertMigration(ctx, migrationId, serverId, "", int64(constants.StartMigration), int64(constants.InProgress), 0, 0, 0) +} + +// StartFileUpload Insert a migration entry to the DB for File upload started +func (p *postgres) StartFileUpload(ctx context.Context, migrationId, serverId string) (storage.Migration, error) { + return p.insertMigration(ctx, migrationId, serverId, "", int64(constants.StartFileUpload), int64(constants.InProgress), 0, 0, 0) +} + +// CompleteFileUpload Insert a migration entry to the DB for File upload completed +func (p *postgres) CompleteFileUpload(ctx context.Context, migrationId, serverId string, totalSucceeded, totalSkipped, totalFailed int64) (storage.Migration, error) { + return p.insertMigration(ctx, migrationId, serverId, "", int64(constants.CompleteFileUpload), int64(constants.Completed), totalSucceeded, totalSkipped, totalFailed) +} + +// CompleteFileUpload Insert a migration entry to the DB for file upload failed +func (p *postgres) FailedFileUpload(ctx context.Context, migrationId, serverId, message string, totalSucceeded, totalSkipped, totalFailed int64) (storage.Migration, error) { + return p.insertMigration(ctx, migrationId, serverId, message, int64(constants.FailedFileUpload), int64(constants.Failed), totalSucceeded, totalSkipped, totalFailed) +} + +// StartUnzip Insert a migration entry to the DB for File unzip started +func (p *postgres) StartUnzip(ctx context.Context, migrationId, serverId string) (storage.Migration, error) { + return p.insertMigration(ctx, migrationId, serverId, "", int64(constants.StartUnzip), int64(constants.InProgress), 0, 0, 0) +} + +// ComplteUnzip Insert a migration entry to the DB for File unzip completed +func (p *postgres) ComplteUnzip(ctx context.Context, migrationId, serverId string, totalSucceeded, totalSkipped, totalFailed int64) (storage.Migration, error) { + return p.insertMigration(ctx, migrationId, serverId, "", int64(constants.ComplteUnzip), int64(constants.Completed), totalSucceeded, totalSkipped, totalFailed) +} + +// FailedUnzip Insert a migration entry to the DB for file unzip failed +func (p *postgres) FailedUnzip(ctx context.Context, migrationId, serverId, message string, totalSucceeded, totalSkipped, totalFailed int64) (storage.Migration, error) { + return p.insertMigration(ctx, migrationId, serverId, message, int64(constants.FailedUnzip), int64(constants.Failed), totalSucceeded, totalSkipped, totalFailed) +} + +// StartZipParsing Insert a migration entry to the DB for zip parsing started +func (p *postgres) StartZipParsing(ctx context.Context, migrationId, serverId string) (storage.Migration, error) { + return p.insertMigration(ctx, migrationId, serverId, "", int64(constants.StartZipParsing), int64(constants.InProgress), 0, 0, 0) +} + +// CompleteZipParsing Insert a migration entry to the DB for zip parsing completed +func (p *postgres) CompleteZipParsing(ctx context.Context, migrationId, serverId string, totalSucceeded, totalSkipped, totalFailed int64) (storage.Migration, error) { + return p.insertMigration(ctx, migrationId, serverId, "", int64(constants.CompleteZipParsing), int64(constants.Completed), totalSucceeded, totalSkipped, totalFailed) +} + +// FailedZipParsing Insert a migration entry to the DB for zip parsing failed +func (p *postgres) FailedZipParsing(ctx context.Context, migrationId, serverId, message string, totalSucceeded, totalSkipped, totalFailed int64) (storage.Migration, error) { + return p.insertMigration(ctx, migrationId, serverId, message, int64(constants.FailedZipParsing), int64(constants.Failed), totalSucceeded, totalSkipped, totalFailed) +} + +// StartOrgMigration Insert a migration entry to the DB for org migration started +func (p *postgres) StartOrgMigration(ctx context.Context, migrationId, serverId string) (storage.Migration, error) { + return p.insertMigration(ctx, migrationId, serverId, "", int64(constants.StartOrgMigration), int64(constants.InProgress), 0, 0, 0) +} + +// CompleteOrgMigration Insert a migration entry to the DB for org migration completed +func (p *postgres) CompleteOrgMigration(ctx context.Context, migrationId, serverId string, totalSucceeded, totalSkipped, totalFailed int64) (storage.Migration, error) { + return p.insertMigration(ctx, migrationId, serverId, "", int64(constants.CompleteOrgMigration), int64(constants.Completed), totalSucceeded, totalSkipped, totalFailed) +} + +// FailedOrgMigration Insert a migration entry to the DB for org migration failed +func (p *postgres) FailedOrgMigration(ctx context.Context, migrationId, serverId, message string, totalSucceeded, totalSkipped, totalFailed int64) (storage.Migration, error) { + return p.insertMigration(ctx, migrationId, serverId, message, int64(constants.FailedOrgMigration), int64(constants.Failed), totalSucceeded, totalSkipped, totalFailed) +} + +// StartUserMigration Insert a migration entry to the DB for user migration started +func (p *postgres) StartUserMigration(ctx context.Context, migrationId, serverId string) (storage.Migration, error) { + return p.insertMigration(ctx, migrationId, serverId, "", int64(constants.StartUserMigration), int64(constants.InProgress), 0, 0, 0) +} + +// CompleteUserMigration Insert a migration entry to the DB for user migration completed +func (p *postgres) CompleteUserMigration(ctx context.Context, migrationId, serverId string, totalSucceeded, totalSkipped, totalFailed int64) (storage.Migration, error) { + return p.insertMigration(ctx, migrationId, serverId, "", int64(constants.CompleteUserMigration), int64(constants.Completed), totalSucceeded, totalSkipped, totalFailed) +} + +// FailedUserMigration Insert a migration entry to the DB for user migration failed +func (p *postgres) FailedUserMigration(ctx context.Context, migrationId, serverId, message string, totalSucceeded, totalSkipped, totalFailed int64) (storage.Migration, error) { + return p.insertMigration(ctx, migrationId, serverId, message, int64(constants.FailedUserMigration), int64(constants.Failed), totalSucceeded, totalSkipped, totalFailed) +} + +// StartAssciation Insert a migration entry to the DB for Association of users to orgs started +func (p *postgres) StartAssciation(ctx context.Context, migrationId, serverId string) (storage.Migration, error) { + return p.insertMigration(ctx, migrationId, serverId, "", int64(constants.StartAssciation), int64(constants.InProgress), 0, 0, 0) +} + +// CompleteAssciation Insert a migration entry to the DB for Association of users to orgs completed +func (p *postgres) CompleteAssciation(ctx context.Context, migrationId, serverId string, totalSucceeded, totalSkipped, totalFailed int64) (storage.Migration, error) { + return p.insertMigration(ctx, migrationId, serverId, "", int64(constants.CompleteAssciation), int64(constants.Completed), totalSucceeded, totalSkipped, totalFailed) +} + +// FailedAssciation Insert a migration entry to the DB for Association of users to orgs failed +func (p *postgres) FailedAssciation(ctx context.Context, migrationId, serverId, message string, totalSucceeded, totalSkipped, totalFailed int64) (storage.Migration, error) { + return p.insertMigration(ctx, migrationId, serverId, message, int64(constants.FailedAssciation), int64(constants.Failed), totalSucceeded, totalSkipped, totalFailed) +} + +// StartPermissionMigration Insert a migration entry to the DB for migrating user permissions started +func (p *postgres) StartPermissionMigration(ctx context.Context, migrationId, serverId string) (storage.Migration, error) { + return p.insertMigration(ctx, migrationId, serverId, "", int64(constants.StartPermissionMigration), int64(constants.InProgress), 0, 0, 0) +} + +// CompletePermissionMigration Insert a migration entry to the DB for migrating user permissions completed +func (p *postgres) CompletePermissionMigration(ctx context.Context, migrationId, serverId string, totalSucceeded, totalSkipped, totalFailed int64) (storage.Migration, error) { + return p.insertMigration(ctx, migrationId, serverId, "", int64(constants.CompletePermissionMigration), int64(constants.Completed), totalSucceeded, totalSkipped, totalFailed) +} + +// FailedPermissionMigration Insert a migration entry to the DB for migrating user permissions failed +func (p *postgres) FailedPermissionMigration(ctx context.Context, migrationId, serverId, message string, totalSucceeded, totalSkipped, totalFailed int64) (storage.Migration, error) { + return p.insertMigration(ctx, migrationId, serverId, message, int64(constants.FailedPermissionMigration), int64(constants.Failed), totalSucceeded, totalSkipped, totalFailed) +} + +// CompleteMigration Insert a migration entry to the DB for migration completed +func (p *postgres) CompleteMigration(ctx context.Context, migrationId, serverId string, totalSucceeded, totalSkipped, totalFailed int64) (storage.Migration, error) { + return p.insertMigration(ctx, migrationId, serverId, "", int64(constants.CompleteMigration), int64(constants.Completed), totalSucceeded, totalSkipped, totalFailed) +} + +//TODO: Optimize the function parameters using variadic +//insertMigration Inserts an entry to the DB +func (p *postgres) insertMigration(ctx context.Context, migrationId, serverId, message string, migTypeId, migStatusId, totalSucceeded, totalSkipped, totalFailed int64) (storage.Migration, error) { + + var m storage.Migration + var mByte []byte + + query := "SELECT insert_migration($1, $2, $3, $4, $5, $6, $7, $8)" + row := p.db.QueryRowContext(ctx, query, migrationId, serverId, migTypeId, migStatusId, totalSucceeded, totalSkipped, totalFailed, message) + err := row.Scan(&mByte) + if err != nil { + return storage.Migration{}, err + } + err = json.Unmarshal(mByte, &m) + if err != nil { + return storage.Migration{}, err + } + + return m, nil +} diff --git a/components/infra-proxy-service/storage/postgres/postgres.go b/components/infra-proxy-service/storage/postgres/postgres.go index 8dceda2421c..2163bb901f5 100644 --- a/components/infra-proxy-service/storage/postgres/postgres.go +++ b/components/infra-proxy-service/storage/postgres/postgres.go @@ -26,17 +26,32 @@ type querier interface { } // New instantiates and returns a postgres storage implementation -func New(logger logger.Logger, migrationConfig migration.Config, authzClient authz.AuthorizationServiceClient) (storage.Storage, error) { +func New(logger logger.Logger, migrationConfig migration.Config, authzClient authz.AuthorizationServiceClient) (storage.Storage, storage.MigrationStorage, error) { db, err := initPostgresDB(migrationConfig.PGURL.String()) if err != nil { - return nil, errors.Wrap(err, "initialize database") + return nil, nil, errors.Wrap(err, "initialize database") } if err := migrationConfig.Migrate(); err != nil { - return nil, errors.Wrap(err, "database migrations") + return nil, nil, errors.Wrap(err, "database migrations") + } + + return &postgres{db, logger, authzClient}, &postgres{db, logger, authzClient}, nil +} + +// New instantiates and returns a postgres migration implementation +func NewMigration(logger logger.Logger, migrationConfig migration.Config, authzClient authz.AuthorizationServiceClient) (storage.MigrationStorage, error) { + + db, err := initPostgresDB(migrationConfig.PGURL.String()) + if err != nil { + return nil, errors.Wrap(err, "initialize database") } + // if err := migrationConfig.Migrate(); err != nil { + // return nil, errors.Wrap(err, "database migrations") + // } + return &postgres{db, logger, authzClient}, nil } diff --git a/components/infra-proxy-service/storage/storage.go b/components/infra-proxy-service/storage/storage.go index f5e2928b636..ac2b3b2368b 100644 --- a/components/infra-proxy-service/storage/storage.go +++ b/components/infra-proxy-service/storage/storage.go @@ -29,6 +29,32 @@ type Storage interface { GetAutomateInfraServerUsers(ctx context.Context, serverId string) ([]User, error) } +type MigrationStorage interface { + StartMigration(ctx context.Context, migrationId, serverId string) (Migration, error) + StartFileUpload(ctx context.Context, migrationId, serverId string) (Migration, error) + CompleteFileUpload(ctx context.Context, migrationId, serverId string, totalSucceeded, totalSkipped, totalFailed int64) (Migration, error) + FailedFileUpload(ctx context.Context, migrationId, serverId, message string, totalSucceeded, totalSkipped, totalFailed int64) (Migration, error) + StartUnzip(ctx context.Context, migrationId, serverId string) (Migration, error) + ComplteUnzip(ctx context.Context, migrationId, serverId string, totalSucceeded, totalSkipped, totalFailed int64) (Migration, error) + FailedUnzip(ctx context.Context, migrationId, serverId, message string, totalSucceeded, totalSkipped, totalFailed int64) (Migration, error) + StartZipParsing(ctx context.Context, migrationId, serverId string) (Migration, error) + CompleteZipParsing(ctx context.Context, migrationId, serverId string, totalSucceeded, totalSkipped, totalFailed int64) (Migration, error) + FailedZipParsing(ctx context.Context, migrationId, serverId, message string, totalSucceeded, totalSkipped, totalFailed int64) (Migration, error) + StartOrgMigration(ctx context.Context, migrationId, serverId string) (Migration, error) + CompleteOrgMigration(ctx context.Context, migrationId, serverId string, totalSucceeded, totalSkipped, totalFailed int64) (Migration, error) + FailedOrgMigration(ctx context.Context, migrationId, serverId, message string, totalSucceeded, totalSkipped, totalFailed int64) (Migration, error) + StartUserMigration(ctx context.Context, migrationId, serverId string) (Migration, error) + CompleteUserMigration(ctx context.Context, migrationId, serverId string, totalSucceeded, totalSkipped, totalFailed int64) (Migration, error) + FailedUserMigration(ctx context.Context, migrationId, serverId, message string, totalSucceeded, totalSkipped, totalFailed int64) (Migration, error) + StartAssciation(ctx context.Context, migrationId, serverId string) (Migration, error) + CompleteAssciation(ctx context.Context, migrationId, serverId string, totalSucceeded, totalSkipped, totalFailed int64) (Migration, error) + FailedAssciation(ctx context.Context, migrationId, serverId, message string, totalSucceeded, totalSkipped, totalFailed int64) (Migration, error) + StartPermissionMigration(ctx context.Context, migrationId, serverId string) (Migration, error) + CompletePermissionMigration(ctx context.Context, migrationId, serverId string, totalSucceeded, totalSkipped, totalFailed int64) (Migration, error) + FailedPermissionMigration(ctx context.Context, migrationId, serverId, message string, totalSucceeded, totalSkipped, totalFailed int64) (Migration, error) + CompleteMigration(ctx context.Context, migrationId, serverId string, totalSucceeded, totalSkipped, totalFailed int64) (Migration, error) +} + // Resetter is, if exposed, used for tests to reset the storage backend to a // pristine state. type Resetter interface { @@ -73,6 +99,19 @@ type User struct { UpdatedAt time.Time } +type Migration struct { + ID string `json:"id"` + MigrationID string `json:"migration_id"` + ServerID string `json:"server_id"` + TypeID int64 `json:"type_id"` + StatusID int64 `json:"status_id"` + TotalSucceeded int64 `json:"total_succeeded"` + TotalSkipped int64 `json:"total_skipped"` + TotalFailed int64 `json:"total_failed"` + Message string `json:"message"` + UpdatedTimestamp time.Time `json:"updated_timestamp"` +} + // Errors returned from the backend var ( // ErrNotFound is returned when a requested server wasn't found