Skip to content

Commit

Permalink
cmd/cycloid: sync with 1.0.58-rc20
Browse files Browse the repository at this point in the history
  • Loading branch information
tormath1 committed Feb 1, 2021
1 parent abbc689 commit cdbf06e
Show file tree
Hide file tree
Showing 36 changed files with 186 additions and 202 deletions.
6 changes: 3 additions & 3 deletions cmd/cycloid/apikey/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var (
canonical string
name string
description string
roleID uint32
role string
)

func WithFlagName(cmd *cobra.Command) {
Expand All @@ -17,8 +17,8 @@ func WithFlagDescription(cmd *cobra.Command) {
cmd.Flags().StringVar(&description, "description", "", "description of the API key")
}

func WithFlagRoleID(cmd *cobra.Command) {
cmd.Flags().Uint32Var(&roleID, "role-id", 0, "ID of the role")
func WithFlagRole(cmd *cobra.Command) {
cmd.Flags().StringVar(&role, "role", "", "Canonical of the role")
}

func WithFlagCanonical(cmd *cobra.Command) {
Expand Down
23 changes: 7 additions & 16 deletions cmd/cycloid/apikey/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func NewCreateCommand() *cobra.Command {
Short: "create an API key",
Example: `
# create an API key in the org my-org
cy api-key create --role-id 2 --name "CI API key" --description "Cycloid API key to be used in a CI context"
cy api-key create --role my-role --name "CI API key" --description "Cycloid API key to be used in a CI context"
`,
RunE: func(cmd *cobra.Command, args []string) error {
output, err := cmd.Flags().GetString("output")
Expand All @@ -35,41 +35,32 @@ func NewCreateCommand() *cobra.Command {
if err != nil {
return fmt.Errorf("unable to get description flag: %w", err)
}
roleID, err := cmd.Flags().GetUint32("role-id")
role, err := cmd.Flags().GetString("role")
if err != nil {
return fmt.Errorf("unable to get role ID flag: %w", err)
}
canonical, err := cmd.Flags().GetString("canonical")
if err != nil {
return fmt.Errorf("unable to get canonical flag: %w", err)
return fmt.Errorf("unable to get role flag: %w", err)
}
org, err := cmd.Flags().GetString("org")
if err != nil {
return fmt.Errorf("unable to get org flag: %w", err)
}
return create(org, name, canonical, description, output, roleID)
return create(org, name, description, output, role)
},
}

WithFlagName(cmd)
WithFlagDescription(cmd)
WithFlagRoleID(cmd)
WithFlagCanonical(cmd)
WithFlagRole(cmd)

return cmd
}

// create will send the POST request to the API in order to
// create an API token which will be displayed on the screen
func create(org, name, canonical, description, output string, roleID uint32) error {
func create(org, name, description, output, role string) error {
api := common.NewAPI()
m := middleware.NewMiddleware(api)

if len(canonical) == 0 {
canonical = common.GenerateCanonical(name)
}

key, err := m.CreateAPIKey(org, name, canonical, description, roleID)
key, err := m.CreateAPIKey(org, name, description, role)
if err != nil {
return fmt.Errorf("unable to create API key: %w", err)
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/cycloid/catalog-repositories/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ func NewCreateCommand() *cobra.Command {
Short: "create a catalog repository",
Example: `
# create a catalog repository using credential ID 123, branch 'stacks' and git URL
cy --org my-org catalog-repo create --branch stacks --cred 123 --url "[email protected]:my/repo.git" --name my-catalog-name
cy --org my-org catalog-repo create --branch stacks --cred my-cred --url "[email protected]:my/repo.git" --name my-catalog-name
# create a catalog repository using public git repository
cy --org my-org catalog-repo create --branch stacks --url "https://github.com:my/repo.git" --name my-catalog-name
`,
RunE: createCatalogRepository,
}

// create --branch test --cred 105 --url "[email protected]:foo/bla.git" --name catalogname
// create --branch test --cred my-cred --url "[email protected]:foo/bla.git" --name catalogname
common.WithFlagCred(cmd)

common.RequiredFlag(WithFlagName, cmd)
Expand Down Expand Up @@ -65,7 +65,7 @@ func createCatalogRepository(cmd *cobra.Command, args []string) error {
return err
}

cred, err := cmd.Flags().GetUint32("cred")
cred, err := cmd.Flags().GetString("cred")
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/cycloid/catalog-repositories/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ func NewDeleteCommand() *cobra.Command {
# delete a catalog repository with the ID 123
cy --org my-org catalog-repository delete --id 123
`,
RunE: deleteCatalogRepository,
RunE: deleteCatalogRepository,
}

common.RequiredFlag(common.WithFlagID, cmd)
common.RequiredFlag(common.WithFlagCan, cmd)

return cmd
}
Expand All @@ -37,12 +37,12 @@ func deleteCatalogRepository(cmd *cobra.Command, args []string) error {
return err
}

id, err := cmd.Flags().GetUint32("id")
canonical, err := cmd.Flags().GetString("canonical")
if err != nil {
return err
}

if err := m.DeleteCatalogRepository(org, id); err != nil {
if err := m.DeleteCatalogRepository(org, canonical); err != nil {
return errors.Wrap(err, "unable to delete repository")
}
return nil
Expand Down
6 changes: 3 additions & 3 deletions cmd/cycloid/catalog-repositories/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func NewGetCommand() *cobra.Command {
RunE: getCatalogRepository,
}

common.RequiredFlag(common.WithFlagID, cmd)
common.RequiredFlag(common.WithFlagCan, cmd)

return cmd
}
Expand All @@ -40,7 +40,7 @@ func getCatalogRepository(cmd *cobra.Command, args []string) error {
return err
}

id, err := cmd.Flags().GetUint32("id")
can, err := cmd.Flags().GetString("canonical")
if err != nil {
return err
}
Expand All @@ -49,7 +49,7 @@ func getCatalogRepository(cmd *cobra.Command, args []string) error {
return errors.Wrap(err, "unable to get output flag")
}

cr, err := m.GetCatalogRepository(org, id)
cr, err := m.GetCatalogRepository(org, can)
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/cycloid/catalog-repositories/refresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func NewRefreshCommand() *cobra.Command {
RunE: refreshCatalogRepository,
}

common.RequiredFlag(common.WithFlagID, cmd)
common.RequiredFlag(common.WithFlagCan, cmd)

return cmd
}
Expand All @@ -38,16 +38,16 @@ func refreshCatalogRepository(cmd *cobra.Command, args []string) error {
return err
}

id, err := cmd.Flags().GetUint32("id")
can, err := cmd.Flags().GetString("canonical")
if err != nil {
return err
}

cr, err := m.RefreshCatalogRepository(org, id)
cr, err := m.RefreshCatalogRepository(org, can)
if err != nil {
return err
}
fmt.Printf("id: %d name: %s url: %s branch: %s credential_id: %d\n", *cr.ID, *cr.Name, *cr.URL, cr.Branch, cr.CredentialID)
fmt.Printf("id: %d name: %s url: %s branch: %s credential_id: %d\n", *cr.ID, *cr.Name, *cr.URL, cr.Branch, cr.CredentialCanonical)
fmt.Printf("created_at: %v updated_at: %v\n", time.Unix(int64(*cr.CreatedAt), 0), time.Unix(int64(*cr.UpdatedAt), 0))

//TODO: Wait PR merged https://github.com/cycloidio/youdeploy-http-api/pull/2066
Expand Down
8 changes: 4 additions & 4 deletions cmd/cycloid/catalog-repositories/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func NewUpdateCommand() *cobra.Command {
RunE: updateCatalogRepository,
}

common.RequiredFlag(common.WithFlagID, cmd)
common.RequiredFlag(common.WithFlagCan, cmd)
common.RequiredFlag(common.WithFlagCred, cmd)
common.RequiredFlag(WithFlagName, cmd)
common.RequiredFlag(WithFlagBranch, cmd)
Expand All @@ -47,7 +47,7 @@ func updateCatalogRepository(cmd *cobra.Command, args []string) error {
return err
}

id, err := cmd.Flags().GetUint32("id")
can, err := cmd.Flags().GetString("canonical")
if err != nil {
return err
}
Expand All @@ -67,7 +67,7 @@ func updateCatalogRepository(cmd *cobra.Command, args []string) error {
return err
}

cred, err := cmd.Flags().GetUint32("cred")
cred, err := cmd.Flags().GetString("cred")
if err != nil {
return err
}
Expand All @@ -77,7 +77,7 @@ func updateCatalogRepository(cmd *cobra.Command, args []string) error {
return errors.Wrap(err, "unable to get output flag")
}

cr, err := m.UpdateCatalogRepository(org, id, name, url, branch, cred)
cr, err := m.UpdateCatalogRepository(org, can, name, url, branch, cred)
if err != nil {
return errors.Wrap(err, "unable to update catalog repository")
}
Expand Down
22 changes: 14 additions & 8 deletions cmd/cycloid/common/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"github.com/spf13/cobra"
)

var projectFlag string
var envFlag string
var orgFlag string
var credFlag, idFlag uint32
var (
projectFlag, envFlag, orgFlag, credFlag, canFlag string
idFlag uint32
)

func WithFlagOrg(cmd *cobra.Command) string {
flagName := "org"
Expand All @@ -27,16 +27,22 @@ func WithFlagEnv(cmd *cobra.Command) string {
return flagName
}

func WithFlagID(cmd *cobra.Command) string {
flagName := "id"
func WithFlagCan(cmd *cobra.Command) string {
flagName := "canonical"
// TODO how make it nil or without any value in case we don't want any creds ?
cmd.Flags().Uint32Var(&idFlag, flagName, 0, "id")
cmd.Flags().StringVar(&canFlag, flagName, "", "canonical")
return flagName
}

func WithFlagCred(cmd *cobra.Command) string {
flagName := "cred"
// TODO how make it nil or without any value in case we don't want any creds ?
cmd.Flags().Uint32Var(&credFlag, flagName, 0, "cred id")
cmd.Flags().StringVar(&credFlag, flagName, "", "cred canonical")
return flagName
}

func WithFlagID(cmd *cobra.Command) string {
flagName := "id"
cmd.Flags().Uint32Var(&idFlag, flagName, 0, "id")
return flagName
}
4 changes: 2 additions & 2 deletions cmd/cycloid/config-repositories/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func createConfigRepository(cmd *cobra.Command, args []string) error {
return err
}

cred, err := cmd.Flags().GetUint32("cred")
cred, err := cmd.Flags().GetString("cred")
if err != nil {
return err
}
Expand All @@ -79,7 +79,7 @@ func createConfigRepository(cmd *cobra.Command, args []string) error {
return errors.Wrap(err, "unable to get output flag")
}

cr, err := m.CreateConfigRepository(org, name, url, branch, setDefault, cred)
cr, err := m.CreateConfigRepository(org, name, url, branch, cred, setDefault)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/cycloid/config-repositories/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func NewDeleteCommand() *cobra.Command {
PreRunE: internal.CheckAPIAndCLIVersion,
}

common.RequiredFlag(common.WithFlagID, cmd)
common.RequiredFlag(common.WithFlagCan, cmd)

return cmd
}
Expand All @@ -39,12 +39,12 @@ func deleteConfigRepository(cmd *cobra.Command, args []string) error {
return err
}

id, err := cmd.Flags().GetUint32("id")
can, err := cmd.Flags().GetString("canonical")
if err != nil {
return err
}

if err := m.DeleteConfigRepository(org, id); err != nil {
if err := m.DeleteConfigRepository(org, can); err != nil {
return errors.Wrap(err, "unable to delete config repository")
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/cycloid/config-repositories/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func NewGetCommand() *cobra.Command {
PreRunE: internal.CheckAPIAndCLIVersion,
}

common.RequiredFlag(common.WithFlagID, cmd)
common.RequiredFlag(common.WithFlagCan, cmd)

return cmd
}
Expand All @@ -42,7 +42,7 @@ func getConfigRepository(cmd *cobra.Command, args []string) error {
return err
}

id, err := cmd.Flags().GetUint32("id")
can, err := cmd.Flags().GetString("canonical")
if err != nil {
return err
}
Expand All @@ -51,7 +51,7 @@ func getConfigRepository(cmd *cobra.Command, args []string) error {
return errors.Wrap(err, "unable to get output flag")
}

cr, err := m.GetConfigRepository(org, id)
cr, err := m.GetConfigRepository(org, can)
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/cycloid/config-repositories/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func NewUpdateCommand() *cobra.Command {
PreRunE: internal.CheckAPIAndCLIVersion,
}

common.RequiredFlag(common.WithFlagID, cmd)
common.RequiredFlag(common.WithFlagCan, cmd)
common.RequiredFlag(common.WithFlagCred, cmd)
common.RequiredFlag(WithFlagName, cmd)
common.RequiredFlag(WithFlagBranch, cmd)
Expand All @@ -46,7 +46,7 @@ func updateConfigRepository(cmd *cobra.Command, args []string) error {
return err
}

id, err := cmd.Flags().GetUint32("id")
can, err := cmd.Flags().GetString("canonical")
if err != nil {
return err
}
Expand All @@ -71,7 +71,7 @@ func updateConfigRepository(cmd *cobra.Command, args []string) error {
return err
}

cred, err := cmd.Flags().GetUint32("cred")
cred, err := cmd.Flags().GetString("cred")
if err != nil {
return err
}
Expand All @@ -80,7 +80,7 @@ func updateConfigRepository(cmd *cobra.Command, args []string) error {
return errors.Wrap(err, "unable to get output flag")
}

cr, err := m.UpdateConfigRepository(org, id, name, url, branch, setDefault, cred)
cr, err := m.UpdateConfigRepository(org, can, cred, name, url, branch, setDefault)
if err != nil {
return errors.Wrap(err, "unable to update config repository")
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/cycloid/creds/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func NewDeleteCommand() *cobra.Command {
PreRunE: internal.CheckAPIAndCLIVersion,
}

common.RequiredFlag(common.WithFlagID, cmd)
common.RequiredFlag(common.WithFlagCan, cmd)
return cmd
}

Expand All @@ -33,12 +33,12 @@ func del(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
id, err := cmd.Flags().GetUint32("id")
can, err := cmd.Flags().GetString("canonical")
if err != nil {
return err
}

if err := m.DeleteCredential(org, id); err != nil {
if err := m.DeleteCredential(org, can); err != nil {
return errors.Wrap(err, "unable to delete credential")
}
return nil
Expand Down
Loading

0 comments on commit cdbf06e

Please sign in to comment.