-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for account, externalId and aws credentials support (#261)
- Loading branch information
1 parent
7096568
commit 32819e8
Showing
14 changed files
with
814 additions
and
0 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,34 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"github.com/spotinst/spotinst-sdk-go/service/account" | ||
"github.com/spotinst/spotinst-sdk-go/service/account/providers/aws" | ||
"github.com/spotinst/spotinst-sdk-go/spotinst" | ||
"github.com/spotinst/spotinst-sdk-go/spotinst/session" | ||
"github.com/spotinst/spotinst-sdk-go/spotinst/util/stringutil" | ||
"log" | ||
) | ||
|
||
func main() { | ||
sess := session.New() | ||
svc := account.New(sess) | ||
ctx := context.Background() | ||
out, err := svc.CloudProviderAWS().CreateAccount(ctx, &aws.CreateAccountInput{ | ||
Account: &aws.Account{ | ||
Name: spotinst.String("testAcct_123"), | ||
}, | ||
}) | ||
|
||
if err != nil { | ||
log.Fatalf("spotinst: failed to create account: %v", err) | ||
} | ||
|
||
// Output. | ||
if out.Account != nil { | ||
log.Printf("Account %q: %s", | ||
spotinst.StringValue(out.Account.ID), | ||
stringutil.Stringify(out.Account)) | ||
} | ||
|
||
} |
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,24 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"github.com/spotinst/spotinst-sdk-go/service/account" | ||
"github.com/spotinst/spotinst-sdk-go/service/account/providers/aws" | ||
"github.com/spotinst/spotinst-sdk-go/spotinst" | ||
"github.com/spotinst/spotinst-sdk-go/spotinst/session" | ||
"log" | ||
) | ||
|
||
func main() { | ||
sess := session.New() | ||
svc := account.New(sess) | ||
ctx := context.Background() | ||
_, err := svc.CloudProviderAWS().DeleteAccount(ctx, &aws.DeleteAccountInput{ | ||
AccountID: spotinst.String("act-123456"), | ||
}) | ||
|
||
if err != nil { | ||
log.Fatalf("spotinst: failed to delete account: %v", err) | ||
} | ||
|
||
} |
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,31 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"github.com/spotinst/spotinst-sdk-go/service/account" | ||
"github.com/spotinst/spotinst-sdk-go/service/account/providers/aws" | ||
"github.com/spotinst/spotinst-sdk-go/spotinst" | ||
"github.com/spotinst/spotinst-sdk-go/spotinst/session" | ||
"github.com/spotinst/spotinst-sdk-go/spotinst/util/stringutil" | ||
"log" | ||
) | ||
|
||
func main() { | ||
sess := session.New() | ||
svc := account.New(sess) | ||
ctx := context.Background() | ||
out, err := svc.CloudProviderAWS().ReadAccount(ctx, &aws.ReadAccountInput{ | ||
AccountID: spotinst.String("act-123456"), | ||
}) | ||
|
||
if err != nil { | ||
log.Fatalf("spotinst: faccount not found: %v", err) | ||
} | ||
|
||
if out.Account != nil { | ||
log.Printf("Account %q: %s", | ||
spotinst.StringValue(out.Account.ID), | ||
stringutil.Stringify(out.Account)) | ||
} | ||
|
||
} |
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,28 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"github.com/spotinst/spotinst-sdk-go/spotinst" | ||
"log" | ||
|
||
"github.com/spotinst/spotinst-sdk-go/service/account" | ||
"github.com/spotinst/spotinst-sdk-go/service/account/providers/aws" | ||
"github.com/spotinst/spotinst-sdk-go/spotinst/session" | ||
) | ||
|
||
func main() { | ||
sess := session.New() | ||
svc := account.New(sess) | ||
ctx := context.Background() | ||
_, err := svc.CloudProviderAWS().SetCredential(ctx, &aws.SetCredentialInput{ | ||
Credential: &aws.Credential{ | ||
AccountId: spotinst.String("act-12345"), | ||
IamRole: spotinst.String("arn:aws:iam::12345:role/test-role"), | ||
}, | ||
}) | ||
|
||
if err != nil { | ||
log.Fatalf("spotinst: failed to set credential: %v", err) | ||
} | ||
|
||
} |
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,31 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"github.com/spotinst/spotinst-sdk-go/spotinst/util/stringutil" | ||
"log" | ||
|
||
"github.com/spotinst/spotinst-sdk-go/service/account" | ||
"github.com/spotinst/spotinst-sdk-go/service/account/providers/aws" | ||
"github.com/spotinst/spotinst-sdk-go/spotinst" | ||
"github.com/spotinst/spotinst-sdk-go/spotinst/session" | ||
) | ||
|
||
func main() { | ||
sess := session.New() | ||
svc := account.New(sess) | ||
ctx := context.Background() | ||
out, err := svc.CloudProviderAWS().ReadCredential(ctx, &aws.ReadCredentialInput{ | ||
AccountId: spotinst.String("act-12345"), | ||
}) | ||
|
||
if err != nil { | ||
log.Fatalf("spotinst: failed to fetch credential: %v", err) | ||
} | ||
if out != nil { | ||
log.Printf("credential %q: %s", | ||
spotinst.StringValue(out.Credential.AccountId), | ||
stringutil.Stringify(out.Credential.IamRole)) | ||
} | ||
|
||
} |
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,29 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"github.com/spotinst/spotinst-sdk-go/service/account" | ||
"github.com/spotinst/spotinst-sdk-go/service/account/providers/aws" | ||
"github.com/spotinst/spotinst-sdk-go/spotinst" | ||
"github.com/spotinst/spotinst-sdk-go/spotinst/session" | ||
"log" | ||
) | ||
|
||
func main() { | ||
sess := session.New() | ||
svc := account.New(sess) | ||
ctx := context.Background() | ||
out, err := svc.CloudProviderAWS().CreateAWSAccountExternalId(ctx, &aws.CreateAWSAccountExternalIdInput{ | ||
AccountID: spotinst.String("act-12345678"), | ||
}) | ||
|
||
if err != nil { | ||
log.Fatalf("spotinst: failed to genrate externalId %v", err) | ||
} | ||
|
||
if out != nil { | ||
log.Printf("externalId: %s", | ||
spotinst.StringValue(out.AWSAccountExternalId.ExternalId)) | ||
} | ||
|
||
} |
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,29 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"github.com/spotinst/spotinst-sdk-go/service/account" | ||
"github.com/spotinst/spotinst-sdk-go/service/account/providers/aws" | ||
"github.com/spotinst/spotinst-sdk-go/spotinst" | ||
"github.com/spotinst/spotinst-sdk-go/spotinst/session" | ||
"log" | ||
) | ||
|
||
func main() { | ||
sess := session.New() | ||
svc := account.New(sess) | ||
ctx := context.Background() | ||
out, err := svc.CloudProviderAWS().ReadAWSAccountExternalId(ctx, &aws.ReadAWSAccountExternalIdInput{ | ||
AccountID: spotinst.String("act-12345678"), | ||
}) | ||
|
||
if err != nil { | ||
log.Fatalf("spotinst: failed to fetch account: %v", err) | ||
} | ||
|
||
if out != nil { | ||
log.Printf("externalId: %s", | ||
spotinst.StringValue(out.AwsAccountExternalId.ExternalId)) | ||
} | ||
|
||
} |
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,37 @@ | ||
package account | ||
|
||
import ( | ||
"github.com/spotinst/spotinst-sdk-go/service/account/providers/aws" | ||
"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 { | ||
CloudProviderAWS() aws.Service | ||
} | ||
|
||
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(cfg), | ||
} | ||
} | ||
|
||
func (s *ServiceOp) CloudProviderAWS() aws.Service { | ||
return &aws.ServiceOp{ | ||
Client: s.Client, | ||
} | ||
} |
Oops, something went wrong.