From 2df87b28ac96322209219449daa444231e5d4b82 Mon Sep 17 00:00:00 2001 From: Sharad Kesarwani <108344822+sharadkesarwani@users.noreply.github.com> Date: Thu, 28 Sep 2023 21:45:43 +0530 Subject: [PATCH] updated the names to credentials (#264) --- .../create/main.go | 8 +-- .../read/main.go | 8 +-- .../{awscredential.go => awscredentials.go} | 50 +++++++++---------- service/account/providers/aws/service.go | 8 +-- 4 files changed, 37 insertions(+), 37 deletions(-) rename examples/service/{awscredential => awscredentials}/create/main.go (65%) rename examples/service/{awscredential => awscredentials}/read/main.go (71%) rename service/account/providers/aws/{awscredential.go => awscredentials.go} (64%) diff --git a/examples/service/awscredential/create/main.go b/examples/service/awscredentials/create/main.go similarity index 65% rename from examples/service/awscredential/create/main.go rename to examples/service/awscredentials/create/main.go index 9c67c27d..a175377d 100644 --- a/examples/service/awscredential/create/main.go +++ b/examples/service/awscredentials/create/main.go @@ -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"), }, }) diff --git a/examples/service/awscredential/read/main.go b/examples/service/awscredentials/read/main.go similarity index 71% rename from examples/service/awscredential/read/main.go rename to examples/service/awscredentials/read/main.go index 0264112d..02612b8f 100644 --- a/examples/service/awscredential/read/main.go +++ b/examples/service/awscredentials/read/main.go @@ -15,8 +15,8 @@ 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 { @@ -24,8 +24,8 @@ func main() { } 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)) } } diff --git a/service/account/providers/aws/awscredential.go b/service/account/providers/aws/awscredentials.go similarity index 64% rename from service/account/providers/aws/awscredential.go rename to service/account/providers/aws/awscredentials.go index d6758326..6b07b9a4 100644 --- a/service/account/providers/aws/awscredential.go +++ b/service/account/providers/aws/awscredentials.go @@ -10,7 +10,7 @@ import ( "net/http" ) -type Credential struct { +type Credentials struct { IamRole *string `json:"iamRole,omitempty"` AccountId *string `json:"accountId,omitempty"` @@ -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)) @@ -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)) @@ -97,15 +97,15 @@ 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 @@ -113,12 +113,12 @@ func credentialsFromHttpResponse(resp *http.Response) ([]*Credential, error) { 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 } @@ -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 } diff --git a/service/account/providers/aws/service.go b/service/account/providers/aws/service.go index 98846a30..94a3ae0c 100644 --- a/service/account/providers/aws/service.go +++ b/service/account/providers/aws/service.go @@ -13,7 +13,7 @@ import ( // the service. type Service interface { serviceAccount - serviceCredential + serviceCredentials serviceAwsAccountExternalId } @@ -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)