Skip to content

Commit

Permalink
Merge pull request #130 from cycloidio/v1.0.89
Browse files Browse the repository at this point in the history
Bump swagger client to version v1.0.89
  • Loading branch information
gaelL authored Mar 23, 2022
2 parents 5d207fa + e45f584 commit c4e5ac8
Show file tree
Hide file tree
Showing 11 changed files with 221 additions and 6 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## [v1.0.89] _2022-03-08_
- **CHANGED**
- Update client to version v1.0.89
([PR #130](https://github.com/cycloidio/cycloid-cli/pull/130))
- Add the ability to specify canonical for credential create
([PR #130](https://github.com/cycloidio/cycloid-cli/pull/130))
- Add new field-file flag to custom credential create
([PR #130](https://github.com/cycloidio/cycloid-cli/pull/130))

## [v1.0.88] _2022-02-10_
- **CHANGED**
- Update client to version v1.0.88
Expand Down
104 changes: 104 additions & 0 deletions client/client/organization_pipelines/get_pipelines_parameters.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions client/models/pipeline.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions client/models/service_catalog.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.0.88
v1.0.89
7 changes: 7 additions & 0 deletions cmd/cycloid/common/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ func WithFlagCan(cmd *cobra.Command) string {
return flagName
}

func WithPersistentFlagCan(cmd *cobra.Command) string {
flagName := "canonical"
// TODO how make it nil or without any value in case we don't want any creds ?
cmd.PersistentFlags().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 ?
Expand Down
6 changes: 6 additions & 0 deletions cmd/cycloid/creds/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var (
descriptionFlag string
pathFlag string
fieldsFlags map[string]string
fieldsFileFlags map[string]string
usernameFlag string
accessKeyFlag string
secretKeyFlag string
Expand Down Expand Up @@ -79,6 +80,11 @@ func WithFlagField(cmd *cobra.Command) string {
cmd.Flags().StringToStringVar(&fieldsFlags, flagName, nil, "key=value")
return flagName
}
func WithFlagFieldFile(cmd *cobra.Command) string {
flagName := "field-file"
cmd.Flags().StringToStringVar(&fieldsFileFlags, flagName, nil, "key=/file/path")
return flagName
}
func WithFlagType(cmd *cobra.Command) string {
flagName := "type"
cmd.Flags().StringVar(&typeFlag, flagName, "", "type")
Expand Down
34 changes: 31 additions & 3 deletions cmd/cycloid/creds/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package creds
import (
"fmt"
"io/ioutil"
"strings"

"github.com/pkg/errors"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -48,6 +49,7 @@ func NewCreateCommand() *cobra.Command {

WithPersistentFlagDescription(cmd)
common.RequiredPersistentFlag(WithPersistentFlagName, cmd)
common.WithPersistentFlagCan(cmd)
WithPersistentFlagPath(cmd)

// SSH
Expand Down Expand Up @@ -82,10 +84,11 @@ func NewCreateCommand() *cobra.Command {
PreRunE: internal.CheckAPIAndCLIVersion,
Example: `
# create a credential for custom type
cy --org my-org credential create custom --name foo --field my-key=my-value --field my-key2=my-value2
cy --org my-org credential create custom --name foo --field my-key=my-value --field my-key2=my-value2 --field-file my-key3=/file/path
`,
}
common.RequiredFlag(WithFlagField, custom)
WithFlagField(custom)
WithFlagFieldFile(custom)

// AWS
var aws = &cobra.Command{
Expand Down Expand Up @@ -196,6 +199,10 @@ func create(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
can, err := cmd.Flags().GetString("canonical")
if err != nil {
return err
}
description, err := cmd.Flags().GetString("description")
if err != nil {
return err
Expand Down Expand Up @@ -245,6 +252,27 @@ func create(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
fileFields, err := cmd.Flags().GetStringToString("field-file")
if err != nil {
return err
}

if len(fields) == 0 && len(fileFields) == 0 {
return fmt.Errorf("at least one --field or --field-file has to be specified")
}

// Read file fields
if len(fileFields) > 0 {
for f, p := range fileFields {
fc, err := ioutil.ReadFile(p)
if err != nil {
return errors.Wrap(err, fmt.Sprintf("unable to read file path %s", p))
}

fields[f] = strings.TrimSuffix(string(fc), "\n")
}
}

rawCred = &models.CredentialRaw{
Raw: fields,
}
Expand Down Expand Up @@ -366,6 +394,6 @@ func create(cmd *cobra.Command, args []string) error {
return fmt.Errorf("unsupported credential type: %s", credT)
}

err = m.CreateCredential(org, name, credT, rawCred, path, description)
err = m.CreateCredential(org, name, credT, rawCred, path, can, description)
return printer.SmartPrint(p, nil, err, "unable to create credential", printer.Options{}, cmd.OutOrStdout())
}
3 changes: 2 additions & 1 deletion cmd/cycloid/middleware/creds.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
strfmt "github.com/go-openapi/strfmt"
)

func (m *middleware) CreateCredential(org, name, cType string, rawCred *models.CredentialRaw, path, description string) error {
func (m *middleware) CreateCredential(org, name, cType string, rawCred *models.CredentialRaw, path, can, description string) error {

params := organization_credentials.NewCreateCredentialParams()
params.SetOrganizationCanonical(org)
Expand All @@ -27,6 +27,7 @@ func (m *middleware) CreateCredential(org, name, cType string, rawCred *models.C
Path: &path,
Raw: rawCred,
Type: &cType,
Canonical: can,
}

params.SetBody(body)
Expand Down
2 changes: 1 addition & 1 deletion cmd/cycloid/middleware/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Middleware interface {
PushConfig(org string, project string, env string, configs map[string]strfmt.Base64) error
UpdateConfigRepository(org, configRepo, name, url, branch, cred string, setDefault bool) (*models.ConfigRepository, error)

CreateCredential(org, name, cType string, rawCred *models.CredentialRaw, path, description string) error
CreateCredential(org, name, cType string, rawCred *models.CredentialRaw, path, can, description string) error
DeleteCredential(org, cred string) error
GetCredential(org, cred string) (*models.Credential, error)
ListCredentials(org, cType string) ([]*models.CredentialSimple, error)
Expand Down
24 changes: 24 additions & 0 deletions e2e/creds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,30 @@ func TestCreds(t *testing.T) {
assert.Nil(t, cmdErr)
require.Equal(t, "", cmdOut)
})
t.Run("SuccessCredsCreateCustomWithFile", func(t *testing.T) {
// Cleanup just in case
executeCommand([]string{
"--output", "json",
"--org", CY_TEST_ROOT_ORG,
"creds",
"delete",
"--canonical", "cli-custom-file",
})

cmdOut, cmdErr := executeCommand([]string{
"--output", "json",
"--org", CY_TEST_ROOT_ORG,
"creds",
"create",
"custom",
"--name", "cli-custom-file",
"--field", "foo=bar",
"--field-file", "key=/tmp/test_cli-ssh",
})

assert.Nil(t, cmdErr)
require.Equal(t, "", cmdOut)
})

t.Run("SuccessCredsCreateSSH", func(t *testing.T) {
// Cleanup just in case
Expand Down

0 comments on commit c4e5ac8

Please sign in to comment.