From ca87b18a3faa64623a480f902dd1913cd1d7d0fc Mon Sep 17 00:00:00 2001 From: patrapritish1 <59195856+patrapritish1@users.noreply.github.com> Date: Fri, 22 Sep 2023 18:53:37 +0530 Subject: [PATCH] sdk update for ums --- .../administration/policy/create/main.go | 12 +- .../administration/policy/delete/main.go | 6 +- .../administration/policy/list/main.go | 6 +- .../administration/policy/read/main.go | 6 +- .../administration/policy/update/main.go | 8 +- .../administration/user/create/main.go | 6 +- .../administration/user/createProg/main.go | 10 +- .../administration/user/delete/main.go | 6 +- .../service/administration/user/list/main.go | 6 +- .../service/administration/user/read/main.go | 6 +- .../user/updatePolicyMapping/main.go | 52 +++++++++ .../user/updateUserGroupMapping/main.go | 41 +++++++ .../administration/userGroup/create/main.go | 8 +- .../administration/userGroup/delete/main.go | 6 +- .../administration/userGroup/list/main.go | 6 +- .../administration/userGroup/read/main.go | 6 +- .../administration/userGroup/update/main.go | 6 +- .../userGroup/updatePolicyMapping/main.go | 64 +++++++++++ .../userGroup/updateUserMapping/main.go | 41 +++++++ .../policy.go | 2 +- .../service.go | 7 +- .../{administration => organization}/user.go | 105 +++++++++++++++++- .../userGroup.go | 60 +++++++++- spotinst/credentials/provider_env.go | 5 +- 24 files changed, 419 insertions(+), 62 deletions(-) create mode 100644 examples/service/administration/user/updatePolicyMapping/main.go create mode 100644 examples/service/administration/user/updateUserGroupMapping/main.go create mode 100644 examples/service/administration/userGroup/updatePolicyMapping/main.go create mode 100644 examples/service/administration/userGroup/updateUserMapping/main.go rename service/{administration => organization}/policy.go (99%) rename service/{administration => organization}/service.go (83%) rename service/{administration => organization}/user.go (81%) rename service/{administration => organization}/userGroup.go (83%) diff --git a/examples/service/administration/policy/create/main.go b/examples/service/administration/policy/create/main.go index fc8167b2..642fb27b 100644 --- a/examples/service/administration/policy/create/main.go +++ b/examples/service/administration/policy/create/main.go @@ -4,7 +4,7 @@ import ( "context" "log" - "github.com/spotinst/spotinst-sdk-go/service/administration" + "github.com/spotinst/spotinst-sdk-go/service/organization" "github.com/spotinst/spotinst-sdk-go/spotinst" "github.com/spotinst/spotinst-sdk-go/spotinst/session" "github.com/spotinst/spotinst-sdk-go/spotinst/util/stringutil" @@ -22,18 +22,18 @@ func main() { // Optional spotinst.Config values can also be provided as variadic // arguments to the New function. This option allows you to provide // service specific configuration. - svc := administration.New(sess) + svc := organization.New(sess) // Create a new context. ctx := context.Background() // Create a new group. - out, err := svc.CreatePolicy(ctx, &administration.CreatePolicyInput{ - Policy: &administration.Policy{ + out, err := svc.CreatePolicy(ctx, &organization.CreatePolicyInput{ + Policy: &organization.Policy{ Description: spotinst.String("Automation Policy by Terraform"), Name: spotinst.String("AutomationPolicy"), - PolicyContent: &administration.PolicyContent{ - Statements: []*administration.Statement{ + PolicyContent: &organization.PolicyContent{ + Statements: []*organization.Statement{ { Actions: []string{ "ocean:deleteCluster", diff --git a/examples/service/administration/policy/delete/main.go b/examples/service/administration/policy/delete/main.go index 0d6c9c0c..306199be 100644 --- a/examples/service/administration/policy/delete/main.go +++ b/examples/service/administration/policy/delete/main.go @@ -2,7 +2,7 @@ package main import ( "context" - "github.com/spotinst/spotinst-sdk-go/service/administration" + "github.com/spotinst/spotinst-sdk-go/service/organization" "log" "github.com/spotinst/spotinst-sdk-go/spotinst" @@ -21,13 +21,13 @@ func main() { // Optional spotinst.Config values can also be provided as variadic // arguments to the New function. This option allows you to provide // service specific configuration. - svc := administration.New(sess) + svc := organization.New(sess) // Create a new context. ctx := context.Background() // Delete an existing group. - _, err := svc.DeletePolicy(ctx, &administration.DeletePolicyInput{ + _, err := svc.DeletePolicy(ctx, &organization.DeletePolicyInput{ PolicyID: spotinst.String("pol-abcd1234"), }) if err != nil { diff --git a/examples/service/administration/policy/list/main.go b/examples/service/administration/policy/list/main.go index 0580e048..fa0d902e 100644 --- a/examples/service/administration/policy/list/main.go +++ b/examples/service/administration/policy/list/main.go @@ -2,7 +2,7 @@ package main import ( "context" - "github.com/spotinst/spotinst-sdk-go/service/administration" + "github.com/spotinst/spotinst-sdk-go/service/organization" "log" "github.com/spotinst/spotinst-sdk-go/spotinst" @@ -22,13 +22,13 @@ func main() { // Optional spotinst.Config values can also be provided as variadic // arguments to the New function. This option allows you to provide // service specific configuration. - svc := administration.New(sess) + svc := organization.New(sess) // Create a new context. ctx := context.Background() // List all groups. - out, err := svc.ListPolicies(ctx, &administration.ListPoliciesInput{}) + out, err := svc.ListPolicies(ctx, &organization.ListPoliciesInput{}) if err != nil { log.Fatalf("spotinst: failed to list users: %v", err) } diff --git a/examples/service/administration/policy/read/main.go b/examples/service/administration/policy/read/main.go index 39635d6e..fcae17ae 100644 --- a/examples/service/administration/policy/read/main.go +++ b/examples/service/administration/policy/read/main.go @@ -2,7 +2,7 @@ package main import ( "context" - "github.com/spotinst/spotinst-sdk-go/service/administration" + "github.com/spotinst/spotinst-sdk-go/service/organization" "log" "github.com/spotinst/spotinst-sdk-go/spotinst" @@ -22,13 +22,13 @@ func main() { // Optional spotinst.Config values can also be provided as variadic // arguments to the New function. This option allows you to provide // service specific configuration. - svc := administration.New(sess) + svc := organization.New(sess) // Create a new context. ctx := context.Background() // Read group configuration. - out, err := svc.ReadPolicy(ctx, &administration.ReadPolicyInput{ + out, err := svc.ReadPolicy(ctx, &organization.ReadPolicyInput{ PolicyID: spotinst.String("pol-abcd1234"), }) if err != nil { diff --git a/examples/service/administration/policy/update/main.go b/examples/service/administration/policy/update/main.go index 426c6f62..de97098e 100644 --- a/examples/service/administration/policy/update/main.go +++ b/examples/service/administration/policy/update/main.go @@ -4,7 +4,7 @@ import ( "context" "log" - "github.com/spotinst/spotinst-sdk-go/service/administration" + "github.com/spotinst/spotinst-sdk-go/service/organization" "github.com/spotinst/spotinst-sdk-go/spotinst" "github.com/spotinst/spotinst-sdk-go/spotinst/session" "github.com/spotinst/spotinst-sdk-go/spotinst/util/stringutil" @@ -22,14 +22,14 @@ func main() { // Optional spotinst.Config values can also be provided as variadic // arguments to the New function. This option allows you to provide // service specific configuration. - svc := administration.New(sess) + svc := organization.New(sess) // Create a new context. ctx := context.Background() // Create a new group. - out, err := svc.UpdatePolicy(ctx, &administration.UpdatePolicyInput{ - Policy: &administration.Policy{ + out, err := svc.UpdatePolicy(ctx, &organization.UpdatePolicyInput{ + Policy: &organization.Policy{ PolicyID: spotinst.String("pol-abcd1234"), Name: spotinst.String("Automation-Policy-Updated"), }, diff --git a/examples/service/administration/user/create/main.go b/examples/service/administration/user/create/main.go index 35df2938..da05e6a1 100644 --- a/examples/service/administration/user/create/main.go +++ b/examples/service/administration/user/create/main.go @@ -4,7 +4,7 @@ import ( "context" "log" - "github.com/spotinst/spotinst-sdk-go/service/administration" + "github.com/spotinst/spotinst-sdk-go/service/organization" "github.com/spotinst/spotinst-sdk-go/spotinst" "github.com/spotinst/spotinst-sdk-go/spotinst/session" "github.com/spotinst/spotinst-sdk-go/spotinst/util/stringutil" @@ -22,13 +22,13 @@ func main() { // Optional spotinst.Config values can also be provided as variadic // arguments to the New function. This option allows you to provide // service specific configuration. - svc := administration.New(sess) + svc := organization.New(sess) // Create a new context. ctx := context.Background() // Create a new group. - out, err := svc.CreateUser(ctx, &administration.User{ + out, err := svc.CreateUser(ctx, &organization.User{ Email: spotinst.String("testautomation@netapp.com"), FirstName: spotinst.String("test"), LastName: spotinst.String("user"), diff --git a/examples/service/administration/user/createProg/main.go b/examples/service/administration/user/createProg/main.go index e7c6f7ec..402eaddf 100644 --- a/examples/service/administration/user/createProg/main.go +++ b/examples/service/administration/user/createProg/main.go @@ -4,7 +4,7 @@ import ( "context" "log" - "github.com/spotinst/spotinst-sdk-go/service/administration" + "github.com/spotinst/spotinst-sdk-go/service/organization" "github.com/spotinst/spotinst-sdk-go/spotinst" "github.com/spotinst/spotinst-sdk-go/spotinst/session" "github.com/spotinst/spotinst-sdk-go/spotinst/util/stringutil" @@ -22,22 +22,22 @@ func main() { // Optional spotinst.Config values can also be provided as variadic // arguments to the New function. This option allows you to provide // service specific configuration. - svc := administration.New(sess) + svc := organization.New(sess) // Create a new context. ctx := context.Background() // Create a new group. - out, err := svc.CreateProgUser(ctx, &administration.ProgrammaticUser{ + out, err := svc.CreateProgUser(ctx, &organization.ProgrammaticUser{ Name: spotinst.String("test-programmatic-user"), Description: spotinst.String("description"), - Accounts: []*administration.Account{ + Accounts: []*organization.Account{ { Id: spotinst.String("act-a1b2c3d4"), Role: spotinst.String("viewer"), }, }, //Accounts and Policies are exclusive - /*Policies: []*administration.ProgPolicy{ + /*Policies: []*organization.ProgPolicy{ { PolicyId: spotinst.String("pol-abcd1234"), AccountIds: []string{ diff --git a/examples/service/administration/user/delete/main.go b/examples/service/administration/user/delete/main.go index 596a17c7..47ca0f8d 100644 --- a/examples/service/administration/user/delete/main.go +++ b/examples/service/administration/user/delete/main.go @@ -2,7 +2,7 @@ package main import ( "context" - "github.com/spotinst/spotinst-sdk-go/service/administration" + "github.com/spotinst/spotinst-sdk-go/service/organization" "log" "github.com/spotinst/spotinst-sdk-go/spotinst" @@ -21,13 +21,13 @@ func main() { // Optional spotinst.Config values can also be provided as variadic // arguments to the New function. This option allows you to provide // service specific configuration. - svc := administration.New(sess) + svc := organization.New(sess) // Create a new context. ctx := context.Background() // Delete an existing group. - _, err := svc.DeleteUser(ctx, &administration.DeleteUserInput{ + _, err := svc.DeleteUser(ctx, &organization.DeleteUserInput{ UserID: spotinst.String("pu-abcd1234"), }) if err != nil { diff --git a/examples/service/administration/user/list/main.go b/examples/service/administration/user/list/main.go index 8ceac63f..1ad70e3b 100644 --- a/examples/service/administration/user/list/main.go +++ b/examples/service/administration/user/list/main.go @@ -2,7 +2,7 @@ package main import ( "context" - "github.com/spotinst/spotinst-sdk-go/service/administration" + "github.com/spotinst/spotinst-sdk-go/service/organization" "log" "github.com/spotinst/spotinst-sdk-go/spotinst" @@ -22,13 +22,13 @@ func main() { // Optional spotinst.Config values can also be provided as variadic // arguments to the New function. This option allows you to provide // service specific configuration. - svc := administration.New(sess) + svc := organization.New(sess) // Create a new context. ctx := context.Background() // List all groups. - out, err := svc.ListUsers(ctx, &administration.ListUsersInput{}) + out, err := svc.ListUsers(ctx, &organization.ListUsersInput{}) if err != nil { log.Fatalf("spotinst: failed to list users: %v", err) } diff --git a/examples/service/administration/user/read/main.go b/examples/service/administration/user/read/main.go index 4fca9e96..c5c8afa1 100644 --- a/examples/service/administration/user/read/main.go +++ b/examples/service/administration/user/read/main.go @@ -2,7 +2,7 @@ package main import ( "context" - "github.com/spotinst/spotinst-sdk-go/service/administration" + "github.com/spotinst/spotinst-sdk-go/service/organization" "log" "github.com/spotinst/spotinst-sdk-go/spotinst" @@ -22,13 +22,13 @@ func main() { // Optional spotinst.Config values can also be provided as variadic // arguments to the New function. This option allows you to provide // service specific configuration. - svc := administration.New(sess) + svc := organization.New(sess) // Create a new context. ctx := context.Background() // Read group configuration. - out, err := svc.ReadUser(ctx, &administration.ReadUserInput{ + out, err := svc.ReadUser(ctx, &organization.ReadUserInput{ UserID: spotinst.String("u-abcd1234"), }) if err != nil { diff --git a/examples/service/administration/user/updatePolicyMapping/main.go b/examples/service/administration/user/updatePolicyMapping/main.go new file mode 100644 index 00000000..1fcfd788 --- /dev/null +++ b/examples/service/administration/user/updatePolicyMapping/main.go @@ -0,0 +1,52 @@ +package main + +import ( + "context" + "log" + + "github.com/spotinst/spotinst-sdk-go/service/organization" + "github.com/spotinst/spotinst-sdk-go/spotinst" + "github.com/spotinst/spotinst-sdk-go/spotinst/session" +) + +func main() { + // All clients require a Session. The Session provides the client with + // shared configuration such as account and credentials. + // A Session should be shared where possible to take advantage of + // configuration and credential caching. See the session package for + // more information. + sess := session.New() + + // Create a new instance of the service's client with a Session. + // Optional spotinst.Config values can also be provided as variadic + // arguments to the New function. This option allows you to provide + // service specific configuration. + svc := organization.New(sess) + + // Create a new context. + ctx := context.Background() + + // Create a new group. + err := svc.UpdatePolicyMappingOfUser(ctx, &organization.UpdatePolicyMappingOfUserInput{ + UserID: spotinst.String("u-0628514b"), + Policies: []*organization.ProgPolicy{ + &organization.ProgPolicy{ + PolicyId: spotinst.String("pol-abcd1234"), + AccountIds: []string{ + "act-1234abcd", + }, + }, + &organization.ProgPolicy{ + PolicyId: spotinst.String("pol-xyzw1234"), + AccountIds: []string{ + "act-abcd1234", + }, + }, + }, + }) + + if err != nil { + log.Fatalf("spotinst: failed to update policy: %v", err) + } + +} diff --git a/examples/service/administration/user/updateUserGroupMapping/main.go b/examples/service/administration/user/updateUserGroupMapping/main.go new file mode 100644 index 00000000..1d106768 --- /dev/null +++ b/examples/service/administration/user/updateUserGroupMapping/main.go @@ -0,0 +1,41 @@ +package main + +import ( + "context" + "log" + + "github.com/spotinst/spotinst-sdk-go/service/organization" + "github.com/spotinst/spotinst-sdk-go/spotinst" + "github.com/spotinst/spotinst-sdk-go/spotinst/session" +) + +func main() { + // All clients require a Session. The Session provides the client with + // shared configuration such as account and credentials. + // A Session should be shared where possible to take advantage of + // configuration and credential caching. See the session package for + // more information. + sess := session.New() + + // Create a new instance of the service's client with a Session. + // Optional spotinst.Config values can also be provided as variadic + // arguments to the New function. This option allows you to provide + // service specific configuration. + svc := organization.New(sess) + + // Create a new context. + ctx := context.Background() + + // Create a new group. + err := svc.UpdateUserGroupMappingOfUser(ctx, &organization.UpdateUserGroupMappingOfUserInput{ + UserID: spotinst.String("u-abcd1234"), + UserGroupIds: []string{ + "ugr-abcd1234", + }, + }) + + if err != nil { + log.Fatalf("spotinst: failed to update policy: %v", err) + } + +} diff --git a/examples/service/administration/userGroup/create/main.go b/examples/service/administration/userGroup/create/main.go index 11589d0a..696280a9 100644 --- a/examples/service/administration/userGroup/create/main.go +++ b/examples/service/administration/userGroup/create/main.go @@ -4,7 +4,7 @@ import ( "context" "log" - "github.com/spotinst/spotinst-sdk-go/service/administration" + "github.com/spotinst/spotinst-sdk-go/service/organization" "github.com/spotinst/spotinst-sdk-go/spotinst" "github.com/spotinst/spotinst-sdk-go/spotinst/session" "github.com/spotinst/spotinst-sdk-go/spotinst/util/stringutil" @@ -22,19 +22,19 @@ func main() { // Optional spotinst.Config values can also be provided as variadic // arguments to the New function. This option allows you to provide // service specific configuration. - svc := administration.New(sess) + svc := organization.New(sess) // Create a new context. ctx := context.Background() // Create a new group. - out, err := svc.CreateUserGroup(ctx, &administration.UserGroup{ + out, err := svc.CreateUserGroup(ctx, &organization.UserGroup{ Description: spotinst.String("TFUserGroup"), Name: spotinst.String("test-user-group"), UserIds: []string{ "u-abcd1234", }, - Policies: []*administration.UserGroupPolicy{ + Policies: []*organization.UserGroupPolicy{ { AccountIds: []string{ "act-abcd1234", diff --git a/examples/service/administration/userGroup/delete/main.go b/examples/service/administration/userGroup/delete/main.go index cad641bd..4f151985 100644 --- a/examples/service/administration/userGroup/delete/main.go +++ b/examples/service/administration/userGroup/delete/main.go @@ -2,7 +2,7 @@ package main import ( "context" - "github.com/spotinst/spotinst-sdk-go/service/administration" + "github.com/spotinst/spotinst-sdk-go/service/organization" "log" "github.com/spotinst/spotinst-sdk-go/spotinst" @@ -21,13 +21,13 @@ func main() { // Optional spotinst.Config values can also be provided as variadic // arguments to the New function. This option allows you to provide // service specific configuration. - svc := administration.New(sess) + svc := organization.New(sess) // Create a new context. ctx := context.Background() // Delete an existing user group. - _, err := svc.DeleteUserGroup(ctx, &administration.DeleteUserGroupInput{ + _, err := svc.DeleteUserGroup(ctx, &organization.DeleteUserGroupInput{ UserGroupID: spotinst.String("ugr-abcd1234"), }) if err != nil { diff --git a/examples/service/administration/userGroup/list/main.go b/examples/service/administration/userGroup/list/main.go index 729d042c..b3e26bcd 100644 --- a/examples/service/administration/userGroup/list/main.go +++ b/examples/service/administration/userGroup/list/main.go @@ -2,7 +2,7 @@ package main import ( "context" - "github.com/spotinst/spotinst-sdk-go/service/administration" + "github.com/spotinst/spotinst-sdk-go/service/organization" "log" "github.com/spotinst/spotinst-sdk-go/spotinst" @@ -22,13 +22,13 @@ func main() { // Optional spotinst.Config values can also be provided as variadic // arguments to the New function. This option allows you to provide // service specific configuration. - svc := administration.New(sess) + svc := organization.New(sess) // Create a new context. ctx := context.Background() // List all groups. - out, err := svc.ListUserGroups(ctx, &administration.ListUserGroupsInput{}) + out, err := svc.ListUserGroups(ctx, &organization.ListUserGroupsInput{}) if err != nil { log.Fatalf("spotinst: failed to list users: %v", err) } diff --git a/examples/service/administration/userGroup/read/main.go b/examples/service/administration/userGroup/read/main.go index 0928d8a4..61d8c084 100644 --- a/examples/service/administration/userGroup/read/main.go +++ b/examples/service/administration/userGroup/read/main.go @@ -2,7 +2,7 @@ package main import ( "context" - "github.com/spotinst/spotinst-sdk-go/service/administration" + "github.com/spotinst/spotinst-sdk-go/service/organization" "log" "github.com/spotinst/spotinst-sdk-go/spotinst" @@ -22,13 +22,13 @@ func main() { // Optional spotinst.Config values can also be provided as variadic // arguments to the New function. This option allows you to provide // service specific configuration. - svc := administration.New(sess) + svc := organization.New(sess) // Create a new context. ctx := context.Background() // Read group configuration. - out, err := svc.ReadUserGroup(ctx, &administration.ReadUserGroupInput{ + out, err := svc.ReadUserGroup(ctx, &organization.ReadUserGroupInput{ UserGroupID: spotinst.String("ugr-abcd1234"), }) if err != nil { diff --git a/examples/service/administration/userGroup/update/main.go b/examples/service/administration/userGroup/update/main.go index 23e362e5..d5f63203 100644 --- a/examples/service/administration/userGroup/update/main.go +++ b/examples/service/administration/userGroup/update/main.go @@ -4,7 +4,7 @@ import ( "context" "log" - "github.com/spotinst/spotinst-sdk-go/service/administration" + "github.com/spotinst/spotinst-sdk-go/service/organization" "github.com/spotinst/spotinst-sdk-go/spotinst" "github.com/spotinst/spotinst-sdk-go/spotinst/session" ) @@ -21,13 +21,13 @@ func main() { // Optional spotinst.Config values can also be provided as variadic // arguments to the New function. This option allows you to provide // service specific configuration. - svc := administration.New(sess) + svc := organization.New(sess) // Create a new context. ctx := context.Background() // Create a new group. - err := svc.UpdateUserGroup(ctx, &administration.UserGroup{ + err := svc.UpdateUserGroup(ctx, &organization.UserGroup{ UserGroupId: spotinst.String("ugr-525a30dc"), Name: spotinst.String("test-user-group-updated"), }) diff --git a/examples/service/administration/userGroup/updatePolicyMapping/main.go b/examples/service/administration/userGroup/updatePolicyMapping/main.go new file mode 100644 index 00000000..64be3e16 --- /dev/null +++ b/examples/service/administration/userGroup/updatePolicyMapping/main.go @@ -0,0 +1,64 @@ +package main + +import ( + "context" + "log" + + "github.com/spotinst/spotinst-sdk-go/service/organization" + "github.com/spotinst/spotinst-sdk-go/spotinst" + "github.com/spotinst/spotinst-sdk-go/spotinst/session" +) + +func main() { + // All clients require a Session. The Session provides the client with + // shared configuration such as account and credentials. + // A Session should be shared where possible to take advantage of + // configuration and credential caching. See the session package for + // more information. + sess := session.New() + + // Create a new instance of the service's client with a Session. + // Optional spotinst.Config values can also be provided as variadic + // arguments to the New function. This option allows you to provide + // service specific configuration. + svc := organization.New(sess) + + // Create a new context. + ctx := context.Background() + + // Create a new group. + err := svc.UpdatePolicyMappingOfUserGroup(ctx, &organization.UpdatePolicyMappingOfUserGroupInput{ + UserGroupId: spotinst.String("ugr-17ae43d9"), + Policies: []*organization.ProgPolicy{ + &organization.ProgPolicy{ + PolicyId: spotinst.String("pol-b236db1f"), + AccountIds: []string{ + "act-7c46c6df", + }, + }, + &organization.ProgPolicy{ + PolicyId: spotinst.String("pol-08715c90"), + AccountIds: []string{ + "act-7c46c6df", + }, + }, + &organization.ProgPolicy{ + PolicyId: spotinst.String("3"), + AccountIds: []string{ + "act-7c46c6df", + }, + }, + &organization.ProgPolicy{ + PolicyId: spotinst.String("pol-c75d8c06"), + AccountIds: []string{ + "act-7c46c6df", + }, + }, + }, + }) + + if err != nil { + log.Fatalf("spotinst: failed to update user group: %v", err) + } + +} diff --git a/examples/service/administration/userGroup/updateUserMapping/main.go b/examples/service/administration/userGroup/updateUserMapping/main.go new file mode 100644 index 00000000..f75a11ca --- /dev/null +++ b/examples/service/administration/userGroup/updateUserMapping/main.go @@ -0,0 +1,41 @@ +package main + +import ( + "context" + "log" + + "github.com/spotinst/spotinst-sdk-go/service/organization" + "github.com/spotinst/spotinst-sdk-go/spotinst" + "github.com/spotinst/spotinst-sdk-go/spotinst/session" +) + +func main() { + // All clients require a Session. The Session provides the client with + // shared configuration such as account and credentials. + // A Session should be shared where possible to take advantage of + // configuration and credential caching. See the session package for + // more information. + sess := session.New() + + // Create a new instance of the service's client with a Session. + // Optional spotinst.Config values can also be provided as variadic + // arguments to the New function. This option allows you to provide + // service specific configuration. + svc := organization.New(sess) + + // Create a new context. + ctx := context.Background() + + // Create a new group. + err := svc.UpdateUserMappingOfUserGroup(ctx, &organization.UpdateUserMappingOfUserGroupInput{ + UserGroupId: spotinst.String("ugr-abcd1234"), + UserIds: []string{ + "pu-abcd1234", + }, + }) + + if err != nil { + log.Fatalf("spotinst: failed to update user group: %v", err) + } + +} diff --git a/service/administration/policy.go b/service/organization/policy.go similarity index 99% rename from service/administration/policy.go rename to service/organization/policy.go index b07a9f6d..a65d682c 100644 --- a/service/administration/policy.go +++ b/service/organization/policy.go @@ -1,4 +1,4 @@ -package administration +package organization import ( "context" diff --git a/service/administration/service.go b/service/organization/service.go similarity index 83% rename from service/administration/service.go rename to service/organization/service.go index 496b7e17..7c580d74 100644 --- a/service/administration/service.go +++ b/service/organization/service.go @@ -1,4 +1,4 @@ -package administration +package organization import ( "context" @@ -17,7 +17,8 @@ type Service interface { CreateProgUser(context.Context, *ProgrammaticUser) (*CreateProgrammaticUserOutput, error) ReadUser(context.Context, *ReadUserInput) (*ReadUserOutput, error) ReadProgUser(context.Context, *ReadUserInput) (*ReadProgUserOutput, error) - //Update(context.Context, *UpdateUserInput) (*UpdateUserOutput, error) + UpdatePolicyMappingOfUser(context.Context, *UpdatePolicyMappingOfUserInput) error + UpdateUserGroupMappingOfUser(context.Context, *UpdateUserGroupMappingOfUserInput) error DeleteUser(context.Context, *DeleteUserInput) (*DeleteUserOutput, error) ListPolicies(context.Context, *ListPoliciesInput) (*ListPoliciesOutput, error) @@ -30,6 +31,8 @@ type Service interface { CreateUserGroup(context.Context, *UserGroup) (*CreateUserGroupOutput, error) ReadUserGroup(context.Context, *ReadUserGroupInput) (*ReadUserGroupOutput, error) UpdateUserGroup(context.Context, *UserGroup) error + UpdateUserMappingOfUserGroup(context.Context, *UpdateUserMappingOfUserGroupInput) error + UpdatePolicyMappingOfUserGroup(context.Context, *UpdatePolicyMappingOfUserGroupInput) error DeleteUserGroup(context.Context, *DeleteUserGroupInput) (*DeleteUserGroupOutput, error) } diff --git a/service/administration/user.go b/service/organization/user.go similarity index 81% rename from service/administration/user.go rename to service/organization/user.go index 3208d1e0..4d9ab76a 100644 --- a/service/administration/user.go +++ b/service/organization/user.go @@ -1,4 +1,4 @@ -package administration +package organization import ( "context" @@ -30,6 +30,7 @@ type User struct { Groups []*Group `json:"groups,omitempty"` DisplayName *string `json:"displayName,omitempty"` OrganizationId *int `json:"organizationId,omitempty"` + UserGroupIds []string `json:"userGroupIds,omitempty"` // forceSendFields is a list of field names (e.g. "Keys") to // unconditionally include in API requests. By default, fields with @@ -65,6 +66,7 @@ type ProgrammaticUser struct { Accounts []*Account `json:"accounts,omitempty"` Token *string `json:"token,omitempty"` ProgUserId *string `json:"id,omitempty"` + UserGroupIds []string `json:"userGroupIds,omitempty"` forceSendFields []string nullFields []string @@ -327,6 +329,64 @@ func (s *ServiceOp) ReadProgUser(ctx context.Context, input *ReadUserInput) (*Re return output, nil } +type UpdatePolicyMappingOfUserInput struct { + UserID *string `json:"userId,omitempty"` + Policies []*UserPolicy `json:"policies,omitempty"` +} + +func (s *ServiceOp) UpdatePolicyMappingOfUser(ctx context.Context, input *UpdatePolicyMappingOfUserInput) error { + path, err := uritemplates.Expand("/setup/user/{userId}/policyMapping", uritemplates.Values{ + "userId": spotinst.StringValue(input.UserID), + }) + + if err != nil { + return err + } + + // We do not need the ID anymore so let's drop it. + input.UserID = nil + + r := client.NewRequest(http.MethodPut, path) + r.Obj = input + + resp, err := client.RequireOK(s.Client.Do(ctx, r)) + if err != nil { + return err + } + defer resp.Body.Close() + + return nil +} + +type UpdateUserGroupMappingOfUserInput struct { + UserID *string `json:"userId,omitempty"` + UserGroupIds []string `json:"userGroupIds,omitempty"` +} + +func (s *ServiceOp) UpdateUserGroupMappingOfUser(ctx context.Context, input *UpdateUserGroupMappingOfUserInput) error { + path, err := uritemplates.Expand("/setup/user/{userId}/userGroupMapping", uritemplates.Values{ + "userId": spotinst.StringValue(input.UserID), + }) + + if err != nil { + return err + } + + // We do not need the ID anymore so let's drop it. + input.UserID = nil + + r := client.NewRequest(http.MethodPut, path) + r.Obj = input + + resp, err := client.RequireOK(s.Client.Do(ctx, r)) + if err != nil { + return err + } + defer resp.Body.Close() + + return nil +} + func (s *ServiceOp) DeleteUser(ctx context.Context, input *DeleteUserInput) (*DeleteUserOutput, error) { path, err := uritemplates.Expand("/setup/user/{userId}", uritemplates.Values{ "userId": spotinst.StringValue(input.UserID), @@ -388,6 +448,13 @@ func (o *User) SetRole(v *string) *User { return o } +func (o *User) SetUserGroupIds(v []string) *User { + if o.UserGroupIds = v; o.UserGroupIds == nil { + o.nullFields = append(o.nullFields, "UserGroupIds") + } + return o +} + // endregion // region ProgrammaticUser @@ -419,6 +486,13 @@ func (o *ProgrammaticUser) SetPolicies(v []*ProgPolicy) *ProgrammaticUser { return o } +func (o *User) SetUserPolicies(v []*UserPolicy) *User { + if o.Policies = v; o.Policies == nil { + o.nullFields = append(o.nullFields, "Policies") + } + return o +} + func (o *ProgrammaticUser) SetAccounts(v []*Account) *ProgrammaticUser { if o.Accounts = v; o.Accounts == nil { o.nullFields = append(o.nullFields, "Accounts") @@ -426,6 +500,13 @@ func (o *ProgrammaticUser) SetAccounts(v []*Account) *ProgrammaticUser { return o } +func (o *ProgrammaticUser) SetProgUserGroupIds(v []string) *ProgrammaticUser { + if o.UserGroupIds = v; o.UserGroupIds == nil { + o.nullFields = append(o.nullFields, "UserGroupIds") + } + return o +} + // endregion func (o ProgPolicy) MarshalJSON() ([]byte, error) { @@ -450,6 +531,28 @@ func (o *ProgPolicy) SetPolicyId(v *string) *ProgPolicy { //end region +func (o UserPolicy) MarshalJSON() ([]byte, error) { + type noMethod UserPolicy + raw := noMethod(o) + return jsonutil.MarshalJSON(raw, o.forceSendFields, o.nullFields) +} + +func (o *UserPolicy) SetUserPolicyAccountIds(v []string) *UserPolicy { + if o.AccountIds = v; o.AccountIds == nil { + o.nullFields = append(o.nullFields, "AccountIds") + } + return o +} + +func (o *UserPolicy) SetUserPolicyId(v *string) *UserPolicy { + if o.PolicyId = v; o.PolicyId == nil { + o.nullFields = append(o.nullFields, "PolicyId") + } + return o +} + +//end region + func (o Account) MarshalJSON() ([]byte, error) { type noMethod Account raw := noMethod(o) diff --git a/service/administration/userGroup.go b/service/organization/userGroup.go similarity index 83% rename from service/administration/userGroup.go rename to service/organization/userGroup.go index 4a2752cb..84bdf26a 100644 --- a/service/administration/userGroup.go +++ b/service/organization/userGroup.go @@ -1,4 +1,4 @@ -package administration +package organization import ( "context" @@ -212,6 +212,62 @@ func (s *ServiceOp) UpdateUserGroup(ctx context.Context, input *UserGroup) error return nil } +type UpdateUserMappingOfUserGroupInput struct { + UserGroupId *string `json:"userGroupId,omitempty"` + UserIds []string `json:"userIds,omitempty"` +} + +func (s *ServiceOp) UpdateUserMappingOfUserGroup(ctx context.Context, input *UpdateUserMappingOfUserGroupInput) error { + path, err := uritemplates.Expand("/setup/access/userGroup/{userGroupId}/userMapping", uritemplates.Values{ + "userGroupId": spotinst.StringValue(input.UserGroupId), + }) + if err != nil { + return err + } + + // We do not need the ID anymore so let's drop it. + input.UserGroupId = nil + + r := client.NewRequest(http.MethodPut, path) + r.Obj = input + + resp, err := client.RequireOK(s.Client.Do(ctx, r)) + if err != nil { + return err + } + defer resp.Body.Close() + + return nil +} + +type UpdatePolicyMappingOfUserGroupInput struct { + UserGroupId *string `json:"userGroupId,omitempty"` + Policies []*ProgPolicy `json:"policies,omitempty"` +} + +func (s *ServiceOp) UpdatePolicyMappingOfUserGroup(ctx context.Context, input *UpdatePolicyMappingOfUserGroupInput) error { + path, err := uritemplates.Expand("/setup/access/userGroup/{userGroupId}/policyMapping", uritemplates.Values{ + "userGroupId": spotinst.StringValue(input.UserGroupId), + }) + if err != nil { + return err + } + + // We do not need the ID anymore so let's drop it. + input.UserGroupId = nil + + r := client.NewRequest(http.MethodPut, path) + r.Obj = input + + resp, err := client.RequireOK(s.Client.Do(ctx, r)) + if err != nil { + return err + } + defer resp.Body.Close() + + return nil +} + func (s *ServiceOp) DeleteUserGroup(ctx context.Context, input *DeleteUserGroupInput) (*DeleteUserGroupOutput, error) { path, err := uritemplates.Expand("/setup/access/userGroup/{userGroupId}", uritemplates.Values{ "userGroupId": spotinst.StringValue(input.UserGroupID), @@ -230,8 +286,6 @@ func (s *ServiceOp) DeleteUserGroup(ctx context.Context, input *DeleteUserGroupI return &DeleteUserGroupOutput{}, nil } -// region User - func (o UserGroup) MarshalJSON() ([]byte, error) { type noMethod UserGroup raw := noMethod(o) diff --git a/spotinst/credentials/provider_env.go b/spotinst/credentials/provider_env.go index 92b1088e..bd61dccb 100644 --- a/spotinst/credentials/provider_env.go +++ b/spotinst/credentials/provider_env.go @@ -2,7 +2,6 @@ package credentials import ( "fmt" - "os" ) const ( @@ -40,8 +39,8 @@ func NewEnvCredentials() *Credentials { // Retrieve retrieves the keys from the environment. func (e *EnvProvider) Retrieve() (Value, error) { value := Value{ - Token: os.Getenv(EnvCredentialsVarToken), - Account: os.Getenv(EnvCredentialsVarAccount), + Token: "d31949623321d13a43d49176d854cf3fc2b3682cab2604b2d92565af439f6cc8", + Account: "", ProviderName: EnvCredentialsProviderName, }