Skip to content

Commit

Permalink
feat(accounts/userManagement): Added support for userManagement apis (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
pripatra authored Aug 18, 2023
1 parent 3dd47c8 commit 477b163
Show file tree
Hide file tree
Showing 19 changed files with 1,814 additions and 0 deletions.
62 changes: 62 additions & 0 deletions examples/service/administration/policy/create/main.go
Original file line number Diff line number Diff line change
@@ -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("Automation Policy by Terraform"),
Name: spotinst.String("AutomationPolicy"),
PolicyContent: &administration.PolicyContent{
Statements: []*administration.Statement{
{
Actions: []string{
"ocean:deleteCluster",
"ocean:updateCluster",
},
Effect: spotinst.String("ALLOW"),
Resources: []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))
}
}
36 changes: 36 additions & 0 deletions examples/service/administration/policy/delete/main.go
Original file line number Diff line number Diff line change
@@ -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-abcd1234"),
})
if err != nil {
log.Fatalf("spotinst: failed to delete policy: %v", err)
}
}
44 changes: 44 additions & 0 deletions examples/service/administration/policy/list/main.go
Original file line number Diff line number Diff line change
@@ -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))
}
}
}
44 changes: 44 additions & 0 deletions examples/service/administration/policy/read/main.go
Original file line number Diff line number Diff line change
@@ -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.ReadPolicy(ctx, &administration.ReadPolicyInput{
PolicyID: spotinst.String("pol-abcd1234"),
})
if err != nil {
log.Fatalf("spotinst: failed to read policy: %v", err)
}

// Output.
if out.Policy != nil {
log.Printf("User %q: %s",
spotinst.StringValue(out.Policy.PolicyID),
stringutil.Stringify(out.Policy))
}
}
48 changes: 48 additions & 0 deletions examples/service/administration/policy/update/main.go
Original file line number Diff line number Diff line change
@@ -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-abcd1234"),
Name: spotinst.String("Automation-Policy-Updated"),
},
})

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))
}
}
49 changes: 49 additions & 0 deletions examples/service/administration/user/create/main.go
Original file line number Diff line number Diff line change
@@ -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("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 {
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))
}
}
60 changes: 60 additions & 0 deletions examples/service/administration/user/createProg/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
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("test-programmatic-user"),
Description: spotinst.String("description"),
Accounts: []*administration.Account{
{
Id: spotinst.String("act-a1b2c3d4"),
Role: spotinst.String("viewer"),
},
}, //Accounts and Policies are exclusive
/*Policies: []*administration.ProgPolicy{
{
PolicyId: spotinst.String("pol-abcd1234"),
AccountIds: []string{
"act-a1b2c3d4",
},
},
},*/
})

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))
}
}
36 changes: 36 additions & 0 deletions examples/service/administration/user/delete/main.go
Original file line number Diff line number Diff line change
@@ -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("pu-abcd1234"),
})
if err != nil {
log.Fatalf("spotinst: failed to delete user: %v", err)
}
}
Loading

0 comments on commit 477b163

Please sign in to comment.