From 70a7b688a13d7178798e3be49404260b8987aa2c Mon Sep 17 00:00:00 2001 From: Yashvi Jain <91940132+YashviJain01@users.noreply.github.com> Date: Thu, 3 Mar 2022 13:40:32 +0530 Subject: [PATCH] Adding hash password from json and creating local user (#6753) * Adding hash password from json and creating local user Signed-off-by: Yashvi Jain * Lint issues fixed Signed-off-by: Yashvi Jain --- .../migrations/migrations.swagger.json | 4 ++ .../migrations/response/migrations.pb.go | 32 ++++++++---- .../migrations/response/migrations.proto | 2 + .../migrations/response/migrations.pb.go | 31 +++++++---- .../migrations/response/migrations.proto | 2 + .../api/migrations.pb.swagger.go | 4 ++ .../infra_proxy/migrations/migrations.go | 1 + .../migrations/migrations.go | 1 + .../migrations/migrations_test.go | 2 +- .../migrations/pipeline/utility.go | 52 ++++++++++++++++--- .../migrations/pipeline/utility_test.go | 28 ++++++++++ .../infra-proxy-service/pipeline/models.go | 17 +++++- .../infra-proxy-service/pipeline/utils.go | 2 +- 13 files changed, 149 insertions(+), 29 deletions(-) diff --git a/api/external/infra_proxy/migrations/migrations.swagger.json b/api/external/infra_proxy/migrations/migrations.swagger.json index a4b7fc6c6c4..979fbd49783 100644 --- a/api/external/infra_proxy/migrations/migrations.swagger.json +++ b/api/external/infra_proxy/migrations/migrations.swagger.json @@ -283,6 +283,10 @@ "type": "boolean", "format": "boolean", "title": "user is admin or not" + }, + "hash_password": { + "type": "string", + "title": "Local user hashed password" } } }, diff --git a/api/external/infra_proxy/migrations/response/migrations.pb.go b/api/external/infra_proxy/migrations/response/migrations.pb.go index 70d7b1a1263..3b71288d182 100644 --- a/api/external/infra_proxy/migrations/response/migrations.pb.go +++ b/api/external/infra_proxy/migrations/response/migrations.pb.go @@ -380,6 +380,8 @@ type User struct { IsConflicting bool `protobuf:"varint,9,opt,name=is_conflicting,json=isConflicting,proto3" json:"is_conflicting,omitempty"` // user is admin or not IsAdmin bool `protobuf:"varint,10,opt,name=is_admin,json=isAdmin,proto3" json:"is_admin,omitempty"` + //Local user hashed password + HashPassword string `protobuf:"bytes,11,opt,name=hash_password,json=hashPassword,proto3" json:"hash_password,omitempty"` } func (x *User) Reset() { @@ -484,6 +486,13 @@ func (x *User) GetIsAdmin() bool { return false } +func (x *User) GetHashPassword() string { + if x != nil { + return x.HashPassword + } + return "" +} + type ConfirmPreview struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -587,7 +596,7 @@ var file_external_infra_proxy_migrations_response_migrations_proto_rawDesc = []b 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, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x52, 0x05, 0x75, 0x73, 0x65, 0x72, 0x73, 0x22, 0xc5, + 0x73, 0x65, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x52, 0x05, 0x75, 0x73, 0x65, 0x72, 0x73, 0x22, 0xea, 0x02, 0x0a, 0x04, 0x55, 0x73, 0x65, 0x72, 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, 0x14, 0x0a, 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x18, 0x02, 0x20, 0x01, @@ -608,15 +617,18 @@ var file_external_infra_proxy_migrations_response_migrations_proto_rawDesc = []b 0x69, 0x63, 0x74, 0x69, 0x6e, 0x67, 0x18, 0x09, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0d, 0x69, 0x73, 0x43, 0x6f, 0x6e, 0x66, 0x6c, 0x69, 0x63, 0x74, 0x69, 0x6e, 0x67, 0x12, 0x19, 0x0a, 0x08, 0x69, 0x73, 0x5f, 0x61, 0x64, 0x6d, 0x69, 0x6e, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x69, - 0x73, 0x41, 0x64, 0x6d, 0x69, 0x6e, 0x22, 0x33, 0x0a, 0x0e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x72, - 0x6d, 0x50, 0x72, 0x65, 0x76, 0x69, 0x65, 0x77, 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, 0x42, 0x47, 0x5a, 0x45, 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, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2f, 0x72, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x73, 0x41, 0x64, 0x6d, 0x69, 0x6e, 0x12, 0x23, 0x0a, 0x0d, 0x68, 0x61, 0x73, 0x68, 0x5f, 0x70, + 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x68, + 0x61, 0x73, 0x68, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x22, 0x33, 0x0a, 0x0e, 0x43, + 0x6f, 0x6e, 0x66, 0x69, 0x72, 0x6d, 0x50, 0x72, 0x65, 0x76, 0x69, 0x65, 0x77, 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, + 0x42, 0x47, 0x5a, 0x45, 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, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, + 0x2f, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x33, } var ( diff --git a/api/external/infra_proxy/migrations/response/migrations.proto b/api/external/infra_proxy/migrations/response/migrations.proto index a42bdf42fc7..67c1c8d94a4 100644 --- a/api/external/infra_proxy/migrations/response/migrations.proto +++ b/api/external/infra_proxy/migrations/response/migrations.proto @@ -70,6 +70,8 @@ message User { bool is_conflicting=9; // user is admin or not bool is_admin=10; + //Local user hashed password + string hash_password=11; } message ConfirmPreview { diff --git a/api/interservice/infra_proxy/migrations/response/migrations.pb.go b/api/interservice/infra_proxy/migrations/response/migrations.pb.go index 1156a321ea9..bda7f1ee1b4 100644 --- a/api/interservice/infra_proxy/migrations/response/migrations.pb.go +++ b/api/interservice/infra_proxy/migrations/response/migrations.pb.go @@ -380,6 +380,8 @@ type User struct { IsConflicting bool `protobuf:"varint,9,opt,name=is_conflicting,json=isConflicting,proto3" json:"is_conflicting,omitempty" toml:"is_conflicting,omitempty" mapstructure:"is_conflicting,omitempty"` // user is admin or not IsAdmin bool `protobuf:"varint,10,opt,name=is_admin,json=isAdmin,proto3" json:"is_admin,omitempty" toml:"is_admin,omitempty" mapstructure:"is_admin,omitempty"` + //Local User hash password + HashPassword string `protobuf:"bytes,11,opt,name=hash_password,json=hashPassword,proto3" json:"hash_password,omitempty" toml:"hash_password,omitempty" mapstructure:"hash_password,omitempty"` } func (x *User) Reset() { @@ -484,6 +486,13 @@ func (x *User) GetIsAdmin() bool { return false } +func (x *User) GetHashPassword() string { + if x != nil { + return x.HashPassword + } + return "" +} + type ConfirmPreview struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -588,7 +597,7 @@ var file_interservice_infra_proxy_migrations_response_migrations_proto_rawDesc = 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, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x55, 0x73, 0x65, - 0x72, 0x52, 0x05, 0x75, 0x73, 0x65, 0x72, 0x73, 0x22, 0xc5, 0x02, 0x0a, 0x04, 0x55, 0x73, 0x65, + 0x72, 0x52, 0x05, 0x75, 0x73, 0x65, 0x72, 0x73, 0x22, 0xea, 0x02, 0x0a, 0x04, 0x55, 0x73, 0x65, 0x72, 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, 0x14, 0x0a, 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x6d, @@ -609,15 +618,17 @@ var file_interservice_infra_proxy_migrations_response_migrations_proto_rawDesc = 0x18, 0x09, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0d, 0x69, 0x73, 0x43, 0x6f, 0x6e, 0x66, 0x6c, 0x69, 0x63, 0x74, 0x69, 0x6e, 0x67, 0x12, 0x19, 0x0a, 0x08, 0x69, 0x73, 0x5f, 0x61, 0x64, 0x6d, 0x69, 0x6e, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x69, 0x73, 0x41, 0x64, 0x6d, 0x69, 0x6e, - 0x22, 0x33, 0x0a, 0x0e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x72, 0x6d, 0x50, 0x72, 0x65, 0x76, 0x69, - 0x65, 0x77, 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, 0x42, 0x4b, 0x5a, 0x49, 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, 0x6d, - 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2f, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x12, 0x23, 0x0a, 0x0d, 0x68, 0x61, 0x73, 0x68, 0x5f, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, + 0x64, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x68, 0x61, 0x73, 0x68, 0x50, 0x61, 0x73, + 0x73, 0x77, 0x6f, 0x72, 0x64, 0x22, 0x33, 0x0a, 0x0e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x72, 0x6d, + 0x50, 0x72, 0x65, 0x76, 0x69, 0x65, 0x77, 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, 0x42, 0x4b, 0x5a, 0x49, 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, 0x6d, 0x69, 0x67, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2f, 0x72, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/api/interservice/infra_proxy/migrations/response/migrations.proto b/api/interservice/infra_proxy/migrations/response/migrations.proto index 1ef03afa60a..c2b734d9145 100644 --- a/api/interservice/infra_proxy/migrations/response/migrations.proto +++ b/api/interservice/infra_proxy/migrations/response/migrations.proto @@ -69,6 +69,8 @@ message User { bool is_conflicting=9; // user is admin or not bool is_admin=10; + //Local User hash password + string hash_password=11; } message ConfirmPreview { diff --git a/components/automate-gateway/api/migrations.pb.swagger.go b/components/automate-gateway/api/migrations.pb.swagger.go index 00c58beef09..6be6a77d25a 100644 --- a/components/automate-gateway/api/migrations.pb.swagger.go +++ b/components/automate-gateway/api/migrations.pb.swagger.go @@ -286,6 +286,10 @@ func init() { "type": "boolean", "format": "boolean", "title": "user is admin or not" + }, + "hash_password": { + "type": "string", + "title": "Local user hashed password" } } }, diff --git a/components/automate-gateway/handler/infra_proxy/migrations/migrations.go b/components/automate-gateway/handler/infra_proxy/migrations/migrations.go index 66aebe08a96..cce715ee666 100644 --- a/components/automate-gateway/handler/infra_proxy/migrations/migrations.go +++ b/components/automate-gateway/handler/infra_proxy/migrations/migrations.go @@ -88,6 +88,7 @@ func getStagedUser(user *infra_res.User) *gwres.User { stagedUser.Connector = user.Connector stagedUser.IsConflicting = user.IsConflicting stagedUser.IsAdmin = user.IsAdmin + stagedUser.HashPassword = user.HashPassword return stagedUser } diff --git a/components/infra-proxy-service/migrations/migrations.go b/components/infra-proxy-service/migrations/migrations.go index 56dd0b11198..9e92c6434ce 100644 --- a/components/infra-proxy-service/migrations/migrations.go +++ b/components/infra-proxy-service/migrations/migrations.go @@ -291,6 +291,7 @@ func getStagedUser(user pipeline_model.User) *response.User { stagedUser.AutomateUsername = user.AutomateUsername stagedUser.Connector = user.Connector stagedUser.IsConflicting = user.IsConflicting + stagedUser.HashPassword = user.HashPassword return stagedUser } diff --git a/components/infra-proxy-service/migrations/migrations_test.go b/components/infra-proxy-service/migrations/migrations_test.go index c1ffedeb39d..d406615eca7 100644 --- a/components/infra-proxy-service/migrations/migrations_test.go +++ b/components/infra-proxy-service/migrations/migrations_test.go @@ -18,7 +18,7 @@ import ( func TestMigrations(t *testing.T) { ctx := context.Background() _, serviceRef, _, close, _, _ := test.SetupInfraProxyService(ctx, t) - infraMigrationMockClient := infra_migrations.NewMockInfraProxyMigrationClient(gomock.NewController(t)) + infraMigrationMockClient := infra_migrations.NewMockInfraProxyMigrationServiceClient(gomock.NewController(t)) var migrationID = "Fake id" diff --git a/components/infra-proxy-service/migrations/pipeline/utility.go b/components/infra-proxy-service/migrations/pipeline/utility.go index 601ab286465..e421884af98 100644 --- a/components/infra-proxy-service/migrations/pipeline/utility.go +++ b/components/infra-proxy-service/migrations/pipeline/utility.go @@ -597,15 +597,17 @@ func keyDumpTOUser(keyDump []pipeline.KeyDump) []pipeline.User { log.Errorf("failed to pasre user's first, middle and last name: %s", err.Error()) } user := &pipeline.User{ - Username: kd.Username, - Email: kd.Email, - DisplayName: sec["display_name"], - FirstName: sec["first_name"], - LastName: sec["last_name"], - MiddleName: sec["middle_name"], + Username: kd.Username, + Email: kd.Email, + DisplayName: sec["display_name"], + FirstName: sec["first_name"], + LastName: sec["last_name"], + MiddleName: sec["middle_name"], + HashPassword: kd.HashedPassword, } user.SetConnector(kd.ExternalAuthenticationUID) user.SetAutomateUsername(kd.ExternalAuthenticationUID) + users = append(users, *user) } return users @@ -697,3 +699,41 @@ func checkUserExist(ctx context.Context, localUserClient local_user.UsersMgmtSer } return true } + +//createLocalUser Function for reference, will be removed after PopulateUsers Method +func createLocalUsers(ctx context.Context, localUserClient local_user.UsersMgmtServiceClient, result pipeline.Result) (pipeline.Result, error) { + log.Info("Starting with creating local users in automate for migration id: ", result.Meta.MigrationID) + var totalSucceeded, totalSkipped, totalFailed int64 + var err error + for _, user := range result.ParsedResult.Users { + if user.Connector == pipeline.Local && user.ActionOps == pipeline.Insert && !user.IsConflicting { + err = createLocalUser(ctx, localUserClient, user) + if err != nil { + totalFailed++ + continue + } + } + if user.ActionOps == pipeline.Skip { + totalSkipped++ + continue + } + totalSucceeded++ + } + log.Info("Starting with creating local users in automate for migration id: ", result.Meta.MigrationID) + return result, err +} + +func createLocalUser(ctx context.Context, localUserClient local_user.UsersMgmtServiceClient, user pipeline.User) error { + _, err := localUserClient.CreateUser(ctx, &local_user.CreateUserReq{ + Name: user.DisplayName, + Id: user.AutomateUsername, + Password: user.HashPassword, + Email: user.AutomateUsername, + IsHashed: true, + }) + if err != nil { + log.Errorf("Unable to create user in Automate for user : %s with error %s", user.AutomateUsername, err.Error()) + return err + } + return nil +} diff --git a/components/infra-proxy-service/migrations/pipeline/utility_test.go b/components/infra-proxy-service/migrations/pipeline/utility_test.go index fd0c1f8211a..ef97e919071 100644 --- a/components/infra-proxy-service/migrations/pipeline/utility_test.go +++ b/components/infra-proxy-service/migrations/pipeline/utility_test.go @@ -294,3 +294,31 @@ func TestUserExists(t *testing.T) { } } + +func TestCreateNewUserInAutomate(t *testing.T) { + type args struct { + ctx context.Context + localUserClient *local_user.MockUsersMgmtServiceClient + User pipeline.User + MockResult *local_user.User + ErrorWant error + } + tests := []struct { + name string + args args + want1 error + }{ + {name: "Test New User", args: args{ctx: context.Background(), localUserClient: local_user.NewMockUsersMgmtServiceClient(gomock.NewController(t)), User: pipeline.User{AutomateUsername: "test", Username: "test", HashPassword: "okokokokokokoko"}, MockResult: &local_user.User{Name: "test", Id: "test", Email: "test@ok"}, ErrorWant: nil}, want1: nil}, + {name: "Test Already User Exists", args: args{ctx: context.Background(), localUserClient: local_user.NewMockUsersMgmtServiceClient(gomock.NewController(t)), User: pipeline.User{AutomateUsername: "test", Username: "test", HashPassword: "okokokokokokoko"}, MockResult: nil, ErrorWant: errors.New("User already exists")}, want1: errors.New("User already exists")}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + tt.args.localUserClient.EXPECT().CreateUser(tt.args.ctx, gomock.Any()).Return(tt.args.MockResult, tt.args.ErrorWant) + got := createLocalUser(tt.args.ctx, tt.args.localUserClient, tt.args.User) + if got != nil && got.Error() != tt.want1.Error() { + t.Errorf("createLocalUser() got = %v, want %v", got, tt.want1) + } + }) + } + +} diff --git a/components/infra-proxy-service/pipeline/models.go b/components/infra-proxy-service/pipeline/models.go index c01e9def83b..5cd959daa70 100644 --- a/components/infra-proxy-service/pipeline/models.go +++ b/components/infra-proxy-service/pipeline/models.go @@ -94,7 +94,7 @@ type KeyDump struct { ExternalAuthenticationUID interface{} `json:"external_authentication_uid"` RecoveryAuthenticationEnabled interface{} `json:"recovery_authentication_enabled"` Admin bool `json:"admin"` - HashedPassword interface{} `json:"hashed_password"` + HashedPassword string `json:"hashed_password"` Salt interface{} `json:"salt"` HashType interface{} `json:"hash_type"` } @@ -109,6 +109,9 @@ type Org struct { // ActionOps for Insert Skip Update and Delete ActionOps ActionOps `json:"action_ops"` + + //Counts for total,skipped and failed + Counts Counts `json:"counts"` } type User struct { @@ -128,8 +131,14 @@ type User struct { // IsConflicting for user's existence in db IsConflicting bool `json:"is_conflicting"` + //hash password for the local user + HashPassword string `json:"hash_password"` + // ActionOps for Insert Skip Update and Delete ActionOps ActionOps `json:"action_ops"` + + //Counts for total,skipped and failed + Counts Counts `json:"counts"` } type OrgJson struct { @@ -150,3 +159,9 @@ type AdminsJson struct { type UsersJson struct { Username string `json:"username"` } + +type Counts struct { + Succeeded int `json:"total_succeeded"` + Failed int `json:"total_failed"` + Skipped int `json:"total_skipped"` +} diff --git a/components/infra-proxy-service/pipeline/utils.go b/components/infra-proxy-service/pipeline/utils.go index b0022462abb..9ed75d5dbec 100644 --- a/components/infra-proxy-service/pipeline/utils.go +++ b/components/infra-proxy-service/pipeline/utils.go @@ -14,6 +14,6 @@ func (usr *User) SetAutomateUsername(uid interface{}) { if uid == nil { usr.AutomateUsername = usr.Username } else { - usr.Connector = uid.(string) + usr.AutomateUsername = uid.(string) } }