From 0af731f89627e098cb4ab70603e9e08b5edfc7f1 Mon Sep 17 00:00:00 2001 From: patrapritish1 <59195856+patrapritish1@users.noreply.github.com> Date: Thu, 3 Aug 2023 22:04:20 +0530 Subject: [PATCH 01/13] added sdk implementation user, policy and usergroup --- .../administration/policy/create/main.go | 62 ++++ .../administration/policy/delete/main.go | 36 ++ .../administration/policy/list/main.go | 44 +++ .../administration/policy/read/main.go | 44 +++ .../administration/policy/update/main.go | 48 +++ .../administration/user/create/main.go | 49 +++ .../administration/user/delete/main.go | 36 ++ .../service/administration/user/list/main.go | 44 +++ .../service/administration/user/read/main.go | 44 +++ .../administration/userGroup/create/main.go | 54 +++ .../administration/userGroup/delete/main.go | 36 ++ .../administration/userGroup/list/main.go | 44 +++ .../administration/userGroup/read/main.go | 44 +++ .../administration/userGroup/update/main.go | 46 +++ service/administration/policy.go | 316 ++++++++++++++++++ service/administration/service.go | 48 +++ service/administration/user.go | 259 ++++++++++++++ service/administration/userGroup.go | 293 ++++++++++++++++ spotinst/credentials/provider_env.go | 7 +- 19 files changed, 1551 insertions(+), 3 deletions(-) create mode 100644 examples/service/administration/policy/create/main.go create mode 100644 examples/service/administration/policy/delete/main.go create mode 100644 examples/service/administration/policy/list/main.go create mode 100644 examples/service/administration/policy/read/main.go create mode 100644 examples/service/administration/policy/update/main.go create mode 100644 examples/service/administration/user/create/main.go create mode 100644 examples/service/administration/user/delete/main.go create mode 100644 examples/service/administration/user/list/main.go create mode 100644 examples/service/administration/user/read/main.go create mode 100644 examples/service/administration/userGroup/create/main.go create mode 100644 examples/service/administration/userGroup/delete/main.go create mode 100644 examples/service/administration/userGroup/list/main.go create mode 100644 examples/service/administration/userGroup/read/main.go create mode 100644 examples/service/administration/userGroup/update/main.go create mode 100644 service/administration/policy.go create mode 100644 service/administration/service.go create mode 100644 service/administration/user.go create mode 100644 service/administration/userGroup.go diff --git a/examples/service/administration/policy/create/main.go b/examples/service/administration/policy/create/main.go new file mode 100644 index 00000000..6c79bc6d --- /dev/null +++ b/examples/service/administration/policy/create/main.go @@ -0,0 +1,62 @@ +package main + +import ( + "context" + "log" + + "github.com/spotinst/spotinst-sdk-go/service/administration" + "github.com/spotinst/spotinst-sdk-go/spotinst" + "github.com/spotinst/spotinst-sdk-go/spotinst/session" + "github.com/spotinst/spotinst-sdk-go/spotinst/util/stringutil" +) + +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 := administration.New(sess) + + // Create a new context. + ctx := context.Background() + + // Create a new group. + out, err := svc.CreatePolicy(ctx, &administration.CreatePolicyInput{ + Policy: &administration.Policy{ + Description: spotinst.String("TFPolicy"), + Name: spotinst.String("Pritish"), + PolicyContent: &administration.PolicyContent{ + Statements: []*administration.Statement{ + { + Actions: spotinst.StringSlice([]string{ + "ocean:deleteCluster", + "ocean:updateCluster", + }), + Effect: spotinst.String("ALLOW"), + Resources: spotinst.StringSlice([]string{ + "*", + }), + }, + }, + }, + }, + }) + + if err != nil { + log.Fatalf("spotinst: failed to create policy: %v", err) + } + + // Output. + if out.Policy != nil { + log.Printf("Policy %q: %s", + spotinst.StringValue(out.Policy.PolicyID), + stringutil.Stringify(out.Policy)) + } +} diff --git a/examples/service/administration/policy/delete/main.go b/examples/service/administration/policy/delete/main.go new file mode 100644 index 00000000..9768cc99 --- /dev/null +++ b/examples/service/administration/policy/delete/main.go @@ -0,0 +1,36 @@ +package main + +import ( + "context" + "github.com/spotinst/spotinst-sdk-go/service/administration" + "log" + + "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 := administration.New(sess) + + // Create a new context. + ctx := context.Background() + + // Delete an existing user group. + _, err := svc.DeleteUserGroup(ctx, &administration.DeleteUserGroupInput{ + UserGroupID: spotinst.String("ugr-9141021f"), + }) + if err != nil { + log.Fatalf("spotinst: failed to delete user group: %v", err) + } +} diff --git a/examples/service/administration/policy/list/main.go b/examples/service/administration/policy/list/main.go new file mode 100644 index 00000000..0580e048 --- /dev/null +++ b/examples/service/administration/policy/list/main.go @@ -0,0 +1,44 @@ +package main + +import ( + "context" + "github.com/spotinst/spotinst-sdk-go/service/administration" + "log" + + "github.com/spotinst/spotinst-sdk-go/spotinst" + "github.com/spotinst/spotinst-sdk-go/spotinst/session" + "github.com/spotinst/spotinst-sdk-go/spotinst/util/stringutil" +) + +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 := administration.New(sess) + + // Create a new context. + ctx := context.Background() + + // List all groups. + out, err := svc.ListPolicies(ctx, &administration.ListPoliciesInput{}) + if err != nil { + log.Fatalf("spotinst: failed to list users: %v", err) + } + + // Output all groups, if any. + if len(out.Policies) > 0 { + for _, Policy := range out.Policies { + log.Printf("Policy %q: %s", + spotinst.StringValue(Policy.PolicyID), + stringutil.Stringify(Policy)) + } + } +} diff --git a/examples/service/administration/policy/read/main.go b/examples/service/administration/policy/read/main.go new file mode 100644 index 00000000..626986ce --- /dev/null +++ b/examples/service/administration/policy/read/main.go @@ -0,0 +1,44 @@ +package main + +import ( + "context" + "github.com/spotinst/spotinst-sdk-go/service/administration" + "log" + + "github.com/spotinst/spotinst-sdk-go/spotinst" + "github.com/spotinst/spotinst-sdk-go/spotinst/session" + "github.com/spotinst/spotinst-sdk-go/spotinst/util/stringutil" +) + +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 := administration.New(sess) + + // Create a new context. + ctx := context.Background() + + // Read group configuration. + out, err := svc.ReadUser(ctx, &administration.ReadUserInput{ + UserID: spotinst.String("u-989ac40c"), + }) + if err != nil { + log.Fatalf("spotinst: failed to read group: %v", err) + } + + // Output. + if out.User != nil { + log.Printf("User %q: %s", + spotinst.StringValue(out.User.UserID), + stringutil.Stringify(out.User)) + } +} diff --git a/examples/service/administration/policy/update/main.go b/examples/service/administration/policy/update/main.go new file mode 100644 index 00000000..6f5af5ec --- /dev/null +++ b/examples/service/administration/policy/update/main.go @@ -0,0 +1,48 @@ +package main + +import ( + "context" + "log" + + "github.com/spotinst/spotinst-sdk-go/service/administration" + "github.com/spotinst/spotinst-sdk-go/spotinst" + "github.com/spotinst/spotinst-sdk-go/spotinst/session" + "github.com/spotinst/spotinst-sdk-go/spotinst/util/stringutil" +) + +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 := administration.New(sess) + + // Create a new context. + ctx := context.Background() + + // Create a new group. + out, err := svc.UpdatePolicy(ctx, &administration.UpdatePolicyInput{ + Policy: &administration.Policy{ + PolicyID: spotinst.String("pol-c75d8c06"), + Name: spotinst.String("PritishUpdated"), + }, + }) + + if err != nil { + log.Fatalf("spotinst: failed to update policy: %v", err) + } + + // Output. + if out.Policy != nil { + log.Printf("Policy %q: %s", + spotinst.StringValue(out.Policy.PolicyID), + stringutil.Stringify(out.Policy)) + } +} diff --git a/examples/service/administration/user/create/main.go b/examples/service/administration/user/create/main.go new file mode 100644 index 00000000..eec71916 --- /dev/null +++ b/examples/service/administration/user/create/main.go @@ -0,0 +1,49 @@ +package main + +import ( + "context" + "log" + + "github.com/spotinst/spotinst-sdk-go/service/administration" + "github.com/spotinst/spotinst-sdk-go/spotinst" + "github.com/spotinst/spotinst-sdk-go/spotinst/session" + "github.com/spotinst/spotinst-sdk-go/spotinst/util/stringutil" +) + +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 := administration.New(sess) + + // Create a new context. + ctx := context.Background() + + // Create a new group. + out, err := svc.CreateUser(ctx, &administration.User{ + Email: spotinst.String("pritishp@netapp.com"), + FirstName: spotinst.String("Pritish"), + LastName: spotinst.String("Patra"), + Password: spotinst.String("naradMuni@108"), + Role: spotinst.String("admin"), + }, spotinst.Bool(true)) + + if err != nil { + log.Fatalf("spotinst: failed to create user: %v", err) + } + + // Output. + if out.User != nil { + log.Printf("User %q: %s", + spotinst.StringValue(out.User.UserID), + stringutil.Stringify(out.User)) + } +} diff --git a/examples/service/administration/user/delete/main.go b/examples/service/administration/user/delete/main.go new file mode 100644 index 00000000..9b6d1bae --- /dev/null +++ b/examples/service/administration/user/delete/main.go @@ -0,0 +1,36 @@ +package main + +import ( + "context" + "github.com/spotinst/spotinst-sdk-go/service/administration" + "log" + + "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 := administration.New(sess) + + // Create a new context. + ctx := context.Background() + + // Delete an existing group. + _, err := svc.DeleteUser(ctx, &administration.DeleteUserInput{ + UserID: spotinst.String("u-989ac40c"), + }) + if err != nil { + log.Fatalf("spotinst: failed to delete user: %v", err) + } +} diff --git a/examples/service/administration/user/list/main.go b/examples/service/administration/user/list/main.go new file mode 100644 index 00000000..8ceac63f --- /dev/null +++ b/examples/service/administration/user/list/main.go @@ -0,0 +1,44 @@ +package main + +import ( + "context" + "github.com/spotinst/spotinst-sdk-go/service/administration" + "log" + + "github.com/spotinst/spotinst-sdk-go/spotinst" + "github.com/spotinst/spotinst-sdk-go/spotinst/session" + "github.com/spotinst/spotinst-sdk-go/spotinst/util/stringutil" +) + +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 := administration.New(sess) + + // Create a new context. + ctx := context.Background() + + // List all groups. + out, err := svc.ListUsers(ctx, &administration.ListUsersInput{}) + if err != nil { + log.Fatalf("spotinst: failed to list users: %v", err) + } + + // Output all groups, if any. + if len(out.Users) > 0 { + for _, User := range out.Users { + log.Printf("User %q: %s", + spotinst.StringValue(User.UserID), + stringutil.Stringify(User)) + } + } +} diff --git a/examples/service/administration/user/read/main.go b/examples/service/administration/user/read/main.go new file mode 100644 index 00000000..626986ce --- /dev/null +++ b/examples/service/administration/user/read/main.go @@ -0,0 +1,44 @@ +package main + +import ( + "context" + "github.com/spotinst/spotinst-sdk-go/service/administration" + "log" + + "github.com/spotinst/spotinst-sdk-go/spotinst" + "github.com/spotinst/spotinst-sdk-go/spotinst/session" + "github.com/spotinst/spotinst-sdk-go/spotinst/util/stringutil" +) + +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 := administration.New(sess) + + // Create a new context. + ctx := context.Background() + + // Read group configuration. + out, err := svc.ReadUser(ctx, &administration.ReadUserInput{ + UserID: spotinst.String("u-989ac40c"), + }) + if err != nil { + log.Fatalf("spotinst: failed to read group: %v", err) + } + + // Output. + if out.User != nil { + log.Printf("User %q: %s", + spotinst.StringValue(out.User.UserID), + stringutil.Stringify(out.User)) + } +} diff --git a/examples/service/administration/userGroup/create/main.go b/examples/service/administration/userGroup/create/main.go new file mode 100644 index 00000000..b7b8cee9 --- /dev/null +++ b/examples/service/administration/userGroup/create/main.go @@ -0,0 +1,54 @@ +package main + +import ( + "context" + "log" + + "github.com/spotinst/spotinst-sdk-go/service/administration" + "github.com/spotinst/spotinst-sdk-go/spotinst" + "github.com/spotinst/spotinst-sdk-go/spotinst/session" + "github.com/spotinst/spotinst-sdk-go/spotinst/util/stringutil" +) + +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 := administration.New(sess) + + // Create a new context. + ctx := context.Background() + + // Create a new group. + out, err := svc.CreateUserGroup(ctx, &administration.UserGroup{ + Description: spotinst.String("TFUserGroup"), + Name: spotinst.String("Pritish"), + Policies: []*administration.UserGroupPolicy{ + { + AccountIds: spotinst.StringSlice([]string{ + "act-7c46c6df", + }), + PolicyId: spotinst.String("pol-c063c6c9"), + }, + }, + }) + + if err != nil { + log.Fatalf("spotinst: failed to create user group: %v", err) + } + + // Output. + if out.UserGroup != nil { + log.Printf("UserGroup %q: %s", + spotinst.StringValue(out.UserGroup.UserGroupId), + stringutil.Stringify(out.UserGroup)) + } +} diff --git a/examples/service/administration/userGroup/delete/main.go b/examples/service/administration/userGroup/delete/main.go new file mode 100644 index 00000000..03674283 --- /dev/null +++ b/examples/service/administration/userGroup/delete/main.go @@ -0,0 +1,36 @@ +package main + +import ( + "context" + "github.com/spotinst/spotinst-sdk-go/service/administration" + "log" + + "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 := administration.New(sess) + + // Create a new context. + ctx := context.Background() + + // Delete an existing group. + _, err := svc.DeletePolicy(ctx, &administration.DeletePolicyInput{ + PolicyID: spotinst.String("pol-c75d8c06"), + }) + if err != nil { + log.Fatalf("spotinst: failed to delete policy: %v", err) + } +} diff --git a/examples/service/administration/userGroup/list/main.go b/examples/service/administration/userGroup/list/main.go new file mode 100644 index 00000000..729d042c --- /dev/null +++ b/examples/service/administration/userGroup/list/main.go @@ -0,0 +1,44 @@ +package main + +import ( + "context" + "github.com/spotinst/spotinst-sdk-go/service/administration" + "log" + + "github.com/spotinst/spotinst-sdk-go/spotinst" + "github.com/spotinst/spotinst-sdk-go/spotinst/session" + "github.com/spotinst/spotinst-sdk-go/spotinst/util/stringutil" +) + +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 := administration.New(sess) + + // Create a new context. + ctx := context.Background() + + // List all groups. + out, err := svc.ListUserGroups(ctx, &administration.ListUserGroupsInput{}) + if err != nil { + log.Fatalf("spotinst: failed to list users: %v", err) + } + + // Output all groups, if any. + if len(out.UserGroups) > 0 { + for _, UserGroup := range out.UserGroups { + log.Printf("UserGroup %q: %s", + spotinst.StringValue(UserGroup.UserGroupId), + stringutil.Stringify(UserGroup)) + } + } +} diff --git a/examples/service/administration/userGroup/read/main.go b/examples/service/administration/userGroup/read/main.go new file mode 100644 index 00000000..41ab779f --- /dev/null +++ b/examples/service/administration/userGroup/read/main.go @@ -0,0 +1,44 @@ +package main + +import ( + "context" + "github.com/spotinst/spotinst-sdk-go/service/administration" + "log" + + "github.com/spotinst/spotinst-sdk-go/spotinst" + "github.com/spotinst/spotinst-sdk-go/spotinst/session" + "github.com/spotinst/spotinst-sdk-go/spotinst/util/stringutil" +) + +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 := administration.New(sess) + + // Create a new context. + ctx := context.Background() + + // Read group configuration. + out, err := svc.ReadUserGroup(ctx, &administration.ReadUserGroupInput{ + UserGroupID: spotinst.String("ugr-9141021f"), + }) + if err != nil { + log.Fatalf("spotinst: failed to read user group: %v", err) + } + + // Output. + if out.UserGroup != nil { + log.Printf("UserGroup %q: %s", + spotinst.StringValue(out.UserGroup.UserGroupId), + stringutil.Stringify(out.UserGroup)) + } +} diff --git a/examples/service/administration/userGroup/update/main.go b/examples/service/administration/userGroup/update/main.go new file mode 100644 index 00000000..c159c99d --- /dev/null +++ b/examples/service/administration/userGroup/update/main.go @@ -0,0 +1,46 @@ +package main + +import ( + "context" + "log" + + "github.com/spotinst/spotinst-sdk-go/service/administration" + "github.com/spotinst/spotinst-sdk-go/spotinst" + "github.com/spotinst/spotinst-sdk-go/spotinst/session" + "github.com/spotinst/spotinst-sdk-go/spotinst/util/stringutil" +) + +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 := administration.New(sess) + + // Create a new context. + ctx := context.Background() + + // Create a new group. + out, err := svc.UpdateUserGroup(ctx, &administration.UserGroup{ + UserGroupId: spotinst.String("ugr-9141021f"), + Name: spotinst.String("PritishUpdated"), + }) + + if err != nil { + log.Fatalf("spotinst: failed to update user group: %v", err) + } + + // Output. + if out.UserGroup != nil { + log.Printf("UserGroup %q: %s", + spotinst.StringValue(out.UserGroup.UserGroupId), + stringutil.Stringify(out.UserGroup)) + } +} diff --git a/service/administration/policy.go b/service/administration/policy.go new file mode 100644 index 00000000..6bdcc982 --- /dev/null +++ b/service/administration/policy.go @@ -0,0 +1,316 @@ +package administration + +import ( + "context" + "encoding/json" + "io/ioutil" + "net/http" + + "github.com/spotinst/spotinst-sdk-go/spotinst" + "github.com/spotinst/spotinst-sdk-go/spotinst/client" + "github.com/spotinst/spotinst-sdk-go/spotinst/util/jsonutil" + "github.com/spotinst/spotinst-sdk-go/spotinst/util/uritemplates" +) + +type Policy struct { + Description *string `json:"description,omitempty"` + Name *string `json:"name,omitempty"` + PolicyContent *PolicyContent `json:"policyContent,omitempty"` + PolicyID *string `json:"id,omitempty"` + + // forceSendFields is a list of field names (e.g. "Keys") to + // unconditionally include in API requests. By default, fields with + // empty values are omitted from API requests. However, any non-pointer, + // non-interface field appearing in ForceSendFields will be sent to the + // server regardless of whether the field is empty or not. This may be + // used to include empty fields in Patch requests. + forceSendFields []string + + // nullFields is a list of field names (e.g. "Keys") to include in API + // requests with the JSON null value. By default, fields with empty + // values are omitted from API requests. However, any field with an + // empty value appearing in NullFields will be sent to the server as + // null. It is an error if a field in this list has a non-empty value. + // This may be used to include null fields in Patch requests. + nullFields []string +} + +type PolicyContent struct { + Statements []*Statement `json:"statements,omitempty"` + + forceSendFields []string + nullFields []string +} + +type Statement struct { + Actions []*string `json:"actions,omitempty"` + Effect *string `json:"effect,omitempty"` + Resources []*string `json:"resources,omitempty"` + + forceSendFields []string + nullFields []string +} + +type ListPoliciesInput struct{} + +type ListPoliciesOutput struct { + Policies []*Policy `json:"policies,omitempty"` +} + +type CreatePolicyInput struct { + Policy *Policy `json:"policy,omitempty"` +} + +type CreatePolicyOutput struct { + Policy *Policy `json:"policy,omitempty"` +} + +type ReadPolicyInput struct { + PolicyID *string `json:"policyId,omitempty"` +} + +type ReadPolicyOutput struct { + Policy *Policy `json:"policy,omitempty"` +} + +type UpdatePolicyInput struct { + Policy *Policy `json:"policy,omitempty"` +} + +type UpdatePolicyOutput struct { + Policy *Policy `json:"policy,omitempty"` +} + +type DeletePolicyInput struct { + PolicyID *string `json:"id,omitempty"` +} + +type DeletePolicyOutput struct{} + +func policyFromJSON(in []byte) (*Policy, error) { + b := new(Policy) + if err := json.Unmarshal(in, b); err != nil { + return nil, err + } + return b, nil +} + +func policiesFromJSON(in []byte) ([]*Policy, error) { + var rw client.Response + if err := json.Unmarshal(in, &rw); err != nil { + return nil, err + } + out := make([]*Policy, len(rw.Response.Items)) + if len(out) == 0 { + return out, nil + } + for i, rb := range rw.Response.Items { + b, err := policyFromJSON(rb) + if err != nil { + return nil, err + } + out[i] = b + } + return out, nil +} + +func policiesFromHttpResponse(resp *http.Response) ([]*Policy, error) { + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + return nil, err + } + return policiesFromJSON(body) +} + +func (s *ServiceOp) ListPolicies(ctx context.Context, input *ListPoliciesInput) (*ListPoliciesOutput, error) { + r := client.NewRequest(http.MethodGet, "/setup/organization/policy") + resp, err := client.RequireOK(s.Client.Do(ctx, r)) + if err != nil { + return nil, err + } + defer resp.Body.Close() + + gs, err := policiesFromHttpResponse(resp) + if err != nil { + return nil, err + } + + return &ListPoliciesOutput{Policies: gs}, nil +} + +func (s *ServiceOp) CreatePolicy(ctx context.Context, input *CreatePolicyInput) (*CreatePolicyOutput, error) { + r := client.NewRequest(http.MethodPost, "/setup/access/policy") + r.Obj = input + + resp, err := client.RequireOK(s.Client.Do(ctx, r)) + if err != nil { + return nil, err + } + defer resp.Body.Close() + + ss, err := policiesFromHttpResponse(resp) + if err != nil { + return nil, err + } + + output := new(CreatePolicyOutput) + if len(ss) > 0 { + output.Policy = ss[0] + } + + return output, nil +} + +func (s *ServiceOp) ReadPolicy(ctx context.Context, input *ReadPolicyInput) (*ReadPolicyOutput, error) { + path, err := uritemplates.Expand("/setup/access/policy/{policyId}", uritemplates.Values{ + "policyId": spotinst.StringValue(input.PolicyID), + }) + if err != nil { + return nil, err + } + + r := client.NewRequest(http.MethodGet, path) + resp, err := client.RequireOK(s.Client.Do(ctx, r)) + if err != nil { + return nil, err + } + defer resp.Body.Close() + + ss, err := policiesFromHttpResponse(resp) + if err != nil { + return nil, err + } + + output := new(ReadPolicyOutput) + if len(ss) > 0 { + output.Policy = ss[0] + } + + return output, nil +} + +func (s *ServiceOp) UpdatePolicy(ctx context.Context, input *UpdatePolicyInput) (*UpdatePolicyOutput, error) { + path, err := uritemplates.Expand("/setup/access/policy/{policyId}", uritemplates.Values{ + "policyId": spotinst.StringValue(input.Policy.PolicyID), + }) + if err != nil { + return nil, err + } + + // We do not need the ID anymore so let's drop it. + input.Policy.PolicyID = nil + + r := client.NewRequest(http.MethodPut, path) + r.Obj = input + + resp, err := client.RequireOK(s.Client.Do(ctx, r)) + if err != nil { + return nil, err + } + defer resp.Body.Close() + + ss, err := policiesFromHttpResponse(resp) + if err != nil { + return nil, err + } + + output := new(UpdatePolicyOutput) + if len(ss) > 0 { + output.Policy = ss[0] + } + + return output, nil +} + +func (s *ServiceOp) DeletePolicy(ctx context.Context, input *DeletePolicyInput) (*DeletePolicyOutput, error) { + path, err := uritemplates.Expand("/setup/access/policy/{policyId}", uritemplates.Values{ + "policyId": spotinst.StringValue(input.PolicyID), + }) + if err != nil { + return nil, err + } + + r := client.NewRequest(http.MethodDelete, path) + resp, err := client.RequireOK(s.Client.Do(ctx, r)) + if err != nil { + return nil, err + } + defer resp.Body.Close() + + return &DeletePolicyOutput{}, nil +} + +// region Policy + +func (o Policy) MarshalJSON() ([]byte, error) { + type noMethod Policy + raw := noMethod(o) + return jsonutil.MarshalJSON(raw, o.forceSendFields, o.nullFields) +} + +func (o *Policy) SetDescription(v *string) *Policy { + if o.Description = v; o.Description == nil { + o.nullFields = append(o.nullFields, "Description") + } + return o +} + +func (o *Policy) SetName(v *string) *Policy { + if o.Name = v; o.Name == nil { + o.nullFields = append(o.nullFields, "Name") + } + return o +} + +func (o *Policy) SetPolicyContent(v *PolicyContent) *Policy { + if o.PolicyContent = v; o.PolicyContent == nil { + o.nullFields = append(o.nullFields, "PolicyContent") + } + return o +} + +// endregion + +func (o PolicyContent) MarshalJSON() ([]byte, error) { + type noMethod PolicyContent + raw := noMethod(o) + return jsonutil.MarshalJSON(raw, o.forceSendFields, o.nullFields) +} + +func (o *PolicyContent) SetStatements(v []*Statement) *PolicyContent { + if o.Statements = v; o.Statements == nil { + o.nullFields = append(o.nullFields, "Statements") + } + return o +} + +// endregion + +func (o Statement) MarshalJSON() ([]byte, error) { + type noMethod Statement + raw := noMethod(o) + return jsonutil.MarshalJSON(raw, o.forceSendFields, o.nullFields) +} + +func (o *Statement) SetEffect(v *string) *Statement { + if o.Effect = v; o.Effect == nil { + o.nullFields = append(o.nullFields, "Effect") + } + return o +} + +func (o *Statement) SetResources(v []*string) *Statement { + if o.Resources = v; o.Resources == nil { + o.nullFields = append(o.nullFields, "Resources") + } + return o +} + +func (o *Statement) SetActions(v []*string) *Statement { + if o.Actions = v; o.Actions == nil { + o.nullFields = append(o.nullFields, "Actions") + } + return o +} + +// endregion diff --git a/service/administration/service.go b/service/administration/service.go new file mode 100644 index 00000000..01407b1a --- /dev/null +++ b/service/administration/service.go @@ -0,0 +1,48 @@ +package administration + +import ( + "context" + + "github.com/spotinst/spotinst-sdk-go/spotinst" + "github.com/spotinst/spotinst-sdk-go/spotinst/client" + "github.com/spotinst/spotinst-sdk-go/spotinst/session" +) + +// Service provides the API operation methods for making requests to endpoints +// of the Spotinst API. See this package's package overview docs for details on +// the service. +type Service interface { + ListUsers(context.Context, *ListUsersInput) (*ListUsersOutput, error) + CreateUser(context.Context, *User, *bool) (*CreateUserOutput, error) + ReadUser(context.Context, *ReadUserInput) (*ReadUserOutput, error) + //Update(context.Context, *UpdateUserInput) (*UpdateUserOutput, error) + DeleteUser(context.Context, *DeleteUserInput) (*DeleteUserOutput, error) + + ListPolicies(context.Context, *ListPoliciesInput) (*ListPoliciesOutput, error) + CreatePolicy(context.Context, *CreatePolicyInput) (*CreatePolicyOutput, error) + //ReadPolicy(context.Context, *ReadPolicyInput) (*ReadPolicyOutput, error) + UpdatePolicy(context.Context, *UpdatePolicyInput) (*UpdatePolicyOutput, error) + DeletePolicy(context.Context, *DeletePolicyInput) (*DeletePolicyOutput, error) + + ListUserGroups(context.Context, *ListUserGroupsInput) (*ListUserGroupsOutput, error) + CreateUserGroup(context.Context, *UserGroup) (*CreateUserGroupOutput, error) + ReadUserGroup(context.Context, *ReadUserGroupInput) (*ReadUserGroupOutput, error) + UpdateUserGroup(context.Context, *UserGroup) (*UpdateUserGroupOutput, error) + DeleteUserGroup(context.Context, *DeleteUserGroupInput) (*DeleteUserGroupOutput, error) +} + +type ServiceOp struct { + Client *client.Client +} + +var _ Service = &ServiceOp{} + +func New(sess *session.Session, cfgs ...*spotinst.Config) *ServiceOp { + cfg := &spotinst.Config{} + cfg.Merge(sess.Config) + cfg.Merge(cfgs...) + + return &ServiceOp{ + Client: client.New(sess.Config), + } +} diff --git a/service/administration/user.go b/service/administration/user.go new file mode 100644 index 00000000..dbac931a --- /dev/null +++ b/service/administration/user.go @@ -0,0 +1,259 @@ +package administration + +import ( + "context" + "encoding/json" + "io/ioutil" + "net/http" + "strconv" + "time" + + "github.com/spotinst/spotinst-sdk-go/spotinst" + "github.com/spotinst/spotinst-sdk-go/spotinst/client" + "github.com/spotinst/spotinst-sdk-go/spotinst/util/jsonutil" + "github.com/spotinst/spotinst-sdk-go/spotinst/util/uritemplates" +) + +type User struct { + Email *string `json:"email,omitempty"` + FirstName *string `json:"firstName,omitempty"` + LastName *string `json:"lastName,omitempty"` + Password *string `json:"password,omitempty"` + Role *string `json:"role,omitempty"` + UserID *string `json:"userId,omitempty"` + Username *string `json:"username,omitempty"` + Type *string `json:"type,omitempty"` + Mfa *bool `json:"mfa,omitempty"` + Policies []*UserPolicy `json:"policies,omitempty"` + Tokens []*Token `json:"tokens,omitempty"` + + // forceSendFields is a list of field names (e.g. "Keys") to + // unconditionally include in API requests. By default, fields with + // empty values are omitted from API requests. However, any non-pointer, + // non-interface field appearing in ForceSendFields will be sent to the + // server regardless of whether the field is empty or not. This may be + // used to include empty fields in Patch requests. + forceSendFields []string + + // nullFields is a list of field names (e.g. "Keys") to include in API + // requests with the JSON null value. By default, fields with empty + // values are omitted from API requests. However, any field with an + // empty value appearing in NullFields will be sent to the server as + // null. It is an error if a field in this list has a non-empty value. + // This may be used to include null fields in Patch requests. + nullFields []string +} + +type UserPolicy struct { + PolicyId *string `json:"policyId,omitempty"` + PolicyName *string `json:"policyName,omitempty"` + PolicyType *string `json:"policyType,omitempty"` + + forceSendFields []string + nullFields []string +} + +type Token struct { + Name *string `json:"name,omitempty"` + CreatedAt *time.Time `json:"createdAt,omitempty"` + PolicyType *string `json:"policyType,omitempty"` + TokenId *int `json:"tokenId,omitempty"` + TokenLastDigits *string `json:"tokenLastDigits,omitempty"` + + forceSendFields []string + nullFields []string +} + +type ListUsersInput struct{} + +type ListUsersOutput struct { + Users []*User `json:"users,omitempty"` +} + +type CreateUserInput struct { +} + +type CreateUserOutput struct { + User *User `json:"user,omitempty"` +} + +type ReadUserInput struct { + UserID *string `json:"userId,omitempty"` +} + +type ReadUserOutput struct { + User *User `json:"user,omitempty"` +} + +type DeleteUserInput struct { + UserID *string `json:"userId,omitempty"` +} + +type DeleteUserOutput struct{} + +func userFromJSON(in []byte) (*User, error) { + b := new(User) + if err := json.Unmarshal(in, b); err != nil { + return nil, err + } + return b, nil +} + +func usersFromJSON(in []byte) ([]*User, error) { + var rw client.Response + if err := json.Unmarshal(in, &rw); err != nil { + return nil, err + } + out := make([]*User, len(rw.Response.Items)) + if len(out) == 0 { + return out, nil + } + for i, rb := range rw.Response.Items { + b, err := userFromJSON(rb) + if err != nil { + return nil, err + } + out[i] = b + } + return out, nil +} + +func usersFromHttpResponse(resp *http.Response) ([]*User, error) { + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + return nil, err + } + return usersFromJSON(body) +} + +func (s *ServiceOp) ListUsers(ctx context.Context, input *ListUsersInput) (*ListUsersOutput, error) { + r := client.NewRequest(http.MethodGet, "/setup/organization/user") + resp, err := client.RequireOK(s.Client.Do(ctx, r)) + if err != nil { + return nil, err + } + defer resp.Body.Close() + + gs, err := usersFromHttpResponse(resp) + if err != nil { + return nil, err + } + + return &ListUsersOutput{Users: gs}, nil +} + +func (s *ServiceOp) CreateUser(ctx context.Context, input *User, generateToken *bool) (*CreateUserOutput, error) { + r := client.NewRequest(http.MethodPost, "/setup/user") + genToken := strconv.FormatBool(spotinst.BoolValue(generateToken)) + r.Params.Set("generateToken", genToken) + r.Obj = input + + resp, err := client.RequireOK(s.Client.Do(ctx, r)) + if err != nil { + return nil, err + } + defer resp.Body.Close() + + ss, err := usersFromHttpResponse(resp) + if err != nil { + return nil, err + } + + output := new(CreateUserOutput) + if len(ss) > 0 { + output.User = ss[0] + } + + return output, nil +} + +func (s *ServiceOp) ReadUser(ctx context.Context, input *ReadUserInput) (*ReadUserOutput, error) { + path, err := uritemplates.Expand("/setup/user/{userId}", uritemplates.Values{ + "userId": spotinst.StringValue(input.UserID), + }) + if err != nil { + return nil, err + } + + r := client.NewRequest(http.MethodGet, path) + resp, err := client.RequireOK(s.Client.Do(ctx, r)) + if err != nil { + return nil, err + } + defer resp.Body.Close() + + ss, err := usersFromHttpResponse(resp) + if err != nil { + return nil, err + } + + output := new(ReadUserOutput) + if len(ss) > 0 { + output.User = ss[0] + } + + return output, 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), + }) + if err != nil { + return nil, err + } + + r := client.NewRequest(http.MethodDelete, path) + resp, err := client.RequireOK(s.Client.Do(ctx, r)) + if err != nil { + return nil, err + } + defer resp.Body.Close() + + return &DeleteUserOutput{}, nil +} + +// region User + +func (o User) MarshalJSON() ([]byte, error) { + type noMethod User + raw := noMethod(o) + return jsonutil.MarshalJSON(raw, o.forceSendFields, o.nullFields) +} + +func (o *User) SetEmail(v *string) *User { + if o.Email = v; o.Email == nil { + o.nullFields = append(o.nullFields, "Email") + } + return o +} + +func (o *User) SetFirstName(v *string) *User { + if o.FirstName = v; o.FirstName == nil { + o.nullFields = append(o.nullFields, "FirstName") + } + return o +} + +func (o *User) SetLastName(v *string) *User { + if o.LastName = v; o.LastName == nil { + o.nullFields = append(o.nullFields, "LastName") + } + return o +} + +func (o *User) SetPassword(v *string) *User { + if o.Password = v; o.Password == nil { + o.nullFields = append(o.nullFields, "Password") + } + return o +} + +func (o *User) SetRole(v *string) *User { + if o.Role = v; o.Role == nil { + o.nullFields = append(o.nullFields, "Role") + } + return o +} + +// endregion diff --git a/service/administration/userGroup.go b/service/administration/userGroup.go new file mode 100644 index 00000000..d5c6c749 --- /dev/null +++ b/service/administration/userGroup.go @@ -0,0 +1,293 @@ +package administration + +import ( + "context" + "encoding/json" + "io/ioutil" + "net/http" + + "github.com/spotinst/spotinst-sdk-go/spotinst" + "github.com/spotinst/spotinst-sdk-go/spotinst/client" + "github.com/spotinst/spotinst-sdk-go/spotinst/util/jsonutil" + "github.com/spotinst/spotinst-sdk-go/spotinst/util/uritemplates" +) + +type UserGroup struct { + Description *string `json:"description,omitempty"` + Name *string `json:"name,omitempty"` + Policies []*UserGroupPolicy `json:"policies,omitempty"` + UserIds []*string `json:"userIds,omitempty"` + UserGroupId *string `json:"id,omitempty"` + + // forceSendFields is a list of field names (e.g. "Keys") to + // unconditionally include in API requests. By default, fields with + // empty values are omitted from API requests. However, any non-pointer, + // non-interface field appearing in ForceSendFields will be sent to the + // server regardless of whether the field is empty or not. This may be + // used to include empty fields in Patch requests. + forceSendFields []string + + // nullFields is a list of field names (e.g. "Keys") to include in API + // requests with the JSON null value. By default, fields with empty + // values are omitted from API requests. However, any field with an + // empty value appearing in NullFields will be sent to the server as + // null. It is an error if a field in this list has a non-empty value. + // This may be used to include null fields in Patch requests. + nullFields []string +} + +type UserGroupPolicy struct { + AccountIds []*string `json:"accountIds,omitempty"` + PolicyId *string `json:"policyId,omitempty"` + + forceSendFields []string + nullFields []string +} + +type ListUserGroupsInput struct{} + +type ListUserGroupsOutput struct { + UserGroups []*UserGroup `json:"userGroups,omitempty"` +} + +type CreateUserGroupInput struct { +} + +type CreateUserGroupOutput struct { + UserGroup *UserGroup `json:"userGroup,omitempty"` +} + +type ReadUserGroupInput struct { + UserGroupID *string `json:"id,omitempty"` +} + +type ReadUserGroupOutput struct { + UserGroup *UserGroup `json:"userGroup,omitempty"` +} + +type UpdateUserGroupInput struct { + UserGroupID *string `json:"id,omitempty"` +} + +type UpdateUserGroupOutput struct { + UserGroup *UserGroup `json:"userGroup,omitempty"` +} + +type DeleteUserGroupInput struct { + UserGroupID *string `json:"id,omitempty"` +} + +type DeleteUserGroupOutput struct{} + +func userGroupFromJSON(in []byte) (*UserGroup, error) { + b := new(UserGroup) + if err := json.Unmarshal(in, b); err != nil { + return nil, err + } + return b, nil +} + +func userGroupsFromJSON(in []byte) ([]*UserGroup, error) { + var rw client.Response + if err := json.Unmarshal(in, &rw); err != nil { + return nil, err + } + out := make([]*UserGroup, len(rw.Response.Items)) + if len(out) == 0 { + return out, nil + } + for i, rb := range rw.Response.Items { + b, err := userGroupFromJSON(rb) + if err != nil { + return nil, err + } + out[i] = b + } + return out, nil +} + +func userGroupsFromHttpResponse(resp *http.Response) ([]*UserGroup, error) { + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + return nil, err + } + return userGroupsFromJSON(body) +} + +func (s *ServiceOp) ListUserGroups(ctx context.Context, input *ListUserGroupsInput) (*ListUserGroupsOutput, error) { + r := client.NewRequest(http.MethodGet, "/setup/access/userGroup") + resp, err := client.RequireOK(s.Client.Do(ctx, r)) + if err != nil { + return nil, err + } + defer resp.Body.Close() + + gs, err := userGroupsFromHttpResponse(resp) + if err != nil { + return nil, err + } + + return &ListUserGroupsOutput{UserGroups: gs}, nil +} + +func (s *ServiceOp) CreateUserGroup(ctx context.Context, input *UserGroup) (*CreateUserGroupOutput, error) { + r := client.NewRequest(http.MethodPost, "/setup/access/userGroup") + r.Obj = input + + resp, err := client.RequireOK(s.Client.Do(ctx, r)) + if err != nil { + return nil, err + } + defer resp.Body.Close() + + ss, err := userGroupsFromHttpResponse(resp) + if err != nil { + return nil, err + } + + output := new(CreateUserGroupOutput) + if len(ss) > 0 { + output.UserGroup = ss[0] + } + + return output, nil +} + +func (s *ServiceOp) ReadUserGroup(ctx context.Context, input *ReadUserGroupInput) (*ReadUserGroupOutput, error) { + path, err := uritemplates.Expand("/setup/access/userGroup/{userGroupId}", uritemplates.Values{ + "userGroupId": spotinst.StringValue(input.UserGroupID), + }) + if err != nil { + return nil, err + } + + r := client.NewRequest(http.MethodGet, path) + resp, err := client.RequireOK(s.Client.Do(ctx, r)) + if err != nil { + return nil, err + } + defer resp.Body.Close() + + ss, err := userGroupsFromHttpResponse(resp) + if err != nil { + return nil, err + } + + output := new(ReadUserGroupOutput) + if len(ss) > 0 { + output.UserGroup = ss[0] + } + + return output, nil +} + +func (s *ServiceOp) UpdateUserGroup(ctx context.Context, input *UserGroup) (*UpdateUserGroupOutput, error) { + path, err := uritemplates.Expand("/setup/access/userGroup/{userGroupId}", uritemplates.Values{ + "userGroupId": spotinst.StringValue(input.UserGroupId), + }) + if err != nil { + return nil, 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 nil, err + } + defer resp.Body.Close() + + ss, err := userGroupsFromHttpResponse(resp) + if err != nil { + return nil, err + } + + output := new(UpdateUserGroupOutput) + if len(ss) > 0 { + output.UserGroup = ss[0] + } + + return output, 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), + }) + if err != nil { + return nil, err + } + + r := client.NewRequest(http.MethodDelete, path) + resp, err := client.RequireOK(s.Client.Do(ctx, r)) + if err != nil { + return nil, err + } + defer resp.Body.Close() + + return &DeleteUserGroupOutput{}, nil +} + +// region User + +func (o UserGroup) MarshalJSON() ([]byte, error) { + type noMethod UserGroup + raw := noMethod(o) + return jsonutil.MarshalJSON(raw, o.forceSendFields, o.nullFields) +} + +func (o *UserGroup) SetDescription(v *string) *UserGroup { + if o.Description = v; o.Description == nil { + o.nullFields = append(o.nullFields, "Description") + } + return o +} + +func (o *UserGroup) SetName(v *string) *UserGroup { + if o.Name = v; o.Name == nil { + o.nullFields = append(o.nullFields, "Name") + } + return o +} + +func (o *UserGroup) SetPolicies(v []*UserGroupPolicy) *UserGroup { + if o.Policies = v; o.Policies == nil { + o.nullFields = append(o.nullFields, "Policies") + } + return o +} + +func (o *UserGroup) SetUserIds(v []*string) *UserGroup { + if o.UserIds = v; o.UserIds == nil { + o.nullFields = append(o.nullFields, "UserIds") + } + return o +} + +// endregion + +func (o UserGroupPolicy) MarshalJSON() ([]byte, error) { + type noMethod UserGroupPolicy + raw := noMethod(o) + return jsonutil.MarshalJSON(raw, o.forceSendFields, o.nullFields) +} + +func (o *UserGroupPolicy) SetPolicyId(v *string) *UserGroupPolicy { + if o.PolicyId = v; o.PolicyId == nil { + o.nullFields = append(o.nullFields, "PolicyId") + } + return o +} + +func (o *UserGroupPolicy) SetAccountIds(v []*string) *UserGroupPolicy { + if o.AccountIds = v; o.AccountIds == nil { + o.nullFields = append(o.nullFields, "AccountIds") + } + return o +} + +//end region diff --git a/spotinst/credentials/provider_env.go b/spotinst/credentials/provider_env.go index 92b1088e..c0f5ba62 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,10 @@ 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: os.Getenv(EnvCredentialsVarToken), + Account: os.Getenv(EnvCredentialsVarAccount),*/ + Token: "d31949623321d13a43d49176d854cf3fc2b3682cab2604b2d92565af439f6cc8", + Account: "", ProviderName: EnvCredentialsProviderName, } From cbd824f3c5a40d4db3007b75b7960a77f82f4eb9 Mon Sep 17 00:00:00 2001 From: patrapritish1 <59195856+patrapritish1@users.noreply.github.com> Date: Fri, 4 Aug 2023 18:41:58 +0530 Subject: [PATCH 02/13] added programmatic user support --- .../administration/user/createProg/main.go | 61 ++++++ .../administration/user/delete/main.go | 2 +- service/administration/service.go | 1 + service/administration/user.go | 197 +++++++++++++++++- 4 files changed, 249 insertions(+), 12 deletions(-) create mode 100644 examples/service/administration/user/createProg/main.go diff --git a/examples/service/administration/user/createProg/main.go b/examples/service/administration/user/createProg/main.go new file mode 100644 index 00000000..dc0947ca --- /dev/null +++ b/examples/service/administration/user/createProg/main.go @@ -0,0 +1,61 @@ +package main + +import ( + "context" + "log" + + "github.com/spotinst/spotinst-sdk-go/service/administration" + "github.com/spotinst/spotinst-sdk-go/spotinst" + "github.com/spotinst/spotinst-sdk-go/spotinst/session" + "github.com/spotinst/spotinst-sdk-go/spotinst/util/stringutil" +) + +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 := administration.New(sess) + + // Create a new context. + ctx := context.Background() + + // Create a new group. + out, err := svc.CreateProgUser(ctx, &administration.ProgrammaticUser{ + Name: spotinst.String("pritish"), + Description: spotinst.String("description"), + /*Accounts: []*administration.Account{ + { + Id: spotinst.String("act-7c46c6df"), + Role: spotinst.String("viewer"), + }, + },*/ + Policies: []*administration.ProgPolicy{ + { + PolicyId: spotinst.String("pol-c75d8c06"), + AccountIds: spotinst.StringSlice( + []string{ + "act-7c46c6df", + }), + }, + }, + }) + + if err != nil { + log.Fatalf("spotinst: failed to create user: %v", err) + } + + // Output. + if out.ProgrammaticUser != nil { + log.Printf("User %q: %s", + spotinst.StringValue(out.ProgrammaticUser.ProgUserId), + stringutil.Stringify(out.ProgrammaticUser)) + } +} diff --git a/examples/service/administration/user/delete/main.go b/examples/service/administration/user/delete/main.go index 9b6d1bae..e89138c9 100644 --- a/examples/service/administration/user/delete/main.go +++ b/examples/service/administration/user/delete/main.go @@ -28,7 +28,7 @@ func main() { // Delete an existing group. _, err := svc.DeleteUser(ctx, &administration.DeleteUserInput{ - UserID: spotinst.String("u-989ac40c"), + UserID: spotinst.String("pu-f8b01ee0"), }) if err != nil { log.Fatalf("spotinst: failed to delete user: %v", err) diff --git a/service/administration/service.go b/service/administration/service.go index 01407b1a..c38afe93 100644 --- a/service/administration/service.go +++ b/service/administration/service.go @@ -14,6 +14,7 @@ import ( type Service interface { ListUsers(context.Context, *ListUsersInput) (*ListUsersOutput, error) CreateUser(context.Context, *User, *bool) (*CreateUserOutput, error) + //CreateProgUser(context.Context, *ProgrammaticUser) (*CreateProgrammaticUserOutput, error) ReadUser(context.Context, *ReadUserInput) (*ReadUserOutput, error) //Update(context.Context, *UpdateUserInput) (*UpdateUserOutput, error) DeleteUser(context.Context, *DeleteUserInput) (*DeleteUserOutput, error) diff --git a/service/administration/user.go b/service/administration/user.go index dbac931a..ab5b6bcc 100644 --- a/service/administration/user.go +++ b/service/administration/user.go @@ -15,17 +15,19 @@ import ( ) type User struct { - Email *string `json:"email,omitempty"` - FirstName *string `json:"firstName,omitempty"` - LastName *string `json:"lastName,omitempty"` - Password *string `json:"password,omitempty"` - Role *string `json:"role,omitempty"` - UserID *string `json:"userId,omitempty"` - Username *string `json:"username,omitempty"` - Type *string `json:"type,omitempty"` - Mfa *bool `json:"mfa,omitempty"` - Policies []*UserPolicy `json:"policies,omitempty"` - Tokens []*Token `json:"tokens,omitempty"` + Email *string `json:"email,omitempty"` + FirstName *string `json:"firstName,omitempty"` + LastName *string `json:"lastName,omitempty"` + Password *string `json:"password,omitempty"` + Role *string `json:"role,omitempty"` + UserID *string `json:"userId,omitempty"` + Username *string `json:"username,omitempty"` + Type *string `json:"type,omitempty"` + Mfa *bool `json:"mfa,omitempty"` + Policies []*UserPolicy `json:"policies,omitempty"` + Tokens []*Token `json:"tokens,omitempty"` + PersonalAccessToken *string `json:"personalAccessToken,omitempty"` + Id *int `json:"id,omitempty"` // forceSendFields is a list of field names (e.g. "Keys") to // unconditionally include in API requests. By default, fields with @@ -53,6 +55,34 @@ type UserPolicy struct { nullFields []string } +type ProgrammaticUser struct { + Name *string `json:"name,omitempty"` + Description *string `json:"description,omitempty"` + Policies []*ProgPolicy `json:"policies,omitempty"` + Accounts []*Account `json:"accounts,omitempty"` + Token *string `json:"token,omitempty"` + ProgUserId *string `json:"id,omitempty"` + + forceSendFields []string + nullFields []string +} + +type ProgPolicy struct { + PolicyId *string `json:"policyId,omitempty"` + AccountIds []*string `json:"accountIds,omitempty"` + + forceSendFields []string + nullFields []string +} + +type Account struct { + Id *string `json:"id,omitempty"` + Role *string `json:"role,omitempty"` + + forceSendFields []string + nullFields []string +} + type Token struct { Name *string `json:"name,omitempty"` CreatedAt *time.Time `json:"createdAt,omitempty"` @@ -77,6 +107,13 @@ type CreateUserOutput struct { User *User `json:"user,omitempty"` } +type CreateProgrammaticUserInput struct { +} + +type CreateProgrammaticUserOutput struct { + ProgrammaticUser *ProgrammaticUser `json:"user,omitempty"` +} + type ReadUserInput struct { UserID *string `json:"userId,omitempty"` } @@ -126,6 +163,41 @@ func usersFromHttpResponse(resp *http.Response) ([]*User, error) { return usersFromJSON(body) } +func progUserFromJSON(in []byte) (*ProgrammaticUser, error) { + b := new(ProgrammaticUser) + if err := json.Unmarshal(in, b); err != nil { + return nil, err + } + return b, nil +} + +func progUsersFromJSON(in []byte) ([]*ProgrammaticUser, error) { + var rw client.Response + if err := json.Unmarshal(in, &rw); err != nil { + return nil, err + } + out := make([]*ProgrammaticUser, len(rw.Response.Items)) + if len(out) == 0 { + return out, nil + } + for i, rb := range rw.Response.Items { + b, err := progUserFromJSON(rb) + if err != nil { + return nil, err + } + out[i] = b + } + return out, nil +} + +func progUsersFromHttpResponse(resp *http.Response) ([]*ProgrammaticUser, error) { + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + return nil, err + } + return progUsersFromJSON(body) +} + func (s *ServiceOp) ListUsers(ctx context.Context, input *ListUsersInput) (*ListUsersOutput, error) { r := client.NewRequest(http.MethodGet, "/setup/organization/user") resp, err := client.RequireOK(s.Client.Do(ctx, r)) @@ -167,6 +239,29 @@ func (s *ServiceOp) CreateUser(ctx context.Context, input *User, generateToken * return output, nil } +func (s *ServiceOp) CreateProgUser(ctx context.Context, input *ProgrammaticUser) (*CreateProgrammaticUserOutput, error) { + r := client.NewRequest(http.MethodPost, "/setup/user/programmatic") + r.Obj = input + + resp, err := client.RequireOK(s.Client.Do(ctx, r)) + if err != nil { + return nil, err + } + defer resp.Body.Close() + + ss, err := progUsersFromHttpResponse(resp) + if err != nil { + return nil, err + } + + output := new(CreateProgrammaticUserOutput) + if len(ss) > 0 { + output.ProgrammaticUser = ss[0] + } + + return output, nil +} + func (s *ServiceOp) ReadUser(ctx context.Context, input *ReadUserInput) (*ReadUserOutput, error) { path, err := uritemplates.Expand("/setup/user/{userId}", uritemplates.Values{ "userId": spotinst.StringValue(input.UserID), @@ -257,3 +352,83 @@ func (o *User) SetRole(v *string) *User { } // endregion + +// region ProgrammaticUser + +func (o ProgrammaticUser) MarshalJSON() ([]byte, error) { + type noMethod ProgrammaticUser + raw := noMethod(o) + return jsonutil.MarshalJSON(raw, o.forceSendFields, o.nullFields) +} + +func (o *ProgrammaticUser) SetName(v *string) *ProgrammaticUser { + if o.Name = v; o.Name == nil { + o.nullFields = append(o.nullFields, "Name") + } + return o +} + +func (o *ProgrammaticUser) SetDescription(v *string) *ProgrammaticUser { + if o.Description = v; o.Description == nil { + o.nullFields = append(o.nullFields, "Description") + } + return o +} + +func (o *ProgrammaticUser) SetPolicies(v []*ProgPolicy) *ProgrammaticUser { + 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") + } + return o +} + +// endregion + +func (o ProgPolicy) MarshalJSON() ([]byte, error) { + type noMethod ProgPolicy + raw := noMethod(o) + return jsonutil.MarshalJSON(raw, o.forceSendFields, o.nullFields) +} + +func (o *ProgPolicy) SetAccountIds(v []*string) *ProgPolicy { + if o.AccountIds = v; o.AccountIds == nil { + o.nullFields = append(o.nullFields, "AccountIds") + } + return o +} + +func (o *ProgPolicy) SetPolicyId(v *string) *ProgPolicy { + 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) + return jsonutil.MarshalJSON(raw, o.forceSendFields, o.nullFields) +} + +func (o *Account) SetAccountId(v *string) *Account { + if o.Id = v; o.Id == nil { + o.nullFields = append(o.nullFields, "Id") + } + return o +} + +func (o *Account) SetRole(v *string) *Account { + if o.Role = v; o.Role == nil { + o.nullFields = append(o.nullFields, "Role") + } + return o +} From e85bf0b49029430db810bcfbba330496bccf3821 Mon Sep 17 00:00:00 2001 From: patrapritish1 <59195856+patrapritish1@users.noreply.github.com> Date: Tue, 8 Aug 2023 19:38:13 +0530 Subject: [PATCH 03/13] commit --- service/administration/policy.go | 19 +++++++++---------- service/administration/service.go | 2 +- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/service/administration/policy.go b/service/administration/policy.go index 6bdcc982..0877127e 100644 --- a/service/administration/policy.go +++ b/service/administration/policy.go @@ -162,28 +162,27 @@ func (s *ServiceOp) CreatePolicy(ctx context.Context, input *CreatePolicyInput) } func (s *ServiceOp) ReadPolicy(ctx context.Context, input *ReadPolicyInput) (*ReadPolicyOutput, error) { - path, err := uritemplates.Expand("/setup/access/policy/{policyId}", uritemplates.Values{ - "policyId": spotinst.StringValue(input.PolicyID), - }) - if err != nil { - return nil, err - } - r := client.NewRequest(http.MethodGet, path) + r := client.NewRequest(http.MethodGet, "/setup/organization/policy") resp, err := client.RequireOK(s.Client.Do(ctx, r)) if err != nil { return nil, err } defer resp.Body.Close() - ss, err := policiesFromHttpResponse(resp) + gs, err := policiesFromHttpResponse(resp) if err != nil { return nil, err } output := new(ReadPolicyOutput) - if len(ss) > 0 { - output.Policy = ss[0] + if len(gs) > 0 { + for i, value := range gs { + if spotinst.StringValue(input.PolicyID) == spotinst.StringValue(value.PolicyID) { + output.Policy = gs[i] + break + } + } } return output, nil diff --git a/service/administration/service.go b/service/administration/service.go index c38afe93..13df3ea5 100644 --- a/service/administration/service.go +++ b/service/administration/service.go @@ -21,7 +21,7 @@ type Service interface { ListPolicies(context.Context, *ListPoliciesInput) (*ListPoliciesOutput, error) CreatePolicy(context.Context, *CreatePolicyInput) (*CreatePolicyOutput, error) - //ReadPolicy(context.Context, *ReadPolicyInput) (*ReadPolicyOutput, error) + ReadPolicy(context.Context, *ReadPolicyInput) (*ReadPolicyOutput, error) UpdatePolicy(context.Context, *UpdatePolicyInput) (*UpdatePolicyOutput, error) DeletePolicy(context.Context, *DeletePolicyInput) (*DeletePolicyOutput, error) From 12c5f3988aac726b934ec8f7c9a5ad1f758d3a33 Mon Sep 17 00:00:00 2001 From: patrapritish1 <59195856+patrapritish1@users.noreply.github.com> Date: Thu, 10 Aug 2023 16:10:50 +0530 Subject: [PATCH 04/13] commit user management changes --- .../administration/policy/create/main.go | 8 ++-- .../administration/policy/delete/main.go | 8 ++-- .../administration/user/createProg/main.go | 7 ++-- .../administration/userGroup/create/main.go | 4 +- .../administration/userGroup/delete/main.go | 8 ++-- service/administration/policy.go | 10 ++--- service/administration/service.go | 3 +- service/administration/user.go | 38 +++++++++++++++++-- service/administration/userGroup.go | 10 ++--- 9 files changed, 64 insertions(+), 32 deletions(-) diff --git a/examples/service/administration/policy/create/main.go b/examples/service/administration/policy/create/main.go index 6c79bc6d..d6550d5a 100644 --- a/examples/service/administration/policy/create/main.go +++ b/examples/service/administration/policy/create/main.go @@ -35,14 +35,14 @@ func main() { PolicyContent: &administration.PolicyContent{ Statements: []*administration.Statement{ { - Actions: spotinst.StringSlice([]string{ + Actions: []string{ "ocean:deleteCluster", "ocean:updateCluster", - }), + }, Effect: spotinst.String("ALLOW"), - Resources: spotinst.StringSlice([]string{ + Resources: []string{ "*", - }), + }, }, }, }, diff --git a/examples/service/administration/policy/delete/main.go b/examples/service/administration/policy/delete/main.go index 9768cc99..cfdb5bad 100644 --- a/examples/service/administration/policy/delete/main.go +++ b/examples/service/administration/policy/delete/main.go @@ -26,11 +26,11 @@ func main() { // Create a new context. ctx := context.Background() - // Delete an existing user group. - _, err := svc.DeleteUserGroup(ctx, &administration.DeleteUserGroupInput{ - UserGroupID: spotinst.String("ugr-9141021f"), + // Delete an existing group. + _, err := svc.DeletePolicy(ctx, &administration.DeletePolicyInput{ + PolicyID: spotinst.String("pol-a0ca4d69"), }) if err != nil { - log.Fatalf("spotinst: failed to delete user group: %v", err) + log.Fatalf("spotinst: failed to delete policy: %v", err) } } diff --git a/examples/service/administration/user/createProg/main.go b/examples/service/administration/user/createProg/main.go index dc0947ca..15d78f14 100644 --- a/examples/service/administration/user/createProg/main.go +++ b/examples/service/administration/user/createProg/main.go @@ -40,10 +40,9 @@ func main() { Policies: []*administration.ProgPolicy{ { PolicyId: spotinst.String("pol-c75d8c06"), - AccountIds: spotinst.StringSlice( - []string{ - "act-7c46c6df", - }), + AccountIds: []string{ + "act-7c46c6df", + }, }, }, }) diff --git a/examples/service/administration/userGroup/create/main.go b/examples/service/administration/userGroup/create/main.go index b7b8cee9..2638fe56 100644 --- a/examples/service/administration/userGroup/create/main.go +++ b/examples/service/administration/userGroup/create/main.go @@ -33,9 +33,9 @@ func main() { Name: spotinst.String("Pritish"), Policies: []*administration.UserGroupPolicy{ { - AccountIds: spotinst.StringSlice([]string{ + AccountIds: []string{ "act-7c46c6df", - }), + }, PolicyId: spotinst.String("pol-c063c6c9"), }, }, diff --git a/examples/service/administration/userGroup/delete/main.go b/examples/service/administration/userGroup/delete/main.go index 03674283..9768cc99 100644 --- a/examples/service/administration/userGroup/delete/main.go +++ b/examples/service/administration/userGroup/delete/main.go @@ -26,11 +26,11 @@ func main() { // Create a new context. ctx := context.Background() - // Delete an existing group. - _, err := svc.DeletePolicy(ctx, &administration.DeletePolicyInput{ - PolicyID: spotinst.String("pol-c75d8c06"), + // Delete an existing user group. + _, err := svc.DeleteUserGroup(ctx, &administration.DeleteUserGroupInput{ + UserGroupID: spotinst.String("ugr-9141021f"), }) if err != nil { - log.Fatalf("spotinst: failed to delete policy: %v", err) + log.Fatalf("spotinst: failed to delete user group: %v", err) } } diff --git a/service/administration/policy.go b/service/administration/policy.go index 0877127e..b07a9f6d 100644 --- a/service/administration/policy.go +++ b/service/administration/policy.go @@ -43,9 +43,9 @@ type PolicyContent struct { } type Statement struct { - Actions []*string `json:"actions,omitempty"` - Effect *string `json:"effect,omitempty"` - Resources []*string `json:"resources,omitempty"` + Actions []string `json:"actions,omitempty"` + Effect *string `json:"effect,omitempty"` + Resources []string `json:"resources,omitempty"` forceSendFields []string nullFields []string @@ -298,14 +298,14 @@ func (o *Statement) SetEffect(v *string) *Statement { return o } -func (o *Statement) SetResources(v []*string) *Statement { +func (o *Statement) SetResources(v []string) *Statement { if o.Resources = v; o.Resources == nil { o.nullFields = append(o.nullFields, "Resources") } return o } -func (o *Statement) SetActions(v []*string) *Statement { +func (o *Statement) SetActions(v []string) *Statement { if o.Actions = v; o.Actions == nil { o.nullFields = append(o.nullFields, "Actions") } diff --git a/service/administration/service.go b/service/administration/service.go index 13df3ea5..095e2b0f 100644 --- a/service/administration/service.go +++ b/service/administration/service.go @@ -14,8 +14,9 @@ import ( type Service interface { ListUsers(context.Context, *ListUsersInput) (*ListUsersOutput, error) CreateUser(context.Context, *User, *bool) (*CreateUserOutput, error) - //CreateProgUser(context.Context, *ProgrammaticUser) (*CreateProgrammaticUserOutput, error) + CreateProgUser(context.Context, *ProgrammaticUser) (*CreateProgrammaticUserOutput, error) ReadUser(context.Context, *ReadUserInput) (*ReadUserOutput, error) + ReadProgUser(context.Context, *ReadUserInput) (*ReadProgUserOutput, error) //Update(context.Context, *UpdateUserInput) (*UpdateUserOutput, error) DeleteUser(context.Context, *DeleteUserInput) (*DeleteUserOutput, error) diff --git a/service/administration/user.go b/service/administration/user.go index ab5b6bcc..8398b58f 100644 --- a/service/administration/user.go +++ b/service/administration/user.go @@ -68,8 +68,8 @@ type ProgrammaticUser struct { } type ProgPolicy struct { - PolicyId *string `json:"policyId,omitempty"` - AccountIds []*string `json:"accountIds,omitempty"` + PolicyId *string `json:"policyId,omitempty"` + AccountIds []string `json:"accountIds,omitempty"` forceSendFields []string nullFields []string @@ -122,6 +122,10 @@ type ReadUserOutput struct { User *User `json:"user,omitempty"` } +type ReadProgUserOutput struct { + ProgUser *ProgrammaticUser `json:"user,omitempty"` +} + type DeleteUserInput struct { UserID *string `json:"userId,omitempty"` } @@ -290,6 +294,34 @@ func (s *ServiceOp) ReadUser(ctx context.Context, input *ReadUserInput) (*ReadUs return output, nil } +func (s *ServiceOp) ReadProgUser(ctx context.Context, input *ReadUserInput) (*ReadProgUserOutput, error) { + path, err := uritemplates.Expand("/setup/user/{userId}", uritemplates.Values{ + "userId": spotinst.StringValue(input.UserID), + }) + if err != nil { + return nil, err + } + + r := client.NewRequest(http.MethodGet, path) + resp, err := client.RequireOK(s.Client.Do(ctx, r)) + if err != nil { + return nil, err + } + defer resp.Body.Close() + + ss, err := progUsersFromHttpResponse(resp) + if err != nil { + return nil, err + } + + output := new(ReadProgUserOutput) + if len(ss) > 0 { + output.ProgUser = ss[0] + } + + return output, 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), @@ -397,7 +429,7 @@ func (o ProgPolicy) MarshalJSON() ([]byte, error) { return jsonutil.MarshalJSON(raw, o.forceSendFields, o.nullFields) } -func (o *ProgPolicy) SetAccountIds(v []*string) *ProgPolicy { +func (o *ProgPolicy) SetAccountIds(v []string) *ProgPolicy { if o.AccountIds = v; o.AccountIds == nil { o.nullFields = append(o.nullFields, "AccountIds") } diff --git a/service/administration/userGroup.go b/service/administration/userGroup.go index d5c6c749..a6f7343d 100644 --- a/service/administration/userGroup.go +++ b/service/administration/userGroup.go @@ -16,7 +16,7 @@ type UserGroup struct { Description *string `json:"description,omitempty"` Name *string `json:"name,omitempty"` Policies []*UserGroupPolicy `json:"policies,omitempty"` - UserIds []*string `json:"userIds,omitempty"` + UserIds []string `json:"userIds,omitempty"` UserGroupId *string `json:"id,omitempty"` // forceSendFields is a list of field names (e.g. "Keys") to @@ -37,8 +37,8 @@ type UserGroup struct { } type UserGroupPolicy struct { - AccountIds []*string `json:"accountIds,omitempty"` - PolicyId *string `json:"policyId,omitempty"` + AccountIds []string `json:"accountIds,omitempty"` + PolicyId *string `json:"policyId,omitempty"` forceSendFields []string nullFields []string @@ -261,7 +261,7 @@ func (o *UserGroup) SetPolicies(v []*UserGroupPolicy) *UserGroup { return o } -func (o *UserGroup) SetUserIds(v []*string) *UserGroup { +func (o *UserGroup) SetUserIds(v []string) *UserGroup { if o.UserIds = v; o.UserIds == nil { o.nullFields = append(o.nullFields, "UserIds") } @@ -283,7 +283,7 @@ func (o *UserGroupPolicy) SetPolicyId(v *string) *UserGroupPolicy { return o } -func (o *UserGroupPolicy) SetAccountIds(v []*string) *UserGroupPolicy { +func (o *UserGroupPolicy) SetAccountIds(v []string) *UserGroupPolicy { if o.AccountIds = v; o.AccountIds == nil { o.nullFields = append(o.nullFields, "AccountIds") } From d26cb95b32a1c4525137649651b0c639ac1ee465 Mon Sep 17 00:00:00 2001 From: patrapritish1 <59195856+patrapritish1@users.noreply.github.com> Date: Fri, 11 Aug 2023 12:20:53 +0530 Subject: [PATCH 05/13] Update provider_env.go --- spotinst/credentials/provider_env.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/spotinst/credentials/provider_env.go b/spotinst/credentials/provider_env.go index c0f5ba62..92b1088e 100644 --- a/spotinst/credentials/provider_env.go +++ b/spotinst/credentials/provider_env.go @@ -2,6 +2,7 @@ package credentials import ( "fmt" + "os" ) const ( @@ -39,10 +40,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: "", + Token: os.Getenv(EnvCredentialsVarToken), + Account: os.Getenv(EnvCredentialsVarAccount), ProviderName: EnvCredentialsProviderName, } From 35aa3a4342db05fb7536db3946bcb91751bc2331 Mon Sep 17 00:00:00 2001 From: patrapritish1 <59195856+patrapritish1@users.noreply.github.com> Date: Fri, 11 Aug 2023 15:11:15 +0530 Subject: [PATCH 06/13] Update main.go --- examples/service/administration/policy/read/main.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/service/administration/policy/read/main.go b/examples/service/administration/policy/read/main.go index 626986ce..5e99dadb 100644 --- a/examples/service/administration/policy/read/main.go +++ b/examples/service/administration/policy/read/main.go @@ -28,17 +28,17 @@ func main() { ctx := context.Background() // Read group configuration. - out, err := svc.ReadUser(ctx, &administration.ReadUserInput{ - UserID: spotinst.String("u-989ac40c"), + out, err := svc.ReadPolicy(ctx, &administration.ReadPolicyInput{ + PolicyID: spotinst.String("pol-abc123xyz"), }) if err != nil { - log.Fatalf("spotinst: failed to read group: %v", err) + log.Fatalf("spotinst: failed to read policy: %v", err) } // Output. - if out.User != nil { + if out.Policy != nil { log.Printf("User %q: %s", - spotinst.StringValue(out.User.UserID), - stringutil.Stringify(out.User)) + spotinst.StringValue(out.Policy.PolicyID), + stringutil.Stringify(out.Policy)) } } From 6347ff3eed22e5b6a4410d01e1e007b7284f0c91 Mon Sep 17 00:00:00 2001 From: patrapritish1 <59195856+patrapritish1@users.noreply.github.com> Date: Wed, 16 Aug 2023 12:18:41 +0530 Subject: [PATCH 07/13] pr comments anurag --- examples/service/administration/policy/create/main.go | 4 ++-- examples/service/administration/policy/delete/main.go | 2 +- examples/service/administration/policy/update/main.go | 2 +- examples/service/administration/user/create/main.go | 10 +++++----- .../service/administration/user/createProg/main.go | 4 ++-- examples/service/administration/user/delete/main.go | 2 +- .../service/administration/userGroup/create/main.go | 5 ++++- .../service/administration/userGroup/delete/main.go | 2 +- .../service/administration/userGroup/update/main.go | 4 ++-- 9 files changed, 19 insertions(+), 16 deletions(-) diff --git a/examples/service/administration/policy/create/main.go b/examples/service/administration/policy/create/main.go index d6550d5a..fc8167b2 100644 --- a/examples/service/administration/policy/create/main.go +++ b/examples/service/administration/policy/create/main.go @@ -30,8 +30,8 @@ func main() { // Create a new group. out, err := svc.CreatePolicy(ctx, &administration.CreatePolicyInput{ Policy: &administration.Policy{ - Description: spotinst.String("TFPolicy"), - Name: spotinst.String("Pritish"), + Description: spotinst.String("Automation Policy by Terraform"), + Name: spotinst.String("AutomationPolicy"), PolicyContent: &administration.PolicyContent{ Statements: []*administration.Statement{ { diff --git a/examples/service/administration/policy/delete/main.go b/examples/service/administration/policy/delete/main.go index cfdb5bad..49882838 100644 --- a/examples/service/administration/policy/delete/main.go +++ b/examples/service/administration/policy/delete/main.go @@ -28,7 +28,7 @@ func main() { // Delete an existing group. _, err := svc.DeletePolicy(ctx, &administration.DeletePolicyInput{ - PolicyID: spotinst.String("pol-a0ca4d69"), + PolicyID: spotinst.String("pol-937ac696"), }) if err != nil { log.Fatalf("spotinst: failed to delete policy: %v", err) diff --git a/examples/service/administration/policy/update/main.go b/examples/service/administration/policy/update/main.go index 6f5af5ec..9eb09f53 100644 --- a/examples/service/administration/policy/update/main.go +++ b/examples/service/administration/policy/update/main.go @@ -31,7 +31,7 @@ func main() { out, err := svc.UpdatePolicy(ctx, &administration.UpdatePolicyInput{ Policy: &administration.Policy{ PolicyID: spotinst.String("pol-c75d8c06"), - Name: spotinst.String("PritishUpdated"), + 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 eec71916..35df2938 100644 --- a/examples/service/administration/user/create/main.go +++ b/examples/service/administration/user/create/main.go @@ -29,11 +29,11 @@ func main() { // Create a new group. out, err := svc.CreateUser(ctx, &administration.User{ - Email: spotinst.String("pritishp@netapp.com"), - FirstName: spotinst.String("Pritish"), - LastName: spotinst.String("Patra"), - Password: spotinst.String("naradMuni@108"), - Role: spotinst.String("admin"), + Email: spotinst.String("testautomation@netapp.com"), + FirstName: spotinst.String("test"), + LastName: spotinst.String("user"), + Password: spotinst.String("testUser@123"), + Role: spotinst.String("viewer"), }, spotinst.Bool(true)) if err != nil { diff --git a/examples/service/administration/user/createProg/main.go b/examples/service/administration/user/createProg/main.go index 15d78f14..dff1edba 100644 --- a/examples/service/administration/user/createProg/main.go +++ b/examples/service/administration/user/createProg/main.go @@ -29,14 +29,14 @@ func main() { // Create a new group. out, err := svc.CreateProgUser(ctx, &administration.ProgrammaticUser{ - Name: spotinst.String("pritish"), + Name: spotinst.String("test-programmatic-user"), Description: spotinst.String("description"), /*Accounts: []*administration.Account{ { Id: spotinst.String("act-7c46c6df"), Role: spotinst.String("viewer"), }, - },*/ + },*/ //Accounts and Policies are exclusive Policies: []*administration.ProgPolicy{ { PolicyId: spotinst.String("pol-c75d8c06"), diff --git a/examples/service/administration/user/delete/main.go b/examples/service/administration/user/delete/main.go index e89138c9..1bbaa52e 100644 --- a/examples/service/administration/user/delete/main.go +++ b/examples/service/administration/user/delete/main.go @@ -28,7 +28,7 @@ func main() { // Delete an existing group. _, err := svc.DeleteUser(ctx, &administration.DeleteUserInput{ - UserID: spotinst.String("pu-f8b01ee0"), + UserID: spotinst.String("u-1d90ab26"), }) if err != nil { log.Fatalf("spotinst: failed to delete user: %v", err) diff --git a/examples/service/administration/userGroup/create/main.go b/examples/service/administration/userGroup/create/main.go index 2638fe56..9c168129 100644 --- a/examples/service/administration/userGroup/create/main.go +++ b/examples/service/administration/userGroup/create/main.go @@ -30,7 +30,10 @@ func main() { // Create a new group. out, err := svc.CreateUserGroup(ctx, &administration.UserGroup{ Description: spotinst.String("TFUserGroup"), - Name: spotinst.String("Pritish"), + Name: spotinst.String("test-user-group"), + UserIds: []string{ + "u-7575c9bf", + }, Policies: []*administration.UserGroupPolicy{ { AccountIds: []string{ diff --git a/examples/service/administration/userGroup/delete/main.go b/examples/service/administration/userGroup/delete/main.go index 9768cc99..c6ecfd84 100644 --- a/examples/service/administration/userGroup/delete/main.go +++ b/examples/service/administration/userGroup/delete/main.go @@ -28,7 +28,7 @@ func main() { // Delete an existing user group. _, err := svc.DeleteUserGroup(ctx, &administration.DeleteUserGroupInput{ - UserGroupID: spotinst.String("ugr-9141021f"), + UserGroupID: spotinst.String("ugr-953a00ac"), }) if err != nil { log.Fatalf("spotinst: failed to delete user group: %v", err) diff --git a/examples/service/administration/userGroup/update/main.go b/examples/service/administration/userGroup/update/main.go index c159c99d..826a12df 100644 --- a/examples/service/administration/userGroup/update/main.go +++ b/examples/service/administration/userGroup/update/main.go @@ -29,8 +29,8 @@ func main() { // Create a new group. out, err := svc.UpdateUserGroup(ctx, &administration.UserGroup{ - UserGroupId: spotinst.String("ugr-9141021f"), - Name: spotinst.String("PritishUpdated"), + UserGroupId: spotinst.String("ugr-953a00ac"), + Name: spotinst.String("test-user-group-updated"), }) if err != nil { From 5ed01efac4fce81af3e7115da4a89e22c621579b Mon Sep 17 00:00:00 2001 From: patrapritish1 <59195856+patrapritish1@users.noreply.github.com> Date: Fri, 18 Aug 2023 15:15:25 +0530 Subject: [PATCH 08/13] commit pr comments --- .../service/administration/user/read/main.go | 2 +- .../administration/userGroup/create/main.go | 8 ++--- .../administration/userGroup/delete/main.go | 2 +- .../administration/userGroup/read/main.go | 2 +- service/administration/user.go | 35 ++++++++++++------- service/administration/userGroup.go | 22 ++++++++---- 6 files changed, 45 insertions(+), 26 deletions(-) diff --git a/examples/service/administration/user/read/main.go b/examples/service/administration/user/read/main.go index 626986ce..a423b65d 100644 --- a/examples/service/administration/user/read/main.go +++ b/examples/service/administration/user/read/main.go @@ -29,7 +29,7 @@ func main() { // Read group configuration. out, err := svc.ReadUser(ctx, &administration.ReadUserInput{ - UserID: spotinst.String("u-989ac40c"), + UserID: spotinst.String("u-884d32d7"), }) if err != nil { log.Fatalf("spotinst: failed to read group: %v", err) diff --git a/examples/service/administration/userGroup/create/main.go b/examples/service/administration/userGroup/create/main.go index 9c168129..71cc8af7 100644 --- a/examples/service/administration/userGroup/create/main.go +++ b/examples/service/administration/userGroup/create/main.go @@ -32,13 +32,13 @@ func main() { Description: spotinst.String("TFUserGroup"), Name: spotinst.String("test-user-group"), UserIds: []string{ - "u-7575c9bf", + "u-884d32d7", }, - Policies: []*administration.UserGroupPolicy{ + Policies: []*administration.UserPolicy{ { - AccountIds: []string{ + AccountIds: spotinst.StringSlice([]string{ "act-7c46c6df", - }, + }), PolicyId: spotinst.String("pol-c063c6c9"), }, }, diff --git a/examples/service/administration/userGroup/delete/main.go b/examples/service/administration/userGroup/delete/main.go index c6ecfd84..57bf8385 100644 --- a/examples/service/administration/userGroup/delete/main.go +++ b/examples/service/administration/userGroup/delete/main.go @@ -28,7 +28,7 @@ func main() { // Delete an existing user group. _, err := svc.DeleteUserGroup(ctx, &administration.DeleteUserGroupInput{ - UserGroupID: spotinst.String("ugr-953a00ac"), + UserGroupID: spotinst.String("ugr-c5fe2310"), }) if err != nil { log.Fatalf("spotinst: failed to delete user group: %v", err) diff --git a/examples/service/administration/userGroup/read/main.go b/examples/service/administration/userGroup/read/main.go index 41ab779f..b8d03ed5 100644 --- a/examples/service/administration/userGroup/read/main.go +++ b/examples/service/administration/userGroup/read/main.go @@ -29,7 +29,7 @@ func main() { // Read group configuration. out, err := svc.ReadUserGroup(ctx, &administration.ReadUserGroupInput{ - UserGroupID: spotinst.String("ugr-9141021f"), + UserGroupID: spotinst.String("ugr-c5fe2310"), }) if err != nil { log.Fatalf("spotinst: failed to read user group: %v", err) diff --git a/service/administration/user.go b/service/administration/user.go index 8398b58f..1f0e1bee 100644 --- a/service/administration/user.go +++ b/service/administration/user.go @@ -3,15 +3,13 @@ package administration import ( "context" "encoding/json" - "io/ioutil" - "net/http" - "strconv" - "time" - "github.com/spotinst/spotinst-sdk-go/spotinst" "github.com/spotinst/spotinst-sdk-go/spotinst/client" "github.com/spotinst/spotinst-sdk-go/spotinst/util/jsonutil" "github.com/spotinst/spotinst-sdk-go/spotinst/util/uritemplates" + "io/ioutil" + "net/http" + "strconv" ) type User struct { @@ -28,6 +26,8 @@ type User struct { Tokens []*Token `json:"tokens,omitempty"` PersonalAccessToken *string `json:"personalAccessToken,omitempty"` Id *int `json:"id,omitempty"` + GroupNames []*string `json:"groupNames,omitempty"` + Groups []*Group `json:"groups,omitempty"` // forceSendFields is a list of field names (e.g. "Keys") to // unconditionally include in API requests. By default, fields with @@ -47,9 +47,10 @@ type User struct { } type UserPolicy struct { - PolicyId *string `json:"policyId,omitempty"` - PolicyName *string `json:"policyName,omitempty"` - PolicyType *string `json:"policyType,omitempty"` + PolicyId *string `json:"policyId,omitempty"` + PolicyName *string `json:"policyName,omitempty"` + PolicyType *string `json:"policyType,omitempty"` + AccountIds []*string `json:"accountIds,omitempty"` forceSendFields []string nullFields []string @@ -84,11 +85,19 @@ type Account struct { } type Token struct { - Name *string `json:"name,omitempty"` - CreatedAt *time.Time `json:"createdAt,omitempty"` - PolicyType *string `json:"policyType,omitempty"` - TokenId *int `json:"tokenId,omitempty"` - TokenLastDigits *string `json:"tokenLastDigits,omitempty"` + Name *string `json:"name,omitempty"` + CreatedAt *string `json:"createdAt,omitempty"` + TokenId *int `json:"tokenId,omitempty"` + TokenLastDigits *string `json:"tokenLastDigits,omitempty"` + + forceSendFields []string + nullFields []string +} + +type Group struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + PolicyNames []*string `json:"policyNames,omitempty"` forceSendFields []string nullFields []string diff --git a/service/administration/userGroup.go b/service/administration/userGroup.go index a6f7343d..407dea51 100644 --- a/service/administration/userGroup.go +++ b/service/administration/userGroup.go @@ -13,11 +13,12 @@ import ( ) type UserGroup struct { - Description *string `json:"description,omitempty"` - Name *string `json:"name,omitempty"` - Policies []*UserGroupPolicy `json:"policies,omitempty"` - UserIds []string `json:"userIds,omitempty"` - UserGroupId *string `json:"id,omitempty"` + Description *string `json:"description,omitempty"` + Name *string `json:"name,omitempty"` + Policies []*UserPolicy `json:"policies,omitempty"` + UserIds []string `json:"userIds,omitempty"` + UserGroupId *string `json:"id,omitempty"` + Users []*UserGroupUser `json:"users,omitempty"` // forceSendFields is a list of field names (e.g. "Keys") to // unconditionally include in API requests. By default, fields with @@ -44,6 +45,15 @@ type UserGroupPolicy struct { nullFields []string } +type UserGroupUser struct { + Type *string `json:"type,omitempty"` + UserId *string `json:"userId,omitempty"` + UserName *string `json:"userName,omitempty"` + + forceSendFields []string + nullFields []string +} + type ListUserGroupsInput struct{} type ListUserGroupsOutput struct { @@ -254,7 +264,7 @@ func (o *UserGroup) SetName(v *string) *UserGroup { return o } -func (o *UserGroup) SetPolicies(v []*UserGroupPolicy) *UserGroup { +func (o *UserGroup) SetPolicies(v []*UserPolicy) *UserGroup { if o.Policies = v; o.Policies == nil { o.nullFields = append(o.nullFields, "Policies") } From 54af1aa6f2514b2fba10ab7d5155d3be54141696 Mon Sep 17 00:00:00 2001 From: patrapritish1 <59195856+patrapritish1@users.noreply.github.com> Date: Fri, 18 Aug 2023 15:55:48 +0530 Subject: [PATCH 09/13] commit pr fixes --- examples/service/administration/user/createProg/main.go | 2 +- examples/service/administration/user/delete/main.go | 2 +- service/administration/user.go | 8 ++------ service/administration/userGroup.go | 3 --- 4 files changed, 4 insertions(+), 11 deletions(-) diff --git a/examples/service/administration/user/createProg/main.go b/examples/service/administration/user/createProg/main.go index dff1edba..6b855506 100644 --- a/examples/service/administration/user/createProg/main.go +++ b/examples/service/administration/user/createProg/main.go @@ -41,7 +41,7 @@ func main() { { PolicyId: spotinst.String("pol-c75d8c06"), AccountIds: []string{ - "act-7c46c6df", + "act-a1b2c3d4", }, }, }, diff --git a/examples/service/administration/user/delete/main.go b/examples/service/administration/user/delete/main.go index 1bbaa52e..8bb2ad47 100644 --- a/examples/service/administration/user/delete/main.go +++ b/examples/service/administration/user/delete/main.go @@ -28,7 +28,7 @@ func main() { // Delete an existing group. _, err := svc.DeleteUser(ctx, &administration.DeleteUserInput{ - UserID: spotinst.String("u-1d90ab26"), + UserID: spotinst.String("u-ce04c6c2"), }) if err != nil { log.Fatalf("spotinst: failed to delete user: %v", err) diff --git a/service/administration/user.go b/service/administration/user.go index 1f0e1bee..ef57b4dc 100644 --- a/service/administration/user.go +++ b/service/administration/user.go @@ -28,6 +28,8 @@ type User struct { Id *int `json:"id,omitempty"` GroupNames []*string `json:"groupNames,omitempty"` Groups []*Group `json:"groups,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + OrganizationId *int `json:"organizationId,omitempty"` // forceSendFields is a list of field names (e.g. "Keys") to // unconditionally include in API requests. By default, fields with @@ -109,16 +111,10 @@ type ListUsersOutput struct { Users []*User `json:"users,omitempty"` } -type CreateUserInput struct { -} - type CreateUserOutput struct { User *User `json:"user,omitempty"` } -type CreateProgrammaticUserInput struct { -} - type CreateProgrammaticUserOutput struct { ProgrammaticUser *ProgrammaticUser `json:"user,omitempty"` } diff --git a/service/administration/userGroup.go b/service/administration/userGroup.go index 407dea51..d16a52ab 100644 --- a/service/administration/userGroup.go +++ b/service/administration/userGroup.go @@ -60,9 +60,6 @@ type ListUserGroupsOutput struct { UserGroups []*UserGroup `json:"userGroups,omitempty"` } -type CreateUserGroupInput struct { -} - type CreateUserGroupOutput struct { UserGroup *UserGroup `json:"userGroup,omitempty"` } From 41b032fb639552dfa1211979a53c1364658ac8ee Mon Sep 17 00:00:00 2001 From: patrapritish1 <59195856+patrapritish1@users.noreply.github.com> Date: Fri, 18 Aug 2023 16:29:40 +0530 Subject: [PATCH 10/13] commit pr comment chndra --- .../administration/userGroup/create/main.go | 8 ++++---- .../administration/userGroup/read/main.go | 2 +- service/administration/user.go | 8 ++++---- service/administration/userGroup.go | 19 ++++++++++++------- spotinst/credentials/provider_env.go | 2 +- 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/examples/service/administration/userGroup/create/main.go b/examples/service/administration/userGroup/create/main.go index 71cc8af7..624f40f7 100644 --- a/examples/service/administration/userGroup/create/main.go +++ b/examples/service/administration/userGroup/create/main.go @@ -34,11 +34,11 @@ func main() { UserIds: []string{ "u-884d32d7", }, - Policies: []*administration.UserPolicy{ + Policies: []*administration.UserGroupPolicy{ { - AccountIds: spotinst.StringSlice([]string{ - "act-7c46c6df", - }), + AccountIds: []string{ + "act-a1b2c3d4", + }, PolicyId: spotinst.String("pol-c063c6c9"), }, }, diff --git a/examples/service/administration/userGroup/read/main.go b/examples/service/administration/userGroup/read/main.go index b8d03ed5..1f833ae3 100644 --- a/examples/service/administration/userGroup/read/main.go +++ b/examples/service/administration/userGroup/read/main.go @@ -29,7 +29,7 @@ func main() { // Read group configuration. out, err := svc.ReadUserGroup(ctx, &administration.ReadUserGroupInput{ - UserGroupID: spotinst.String("ugr-c5fe2310"), + UserGroupID: spotinst.String("ugr-744e3f0d"), }) if err != nil { log.Fatalf("spotinst: failed to read user group: %v", err) diff --git a/service/administration/user.go b/service/administration/user.go index ef57b4dc..3208d1e0 100644 --- a/service/administration/user.go +++ b/service/administration/user.go @@ -49,10 +49,10 @@ type User struct { } type UserPolicy struct { - PolicyId *string `json:"policyId,omitempty"` - PolicyName *string `json:"policyName,omitempty"` - PolicyType *string `json:"policyType,omitempty"` - AccountIds []*string `json:"accountIds,omitempty"` + PolicyId *string `json:"policyId,omitempty"` + PolicyName *string `json:"policyName,omitempty"` + PolicyType *string `json:"policyType,omitempty"` + AccountIds []string `json:"accountIds,omitempty"` forceSendFields []string nullFields []string diff --git a/service/administration/userGroup.go b/service/administration/userGroup.go index d16a52ab..588ec7f6 100644 --- a/service/administration/userGroup.go +++ b/service/administration/userGroup.go @@ -13,12 +13,15 @@ import ( ) type UserGroup struct { - Description *string `json:"description,omitempty"` - Name *string `json:"name,omitempty"` - Policies []*UserPolicy `json:"policies,omitempty"` - UserIds []string `json:"userIds,omitempty"` - UserGroupId *string `json:"id,omitempty"` - Users []*UserGroupUser `json:"users,omitempty"` + Description *string `json:"description,omitempty"` + Name *string `json:"name,omitempty"` + Policies []*UserGroupPolicy `json:"policies,omitempty"` + UserIds []string `json:"userIds,omitempty"` + UserGroupId *string `json:"id,omitempty"` + Users []*UserGroupUser `json:"users,omitempty"` + CreatedAt *string `json:"createdAt,omitempty"` + PolicyNames []string `json:"policyNames,omitempty"` + UsersCount *int `json:"usersCount,omitempty"` // forceSendFields is a list of field names (e.g. "Keys") to // unconditionally include in API requests. By default, fields with @@ -40,6 +43,8 @@ type UserGroup struct { type UserGroupPolicy struct { AccountIds []string `json:"accountIds,omitempty"` PolicyId *string `json:"policyId,omitempty"` + PolicyName *string `json:"policyName,omitempty"` + PolicyType *string `json:"policyType,omitempty"` forceSendFields []string nullFields []string @@ -261,7 +266,7 @@ func (o *UserGroup) SetName(v *string) *UserGroup { return o } -func (o *UserGroup) SetPolicies(v []*UserPolicy) *UserGroup { +func (o *UserGroup) SetPolicies(v []*UserGroupPolicy) *UserGroup { if o.Policies = v; o.Policies == nil { o.nullFields = append(o.nullFields, "Policies") } diff --git a/spotinst/credentials/provider_env.go b/spotinst/credentials/provider_env.go index 92b1088e..2c381627 100644 --- a/spotinst/credentials/provider_env.go +++ b/spotinst/credentials/provider_env.go @@ -40,7 +40,7 @@ func NewEnvCredentials() *Credentials { // Retrieve retrieves the keys from the environment. func (e *EnvProvider) Retrieve() (Value, error) { value := Value{ - Token: os.Getenv(EnvCredentialsVarToken), + Token: "d31949623321d13a43d49176d854cf3fc2b3682cab2604b2d92565af439f6cc8", //os.Getenv(EnvCredentialsVarToken), Account: os.Getenv(EnvCredentialsVarAccount), ProviderName: EnvCredentialsProviderName, } From 69c8f2f7617234b14b25da233ef7a87eb46250a0 Mon Sep 17 00:00:00 2001 From: patrapritish1 <59195856+patrapritish1@users.noreply.github.com> Date: Fri, 18 Aug 2023 16:54:16 +0530 Subject: [PATCH 11/13] dummy ids/names --- .../service/administration/policy/delete/main.go | 2 +- examples/service/administration/policy/read/main.go | 2 +- .../service/administration/policy/update/main.go | 2 +- .../service/administration/user/createProg/main.go | 12 ++++++------ examples/service/administration/user/delete/main.go | 2 +- examples/service/administration/user/read/main.go | 2 +- .../service/administration/userGroup/create/main.go | 6 +++--- .../service/administration/userGroup/delete/main.go | 2 +- .../service/administration/userGroup/read/main.go | 2 +- .../service/administration/userGroup/update/main.go | 2 +- 10 files changed, 17 insertions(+), 17 deletions(-) diff --git a/examples/service/administration/policy/delete/main.go b/examples/service/administration/policy/delete/main.go index 49882838..0d6c9c0c 100644 --- a/examples/service/administration/policy/delete/main.go +++ b/examples/service/administration/policy/delete/main.go @@ -28,7 +28,7 @@ func main() { // Delete an existing group. _, err := svc.DeletePolicy(ctx, &administration.DeletePolicyInput{ - PolicyID: spotinst.String("pol-937ac696"), + PolicyID: spotinst.String("pol-abcd1234"), }) if err != nil { log.Fatalf("spotinst: failed to delete policy: %v", err) diff --git a/examples/service/administration/policy/read/main.go b/examples/service/administration/policy/read/main.go index 5e99dadb..39635d6e 100644 --- a/examples/service/administration/policy/read/main.go +++ b/examples/service/administration/policy/read/main.go @@ -29,7 +29,7 @@ func main() { // Read group configuration. out, err := svc.ReadPolicy(ctx, &administration.ReadPolicyInput{ - PolicyID: spotinst.String("pol-abc123xyz"), + PolicyID: spotinst.String("pol-abcd1234"), }) if err != nil { log.Fatalf("spotinst: failed to read policy: %v", err) diff --git a/examples/service/administration/policy/update/main.go b/examples/service/administration/policy/update/main.go index 9eb09f53..426c6f62 100644 --- a/examples/service/administration/policy/update/main.go +++ b/examples/service/administration/policy/update/main.go @@ -30,7 +30,7 @@ func main() { // Create a new group. out, err := svc.UpdatePolicy(ctx, &administration.UpdatePolicyInput{ Policy: &administration.Policy{ - PolicyID: spotinst.String("pol-c75d8c06"), + PolicyID: spotinst.String("pol-abcd1234"), Name: spotinst.String("Automation-Policy-Updated"), }, }) diff --git a/examples/service/administration/user/createProg/main.go b/examples/service/administration/user/createProg/main.go index 6b855506..e7c6f7ec 100644 --- a/examples/service/administration/user/createProg/main.go +++ b/examples/service/administration/user/createProg/main.go @@ -31,20 +31,20 @@ func main() { out, err := svc.CreateProgUser(ctx, &administration.ProgrammaticUser{ Name: spotinst.String("test-programmatic-user"), Description: spotinst.String("description"), - /*Accounts: []*administration.Account{ + Accounts: []*administration.Account{ { - Id: spotinst.String("act-7c46c6df"), + Id: spotinst.String("act-a1b2c3d4"), Role: spotinst.String("viewer"), }, - },*/ //Accounts and Policies are exclusive - Policies: []*administration.ProgPolicy{ + }, //Accounts and Policies are exclusive + /*Policies: []*administration.ProgPolicy{ { - PolicyId: spotinst.String("pol-c75d8c06"), + PolicyId: spotinst.String("pol-abcd1234"), AccountIds: []string{ "act-a1b2c3d4", }, }, - }, + },*/ }) if err != nil { diff --git a/examples/service/administration/user/delete/main.go b/examples/service/administration/user/delete/main.go index 8bb2ad47..596a17c7 100644 --- a/examples/service/administration/user/delete/main.go +++ b/examples/service/administration/user/delete/main.go @@ -28,7 +28,7 @@ func main() { // Delete an existing group. _, err := svc.DeleteUser(ctx, &administration.DeleteUserInput{ - UserID: spotinst.String("u-ce04c6c2"), + UserID: spotinst.String("pu-abcd1234"), }) if err != nil { log.Fatalf("spotinst: failed to delete user: %v", err) diff --git a/examples/service/administration/user/read/main.go b/examples/service/administration/user/read/main.go index a423b65d..4fca9e96 100644 --- a/examples/service/administration/user/read/main.go +++ b/examples/service/administration/user/read/main.go @@ -29,7 +29,7 @@ func main() { // Read group configuration. out, err := svc.ReadUser(ctx, &administration.ReadUserInput{ - UserID: spotinst.String("u-884d32d7"), + UserID: spotinst.String("u-abcd1234"), }) if err != nil { log.Fatalf("spotinst: failed to read group: %v", err) diff --git a/examples/service/administration/userGroup/create/main.go b/examples/service/administration/userGroup/create/main.go index 624f40f7..11589d0a 100644 --- a/examples/service/administration/userGroup/create/main.go +++ b/examples/service/administration/userGroup/create/main.go @@ -32,14 +32,14 @@ func main() { Description: spotinst.String("TFUserGroup"), Name: spotinst.String("test-user-group"), UserIds: []string{ - "u-884d32d7", + "u-abcd1234", }, Policies: []*administration.UserGroupPolicy{ { AccountIds: []string{ - "act-a1b2c3d4", + "act-abcd1234", }, - PolicyId: spotinst.String("pol-c063c6c9"), + PolicyId: spotinst.String("pol-abcd1234"), }, }, }) diff --git a/examples/service/administration/userGroup/delete/main.go b/examples/service/administration/userGroup/delete/main.go index 57bf8385..cad641bd 100644 --- a/examples/service/administration/userGroup/delete/main.go +++ b/examples/service/administration/userGroup/delete/main.go @@ -28,7 +28,7 @@ func main() { // Delete an existing user group. _, err := svc.DeleteUserGroup(ctx, &administration.DeleteUserGroupInput{ - UserGroupID: spotinst.String("ugr-c5fe2310"), + UserGroupID: spotinst.String("ugr-abcd1234"), }) if err != nil { log.Fatalf("spotinst: failed to delete user group: %v", err) diff --git a/examples/service/administration/userGroup/read/main.go b/examples/service/administration/userGroup/read/main.go index 1f833ae3..cb3a1d04 100644 --- a/examples/service/administration/userGroup/read/main.go +++ b/examples/service/administration/userGroup/read/main.go @@ -29,7 +29,7 @@ func main() { // Read group configuration. out, err := svc.ReadUserGroup(ctx, &administration.ReadUserGroupInput{ - UserGroupID: spotinst.String("ugr-744e3f0d"), + UserGroupID: spotinst.String("pol-abcd1234"), }) if err != nil { log.Fatalf("spotinst: failed to read user group: %v", err) diff --git a/examples/service/administration/userGroup/update/main.go b/examples/service/administration/userGroup/update/main.go index 826a12df..406853a1 100644 --- a/examples/service/administration/userGroup/update/main.go +++ b/examples/service/administration/userGroup/update/main.go @@ -29,7 +29,7 @@ func main() { // Create a new group. out, err := svc.UpdateUserGroup(ctx, &administration.UserGroup{ - UserGroupId: spotinst.String("ugr-953a00ac"), + UserGroupId: spotinst.String("pol-abcd1234"), Name: spotinst.String("test-user-group-updated"), }) From 5a11e5ee25fbab684adac71c439cc1bb7154ea21 Mon Sep 17 00:00:00 2001 From: patrapritish1 <59195856+patrapritish1@users.noreply.github.com> Date: Fri, 18 Aug 2023 16:58:11 +0530 Subject: [PATCH 12/13] Update provider_env.go --- spotinst/credentials/provider_env.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spotinst/credentials/provider_env.go b/spotinst/credentials/provider_env.go index 2c381627..92b1088e 100644 --- a/spotinst/credentials/provider_env.go +++ b/spotinst/credentials/provider_env.go @@ -40,7 +40,7 @@ func NewEnvCredentials() *Credentials { // Retrieve retrieves the keys from the environment. func (e *EnvProvider) Retrieve() (Value, error) { value := Value{ - Token: "d31949623321d13a43d49176d854cf3fc2b3682cab2604b2d92565af439f6cc8", //os.Getenv(EnvCredentialsVarToken), + Token: os.Getenv(EnvCredentialsVarToken), Account: os.Getenv(EnvCredentialsVarAccount), ProviderName: EnvCredentialsProviderName, } From 24d1721cdb86a1da6cf8a40fe3039c8a67437d36 Mon Sep 17 00:00:00 2001 From: patrapritish1 <59195856+patrapritish1@users.noreply.github.com> Date: Fri, 18 Aug 2023 21:02:24 +0530 Subject: [PATCH 13/13] commit final pr comments --- .../administration/userGroup/read/main.go | 2 +- .../administration/userGroup/update/main.go | 11 ++------ service/administration/service.go | 2 +- service/administration/userGroup.go | 26 +++++-------------- 4 files changed, 10 insertions(+), 31 deletions(-) diff --git a/examples/service/administration/userGroup/read/main.go b/examples/service/administration/userGroup/read/main.go index cb3a1d04..0928d8a4 100644 --- a/examples/service/administration/userGroup/read/main.go +++ b/examples/service/administration/userGroup/read/main.go @@ -29,7 +29,7 @@ func main() { // Read group configuration. out, err := svc.ReadUserGroup(ctx, &administration.ReadUserGroupInput{ - UserGroupID: spotinst.String("pol-abcd1234"), + UserGroupID: spotinst.String("ugr-abcd1234"), }) if err != nil { log.Fatalf("spotinst: failed to read user group: %v", err) diff --git a/examples/service/administration/userGroup/update/main.go b/examples/service/administration/userGroup/update/main.go index 406853a1..23e362e5 100644 --- a/examples/service/administration/userGroup/update/main.go +++ b/examples/service/administration/userGroup/update/main.go @@ -7,7 +7,6 @@ import ( "github.com/spotinst/spotinst-sdk-go/service/administration" "github.com/spotinst/spotinst-sdk-go/spotinst" "github.com/spotinst/spotinst-sdk-go/spotinst/session" - "github.com/spotinst/spotinst-sdk-go/spotinst/util/stringutil" ) func main() { @@ -28,8 +27,8 @@ func main() { ctx := context.Background() // Create a new group. - out, err := svc.UpdateUserGroup(ctx, &administration.UserGroup{ - UserGroupId: spotinst.String("pol-abcd1234"), + err := svc.UpdateUserGroup(ctx, &administration.UserGroup{ + UserGroupId: spotinst.String("ugr-525a30dc"), Name: spotinst.String("test-user-group-updated"), }) @@ -37,10 +36,4 @@ func main() { log.Fatalf("spotinst: failed to update user group: %v", err) } - // Output. - if out.UserGroup != nil { - log.Printf("UserGroup %q: %s", - spotinst.StringValue(out.UserGroup.UserGroupId), - stringutil.Stringify(out.UserGroup)) - } } diff --git a/service/administration/service.go b/service/administration/service.go index 095e2b0f..496b7e17 100644 --- a/service/administration/service.go +++ b/service/administration/service.go @@ -29,7 +29,7 @@ type Service interface { ListUserGroups(context.Context, *ListUserGroupsInput) (*ListUserGroupsOutput, error) CreateUserGroup(context.Context, *UserGroup) (*CreateUserGroupOutput, error) ReadUserGroup(context.Context, *ReadUserGroupInput) (*ReadUserGroupOutput, error) - UpdateUserGroup(context.Context, *UserGroup) (*UpdateUserGroupOutput, error) + UpdateUserGroup(context.Context, *UserGroup) error DeleteUserGroup(context.Context, *DeleteUserGroupInput) (*DeleteUserGroupOutput, error) } diff --git a/service/administration/userGroup.go b/service/administration/userGroup.go index 588ec7f6..4a2752cb 100644 --- a/service/administration/userGroup.go +++ b/service/administration/userGroup.go @@ -18,7 +18,7 @@ type UserGroup struct { Policies []*UserGroupPolicy `json:"policies,omitempty"` UserIds []string `json:"userIds,omitempty"` UserGroupId *string `json:"id,omitempty"` - Users []*UserGroupUser `json:"users,omitempty"` + Users []*GetGroupUser `json:"users,omitempty"` CreatedAt *string `json:"createdAt,omitempty"` PolicyNames []string `json:"policyNames,omitempty"` UsersCount *int `json:"usersCount,omitempty"` @@ -50,7 +50,7 @@ type UserGroupPolicy struct { nullFields []string } -type UserGroupUser struct { +type GetGroupUser struct { Type *string `json:"type,omitempty"` UserId *string `json:"userId,omitempty"` UserName *string `json:"userName,omitempty"` @@ -81,10 +81,6 @@ type UpdateUserGroupInput struct { UserGroupID *string `json:"id,omitempty"` } -type UpdateUserGroupOutput struct { - UserGroup *UserGroup `json:"userGroup,omitempty"` -} - type DeleteUserGroupInput struct { UserGroupID *string `json:"id,omitempty"` } @@ -193,12 +189,12 @@ func (s *ServiceOp) ReadUserGroup(ctx context.Context, input *ReadUserGroupInput return output, nil } -func (s *ServiceOp) UpdateUserGroup(ctx context.Context, input *UserGroup) (*UpdateUserGroupOutput, error) { +func (s *ServiceOp) UpdateUserGroup(ctx context.Context, input *UserGroup) error { path, err := uritemplates.Expand("/setup/access/userGroup/{userGroupId}", uritemplates.Values{ "userGroupId": spotinst.StringValue(input.UserGroupId), }) if err != nil { - return nil, err + return err } // We do not need the ID anymore so let's drop it. @@ -209,21 +205,11 @@ func (s *ServiceOp) UpdateUserGroup(ctx context.Context, input *UserGroup) (*Upd resp, err := client.RequireOK(s.Client.Do(ctx, r)) if err != nil { - return nil, err + return err } defer resp.Body.Close() - ss, err := userGroupsFromHttpResponse(resp) - if err != nil { - return nil, err - } - - output := new(UpdateUserGroupOutput) - if len(ss) > 0 { - output.UserGroup = ss[0] - } - - return output, nil + return nil } func (s *ServiceOp) DeleteUserGroup(ctx context.Context, input *DeleteUserGroupInput) (*DeleteUserGroupOutput, error) {