Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed function name and updated all credential to credentials including struct #264

Merged
merged 17 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
8a142de
added support for create, read and delete account
sharadkesarwani Sep 12, 2023
5cb8381
Added support for externalId, setCredential, modified client.go and r…
sharadkesarwani Sep 13, 2023
8a274cc
Merge branch 'main' into SPOTAUT-14860-support-acctMgmt-apis
sharadkesarwani Sep 13, 2023
5b12e46
fixed set credential API support
sharadkesarwani Sep 14, 2023
6f3b161
removed commented code from awscredentials.go
sharadkesarwani Sep 14, 2023
355f658
Added setters for credential attributes and renamed CreateCredentialI…
sharadkesarwani Sep 14, 2023
be57b06
Removed support for externalId creation.
sharadkesarwani Sep 24, 2023
cab1176
Merge branch 'main' into SPOTAUT-14860-support-acctMgmt-apis
sharadkesarwani Sep 24, 2023
88e4849
Fixed input variable names in example file of create account and set …
sharadkesarwani Sep 25, 2023
d5030e4
Removed updatedAt field from account and updatedAt, createdAt from se…
sharadkesarwani Sep 25, 2023
75cd481
removed commented code
sharadkesarwani Sep 25, 2023
5686571
Added support for externalId APIs
sharadkesarwani Sep 26, 2023
47fe200
Removed comment description for forceSendFields and nullFields
sharadkesarwani Sep 27, 2023
2a2e4f7
Added description for field forceSendFields and nullFields
sharadkesarwani Sep 27, 2023
5225c99
Changed function name and updated all credential to credentials inclu…
sharadkesarwani Sep 28, 2023
7665f6a
Merge branch 'main' into SPOTAUT-14860-support-acctMgmt-apis
sharadkesarwani Sep 28, 2023
2e58c6e
modified file and folder name.
sharadkesarwani Sep 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ 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"),
_, err := svc.CloudProviderAWS().Credentials(ctx, &aws.SetCredentialsInput{
Credentials: &aws.Credentials{
AccountId: spotinst.String("act-c4842ba3"),
IamRole: spotinst.String("arn:aws:iam::253244684816:role/terraform-role-sept"),
},
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ 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"),
out, err := svc.CloudProviderAWS().ReadCredentials(ctx, &aws.ReadCredentialsInput{
AccountId: spotinst.String("act-c4842ba3"),
})

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))
spotinst.StringValue(out.Credentials.AccountId),
stringutil.Stringify(out.Credentials.IamRole))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"net/http"
)

type Credential struct {
type Credentials struct {
IamRole *string `json:"iamRole,omitempty"`
AccountId *string `json:"accountId,omitempty"`

Expand All @@ -19,39 +19,39 @@ type Credential struct {
nullFields []string
}

func (o Credential) MarshalJSON() ([]byte, error) {
type noMethod Credential
func (o Credentials) MarshalJSON() ([]byte, error) {
type noMethod Credentials
raw := noMethod(o)
return jsonutil.MarshalJSON(raw, o.forceSendFields, o.nullFields)
}

func (o *Credential) SetIamRole(v *string) *Credential {
func (o *Credentials) SetIamRole(v *string) *Credentials {
if o.IamRole = v; o.IamRole == nil {
o.nullFields = append(o.nullFields, "IamRole")
}
return o
}
func (o *Credential) SetAccountId(v *string) *Credential {
func (o *Credentials) SetAccountId(v *string) *Credentials {
if o.AccountId = v; o.AccountId == nil {
o.nullFields = append(o.nullFields, "AccountId")
}
return o
}

type SetCredentialInput struct {
Credential *Credential `json:"credentials,omitempty"`
type SetCredentialsInput struct {
Credentials *Credentials `json:"credentials,omitempty"`
}
type SetCredentialOutput struct {
Credential *Credential `json:"Credential,omitempty"`
type SetCredentialsOutput struct {
Credentials *Credentials `json:"Credentials,omitempty"`
}

func (s *ServiceOp) SetCredential(ctx context.Context, input *SetCredentialInput) (*SetCredentialOutput, error) {
func (s *ServiceOp) Credentials(ctx context.Context, input *SetCredentialsInput) (*SetCredentialsOutput, error) {
r := client.NewRequest(http.MethodPost, "/setup/credentials/aws")

if input != nil {
r.Params.Set("accountId", spotinst.StringValue(input.Credential.AccountId))
r.Params.Set("accountId", spotinst.StringValue(input.Credentials.AccountId))
}
input.Credential.AccountId = nil
input.Credentials.AccountId = nil
r.Obj = input

resp, err := client.RequireOK(s.Client.DoOrg(ctx, r))
Expand All @@ -65,22 +65,22 @@ func (s *ServiceOp) SetCredential(ctx context.Context, input *SetCredentialInput
return nil, err
}

output := new(SetCredentialOutput)
output := new(SetCredentialsOutput)
if len(gs) > 0 {
output.Credential = gs[0]
output.Credentials = gs[0]
}

return output, nil
}

type ReadCredentialInput struct {
type ReadCredentialsInput struct {
AccountId *string `json:"accountId,omitempty"`
}
type ReadCredentialOutput struct {
Credential *Credential `json:"Credential,omitempty"`
type ReadCredentialsOutput struct {
Credentials *Credentials `json:"Credentials,omitempty"`
}

func (s *ServiceOp) ReadCredential(ctx context.Context, input *ReadCredentialInput) (*ReadCredentialOutput, error) {
func (s *ServiceOp) ReadCredentials(ctx context.Context, input *ReadCredentialsInput) (*ReadCredentialsOutput, error) {
r := client.NewRequest(http.MethodGet, "/setup/credentials/aws")
if input != nil {
r.Params.Set("accountId", spotinst.StringValue(input.AccountId))
Expand All @@ -97,28 +97,28 @@ func (s *ServiceOp) ReadCredential(ctx context.Context, input *ReadCredentialInp
return nil, err
}

output := new(ReadCredentialOutput)
output := new(ReadCredentialsOutput)
if len(gs) > 0 {
output.Credential = gs[0]
output.Credentials = gs[0]
}

return output, nil
}

func credentialsFromHttpResponse(resp *http.Response) ([]*Credential, error) {
func credentialsFromHttpResponse(resp *http.Response) ([]*Credentials, error) {
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
return credentialsFromJSON(body)
}

func credentialsFromJSON(in []byte) ([]*Credential, error) {
func credentialsFromJSON(in []byte) ([]*Credentials, error) {
var rw client.Response
if err := json.Unmarshal(in, &rw); err != nil {
return nil, err
}
out := make([]*Credential, len(rw.Response.Items))
out := make([]*Credentials, len(rw.Response.Items))
if len(out) == 0 {
return out, nil
}
Expand All @@ -132,8 +132,8 @@ func credentialsFromJSON(in []byte) ([]*Credential, error) {
return out, nil
}

func credentialFromJSON(in []byte) (*Credential, error) {
b := new(Credential)
func credentialFromJSON(in []byte) (*Credentials, error) {
b := new(Credentials)
if err := json.Unmarshal(in, b); err != nil {
return nil, err
}
Expand Down
8 changes: 4 additions & 4 deletions service/account/providers/aws/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
// the service.
type Service interface {
serviceAccount
serviceCredential
serviceCredentials
serviceAwsAccountExternalId
}

Expand All @@ -22,9 +22,9 @@ type serviceAccount interface {
DeleteAccount(context.Context, *DeleteAccountInput) (*DeleteAccountOutput, error)
ReadAccount(context.Context, *ReadAccountInput) (*ReadAccountOutput, error)
}
type serviceCredential interface {
SetCredential(context.Context, *SetCredentialInput) (*SetCredentialOutput, error)
ReadCredential(context.Context, *ReadCredentialInput) (*ReadCredentialOutput, error)
type serviceCredentials interface {
Credentials(context.Context, *SetCredentialsInput) (*SetCredentialsOutput, error)
ReadCredentials(context.Context, *ReadCredentialsInput) (*ReadCredentialsOutput, error)
}
type serviceAwsAccountExternalId interface {
CreateAWSAccountExternalId(context.Context, *CreateAWSAccountExternalIdInput) (*CreateAWSAccountExternalIdOutput, error)
Expand Down
Loading