-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
981 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"log" | ||
|
||
scalr "github.com/scalr/go-scalr" | ||
) | ||
|
||
func main() { | ||
config := scalr.DefaultConfig() | ||
config.Headers.Set("Prefer", "profile=internal") | ||
|
||
client, err := scalr.NewClient(config) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// Create a context | ||
ctx := context.Background() | ||
|
||
users := []*scalr.User{{ID: "user-suh84u6vuvidtbg"}} | ||
|
||
// Create a team | ||
opts := scalr.TeamCreateOptions{ | ||
IdentityProvider: &scalr.IdentityProvider{ID: "idp-sohkb0o1phrdmr8"}, | ||
Account: &scalr.Account{ID: "acc-svrcncgh453bi8g"}, | ||
Name: scalr.String("GoTeams4"), | ||
Description: scalr.String("Team created by go-scalr"), | ||
Users: users, // test@scalr.com | ||
} | ||
|
||
team, err := client.Teams.Create(ctx, opts) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
log.Printf("Team created %v", team.ID) | ||
|
||
// Retrieve a team | ||
team, err = client.Teams.Read(ctx, team.ID) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
log.Printf("Team %v Description: %v", team.ID, team.Description) | ||
|
||
// Retrieve all teams | ||
teams, err := client.Teams.List(ctx) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
log.Printf("There are %v teams on the server", len(teams.Items)) | ||
|
||
// Update the team | ||
team, err = client.Teams.Update(ctx, team.ID, scalr.TeamUpdateOptions{ | ||
Description: scalr.String("Edited"), | ||
// Name: scalr.String("Edited"), | ||
// Users: []*scalr.User{}, | ||
}) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
log.Printf("Update Description of the team %v: %v", team.ID, team.Description) | ||
|
||
// Delete the team | ||
err = client.Teams.Delete(ctx, team.ID) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
log.Printf("Deleted team %v", team.ID) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"os" | ||
|
||
scalr "github.com/scalr/go-scalr" | ||
) | ||
|
||
func main() { | ||
config := scalr.DefaultConfig() | ||
config.Headers.Set("Prefer", "profile=internal") | ||
|
||
client, err := scalr.NewClient(config) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// Create a context | ||
ctx := context.Background() | ||
|
||
// Create a user | ||
opts := scalr.UserCreateOptions{ | ||
Email: scalr.String("i.kovalkovskyi6@scalr.com"), | ||
IdentityProvider: &scalr.IdentityProvider{ID: os.Getenv("IDP_ID")}, | ||
Status: scalr.UserStatusActive, | ||
} | ||
|
||
usr, err := client.Users.Create(ctx, opts) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
log.Printf("User created %v", usr.ID) | ||
|
||
// Retrieve a user | ||
usr, err = client.Users.Read(ctx, usr.ID) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
log.Printf("User %v was created at: %v", usr.ID, usr.CreatedAt) | ||
|
||
// Retrieve all users | ||
users, err := client.Users.List(ctx) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
log.Printf("There are %v users on the server", len(users.Items)) | ||
|
||
// Update the user | ||
usr, err = client.Users.Update(ctx, usr.ID, scalr.UserUpdateOptions{ | ||
FullName: scalr.String("Ivan Kovalkovskyi"), | ||
Status: scalr.UserStatusInactive, | ||
}) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
log.Printf("Update status of the user %v: %v", usr.ID, usr.Status) | ||
|
||
// Delete the user | ||
err = client.Users.Delete(ctx, usr.ID) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
log.Printf("Deleted user %v", usr.ID) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package scalr | ||
|
||
// IdentityProvider represents a Scalr IACP IdentityProvider. | ||
type IdentityProvider struct { | ||
ID string `jsonapi:"primary,identity-providers"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.