diff --git a/internal/commands/appserve-show.go b/internal/commands/appserve-show.go index 9ef9703..cd224b1 100644 --- a/internal/commands/appserve-show.go +++ b/internal/commands/appserve-show.go @@ -94,16 +94,14 @@ func printAppServeShow(d domain.AppServeApp, long bool) { t.Style().Options.SeparateHeader = false t.Style().Options.SeparateRows = false if long { - t.AppendHeader(table.Row{"ID", "Version", "Status", "Available Rollback", "Strategy", "Revision", - "Image URL", "Profile", "CREATED_AT", "UPDATED_AT"}) + t.AppendHeader(table.Row{"ID", "Version", "Status", "Available Rollback", "Strategy", "Revision", "Image URL", "Profile", "CREATED_AT", "UPDATED_AT"}) for _, i := range d.AppServeAppTasks { tCreatedAt := helper.ParseTime(i.CreatedAt) var tUpdatedAt string if i.UpdatedAt != nil { tUpdatedAt = helper.ParseTime(*i.UpdatedAt) } - t.AppendRow(table.Row{i.ID, i.Version, i.Status, i.AvailableRollback, i.Strategy, strconv.Itoa(int(i.HelmRevision)), - i.ImageUrl, i.Profile, tCreatedAt, tUpdatedAt}) + t.AppendRow(table.Row{i.ID, i.Version, i.Status, i.AvailableRollback, i.Strategy, strconv.Itoa(int(i.HelmRevision)), i.ImageUrl, i.Profile, tCreatedAt, tUpdatedAt}) } } else { fmt.Println("Not implemented yet.") diff --git a/internal/commands/cloud-account-create.go b/internal/commands/cloud-account-create.go new file mode 100644 index 0000000..5cefa1c --- /dev/null +++ b/internal/commands/cloud-account-create.go @@ -0,0 +1,83 @@ +package commands + +import ( + "fmt" + + _apiClient "github.com/openinfradev/tks-api/pkg/api-client" + "github.com/openinfradev/tks-api/pkg/domain" + "github.com/openinfradev/tks-client/internal/helper" + "github.com/spf13/cobra" +) + +func NewCloudAccountCreateCommand(globalOpts *GlobalOptions) *cobra.Command { + var ( + organizationId string + name string + description string + cloudService string + awsAccountId string + accessKeyId string + secretAccessKey string + ) + + var command = &cobra.Command{ + Use: "create", + Short: "Create a cloud account.", + Long: `Create a cloud account. + + Example: + tks cloud-account create [--awsAccountId AWS_ACCOUNT_ID --accessKeyID ACCESS_KEY_ID --secretAccesssKey SECRET_ACCESS_KEY]`, + RunE: func(cmd *cobra.Command, args []string) error { + if len(args) == 1 { + name = args[0] + } + + if name == "" { + helper.PanicWithError("You must specify name") + } + + input := domain.CreateCloudAccountRequest{ + Name: name, + Description: description, + CloudService: cloudService, + AwsAccountId: awsAccountId, + AccessKeyId: accessKeyId, + SecretAccessKey: secretAccessKey, + } + + apiClient, err := _apiClient.New(globalOpts.ServerAddr, globalOpts.AuthToken) + helper.CheckError(err) + + url := fmt.Sprintf("organizations/%v/cloud-accounts", organizationId) + body, err := apiClient.Post(url, input) + if err != nil { + return err + } + + var out domain.CreateCloudAccountResponse + helper.Transcode(body, &out) + + fmt.Println("cloudAccountId : ", out.ID) + + return nil + }, + } + + command.Flags().StringVarP(&organizationId, "organization-id", "o", "", "the organizationId with cloud accounts") + helper.CheckError(command.MarkFlagRequired("organization-id")) + + command.Flags().StringVarP(&name, "name", "n", "", "the name of cloud account") + command.Flags().StringVarP(&description, "description", "d", "", "the description of cloud account") + command.Flags().StringVar(&cloudService, "cloud-service", "AWS", "the type of cloud account") + + command.Flags().StringVar(&awsAccountId, "aws-account-id", "", "The accountId of aws") + helper.CheckError(command.MarkFlagRequired("aws-account-id")) + + command.Flags().StringVar(&accessKeyId, "access-key-id", "", "The accessKeyId of aws") + helper.CheckError(command.MarkFlagRequired("access-key-id")) + + command.Flags().StringVar(&secretAccessKey, "secret-access-key", "", "The secret access key of accessKey Id") + helper.CheckError(command.MarkFlagRequired("secret-access-key")) + + return command +} diff --git a/internal/commands/cloud-account.go b/internal/commands/cloud-account.go index 272fd7f..dab6c8a 100644 --- a/internal/commands/cloud-account.go +++ b/internal/commands/cloud-account.go @@ -16,6 +16,7 @@ func NewCloudAccountCommand(globalOpts *GlobalOptions) *cobra.Command { }, } + command.AddCommand(NewCloudAccountCreateCommand(globalOpts)) command.AddCommand(NewCloudAccountListCommand(globalOpts)) return command