From 40ae095df2fdfa0e3c0688be0c1792e542c26678 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Opasiak?= Date: Mon, 15 Jul 2024 10:30:36 +0200 Subject: [PATCH 01/71] cli: add linter --- .golangci.yml | 37 +++++++++++++++++++ Makefile | 5 +++ cmd/cycloid/common/flags.go | 6 +-- cmd/cycloid/creds/get.go | 2 +- cmd/cycloid/external-backends/common.go | 2 - .../external-backends/create_events.go | 10 ++--- cmd/cycloid/infrapolicies/common.go | 12 +++--- cmd/cycloid/infrapolicies/create.go | 11 +++--- cmd/cycloid/infrapolicies/delete.go | 8 ++-- cmd/cycloid/infrapolicies/get.go | 8 ++-- cmd/cycloid/infrapolicies/list.go | 10 ++--- cmd/cycloid/infrapolicies/update.go | 15 ++++---- cmd/cycloid/login/list.go | 2 +- cmd/cycloid/middleware/infra-policies.go | 18 ++++----- cmd/cycloid/middleware/middleware.go | 6 +-- cmd/cycloid/middleware/pipeline.go | 2 +- cmd/cycloid/organizations/create.go | 4 +- cmd/cycloid/organizations/delete.go | 4 +- cmd/cycloid/organizations/list-children.go | 4 +- cmd/cycloid/organizations/list.go | 6 +-- cmd/cycloid/pipelines/helpers.go | 12 ++++-- cmd/cycloid/projects/create-env.go | 3 ++ cmd/cycloid/projects/get-env.go | 4 +- cmd/cycloid/stacks/get-config.go | 4 +- cmd/cycloid/stacks/get.go | 2 - e2e/infra_policies_test.go | 8 ++-- main.go | 7 ---- printer/options.go | 2 +- printer/printer.go | 1 + printer/table/printer.go | 2 +- printer/table/printer_test.go | 2 +- 31 files changed, 131 insertions(+), 88 deletions(-) create mode 100644 .golangci.yml diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 00000000..30e1fb1b --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,37 @@ +# options for analysis running +# full configuration example can be found at https://github.com/golangci/golangci-lint/blob/master/.golangci.example.yml +run: + # timeout for analysis, e.g. 30s, 5m, default is 1m + timeout: 10m + concurrency: 4 + go: "1.22" + + +# all available settings of specific linters +linters-settings: + + misspell: + # Correct spellings using locale preferences for US or UK. + # Default is to use a neutral variety of English. + # Setting locale to US will correct the British spelling of 'colour' to 'color'. + locale: US + ignore-words: + - licence + - licences + - utilisation + - cancelled + + staticcheck: + # https://staticcheck.io/docs/options#checks + checks: ["all", "-SA1019", "-SA5012"] + + +linters: + disable-all: true + enable: + - staticcheck + - goimports + - ineffassign + - unused + - unconvert + - misspell diff --git a/Makefile b/Makefile index 204d10ab..8181704e 100644 --- a/Makefile +++ b/Makefile @@ -159,3 +159,8 @@ delete-local-be: ## Creates local BE instance and starts e2e tests. Note! Only f new-changelog-entry: ## Create a new entry for unreleased element @echo ${PATH} docker run -it -v $(CURDIR):/cycloid-cli -w /cycloid-cli cycloid/cycloid-toolkit changie new + +.PHONY: lint +lint: ## Lint the source code + @echo -e "Running golangci-lint" + @golangci-lint run -v diff --git a/cmd/cycloid/common/flags.go b/cmd/cycloid/common/flags.go index 1c3b8c2d..b79ae388 100644 --- a/cmd/cycloid/common/flags.go +++ b/cmd/cycloid/common/flags.go @@ -10,8 +10,8 @@ import ( ) var ( - projectFlag, envFlag, orgFlag, credFlag, canFlag string - idFlag uint32 + projectFlag, envFlag, credFlag, canFlag string + idFlag uint32 ) func GetOrg(cmd *cobra.Command) (org string, err error) { @@ -29,7 +29,7 @@ func GetOrg(cmd *cobra.Command) (org string, err error) { func WithFlagProject(cmd *cobra.Command) string { flagName := "project" - cmd.PersistentFlags().StringVar(&projectFlag, flagName, "", "Project cannonical name") + cmd.PersistentFlags().StringVar(&projectFlag, flagName, "", "Project canonical name") return flagName } diff --git a/cmd/cycloid/creds/get.go b/cmd/cycloid/creds/get.go index 0fcc750a..cea7a00b 100644 --- a/cmd/cycloid/creds/get.go +++ b/cmd/cycloid/creds/get.go @@ -56,5 +56,5 @@ func get(cmd *cobra.Command, args []string) error { } c, err := m.GetCredential(org, can) - return printer.SmartPrint(p, c, err, "unable to get credential", printer.Options{}, cmd.OutOrStdout()) + return printer.SmartPrint(p, c, err, "unable to get credential", printer.Options{}, cmd.OutOrStdout()) } diff --git a/cmd/cycloid/external-backends/common.go b/cmd/cycloid/external-backends/common.go index 4c448535..1559b972 100644 --- a/cmd/cycloid/external-backends/common.go +++ b/cmd/cycloid/external-backends/common.go @@ -7,8 +7,6 @@ var ( regionFlag string awsBucketName string awsBucketPath string - gcpBucketName string - gcpBucketPath string awsS3BucketEndpoint string urls []string prefilters map[string]string diff --git a/cmd/cycloid/external-backends/create_events.go b/cmd/cycloid/external-backends/create_events.go index 024331a5..53b77f30 100644 --- a/cmd/cycloid/external-backends/create_events.go +++ b/cmd/cycloid/external-backends/create_events.go @@ -18,11 +18,11 @@ func createEvents(cmd *cobra.Command, args []string) error { m := middleware.NewMiddleware(api) var ( - err error - cred string - purpose = "events" - ebC models.ExternalBackendConfiguration - engine = cmd.CalledAs() + err error + cred string + purpose = "events" + ebC models.ExternalBackendConfiguration + engine = cmd.CalledAs() ) org, err := common.GetOrg(cmd) diff --git a/cmd/cycloid/infrapolicies/common.go b/cmd/cycloid/infrapolicies/common.go index f28a0384..a7ac31f2 100644 --- a/cmd/cycloid/infrapolicies/common.go +++ b/cmd/cycloid/infrapolicies/common.go @@ -8,7 +8,7 @@ var ( nameFlag string ownerFlag string severityFlag string - cannonicalFlag string + canonicalFlag string descriptionFlag string enabledFlag bool ) @@ -33,7 +33,7 @@ func WithFlagName(cmd *cobra.Command) string { func WithFlagOwner(cmd *cobra.Command) string { flagName := "owner" - cmd.PersistentFlags().StringVar(&ownerFlag, flagName, "", "InfraPolicy's owner cannonical") + cmd.PersistentFlags().StringVar(&ownerFlag, flagName, "", "InfraPolicy's owner canonical") return flagName } @@ -43,9 +43,9 @@ func WithFlagSeverity(cmd *cobra.Command) string { return flagName } -func WithFlagCannonical(cmd *cobra.Command) string { - flagName := "cannonical" - cmd.PersistentFlags().StringVar(&cannonicalFlag, flagName, "", "InfraPolicy's cannonical") +func WithFlagcanonical(cmd *cobra.Command) string { + flagName := "canonical" + cmd.PersistentFlags().StringVar(&canonicalFlag, flagName, "", "InfraPolicy's canonical") return flagName } @@ -57,6 +57,6 @@ func WithFlagDescription(cmd *cobra.Command) string { func WithFlagEnabled(cmd *cobra.Command) string { flagName := "enabled" - cmd.PersistentFlags().BoolVar(&enabledFlag, flagName, false, "Wheter to enable or not the infraPolicy. Note! You have to specify enabled=true|false enabled false|true doesn't work") + cmd.PersistentFlags().BoolVar(&enabledFlag, flagName, false, "Whether to enable or not the infraPolicy. Note! You have to specify enabled=true|false enabled false|true doesn't work") return flagName } diff --git a/cmd/cycloid/infrapolicies/create.go b/cmd/cycloid/infrapolicies/create.go index 9fafb8de..475bb90c 100644 --- a/cmd/cycloid/infrapolicies/create.go +++ b/cmd/cycloid/infrapolicies/create.go @@ -13,7 +13,8 @@ import ( // NewCreateCommand returns the cobra command // to create a new infrapolicy using a file // Note! For boolean flags it is required var=bool -// https://github.com/spf13/cobra/issues/613 +// +// https://github.com/spf13/cobra/issues/613 func NewCreateCommand() *cobra.Command { var cmd = &cobra.Command{ @@ -25,7 +26,7 @@ func NewCreateCommand() *cobra.Command { --policy-path /path/to/file/file.rego \ --name my-policy --description "an awesome infrapolicy" \ - --owner user_cannonical \ + --owner user_canonical \ --severity "advisory" \ --enabled=true `, @@ -37,7 +38,7 @@ func NewCreateCommand() *cobra.Command { common.RequiredFlag(WithFlagOwner, cmd) common.RequiredFlag(WithFlagSeverity, cmd) - WithFlagCannonical(cmd) + WithFlagcanonical(cmd) WithFlagDescription(cmd) WithFlagEnabled(cmd) @@ -74,7 +75,7 @@ func create(cmd *cobra.Command, args []string) error { return err } - cannonical, err := cmd.Flags().GetString("cannonical") + canonical, err := cmd.Flags().GetString("canonical") if err != nil { return err } @@ -101,7 +102,7 @@ func create(cmd *cobra.Command, args []string) error { return errors.Wrap(err, "unable to get printer") } - res, err := m.CreateInfraPolicy(org, policyPath, cannonical, description, name, owner, severity, enabled) + res, err := m.CreateInfraPolicy(org, policyPath, canonical, description, name, owner, severity, enabled) return printer.SmartPrint(p, res, err, "unable to create infrapolicy", printer.Options{}, cmd.OutOrStdout()) } diff --git a/cmd/cycloid/infrapolicies/delete.go b/cmd/cycloid/infrapolicies/delete.go index ecf65619..23327fd6 100644 --- a/cmd/cycloid/infrapolicies/delete.go +++ b/cmd/cycloid/infrapolicies/delete.go @@ -20,12 +20,12 @@ func NewDeleteCommand() *cobra.Command { Example: ` # create a infrapolicy my_policy cy --org my-org ip delete \ - --cannonical my_policy + --canonical my_policy `, RunE: delete, PreRunE: internal.CheckAPIAndCLIVersion, } - common.RequiredFlag(WithFlagCannonical, cmd) + common.RequiredFlag(WithFlagcanonical, cmd) return cmd @@ -40,7 +40,7 @@ func delete(cmd *cobra.Command, args []string) error { return err } - cannonical, err := cmd.Flags().GetString("cannonical") + canonical, err := cmd.Flags().GetString("canonical") if err != nil { return err } @@ -57,7 +57,7 @@ func delete(cmd *cobra.Command, args []string) error { return errors.Wrap(err, "unable to get printer") } - err = m.DeleteInfraPolicy(org, cannonical) + err = m.DeleteInfraPolicy(org, canonical) return printer.SmartPrint(p, nil, err, "unable to delete infrapolicy", printer.Options{}, cmd.OutOrStdout()) } diff --git a/cmd/cycloid/infrapolicies/get.go b/cmd/cycloid/infrapolicies/get.go index 542837be..9cade81e 100644 --- a/cmd/cycloid/infrapolicies/get.go +++ b/cmd/cycloid/infrapolicies/get.go @@ -20,12 +20,12 @@ func NewGetCommand() *cobra.Command { Example: ` # get a infrapolicy my_policy cy --org my-org ip get \ - --cannonical my_policy + --canonical my_policy `, RunE: get, PreRunE: internal.CheckAPIAndCLIVersion, } - common.RequiredFlag(WithFlagCannonical, cmd) + common.RequiredFlag(WithFlagcanonical, cmd) return cmd @@ -40,7 +40,7 @@ func get(cmd *cobra.Command, args []string) error { return err } - cannonical, err := cmd.Flags().GetString("cannonical") + canonical, err := cmd.Flags().GetString("canonical") if err != nil { return err } @@ -57,7 +57,7 @@ func get(cmd *cobra.Command, args []string) error { return errors.Wrap(err, "unable to get printer") } - res, err := m.GetInfraPolicy(org, cannonical) + res, err := m.GetInfraPolicy(org, canonical) return printer.SmartPrint(p, res, err, "unable to get infrapolicy", printer.Options{}, cmd.OutOrStdout()) } diff --git a/cmd/cycloid/infrapolicies/list.go b/cmd/cycloid/infrapolicies/list.go index 74f56424..ce49670d 100644 --- a/cmd/cycloid/infrapolicies/list.go +++ b/cmd/cycloid/infrapolicies/list.go @@ -10,19 +10,19 @@ import ( "github.com/spf13/cobra" ) -// NewLIstCommand returns the cobra command -// to list the infrapolicies in a organisation +// NewListCommand returns the cobra command +// to list the infrapolicies in a organization func NewListCommand() *cobra.Command { var cmd = &cobra.Command{ Use: "list", Short: "list infrapolicies", Example: ` - # list all infrapolicies in an organisation - cy --org my-org ip list -ouput=table|json|yaml + # list all infrapolicies in an organization + cy --org my-org ip list -output=table|json|yaml # parse the result using - cy --org my-org ip list -ouput=json | jq --color-output . + cy --org my-org ip list -output=json | jq --color-output . `, RunE: list, PreRunE: internal.CheckAPIAndCLIVersion, diff --git a/cmd/cycloid/infrapolicies/update.go b/cmd/cycloid/infrapolicies/update.go index 6d10f72e..6ed7622d 100644 --- a/cmd/cycloid/infrapolicies/update.go +++ b/cmd/cycloid/infrapolicies/update.go @@ -13,27 +13,28 @@ import ( // NewUpdateCommand returns the cobra command // to update a infrapolicy // Note! For boolean flags it is required var=bool -// https://github.com/spf13/cobra/issues/613 +// +// https://github.com/spf13/cobra/issues/613 func NewUpdateCommand() *cobra.Command { var cmd = &cobra.Command{ Use: "update", Short: "update a infrapolicy", Example: ` - # update an existent infrapolicy with cannonical my_policy + # update an existent infrapolicy with canonical my_policy cy --org my-org ip update \ - --cannonical my_policy + --canonical my_policy --policy-path /path/to/file/file.rego \ --name my-policy --description "an awesome infrapolicy" \ - --owner user_cannonical \ + --owner user_canonical \ --severity "advisory" \ --enabled=true `, RunE: update, PreRunE: internal.CheckAPIAndCLIVersion, } - common.RequiredFlag(WithFlagCannonical, cmd) + common.RequiredFlag(WithFlagcanonical, cmd) WithFlagPolicyPath(cmd) WithFlagName(cmd) @@ -75,7 +76,7 @@ func update(cmd *cobra.Command, args []string) error { return err } - cannonical, err := cmd.Flags().GetString("cannonical") + canonical, err := cmd.Flags().GetString("canonical") if err != nil { return err } @@ -102,7 +103,7 @@ func update(cmd *cobra.Command, args []string) error { return errors.Wrap(err, "unable to get printer") } - res, err := m.UpdateInfraPolicy(org, cannonical, policyPath, description, name, owner, severity, enabled) + res, err := m.UpdateInfraPolicy(org, canonical, policyPath, description, name, owner, severity, enabled) return printer.SmartPrint(p, res, err, "unable to update infrapolicy", printer.Options{}, cmd.OutOrStdout()) } diff --git a/cmd/cycloid/login/list.go b/cmd/cycloid/login/list.go index bf6183de..9cbd4123 100644 --- a/cmd/cycloid/login/list.go +++ b/cmd/cycloid/login/list.go @@ -50,7 +50,7 @@ func list(output string) error { Name string Token string }{ - Name: name, + Name: name, // Special formatting to display only the 7 last chars of a token Token: o.Token[len(o.Token)-7:], }) diff --git a/cmd/cycloid/middleware/infra-policies.go b/cmd/cycloid/middleware/infra-policies.go index 58fa2a10..1507c1a1 100644 --- a/cmd/cycloid/middleware/infra-policies.go +++ b/cmd/cycloid/middleware/infra-policies.go @@ -40,7 +40,7 @@ func (m *middleware) ValidateInfraPolicies(org, project, env string, plan []byte // CreateInfraPoliciy will create a new infraPolicy // with the rego file suplied -func (m *middleware) CreateInfraPolicy(org, policyFile, policyCanonical, description, policyName, ownerCannonical, severity string, enabled bool) (*models.InfraPolicy, error) { +func (m *middleware) CreateInfraPolicy(org, policyFile, policyCanonical, description, policyName, ownercanonical, severity string, enabled bool) (*models.InfraPolicy, error) { params := organization_infrastructure_policies.NewCreateInfraPolicyParams() params.SetOrganizationCanonical(org) // Reads file content and converts it into string @@ -48,7 +48,7 @@ func (m *middleware) CreateInfraPolicy(org, policyFile, policyCanonical, descrip if err != nil { return nil, fmt.Errorf("Unable to read rego file: %v", err) } - // If cannonical empty,use the default one + // If canonical empty,use the default one if policyCanonical == "" { policyCanonical = common.GenerateCanonical(policyName) } @@ -60,7 +60,7 @@ func (m *middleware) CreateInfraPolicy(org, policyFile, policyCanonical, descrip Description: description, Enabled: enabled, Name: &policyName, - Owner: &ownerCannonical, + Owner: &ownercanonical, Severity: &severity, } @@ -86,10 +86,10 @@ func (m *middleware) CreateInfraPolicy(org, policyFile, policyCanonical, descrip } // DeleteInfraPolicy will delete a infraPolicy -func (m *middleware) DeleteInfraPolicy(org, policyCannonical string) error { +func (m *middleware) DeleteInfraPolicy(org, policycanonical string) error { params := organization_infrastructure_policies.NewDeleteInfraPolicyParams() params.SetOrganizationCanonical(org) - params.SetInfraPolicyCanonical(policyCannonical) + params.SetInfraPolicyCanonical(policycanonical) _, err := m.api.OrganizationInfrastructurePolicies.DeleteInfraPolicy(params, m.api.Credentials(&org)) if err != nil { @@ -98,7 +98,7 @@ func (m *middleware) DeleteInfraPolicy(org, policyCannonical string) error { return nil } -// ListInfraPolicies will list all infraPolicies in an organisation +// ListInfraPolicies will list all infraPolicies in an organization func (m *middleware) ListInfraPolicies(org string) ([]*models.InfraPolicy, error) { params := organization_infrastructure_policies.NewGetInfraPoliciesParams() @@ -120,7 +120,7 @@ func (m *middleware) ListInfraPolicies(org string) ([]*models.InfraPolicy, error return d, nil } -// GetInfraPolicy will list all infraPolicies in an organisation +// GetInfraPolicy will list all infraPolicies in an organization func (m *middleware) GetInfraPolicy(org, infraPolicy string) (*models.InfraPolicy, error) { params := organization_infrastructure_policies.NewGetInfraPolicyParams() @@ -144,7 +144,7 @@ func (m *middleware) GetInfraPolicy(org, infraPolicy string) (*models.InfraPolic } // UpdateInfraPolicy will update an existing infrapolicy with the given params -func (m *middleware) UpdateInfraPolicy(org, infraPolicy, policyFile, description, policyName, ownerCannonical, severity string, enabled bool) (*models.InfraPolicy, error) { +func (m *middleware) UpdateInfraPolicy(org, infraPolicy, policyFile, description, policyName, ownercanonical, severity string, enabled bool) (*models.InfraPolicy, error) { params := organization_infrastructure_policies.NewUpdateInfraPolicyParams() params.SetOrganizationCanonical(org) @@ -162,7 +162,7 @@ func (m *middleware) UpdateInfraPolicy(org, infraPolicy, policyFile, description Description: &description, Enabled: &enabled, Name: &policyName, - Owner: &ownerCannonical, + Owner: &ownercanonical, Severity: &severity, } diff --git a/cmd/cycloid/middleware/middleware.go b/cmd/cycloid/middleware/middleware.go index 52d7f053..337f7f72 100644 --- a/cmd/cycloid/middleware/middleware.go +++ b/cmd/cycloid/middleware/middleware.go @@ -108,11 +108,11 @@ type Middleware interface { // ValidateInfraPolicies will validate the TF plan against OPA policies defined on the Cycloid server ValidateInfraPolicies(org, project, env string, plan []byte) (*models.InfraPoliciesValidationResult, error) // CreateInfraPolicy will create a new infraPolicy with the repo file supplied - CreateInfraPolicy(org, policyFile, policyCanonical, description, policyName, ownerCannonical, severity string, enabled bool) (*models.InfraPolicy, error) - DeleteInfraPolicy(org, policyCannonical string) error + CreateInfraPolicy(org, policyFile, policyCanonical, description, policyName, ownercanonical, severity string, enabled bool) (*models.InfraPolicy, error) + DeleteInfraPolicy(org, policycanonical string) error ListInfraPolicies(org string) ([]*models.InfraPolicy, error) GetInfraPolicy(org, infraPolicy string) (*models.InfraPolicy, error) - UpdateInfraPolicy(org, infraPolicy, policyFile, description, policyName, ownerCannonical, severity string, enabled bool) (*models.InfraPolicy, error) + UpdateInfraPolicy(org, infraPolicy, policyFile, description, policyName, ownercanonical, severity string, enabled bool) (*models.InfraPolicy, error) // CostEstimation will consume the backend API endpoint for cost estimation CostEstimation(org string, plan []byte) (*models.CostEstimationResult, error) diff --git a/cmd/cycloid/middleware/pipeline.go b/cmd/cycloid/middleware/pipeline.go index f3790222..d2b1ac56 100644 --- a/cmd/cycloid/middleware/pipeline.go +++ b/cmd/cycloid/middleware/pipeline.go @@ -149,7 +149,7 @@ func (m *middleware) CreatePipeline(org, project, env, pipeline, variables, usec params.SetOrganizationCanonical(org) params.SetProjectCanonical(project) - vars := common.ReplaceCycloidVarsString(cyCtx, string(variables)) + vars := common.ReplaceCycloidVarsString(cyCtx, variables) pipelineName := common.GetPipelineName(project, env) diff --git a/cmd/cycloid/organizations/create.go b/cmd/cycloid/organizations/create.go index 10a25b97..c55406a2 100644 --- a/cmd/cycloid/organizations/create.go +++ b/cmd/cycloid/organizations/create.go @@ -15,8 +15,8 @@ import ( // Advanced user still can use it passing a user token in CY_TOKEN env var during a login. func NewCreateCommand() *cobra.Command { var cmd = &cobra.Command{ - Use: "create", - Short: "create an organization", + Use: "create", + Short: "create an organization", Hidden: true, Example: ` # create an organization foo diff --git a/cmd/cycloid/organizations/delete.go b/cmd/cycloid/organizations/delete.go index dda49147..e91e5db6 100644 --- a/cmd/cycloid/organizations/delete.go +++ b/cmd/cycloid/organizations/delete.go @@ -13,8 +13,8 @@ import ( func NewDeleteCommand() *cobra.Command { var cmd = &cobra.Command{ - Use: "delete", - Short: "delete an organization", + Use: "delete", + Short: "delete an organization", Hidden: true, Example: ` # delete an organization with canonical name my-org diff --git a/cmd/cycloid/organizations/list-children.go b/cmd/cycloid/organizations/list-children.go index c00489ad..530e4fd4 100644 --- a/cmd/cycloid/organizations/list-children.go +++ b/cmd/cycloid/organizations/list-children.go @@ -13,11 +13,11 @@ import ( func NewListChildrensCommand() *cobra.Command { var cmd = &cobra.Command{ - Use: "list-children", + Use: "list-children", Aliases: []string{ "list-childrens", }, - Short: "list the organization childrens", + Short: "list the organization children", RunE: listChildrens, PreRunE: internal.CheckAPIAndCLIVersion, } diff --git a/cmd/cycloid/organizations/list.go b/cmd/cycloid/organizations/list.go index 782c98d6..83b18cc8 100644 --- a/cmd/cycloid/organizations/list.go +++ b/cmd/cycloid/organizations/list.go @@ -13,9 +13,9 @@ import ( func NewListCommand() *cobra.Command { var cmd = &cobra.Command{ - Use: "list", - Short: "list the organizations", - RunE: list, + Use: "list", + Short: "list the organizations", + RunE: list, Hidden: true, Example: ` # list the organizations diff --git a/cmd/cycloid/pipelines/helpers.go b/cmd/cycloid/pipelines/helpers.go index 95451080..842f4bfa 100644 --- a/cmd/cycloid/pipelines/helpers.go +++ b/cmd/cycloid/pipelines/helpers.go @@ -10,13 +10,13 @@ import ( // only an interface{}. As we are looking for a specific field only, we use this hack to go through different map layers // to get the pipeline variables path type ppVarPath struct { - Destination string `json:",destination"` + Destination string `json:"destination"` } type ppVar struct { - Variables ppVarPath `json:",variables"` + Variables ppVarPath `json:"variables"` } type pp struct { - Pipeline ppVar `json:",pipeline"` + Pipeline ppVar `json:"pipeline"` } // GetPipelineVarsPath get pipeline variables path to use in a config repository @@ -25,9 +25,15 @@ func GetPipelineVarsPath(m middleware.Middleware, org, project, usecase string) // Get stack ref proj, err := m.GetProject(org, project) + if err != nil { + return "", err + } // Get stack config sc, err := m.GetStackConfig(org, *proj.ServiceCatalog.Ref) + if err != nil { + return "", err + } scJson, err := json.Marshal(sc) if err != nil { diff --git a/cmd/cycloid/projects/create-env.go b/cmd/cycloid/projects/create-env.go index 9e6e15d1..08c809c9 100644 --- a/cmd/cycloid/projects/create-env.go +++ b/cmd/cycloid/projects/create-env.go @@ -348,6 +348,9 @@ func createEnv(cmd *cobra.Command, args []string) error { inputs, *projectData.UpdatedAt, ) + if err != nil { + return errors.Wrap(err, "failed to send config to backend") + } errMsg := "failed to send config accepted by backend, returning inputs instead." config, err := m.GetProjectConfig(org, project, env) diff --git a/cmd/cycloid/projects/get-env.go b/cmd/cycloid/projects/get-env.go index c5c0d776..53c3b15f 100644 --- a/cmd/cycloid/projects/get-env.go +++ b/cmd/cycloid/projects/get-env.go @@ -60,14 +60,14 @@ cy --org my-org project get-env-config my-project my-project use_case -o yaml`, func getEnvConfig(cmd *cobra.Command, args []string) error { // Flags have precedence over args - project, err := cmd.Flags().GetString("project") + project, _ := cmd.Flags().GetString("project") if len(args) >= 1 && project == "" { project = args[0] } else if project == "" { return fmt.Errorf("missing project argument") } - env, err := cmd.Flags().GetString("env") + env, _ := cmd.Flags().GetString("env") if len(args) == 2 && env == "" { env = args[1] } else if env == "" { diff --git a/cmd/cycloid/stacks/get-config.go b/cmd/cycloid/stacks/get-config.go index a7c93cb7..9aa114d6 100644 --- a/cmd/cycloid/stacks/get-config.go +++ b/cmd/cycloid/stacks/get-config.go @@ -70,14 +70,14 @@ func getConfig(cmd *cobra.Command, args []string) error { return err } - ref, err := cmd.Flags().GetString("ref") + ref, _ := cmd.Flags().GetString("ref") if len(args) >= 1 && ref == "" { ref = args[0] } else if ref == "" { return fmt.Errorf("missing ref argument.") } - useCase, err := cmd.Flags().GetString("use-case") + useCase, _ := cmd.Flags().GetString("use-case") if len(args) == 2 && useCase == "" { useCase = args[1] } else if useCase == "" { diff --git a/cmd/cycloid/stacks/get.go b/cmd/cycloid/stacks/get.go index 6f8b4ebc..f591829f 100644 --- a/cmd/cycloid/stacks/get.go +++ b/cmd/cycloid/stacks/get.go @@ -58,5 +58,3 @@ func get(cmd *cobra.Command, args []string) error { s, err := m.GetStack(org, ref) return printer.SmartPrint(p, s, err, "unable to get stack", printer.Options{}, cmd.OutOrStdout()) } - - diff --git a/e2e/infra_policies_test.go b/e2e/infra_policies_test.go index 1051057a..74aa6731 100644 --- a/e2e/infra_policies_test.go +++ b/e2e/infra_policies_test.go @@ -15,7 +15,7 @@ func TestInfraPolicies(t *testing.T) { // Checks the succesfull creation of a new infrapolicy // The test validates that the reply of the create method - // contains the cannonical of the created infrapolicy + // contains the canonical of the created infrapolicy t.Run("SuccessInfraPolicyCreate", func(t *testing.T) { WriteFile("/tmp/test-cli-ip.rego", TestInfraPolicySample) @@ -46,7 +46,7 @@ func TestInfraPolicies(t *testing.T) { "--org", CY_TEST_ROOT_ORG, "ip", "get", - "--cannonical", "test", + "--canonical", "test", }) assert.Nil(t, cmdErr) @@ -80,7 +80,7 @@ func TestInfraPolicies(t *testing.T) { "--org", CY_TEST_ROOT_ORG, "ip", "update", - "--cannonical", "test", + "--canonical", "test", "--policy-path", "/tmp/test-cli-ip.rego", "--name", "test", "--description", "changed description", @@ -103,7 +103,7 @@ func TestInfraPolicies(t *testing.T) { "--org", CY_TEST_ROOT_ORG, "ip", "delete", - "--cannonical", "test", + "--canonical", "test", }) assert.Nil(t, cmdErr) diff --git a/main.go b/main.go index 4bb757c9..36110292 100644 --- a/main.go +++ b/main.go @@ -5,19 +5,12 @@ import ( "os" "github.com/cycloidio/cycloid-cli/cmd" - "github.com/cycloidio/cycloid-cli/internal/version" "github.com/spf13/cobra" "github.com/spf13/viper" ) var ( // Used for flags. - cfgFile string - userOutput string - verbosity string - - versionString = fmt.Sprintf("%s, revision %s, branch %s, date %s; go %s", version.Version, version.Revision, version.Branch, version.BuildDate, version.GoVersion) - rootCmd *cobra.Command ) diff --git a/printer/options.go b/printer/options.go index c25f0c2e..e3a78f9a 100644 --- a/printer/options.go +++ b/printer/options.go @@ -2,4 +2,4 @@ package printer // Options is the struct used // to pass options to the printer -type Options struct {} +type Options struct{} diff --git a/printer/printer.go b/printer/printer.go index 3abcb85f..dac1303b 100644 --- a/printer/printer.go +++ b/printer/printer.go @@ -5,6 +5,7 @@ import ( "github.com/pkg/errors" ) + // Printer is an interface that knows how to print runtime objects type Printer interface { // Print will write the object in the writer using the given options diff --git a/printer/table/printer.go b/printer/table/printer.go index ed7f9ab7..c64620e1 100644 --- a/printer/table/printer.go +++ b/printer/table/printer.go @@ -113,7 +113,7 @@ func generate(obj interface{}, opts printer.Options) ([]string, [][]string, erro // the object is a pointer to a struct: // example: *models.ExternalBackend case reflect.Ptr: - // we need to get the Value targetted by this pointer + // we need to get the Value targeted by this pointer elt := rObj.Elem() headers = headersFromStruct(elt, opts) entries = make([][]string, 1) diff --git a/printer/table/printer_test.go b/printer/table/printer_test.go index b5dcdca4..f5fefd3a 100644 --- a/printer/table/printer_test.go +++ b/printer/table/printer_test.go @@ -54,7 +54,7 @@ value a value b abc err := tab.Print(&obj, printer.Options{}, &b) require.NoError(t, err) - assert.Contains(t, b.String(), string(exptNow)) + assert.Contains(t, b.String(), exptNow) }) t.Run("SuccessAvoidNestedStruct", func(t *testing.T) { var ( From e0e5f346dd90f966e73ba11e61106a2cf2b5441b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Opasiak?= Date: Mon, 15 Jul 2024 10:42:58 +0200 Subject: [PATCH 02/71] changelog: add entry for #285 --- changelog/unreleased/Other-ADDED-20240715-084249.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 changelog/unreleased/Other-ADDED-20240715-084249.yaml diff --git a/changelog/unreleased/Other-ADDED-20240715-084249.yaml b/changelog/unreleased/Other-ADDED-20240715-084249.yaml new file mode 100644 index 00000000..278b0f24 --- /dev/null +++ b/changelog/unreleased/Other-ADDED-20240715-084249.yaml @@ -0,0 +1,8 @@ +component: Other +kind: ADDED +body: Added linter for the CLI code +time: 2024-07-15T08:42:49.392878258Z +custom: + DETAILS: "" + PR: "285" + TYPE: CLI From 2ec27cd7add928ae1897687a71e11641eeb2ecf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Opasiak?= Date: Mon, 15 Jul 2024 11:00:54 +0200 Subject: [PATCH 03/71] add code formatters (gci, goimports) --- Makefile | 5 +++++ cmd/cycloid/catalog-repositories/get.go | 5 +++-- cmd/cycloid/common/helpers.go | 11 +++++------ cmd/cycloid/config-repositories/get.go | 5 +++-- cmd/cycloid/creds/update.go | 5 +++-- cmd/cycloid/external-backends/create.go | 3 ++- cmd/cycloid/external-backends/get.go | 3 ++- cmd/cycloid/external-backends/list.go | 7 +++---- cmd/cycloid/external-backends/update.go | 3 ++- cmd/cycloid/infrapolicies/create.go | 5 +++-- cmd/cycloid/infrapolicies/delete.go | 5 +++-- cmd/cycloid/infrapolicies/get.go | 5 +++-- cmd/cycloid/infrapolicies/list.go | 5 +++-- cmd/cycloid/infrapolicies/update.go | 5 +++-- cmd/cycloid/internal/version.go | 5 +++-- cmd/cycloid/middleware/catalog-repositories.go | 3 ++- cmd/cycloid/middleware/config-repositories.go | 3 ++- cmd/cycloid/middleware/creds.go | 3 ++- cmd/cycloid/middleware/errors_test.go | 3 ++- cmd/cycloid/middleware/event.go | 3 ++- cmd/cycloid/middleware/external-backends.go | 3 ++- cmd/cycloid/middleware/infra-policies.go | 3 ++- cmd/cycloid/middleware/kpi.go | 3 ++- cmd/cycloid/middleware/middleware.go | 3 ++- cmd/cycloid/middleware/pipeline.go | 3 ++- cmd/cycloid/middleware/project.go | 5 +++-- cmd/cycloid/middleware/roles.go | 3 ++- cmd/cycloid/middleware/stacks.go | 6 +++--- cmd/cycloid/pipelines/diff.go | 2 +- cmd/cycloid/pipelines/get-build.go | 3 ++- cmd/cycloid/pipelines/update.go | 3 +-- cmd/cycloid/projects/get-env.go | 5 +++-- cmd/cycloid/projects/list.go | 5 +++-- cmd/cycloid/projects/update.go | 3 ++- cmd/cycloid/stacks/validate-form.go | 5 +++-- e2e/events_test.go | 3 ++- main.go | 3 ++- printer/factory/factory_test.go | 5 +++-- printer/json/printer_test.go | 3 ++- printer/table/printer_test.go | 3 ++- printer/yaml/printer.go | 2 +- printer/yaml/printer_test.go | 3 ++- 42 files changed, 103 insertions(+), 66 deletions(-) diff --git a/Makefile b/Makefile index 8181704e..62e317b6 100644 --- a/Makefile +++ b/Makefile @@ -164,3 +164,8 @@ new-changelog-entry: ## Create a new entry for unreleased element lint: ## Lint the source code @echo -e "Running golangci-lint" @golangci-lint run -v + +.PHONY: format-go +format-go: + @gci write --skip-generated -s standard -s default -s "prefix(github.com/cycloidio)" . > /dev/null + @goimports -w -local github.com/cycloidio . diff --git a/cmd/cycloid/catalog-repositories/get.go b/cmd/cycloid/catalog-repositories/get.go index 91a2bb1e..c0eabf4b 100644 --- a/cmd/cycloid/catalog-repositories/get.go +++ b/cmd/cycloid/catalog-repositories/get.go @@ -1,12 +1,13 @@ package catalogRepositories import ( + "github.com/pkg/errors" + "github.com/spf13/cobra" + "github.com/cycloidio/cycloid-cli/cmd/cycloid/common" "github.com/cycloidio/cycloid-cli/cmd/cycloid/middleware" "github.com/cycloidio/cycloid-cli/printer" "github.com/cycloidio/cycloid-cli/printer/factory" - "github.com/pkg/errors" - "github.com/spf13/cobra" ) func NewGetCommand() *cobra.Command { diff --git a/cmd/cycloid/common/helpers.go b/cmd/cycloid/common/helpers.go index 56fcf449..4b1d303d 100644 --- a/cmd/cycloid/common/helpers.go +++ b/cmd/cycloid/common/helpers.go @@ -2,23 +2,22 @@ package common import ( "fmt" + "net/url" "os" "reflect" "regexp" "strings" - "net/url" - - "github.com/cycloidio/cycloid-cli/client/client" - "github.com/cycloidio/cycloid-cli/client/models" - "github.com/cycloidio/cycloid-cli/config" "github.com/go-openapi/runtime" httptransport "github.com/go-openapi/runtime/client" + strfmt "github.com/go-openapi/strfmt" "github.com/pkg/errors" "github.com/spf13/cobra" "github.com/spf13/viper" - strfmt "github.com/go-openapi/strfmt" + "github.com/cycloidio/cycloid-cli/client/client" + "github.com/cycloidio/cycloid-cli/client/models" + "github.com/cycloidio/cycloid-cli/config" ) var orgRe = regexp.MustCompile(`\(\$ organization_canonical \$\)`) diff --git a/cmd/cycloid/config-repositories/get.go b/cmd/cycloid/config-repositories/get.go index 905c55fd..ec9979ef 100644 --- a/cmd/cycloid/config-repositories/get.go +++ b/cmd/cycloid/config-repositories/get.go @@ -1,13 +1,14 @@ package configRepositories import ( + "github.com/pkg/errors" + "github.com/spf13/cobra" + "github.com/cycloidio/cycloid-cli/cmd/cycloid/common" "github.com/cycloidio/cycloid-cli/cmd/cycloid/internal" "github.com/cycloidio/cycloid-cli/cmd/cycloid/middleware" "github.com/cycloidio/cycloid-cli/printer" "github.com/cycloidio/cycloid-cli/printer/factory" - "github.com/pkg/errors" - "github.com/spf13/cobra" ) func NewGetCommand() *cobra.Command { diff --git a/cmd/cycloid/creds/update.go b/cmd/cycloid/creds/update.go index 5996eb7c..b6a6d221 100644 --- a/cmd/cycloid/creds/update.go +++ b/cmd/cycloid/creds/update.go @@ -6,14 +6,15 @@ import ( "os" "strings" + "github.com/pkg/errors" + "github.com/spf13/cobra" + "github.com/cycloidio/cycloid-cli/client/models" "github.com/cycloidio/cycloid-cli/cmd/cycloid/common" "github.com/cycloidio/cycloid-cli/cmd/cycloid/internal" "github.com/cycloidio/cycloid-cli/cmd/cycloid/middleware" "github.com/cycloidio/cycloid-cli/printer" "github.com/cycloidio/cycloid-cli/printer/factory" - "github.com/pkg/errors" - "github.com/spf13/cobra" ) func NewUpdateCommand() *cobra.Command { diff --git a/cmd/cycloid/external-backends/create.go b/cmd/cycloid/external-backends/create.go index a9322109..110ef81a 100644 --- a/cmd/cycloid/external-backends/create.go +++ b/cmd/cycloid/external-backends/create.go @@ -1,9 +1,10 @@ package externalBackends import ( + "github.com/spf13/cobra" + "github.com/cycloidio/cycloid-cli/cmd/cycloid/common" "github.com/cycloidio/cycloid-cli/cmd/cycloid/internal" - "github.com/spf13/cobra" ) const noDefault = false diff --git a/cmd/cycloid/external-backends/get.go b/cmd/cycloid/external-backends/get.go index baa5f10d..00b00f34 100644 --- a/cmd/cycloid/external-backends/get.go +++ b/cmd/cycloid/external-backends/get.go @@ -3,8 +3,9 @@ package externalBackends import ( "fmt" - "github.com/cycloidio/cycloid-cli/cmd/cycloid/internal" "github.com/spf13/cobra" + + "github.com/cycloidio/cycloid-cli/cmd/cycloid/internal" ) func NewGetCommand() *cobra.Command { diff --git a/cmd/cycloid/external-backends/list.go b/cmd/cycloid/external-backends/list.go index e296f18e..07b5e097 100644 --- a/cmd/cycloid/external-backends/list.go +++ b/cmd/cycloid/external-backends/list.go @@ -1,15 +1,14 @@ package externalBackends import ( + "github.com/pkg/errors" + "github.com/spf13/cobra" + "github.com/cycloidio/cycloid-cli/cmd/cycloid/common" "github.com/cycloidio/cycloid-cli/cmd/cycloid/internal" "github.com/cycloidio/cycloid-cli/cmd/cycloid/middleware" "github.com/cycloidio/cycloid-cli/printer" "github.com/cycloidio/cycloid-cli/printer/factory" - - "github.com/spf13/cobra" - - "github.com/pkg/errors" ) var ( diff --git a/cmd/cycloid/external-backends/update.go b/cmd/cycloid/external-backends/update.go index 640bb4a8..ded3571e 100644 --- a/cmd/cycloid/external-backends/update.go +++ b/cmd/cycloid/external-backends/update.go @@ -3,8 +3,9 @@ package externalBackends import ( "fmt" - "github.com/cycloidio/cycloid-cli/cmd/cycloid/internal" "github.com/spf13/cobra" + + "github.com/cycloidio/cycloid-cli/cmd/cycloid/internal" ) func NewUpdateCommand() *cobra.Command { diff --git a/cmd/cycloid/infrapolicies/create.go b/cmd/cycloid/infrapolicies/create.go index 475bb90c..5ade724a 100644 --- a/cmd/cycloid/infrapolicies/create.go +++ b/cmd/cycloid/infrapolicies/create.go @@ -1,13 +1,14 @@ package infrapolicies import ( + "github.com/pkg/errors" + "github.com/spf13/cobra" + "github.com/cycloidio/cycloid-cli/cmd/cycloid/common" "github.com/cycloidio/cycloid-cli/cmd/cycloid/internal" "github.com/cycloidio/cycloid-cli/cmd/cycloid/middleware" "github.com/cycloidio/cycloid-cli/printer" "github.com/cycloidio/cycloid-cli/printer/factory" - "github.com/pkg/errors" - "github.com/spf13/cobra" ) // NewCreateCommand returns the cobra command diff --git a/cmd/cycloid/infrapolicies/delete.go b/cmd/cycloid/infrapolicies/delete.go index 23327fd6..8419a725 100644 --- a/cmd/cycloid/infrapolicies/delete.go +++ b/cmd/cycloid/infrapolicies/delete.go @@ -1,13 +1,14 @@ package infrapolicies import ( + "github.com/pkg/errors" + "github.com/spf13/cobra" + "github.com/cycloidio/cycloid-cli/cmd/cycloid/common" "github.com/cycloidio/cycloid-cli/cmd/cycloid/internal" "github.com/cycloidio/cycloid-cli/cmd/cycloid/middleware" "github.com/cycloidio/cycloid-cli/printer" "github.com/cycloidio/cycloid-cli/printer/factory" - "github.com/pkg/errors" - "github.com/spf13/cobra" ) // NewDeleteCommand returns the cobra command diff --git a/cmd/cycloid/infrapolicies/get.go b/cmd/cycloid/infrapolicies/get.go index 9cade81e..43e4b2e1 100644 --- a/cmd/cycloid/infrapolicies/get.go +++ b/cmd/cycloid/infrapolicies/get.go @@ -1,13 +1,14 @@ package infrapolicies import ( + "github.com/pkg/errors" + "github.com/spf13/cobra" + "github.com/cycloidio/cycloid-cli/cmd/cycloid/common" "github.com/cycloidio/cycloid-cli/cmd/cycloid/internal" "github.com/cycloidio/cycloid-cli/cmd/cycloid/middleware" "github.com/cycloidio/cycloid-cli/printer" "github.com/cycloidio/cycloid-cli/printer/factory" - "github.com/pkg/errors" - "github.com/spf13/cobra" ) // NewGetCommand returns the cobra command diff --git a/cmd/cycloid/infrapolicies/list.go b/cmd/cycloid/infrapolicies/list.go index ce49670d..ab57809c 100644 --- a/cmd/cycloid/infrapolicies/list.go +++ b/cmd/cycloid/infrapolicies/list.go @@ -1,13 +1,14 @@ package infrapolicies import ( + "github.com/pkg/errors" + "github.com/spf13/cobra" + "github.com/cycloidio/cycloid-cli/cmd/cycloid/common" "github.com/cycloidio/cycloid-cli/cmd/cycloid/internal" "github.com/cycloidio/cycloid-cli/cmd/cycloid/middleware" "github.com/cycloidio/cycloid-cli/printer" "github.com/cycloidio/cycloid-cli/printer/factory" - "github.com/pkg/errors" - "github.com/spf13/cobra" ) // NewListCommand returns the cobra command diff --git a/cmd/cycloid/infrapolicies/update.go b/cmd/cycloid/infrapolicies/update.go index 6ed7622d..63ded2ce 100644 --- a/cmd/cycloid/infrapolicies/update.go +++ b/cmd/cycloid/infrapolicies/update.go @@ -1,13 +1,14 @@ package infrapolicies import ( + "github.com/pkg/errors" + "github.com/spf13/cobra" + "github.com/cycloidio/cycloid-cli/cmd/cycloid/common" "github.com/cycloidio/cycloid-cli/cmd/cycloid/internal" "github.com/cycloidio/cycloid-cli/cmd/cycloid/middleware" "github.com/cycloidio/cycloid-cli/printer" "github.com/cycloidio/cycloid-cli/printer/factory" - "github.com/pkg/errors" - "github.com/spf13/cobra" ) // NewUpdateCommand returns the cobra command diff --git a/cmd/cycloid/internal/version.go b/cmd/cycloid/internal/version.go index 3483565d..a5d9aaac 100644 --- a/cmd/cycloid/internal/version.go +++ b/cmd/cycloid/internal/version.go @@ -6,11 +6,12 @@ import ( "os" "regexp" + "github.com/spf13/cobra" + "github.com/spf13/viper" + "github.com/cycloidio/cycloid-cli/cmd/cycloid/common" "github.com/cycloidio/cycloid-cli/cmd/cycloid/middleware" "github.com/cycloidio/cycloid-cli/internal/version" - "github.com/spf13/cobra" - "github.com/spf13/viper" ) func Warning(out io.Writer, msg string) { diff --git a/cmd/cycloid/middleware/catalog-repositories.go b/cmd/cycloid/middleware/catalog-repositories.go index 90d46547..f6fb9648 100644 --- a/cmd/cycloid/middleware/catalog-repositories.go +++ b/cmd/cycloid/middleware/catalog-repositories.go @@ -1,9 +1,10 @@ package middleware import ( + strfmt "github.com/go-openapi/strfmt" + "github.com/cycloidio/cycloid-cli/client/client/organization_service_catalog_sources" "github.com/cycloidio/cycloid-cli/client/models" - strfmt "github.com/go-openapi/strfmt" ) func (m *middleware) ListCatalogRepositories(org string) ([]*models.ServiceCatalogSource, error) { diff --git a/cmd/cycloid/middleware/config-repositories.go b/cmd/cycloid/middleware/config-repositories.go index e2e4d9b5..982a62a1 100644 --- a/cmd/cycloid/middleware/config-repositories.go +++ b/cmd/cycloid/middleware/config-repositories.go @@ -3,10 +3,11 @@ package middleware import ( "strings" + strfmt "github.com/go-openapi/strfmt" + "github.com/cycloidio/cycloid-cli/client/client/organization_config_repositories" "github.com/cycloidio/cycloid-cli/client/models" "github.com/cycloidio/cycloid-cli/cmd/cycloid/common" - strfmt "github.com/go-openapi/strfmt" ) func (m *middleware) PushConfig(org string, project string, env string, configs map[string]strfmt.Base64) error { diff --git a/cmd/cycloid/middleware/creds.go b/cmd/cycloid/middleware/creds.go index a9ae9e75..ba2aa337 100644 --- a/cmd/cycloid/middleware/creds.go +++ b/cmd/cycloid/middleware/creds.go @@ -4,9 +4,10 @@ import ( "fmt" "regexp" + strfmt "github.com/go-openapi/strfmt" + "github.com/cycloidio/cycloid-cli/client/client/organization_credentials" "github.com/cycloidio/cycloid-cli/client/models" - strfmt "github.com/go-openapi/strfmt" ) func (m *middleware) CreateCredential(org, name, cType string, rawCred *models.CredentialRaw, path, can, description string) (*models.Credential, error) { diff --git a/cmd/cycloid/middleware/errors_test.go b/cmd/cycloid/middleware/errors_test.go index e03df5bc..1029fa08 100644 --- a/cmd/cycloid/middleware/errors_test.go +++ b/cmd/cycloid/middleware/errors_test.go @@ -4,10 +4,11 @@ import ( "fmt" "testing" + "github.com/stretchr/testify/assert" + "github.com/cycloidio/cycloid-cli/client/client/organizations" "github.com/cycloidio/cycloid-cli/client/models" "github.com/cycloidio/cycloid-cli/cmd/cycloid/middleware" - "github.com/stretchr/testify/assert" ) func ptrStr(s string) *string { return &s } diff --git a/cmd/cycloid/middleware/event.go b/cmd/cycloid/middleware/event.go index ed48a031..f2badea9 100644 --- a/cmd/cycloid/middleware/event.go +++ b/cmd/cycloid/middleware/event.go @@ -1,9 +1,10 @@ package middleware import ( + strfmt "github.com/go-openapi/strfmt" + "github.com/cycloidio/cycloid-cli/client/client/organizations" "github.com/cycloidio/cycloid-cli/client/models" - strfmt "github.com/go-openapi/strfmt" ) func (m *middleware) SendEvent(org, eventType, title, message, severity string, tags map[string]string, color string) error { diff --git a/cmd/cycloid/middleware/external-backends.go b/cmd/cycloid/middleware/external-backends.go index 202ad10b..ceee1252 100644 --- a/cmd/cycloid/middleware/external-backends.go +++ b/cmd/cycloid/middleware/external-backends.go @@ -3,9 +3,10 @@ package middleware import ( "errors" + "github.com/go-openapi/strfmt" + "github.com/cycloidio/cycloid-cli/client/client/organization_external_backends" "github.com/cycloidio/cycloid-cli/client/models" - "github.com/go-openapi/strfmt" ) func (m *middleware) GetRemoteTFExternalBackend(org string) (*models.ExternalBackend, error) { diff --git a/cmd/cycloid/middleware/infra-policies.go b/cmd/cycloid/middleware/infra-policies.go index 1507c1a1..69f813ee 100644 --- a/cmd/cycloid/middleware/infra-policies.go +++ b/cmd/cycloid/middleware/infra-policies.go @@ -4,10 +4,11 @@ import ( "fmt" "os" + strfmt "github.com/go-openapi/strfmt" + "github.com/cycloidio/cycloid-cli/client/client/organization_infrastructure_policies" "github.com/cycloidio/cycloid-cli/client/models" "github.com/cycloidio/cycloid-cli/cmd/cycloid/common" - strfmt "github.com/go-openapi/strfmt" ) // ValidateInfraPolicies will validate the TF plan against diff --git a/cmd/cycloid/middleware/kpi.go b/cmd/cycloid/middleware/kpi.go index a7e404fe..19f25451 100644 --- a/cmd/cycloid/middleware/kpi.go +++ b/cmd/cycloid/middleware/kpi.go @@ -3,10 +3,11 @@ package middleware import ( "encoding/json" + strfmt "github.com/go-openapi/strfmt" + "github.com/cycloidio/cycloid-cli/client/client/organization_kpis" "github.com/cycloidio/cycloid-cli/client/models" "github.com/cycloidio/cycloid-cli/cmd/cycloid/common" - strfmt "github.com/go-openapi/strfmt" ) func (m *middleware) CreateKpi(name, kpiType, widget, org, project, job, env, config string) (*models.KPI, error) { diff --git a/cmd/cycloid/middleware/middleware.go b/cmd/cycloid/middleware/middleware.go index 337f7f72..71f74a6a 100644 --- a/cmd/cycloid/middleware/middleware.go +++ b/cmd/cycloid/middleware/middleware.go @@ -1,9 +1,10 @@ package middleware import ( + strfmt "github.com/go-openapi/strfmt" + "github.com/cycloidio/cycloid-cli/client/models" "github.com/cycloidio/cycloid-cli/cmd/cycloid/common" - strfmt "github.com/go-openapi/strfmt" ) type Middleware interface { diff --git a/cmd/cycloid/middleware/pipeline.go b/cmd/cycloid/middleware/pipeline.go index d2b1ac56..a6cc1e7e 100644 --- a/cmd/cycloid/middleware/pipeline.go +++ b/cmd/cycloid/middleware/pipeline.go @@ -1,12 +1,13 @@ package middleware import ( + strfmt "github.com/go-openapi/strfmt" + "github.com/cycloidio/cycloid-cli/client/client/organization_pipelines" "github.com/cycloidio/cycloid-cli/client/client/organization_pipelines_jobs" "github.com/cycloidio/cycloid-cli/client/client/organization_pipelines_jobs_build" "github.com/cycloidio/cycloid-cli/client/models" "github.com/cycloidio/cycloid-cli/cmd/cycloid/common" - strfmt "github.com/go-openapi/strfmt" ) func (m *middleware) PausePipeline(org, project, env string) error { diff --git a/cmd/cycloid/middleware/project.go b/cmd/cycloid/middleware/project.go index 8bc8dc2f..aaac101c 100644 --- a/cmd/cycloid/middleware/project.go +++ b/cmd/cycloid/middleware/project.go @@ -4,11 +4,12 @@ import ( "regexp" "strings" + strfmt "github.com/go-openapi/strfmt" + "github.com/pkg/errors" + "github.com/cycloidio/cycloid-cli/client/client/organization_projects" "github.com/cycloidio/cycloid-cli/client/models" "github.com/cycloidio/cycloid-cli/cmd/cycloid/common" - strfmt "github.com/go-openapi/strfmt" - "github.com/pkg/errors" ) func (m *middleware) ListProjects(org string) ([]*models.Project, error) { diff --git a/cmd/cycloid/middleware/roles.go b/cmd/cycloid/middleware/roles.go index 326bed39..95c4256f 100644 --- a/cmd/cycloid/middleware/roles.go +++ b/cmd/cycloid/middleware/roles.go @@ -1,9 +1,10 @@ package middleware import ( + strfmt "github.com/go-openapi/strfmt" + "github.com/cycloidio/cycloid-cli/client/client/organization_roles" "github.com/cycloidio/cycloid-cli/client/models" - strfmt "github.com/go-openapi/strfmt" ) func (m *middleware) ListRoles(org string) ([]*models.Role, error) { diff --git a/cmd/cycloid/middleware/stacks.go b/cmd/cycloid/middleware/stacks.go index c03042d8..013325c3 100644 --- a/cmd/cycloid/middleware/stacks.go +++ b/cmd/cycloid/middleware/stacks.go @@ -3,12 +3,12 @@ package middleware import ( "fmt" + strfmt "github.com/go-openapi/strfmt" + "gopkg.in/yaml.v3" + "github.com/cycloidio/cycloid-cli/client/client/organization_forms" "github.com/cycloidio/cycloid-cli/client/client/service_catalogs" - "github.com/cycloidio/cycloid-cli/client/models" - strfmt "github.com/go-openapi/strfmt" - "gopkg.in/yaml.v3" ) func (m *middleware) ListStacks(org string) ([]*models.ServiceCatalog, error) { diff --git a/cmd/cycloid/pipelines/diff.go b/cmd/cycloid/pipelines/diff.go index 050992c0..0eba2534 100644 --- a/cmd/cycloid/pipelines/diff.go +++ b/cmd/cycloid/pipelines/diff.go @@ -5,13 +5,13 @@ import ( "os" "github.com/pkg/errors" + "github.com/spf13/cobra" "github.com/cycloidio/cycloid-cli/cmd/cycloid/common" "github.com/cycloidio/cycloid-cli/cmd/cycloid/internal" "github.com/cycloidio/cycloid-cli/cmd/cycloid/middleware" "github.com/cycloidio/cycloid-cli/printer" "github.com/cycloidio/cycloid-cli/printer/factory" - "github.com/spf13/cobra" ) func NewDiffCommand() *cobra.Command { diff --git a/cmd/cycloid/pipelines/get-build.go b/cmd/cycloid/pipelines/get-build.go index 1f57c7e9..851e5d02 100644 --- a/cmd/cycloid/pipelines/get-build.go +++ b/cmd/cycloid/pipelines/get-build.go @@ -3,8 +3,9 @@ package pipelines import ( "fmt" - "github.com/cycloidio/cycloid-cli/cmd/cycloid/internal" "github.com/spf13/cobra" + + "github.com/cycloidio/cycloid-cli/cmd/cycloid/internal" ) func NewGetBuildCommand() *cobra.Command { diff --git a/cmd/cycloid/pipelines/update.go b/cmd/cycloid/pipelines/update.go index e45203bc..549dcda4 100644 --- a/cmd/cycloid/pipelines/update.go +++ b/cmd/cycloid/pipelines/update.go @@ -3,11 +3,10 @@ package pipelines import ( "os" + strfmt "github.com/go-openapi/strfmt" "github.com/pkg/errors" "github.com/spf13/cobra" - strfmt "github.com/go-openapi/strfmt" - "github.com/cycloidio/cycloid-cli/cmd/cycloid/common" "github.com/cycloidio/cycloid-cli/cmd/cycloid/internal" "github.com/cycloidio/cycloid-cli/cmd/cycloid/middleware" diff --git a/cmd/cycloid/projects/get-env.go b/cmd/cycloid/projects/get-env.go index 53c3b15f..cfccb37b 100644 --- a/cmd/cycloid/projects/get-env.go +++ b/cmd/cycloid/projects/get-env.go @@ -3,13 +3,14 @@ package projects import ( "fmt" + "github.com/pkg/errors" + "github.com/spf13/cobra" + "github.com/cycloidio/cycloid-cli/cmd/cycloid/common" "github.com/cycloidio/cycloid-cli/cmd/cycloid/internal" "github.com/cycloidio/cycloid-cli/cmd/cycloid/middleware" "github.com/cycloidio/cycloid-cli/printer" "github.com/cycloidio/cycloid-cli/printer/factory" - "github.com/pkg/errors" - "github.com/spf13/cobra" ) func NewGetEnvCommand() *cobra.Command { diff --git a/cmd/cycloid/projects/list.go b/cmd/cycloid/projects/list.go index 7f05e7e4..73875223 100644 --- a/cmd/cycloid/projects/list.go +++ b/cmd/cycloid/projects/list.go @@ -1,13 +1,14 @@ package projects import ( + "github.com/pkg/errors" + "github.com/spf13/cobra" + "github.com/cycloidio/cycloid-cli/cmd/cycloid/common" "github.com/cycloidio/cycloid-cli/cmd/cycloid/internal" "github.com/cycloidio/cycloid-cli/cmd/cycloid/middleware" "github.com/cycloidio/cycloid-cli/printer" "github.com/cycloidio/cycloid-cli/printer/factory" - "github.com/pkg/errors" - "github.com/spf13/cobra" ) func NewListCommand() *cobra.Command { diff --git a/cmd/cycloid/projects/update.go b/cmd/cycloid/projects/update.go index 9204c099..1e1acd94 100644 --- a/cmd/cycloid/projects/update.go +++ b/cmd/cycloid/projects/update.go @@ -3,8 +3,9 @@ package projects import ( "fmt" - "github.com/cycloidio/cycloid-cli/cmd/cycloid/internal" "github.com/spf13/cobra" + + "github.com/cycloidio/cycloid-cli/cmd/cycloid/internal" ) func NewUpdateCommand() *cobra.Command { diff --git a/cmd/cycloid/stacks/validate-form.go b/cmd/cycloid/stacks/validate-form.go index 775d5fa5..4f886112 100644 --- a/cmd/cycloid/stacks/validate-form.go +++ b/cmd/cycloid/stacks/validate-form.go @@ -3,13 +3,14 @@ package stacks import ( "os" + "github.com/pkg/errors" + "github.com/spf13/cobra" + "github.com/cycloidio/cycloid-cli/cmd/cycloid/common" "github.com/cycloidio/cycloid-cli/cmd/cycloid/internal" "github.com/cycloidio/cycloid-cli/cmd/cycloid/middleware" "github.com/cycloidio/cycloid-cli/printer" "github.com/cycloidio/cycloid-cli/printer/factory" - "github.com/pkg/errors" - "github.com/spf13/cobra" ) func NewValidateFormCmd() *cobra.Command { diff --git a/e2e/events_test.go b/e2e/events_test.go index d831e268..9d339703 100644 --- a/e2e/events_test.go +++ b/e2e/events_test.go @@ -1,4 +1,5 @@ -//+build e2e +//go:build e2e +// +build e2e package e2e diff --git a/main.go b/main.go index 36110292..ba0a9513 100644 --- a/main.go +++ b/main.go @@ -4,9 +4,10 @@ import ( "fmt" "os" - "github.com/cycloidio/cycloid-cli/cmd" "github.com/spf13/cobra" "github.com/spf13/viper" + + "github.com/cycloidio/cycloid-cli/cmd" ) var ( diff --git a/printer/factory/factory_test.go b/printer/factory/factory_test.go index b9d698aa..13c9ffb5 100644 --- a/printer/factory/factory_test.go +++ b/printer/factory/factory_test.go @@ -3,11 +3,12 @@ package factory import ( "testing" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/cycloidio/cycloid-cli/printer" "github.com/cycloidio/cycloid-cli/printer/json" "github.com/cycloidio/cycloid-cli/printer/yaml" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestGetPrinter(t *testing.T) { diff --git a/printer/json/printer_test.go b/printer/json/printer_test.go index 5341b93d..76bc04b9 100644 --- a/printer/json/printer_test.go +++ b/printer/json/printer_test.go @@ -4,9 +4,10 @@ import ( "bytes" "testing" - "github.com/cycloidio/cycloid-cli/printer" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + "github.com/cycloidio/cycloid-cli/printer" ) func TestJSONPrinter(t *testing.T) { diff --git a/printer/table/printer_test.go b/printer/table/printer_test.go index f5fefd3a..7b55f37c 100644 --- a/printer/table/printer_test.go +++ b/printer/table/printer_test.go @@ -5,9 +5,10 @@ import ( "testing" "time" - "github.com/cycloidio/cycloid-cli/printer" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + "github.com/cycloidio/cycloid-cli/printer" ) func int64Ptr(i int64) *int64 { diff --git a/printer/yaml/printer.go b/printer/yaml/printer.go index d034bfee..c2584cf6 100644 --- a/printer/yaml/printer.go +++ b/printer/yaml/printer.go @@ -4,9 +4,9 @@ import ( "io" "github.com/pkg/errors" + "gopkg.in/yaml.v3" "github.com/cycloidio/cycloid-cli/printer" - "gopkg.in/yaml.v3" ) // YAML implements the printer interface diff --git a/printer/yaml/printer_test.go b/printer/yaml/printer_test.go index 303ef698..4d25fd39 100644 --- a/printer/yaml/printer_test.go +++ b/printer/yaml/printer_test.go @@ -4,9 +4,10 @@ import ( "bytes" "testing" - "github.com/cycloidio/cycloid-cli/printer" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + "github.com/cycloidio/cycloid-cli/printer" ) func TestYAMLPrinter(t *testing.T) { From 89ebd96535a71bf199488c71b89dab2b574d78bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Opasiak?= Date: Mon, 15 Jul 2024 11:01:55 +0200 Subject: [PATCH 04/71] changelog: add entry for #286 --- changelog/unreleased/Other-ADDED-20240715-090147.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 changelog/unreleased/Other-ADDED-20240715-090147.yaml diff --git a/changelog/unreleased/Other-ADDED-20240715-090147.yaml b/changelog/unreleased/Other-ADDED-20240715-090147.yaml new file mode 100644 index 00000000..4db9f232 --- /dev/null +++ b/changelog/unreleased/Other-ADDED-20240715-090147.yaml @@ -0,0 +1,8 @@ +component: Other +kind: ADDED +body: Added go code formatter +time: 2024-07-15T09:01:47.937110966Z +custom: + DETAILS: "" + PR: "286" + TYPE: CLI From fec9c80754a019aa8e2145b72ecb1b0c90ec8295 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20BARRAS=20HAMPEL?= Date: Mon, 15 Jul 2024 12:37:34 +0200 Subject: [PATCH 05/71] fix: add broken changelog --- changelog/releases/v5.0.66.md | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/changelog/releases/v5.0.66.md b/changelog/releases/v5.0.66.md index a1b42d8e..137a7442 100644 --- a/changelog/releases/v5.0.66.md +++ b/changelog/releases/v5.0.66.md @@ -2,31 +2,4 @@ Cycloid CLI changelog: -### CLI -**BREAKING** -- Env var TOKEN is replaced by CY_API_KEY for giving token via env var. ([CLI#274]) -*The old `TOKEN` env var still works but emits a warning. It will be removed in a futur release.* -**CHANGED** -- Allow to create a project without an environment. ([CLI#278]) -*The env creation with the old flags still exists, but is now deprecated and will be removed in a further release.* -- Allow to use CY_ORG env var to define the current org instead of --org flag ([CLI#274]) -*You can still use the --org flag, the CLI flag will have precedence over the env var.* -- Update client to version v5.0.66 ([CLI#279]) -**FIXED** -- Fix version for release ([CLI#269]) - -- Remove API validation on bad playload from API for catalog repository refresh ([CLI#278]) - -- --org flag is now global ([CLI#274]) -*This fixes inconsistency between commands, you can also set the org via env vars now.* -**SECURITY** -- Make the configuration write as 0600 permissions in user home config ([CLI#274]) - -- Allow to login using CY_API_TOKEN instead of providing the token via --api-token flag ([CLI#274]) -*This will become the default way, using the flag will be deprecated in the future.* - -[CLI#274]: https://github.com/cycloidio/cycloid-cli/pull/274 -[CLI#278]: https://github.com/cycloidio/cycloid-cli/pull/278 -[CLI#279]: https://github.com/cycloidio/cycloid-cli/pull/279 -[CLI#269]: https://github.com/cycloidio/cycloid-cli/pull/269 From 4b8955c90ae70d5f49db703c2f437dc94a2d9fa4 Mon Sep 17 00:00:00 2001 From: cycloid-machine Date: Mon, 15 Jul 2024 14:48:12 +0000 Subject: [PATCH 06/71] [ci skip] v5.1.9 release --- changelog/unreleased/Members-CHANGED-20240715-084537.yaml | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 changelog/unreleased/Members-CHANGED-20240715-084537.yaml diff --git a/changelog/unreleased/Members-CHANGED-20240715-084537.yaml b/changelog/unreleased/Members-CHANGED-20240715-084537.yaml deleted file mode 100644 index bc6e15d2..00000000 --- a/changelog/unreleased/Members-CHANGED-20240715-084537.yaml +++ /dev/null @@ -1,8 +0,0 @@ -component: Members -kind: CHANGED -body: 'Updated members commands to fit the recent endpoints changes. ' -time: 2024-07-15T08:45:37.006029336Z -custom: - DETAILS: "" - PR: "270" - TYPE: CLI From 08d2bd44309b9138fc5b1a5b2d3ef4063cec75e7 Mon Sep 17 00:00:00 2001 From: Cycloid Date: Tue, 16 Jul 2024 08:07:38 +0000 Subject: [PATCH 07/71] Bump swagger client to version v5.1.10 --- client/version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/version b/client/version index 4abefd31..385babdc 100644 --- a/client/version +++ b/client/version @@ -1 +1 @@ -v5.1.9 +v5.1.10 From 583e401d1c0f7d7e5ac3bdcd3ed9a09f8643975a Mon Sep 17 00:00:00 2001 From: Cycloid Date: Tue, 16 Jul 2024 08:08:05 +0000 Subject: [PATCH 08/71] Changelog: Add entry for new version v5.1.10 --- changelog/unreleased/CLI-CHANGED-20240716-080805.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 changelog/unreleased/CLI-CHANGED-20240716-080805.yaml diff --git a/changelog/unreleased/CLI-CHANGED-20240716-080805.yaml b/changelog/unreleased/CLI-CHANGED-20240716-080805.yaml new file mode 100644 index 00000000..188ec228 --- /dev/null +++ b/changelog/unreleased/CLI-CHANGED-20240716-080805.yaml @@ -0,0 +1,8 @@ +component: CLI +kind: CHANGED +body: "Update client to version v5.1.10" +time: 2024-07-16T08:08:05.599744124+00:00 +custom: + DETAILS: "" + PR: "290" + TYPE: CLI From 250f847cf09af3ab2226740d561917e6dc240700 Mon Sep 17 00:00:00 2001 From: Cycloid Date: Wed, 17 Jul 2024 10:37:48 +0000 Subject: [PATCH 09/71] Bump swagger client to version v5.1.14 --- client/version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/version b/client/version index 4abefd31..1c868cc9 100644 --- a/client/version +++ b/client/version @@ -1 +1 @@ -v5.1.9 +v5.1.14 From 37523de6a799f9db5d65f6e2dd0785ed71a79726 Mon Sep 17 00:00:00 2001 From: Cycloid Date: Wed, 17 Jul 2024 10:38:14 +0000 Subject: [PATCH 10/71] Changelog: Add entry for new version v5.1.14 --- changelog/unreleased/CLI-CHANGED-20240717-103814.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 changelog/unreleased/CLI-CHANGED-20240717-103814.yaml diff --git a/changelog/unreleased/CLI-CHANGED-20240717-103814.yaml b/changelog/unreleased/CLI-CHANGED-20240717-103814.yaml new file mode 100644 index 00000000..5002e87c --- /dev/null +++ b/changelog/unreleased/CLI-CHANGED-20240717-103814.yaml @@ -0,0 +1,8 @@ +component: CLI +kind: CHANGED +body: "Update client to version v5.1.14" +time: 2024-07-17T10:38:14.208324933+00:00 +custom: + DETAILS: "" + PR: "291" + TYPE: CLI From fd791f17353ce491e1531481716b58efc3f4fb98 Mon Sep 17 00:00:00 2001 From: Cycloid Date: Wed, 17 Jul 2024 15:58:07 +0000 Subject: [PATCH 11/71] Bump swagger client to version v5.1.15 --- client/version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/version b/client/version index 4abefd31..892b154e 100644 --- a/client/version +++ b/client/version @@ -1 +1 @@ -v5.1.9 +v5.1.15 From 29bc3e49b1d8353f9276eb6b37dadebe12e463ce Mon Sep 17 00:00:00 2001 From: Cycloid Date: Wed, 17 Jul 2024 15:58:30 +0000 Subject: [PATCH 12/71] Changelog: Add entry for new version v5.1.15 --- changelog/unreleased/CLI-CHANGED-20240717-155830.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 changelog/unreleased/CLI-CHANGED-20240717-155830.yaml diff --git a/changelog/unreleased/CLI-CHANGED-20240717-155830.yaml b/changelog/unreleased/CLI-CHANGED-20240717-155830.yaml new file mode 100644 index 00000000..9eff1532 --- /dev/null +++ b/changelog/unreleased/CLI-CHANGED-20240717-155830.yaml @@ -0,0 +1,8 @@ +component: CLI +kind: CHANGED +body: "Update client to version v5.1.15" +time: 2024-07-17T15:58:30.464686970+00:00 +custom: + DETAILS: "" + PR: "292" + TYPE: CLI From 7719465d3a8a9b045676bd3fea311e4207da933c Mon Sep 17 00:00:00 2001 From: Cycloid Date: Thu, 1 Aug 2024 09:06:55 +0000 Subject: [PATCH 13/71] Bump swagger client to version v5.1.26 --- client/models/infrastructure_graph_node.go | 3 +++ client/version | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/client/models/infrastructure_graph_node.go b/client/models/infrastructure_graph_node.go index c1317b0a..75fe9284 100644 --- a/client/models/infrastructure_graph_node.go +++ b/client/models/infrastructure_graph_node.go @@ -29,6 +29,9 @@ type InfrastructureGraphNode struct { // Required: true ID *string `json:"id"` + // name + Name string `json:"name,omitempty"` + // It holds [x,y] // Required: true Position []uint64 `json:"position"` diff --git a/client/version b/client/version index 4abefd31..7dcdfee1 100644 --- a/client/version +++ b/client/version @@ -1 +1 @@ -v5.1.9 +v5.1.26 From cc91dfd15fed4b0634d7df9796017aeea341b639 Mon Sep 17 00:00:00 2001 From: Cycloid Date: Thu, 1 Aug 2024 09:07:26 +0000 Subject: [PATCH 14/71] Changelog: Add entry for new version v5.1.26 --- changelog/unreleased/CLI-CHANGED-20240801-090726.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 changelog/unreleased/CLI-CHANGED-20240801-090726.yaml diff --git a/changelog/unreleased/CLI-CHANGED-20240801-090726.yaml b/changelog/unreleased/CLI-CHANGED-20240801-090726.yaml new file mode 100644 index 00000000..a5fbf4de --- /dev/null +++ b/changelog/unreleased/CLI-CHANGED-20240801-090726.yaml @@ -0,0 +1,8 @@ +component: CLI +kind: CHANGED +body: "Update client to version v5.1.26" +time: 2024-08-01T09:07:26.831715417+00:00 +custom: + DETAILS: "" + PR: "293" + TYPE: CLI From c854fcba610182b121836b30bc6cb98d6a6f01b5 Mon Sep 17 00:00:00 2001 From: Cycloid Date: Wed, 7 Aug 2024 10:01:08 +0000 Subject: [PATCH 15/71] Bump swagger client to version v5.1.30 --- client/models/infrastructure_graph_node.go | 3 +++ client/version | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/client/models/infrastructure_graph_node.go b/client/models/infrastructure_graph_node.go index c1317b0a..75fe9284 100644 --- a/client/models/infrastructure_graph_node.go +++ b/client/models/infrastructure_graph_node.go @@ -29,6 +29,9 @@ type InfrastructureGraphNode struct { // Required: true ID *string `json:"id"` + // name + Name string `json:"name,omitempty"` + // It holds [x,y] // Required: true Position []uint64 `json:"position"` diff --git a/client/version b/client/version index 4abefd31..912c4b64 100644 --- a/client/version +++ b/client/version @@ -1 +1 @@ -v5.1.9 +v5.1.30 From 9a27af1bb2a5f1509634f9984e7d8f3370fbe029 Mon Sep 17 00:00:00 2001 From: Cycloid Date: Wed, 7 Aug 2024 10:01:35 +0000 Subject: [PATCH 16/71] Changelog: Add entry for new version v5.1.30 --- changelog/unreleased/CLI-CHANGED-20240807-100135.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 changelog/unreleased/CLI-CHANGED-20240807-100135.yaml diff --git a/changelog/unreleased/CLI-CHANGED-20240807-100135.yaml b/changelog/unreleased/CLI-CHANGED-20240807-100135.yaml new file mode 100644 index 00000000..abc17595 --- /dev/null +++ b/changelog/unreleased/CLI-CHANGED-20240807-100135.yaml @@ -0,0 +1,8 @@ +component: CLI +kind: CHANGED +body: "Update client to version v5.1.30" +time: 2024-08-07T10:01:35.618953760+00:00 +custom: + DETAILS: "" + PR: "294" + TYPE: CLI From 71af2ee8f006a1b836c5b0fb2adbeded070e4d94 Mon Sep 17 00:00:00 2001 From: Cycloid Date: Wed, 7 Aug 2024 12:45:46 +0000 Subject: [PATCH 17/71] Bump swagger client to version v5.1.31 --- client/models/infrastructure_graph_node.go | 3 +++ client/version | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/client/models/infrastructure_graph_node.go b/client/models/infrastructure_graph_node.go index c1317b0a..75fe9284 100644 --- a/client/models/infrastructure_graph_node.go +++ b/client/models/infrastructure_graph_node.go @@ -29,6 +29,9 @@ type InfrastructureGraphNode struct { // Required: true ID *string `json:"id"` + // name + Name string `json:"name,omitempty"` + // It holds [x,y] // Required: true Position []uint64 `json:"position"` diff --git a/client/version b/client/version index 4abefd31..15f38022 100644 --- a/client/version +++ b/client/version @@ -1 +1 @@ -v5.1.9 +v5.1.31 From b72a73808414b7127f4e0c710193f786b2af637e Mon Sep 17 00:00:00 2001 From: Cycloid Date: Wed, 7 Aug 2024 12:46:06 +0000 Subject: [PATCH 18/71] Changelog: Add entry for new version v5.1.31 --- changelog/unreleased/CLI-CHANGED-20240807-124606.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 changelog/unreleased/CLI-CHANGED-20240807-124606.yaml diff --git a/changelog/unreleased/CLI-CHANGED-20240807-124606.yaml b/changelog/unreleased/CLI-CHANGED-20240807-124606.yaml new file mode 100644 index 00000000..84445662 --- /dev/null +++ b/changelog/unreleased/CLI-CHANGED-20240807-124606.yaml @@ -0,0 +1,8 @@ +component: CLI +kind: CHANGED +body: "Update client to version v5.1.31" +time: 2024-08-07T12:46:06.430201973+00:00 +custom: + DETAILS: "" + PR: "295" + TYPE: CLI From 561dac4fd22c051eb5c1a2458443840ae8ada4b7 Mon Sep 17 00:00:00 2001 From: Cycloid Date: Thu, 22 Aug 2024 12:22:36 +0000 Subject: [PATCH 19/71] Bump swagger client to version v5.1.35 --- client/models/infrastructure_graph_node.go | 3 +++ client/version | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/client/models/infrastructure_graph_node.go b/client/models/infrastructure_graph_node.go index c1317b0a..75fe9284 100644 --- a/client/models/infrastructure_graph_node.go +++ b/client/models/infrastructure_graph_node.go @@ -29,6 +29,9 @@ type InfrastructureGraphNode struct { // Required: true ID *string `json:"id"` + // name + Name string `json:"name,omitempty"` + // It holds [x,y] // Required: true Position []uint64 `json:"position"` diff --git a/client/version b/client/version index 4abefd31..87f19041 100644 --- a/client/version +++ b/client/version @@ -1 +1 @@ -v5.1.9 +v5.1.35 From 09cb2c1290589cde32702a9b41a12c361b205dd1 Mon Sep 17 00:00:00 2001 From: Cycloid Date: Thu, 22 Aug 2024 12:23:05 +0000 Subject: [PATCH 20/71] Changelog: Add entry for new version v5.1.35 --- changelog/unreleased/CLI-CHANGED-20240822-122305.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 changelog/unreleased/CLI-CHANGED-20240822-122305.yaml diff --git a/changelog/unreleased/CLI-CHANGED-20240822-122305.yaml b/changelog/unreleased/CLI-CHANGED-20240822-122305.yaml new file mode 100644 index 00000000..d8ab61e1 --- /dev/null +++ b/changelog/unreleased/CLI-CHANGED-20240822-122305.yaml @@ -0,0 +1,8 @@ +component: CLI +kind: CHANGED +body: "Update client to version v5.1.35" +time: 2024-08-22T12:23:05.708940959+00:00 +custom: + DETAILS: "" + PR: "296" + TYPE: CLI From 47359de81986aafe0568b37af5608bbee1ac7903 Mon Sep 17 00:00:00 2001 From: Cycloid Date: Mon, 9 Sep 2024 15:50:34 +0000 Subject: [PATCH 21/71] Bump swagger client to version v5.1.43 --- .../create_environment_parameters.go | 197 +++++++ .../create_environment_responses.go | 552 ++++++++++++++++++ .../delete_environment_parameters.go | 195 +++++++ .../delete_environment_responses.go | 380 ++++++++++++ .../delete_project_environment_parameters.go | 195 ------- .../delete_project_environment_responses.go | 380 ------------ .../organization_projects_client.go | 116 +++- .../update_environment_parameters.go | 219 +++++++ .../update_environment_responses.go | 490 ++++++++++++++++ client/models/infrastructure_graph_node.go | 3 + client/models/new_environment.go | 30 + client/models/update_environment.go | 156 +++++ client/version | 2 +- 13 files changed, 2321 insertions(+), 594 deletions(-) create mode 100644 client/client/organization_projects/create_environment_parameters.go create mode 100644 client/client/organization_projects/create_environment_responses.go create mode 100644 client/client/organization_projects/delete_environment_parameters.go create mode 100644 client/client/organization_projects/delete_environment_responses.go delete mode 100644 client/client/organization_projects/delete_project_environment_parameters.go delete mode 100644 client/client/organization_projects/delete_project_environment_responses.go create mode 100644 client/client/organization_projects/update_environment_parameters.go create mode 100644 client/client/organization_projects/update_environment_responses.go create mode 100644 client/models/update_environment.go diff --git a/client/client/organization_projects/create_environment_parameters.go b/client/client/organization_projects/create_environment_parameters.go new file mode 100644 index 00000000..737554b9 --- /dev/null +++ b/client/client/organization_projects/create_environment_parameters.go @@ -0,0 +1,197 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package organization_projects + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + "net/http" + "time" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + cr "github.com/go-openapi/runtime/client" + "github.com/go-openapi/strfmt" + + "github.com/cycloidio/cycloid-cli/client/models" +) + +// NewCreateEnvironmentParams creates a new CreateEnvironmentParams object, +// with the default timeout for this client. +// +// Default values are not hydrated, since defaults are normally applied by the API server side. +// +// To enforce default values in parameter, use SetDefaults or WithDefaults. +func NewCreateEnvironmentParams() *CreateEnvironmentParams { + return &CreateEnvironmentParams{ + timeout: cr.DefaultTimeout, + } +} + +// NewCreateEnvironmentParamsWithTimeout creates a new CreateEnvironmentParams object +// with the ability to set a timeout on a request. +func NewCreateEnvironmentParamsWithTimeout(timeout time.Duration) *CreateEnvironmentParams { + return &CreateEnvironmentParams{ + timeout: timeout, + } +} + +// NewCreateEnvironmentParamsWithContext creates a new CreateEnvironmentParams object +// with the ability to set a context for a request. +func NewCreateEnvironmentParamsWithContext(ctx context.Context) *CreateEnvironmentParams { + return &CreateEnvironmentParams{ + Context: ctx, + } +} + +// NewCreateEnvironmentParamsWithHTTPClient creates a new CreateEnvironmentParams object +// with the ability to set a custom HTTPClient for a request. +func NewCreateEnvironmentParamsWithHTTPClient(client *http.Client) *CreateEnvironmentParams { + return &CreateEnvironmentParams{ + HTTPClient: client, + } +} + +/* +CreateEnvironmentParams contains all the parameters to send to the API endpoint + + for the create environment operation. + + Typically these are written to a http.Request. +*/ +type CreateEnvironmentParams struct { + + /* Body. + + The canonical of the environment to create and its configuration. + */ + Body *models.NewEnvironment + + /* OrganizationCanonical. + + A canonical of an organization. + */ + OrganizationCanonical string + + /* ProjectCanonical. + + A canonical of a project. + */ + ProjectCanonical string + + timeout time.Duration + Context context.Context + HTTPClient *http.Client +} + +// WithDefaults hydrates default values in the create environment params (not the query body). +// +// All values with no default are reset to their zero value. +func (o *CreateEnvironmentParams) WithDefaults() *CreateEnvironmentParams { + o.SetDefaults() + return o +} + +// SetDefaults hydrates default values in the create environment params (not the query body). +// +// All values with no default are reset to their zero value. +func (o *CreateEnvironmentParams) SetDefaults() { + // no default values defined for this parameter +} + +// WithTimeout adds the timeout to the create environment params +func (o *CreateEnvironmentParams) WithTimeout(timeout time.Duration) *CreateEnvironmentParams { + o.SetTimeout(timeout) + return o +} + +// SetTimeout adds the timeout to the create environment params +func (o *CreateEnvironmentParams) SetTimeout(timeout time.Duration) { + o.timeout = timeout +} + +// WithContext adds the context to the create environment params +func (o *CreateEnvironmentParams) WithContext(ctx context.Context) *CreateEnvironmentParams { + o.SetContext(ctx) + return o +} + +// SetContext adds the context to the create environment params +func (o *CreateEnvironmentParams) SetContext(ctx context.Context) { + o.Context = ctx +} + +// WithHTTPClient adds the HTTPClient to the create environment params +func (o *CreateEnvironmentParams) WithHTTPClient(client *http.Client) *CreateEnvironmentParams { + o.SetHTTPClient(client) + return o +} + +// SetHTTPClient adds the HTTPClient to the create environment params +func (o *CreateEnvironmentParams) SetHTTPClient(client *http.Client) { + o.HTTPClient = client +} + +// WithBody adds the body to the create environment params +func (o *CreateEnvironmentParams) WithBody(body *models.NewEnvironment) *CreateEnvironmentParams { + o.SetBody(body) + return o +} + +// SetBody adds the body to the create environment params +func (o *CreateEnvironmentParams) SetBody(body *models.NewEnvironment) { + o.Body = body +} + +// WithOrganizationCanonical adds the organizationCanonical to the create environment params +func (o *CreateEnvironmentParams) WithOrganizationCanonical(organizationCanonical string) *CreateEnvironmentParams { + o.SetOrganizationCanonical(organizationCanonical) + return o +} + +// SetOrganizationCanonical adds the organizationCanonical to the create environment params +func (o *CreateEnvironmentParams) SetOrganizationCanonical(organizationCanonical string) { + o.OrganizationCanonical = organizationCanonical +} + +// WithProjectCanonical adds the projectCanonical to the create environment params +func (o *CreateEnvironmentParams) WithProjectCanonical(projectCanonical string) *CreateEnvironmentParams { + o.SetProjectCanonical(projectCanonical) + return o +} + +// SetProjectCanonical adds the projectCanonical to the create environment params +func (o *CreateEnvironmentParams) SetProjectCanonical(projectCanonical string) { + o.ProjectCanonical = projectCanonical +} + +// WriteToRequest writes these params to a swagger request +func (o *CreateEnvironmentParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { + + if err := r.SetTimeout(o.timeout); err != nil { + return err + } + var res []error + if o.Body != nil { + if err := r.SetBodyParam(o.Body); err != nil { + return err + } + } + + // path param organization_canonical + if err := r.SetPathParam("organization_canonical", o.OrganizationCanonical); err != nil { + return err + } + + // path param project_canonical + if err := r.SetPathParam("project_canonical", o.ProjectCanonical); err != nil { + return err + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/client/client/organization_projects/create_environment_responses.go b/client/client/organization_projects/create_environment_responses.go new file mode 100644 index 00000000..f1848a08 --- /dev/null +++ b/client/client/organization_projects/create_environment_responses.go @@ -0,0 +1,552 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package organization_projects + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + "encoding/json" + "fmt" + "io" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" + "github.com/go-openapi/validate" + + "github.com/cycloidio/cycloid-cli/client/models" +) + +// CreateEnvironmentReader is a Reader for the CreateEnvironment structure. +type CreateEnvironmentReader struct { + formats strfmt.Registry +} + +// ReadResponse reads a server response into the received o. +func (o *CreateEnvironmentReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + switch response.Code() { + case 200: + result := NewCreateEnvironmentOK() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return result, nil + case 404: + result := NewCreateEnvironmentNotFound() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + case 411: + result := NewCreateEnvironmentLengthRequired() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + case 422: + result := NewCreateEnvironmentUnprocessableEntity() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + default: + result := NewCreateEnvironmentDefault(response.Code()) + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + if response.Code()/100 == 2 { + return result, nil + } + return nil, result + } +} + +// NewCreateEnvironmentOK creates a CreateEnvironmentOK with default headers values +func NewCreateEnvironmentOK() *CreateEnvironmentOK { + return &CreateEnvironmentOK{} +} + +/* +CreateEnvironmentOK describes a response with status code 200, with default header values. + +Environment created. The body contains the information of the new environment. +*/ +type CreateEnvironmentOK struct { + Payload *CreateEnvironmentOKBody +} + +// IsSuccess returns true when this create environment o k response has a 2xx status code +func (o *CreateEnvironmentOK) IsSuccess() bool { + return true +} + +// IsRedirect returns true when this create environment o k response has a 3xx status code +func (o *CreateEnvironmentOK) IsRedirect() bool { + return false +} + +// IsClientError returns true when this create environment o k response has a 4xx status code +func (o *CreateEnvironmentOK) IsClientError() bool { + return false +} + +// IsServerError returns true when this create environment o k response has a 5xx status code +func (o *CreateEnvironmentOK) IsServerError() bool { + return false +} + +// IsCode returns true when this create environment o k response a status code equal to that given +func (o *CreateEnvironmentOK) IsCode(code int) bool { + return code == 200 +} + +// Code gets the status code for the create environment o k response +func (o *CreateEnvironmentOK) Code() int { + return 200 +} + +func (o *CreateEnvironmentOK) Error() string { + payload, _ := json.Marshal(o.Payload) + return fmt.Sprintf("[POST /organizations/{organization_canonical}/projects/{project_canonical}/environments][%d] createEnvironmentOK %s", 200, payload) +} + +func (o *CreateEnvironmentOK) String() string { + payload, _ := json.Marshal(o.Payload) + return fmt.Sprintf("[POST /organizations/{organization_canonical}/projects/{project_canonical}/environments][%d] createEnvironmentOK %s", 200, payload) +} + +func (o *CreateEnvironmentOK) GetPayload() *CreateEnvironmentOKBody { + return o.Payload +} + +func (o *CreateEnvironmentOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(CreateEnvironmentOKBody) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewCreateEnvironmentNotFound creates a CreateEnvironmentNotFound with default headers values +func NewCreateEnvironmentNotFound() *CreateEnvironmentNotFound { + return &CreateEnvironmentNotFound{} +} + +/* +CreateEnvironmentNotFound describes a response with status code 404, with default header values. + +The response sent when any of the entities present in the path is not found. +*/ +type CreateEnvironmentNotFound struct { + + /* The length of the response body in octets (8-bit bytes). + + Format: uint64 + */ + ContentLength uint64 + + Payload *models.ErrorPayload +} + +// IsSuccess returns true when this create environment not found response has a 2xx status code +func (o *CreateEnvironmentNotFound) IsSuccess() bool { + return false +} + +// IsRedirect returns true when this create environment not found response has a 3xx status code +func (o *CreateEnvironmentNotFound) IsRedirect() bool { + return false +} + +// IsClientError returns true when this create environment not found response has a 4xx status code +func (o *CreateEnvironmentNotFound) IsClientError() bool { + return true +} + +// IsServerError returns true when this create environment not found response has a 5xx status code +func (o *CreateEnvironmentNotFound) IsServerError() bool { + return false +} + +// IsCode returns true when this create environment not found response a status code equal to that given +func (o *CreateEnvironmentNotFound) IsCode(code int) bool { + return code == 404 +} + +// Code gets the status code for the create environment not found response +func (o *CreateEnvironmentNotFound) Code() int { + return 404 +} + +func (o *CreateEnvironmentNotFound) Error() string { + payload, _ := json.Marshal(o.Payload) + return fmt.Sprintf("[POST /organizations/{organization_canonical}/projects/{project_canonical}/environments][%d] createEnvironmentNotFound %s", 404, payload) +} + +func (o *CreateEnvironmentNotFound) String() string { + payload, _ := json.Marshal(o.Payload) + return fmt.Sprintf("[POST /organizations/{organization_canonical}/projects/{project_canonical}/environments][%d] createEnvironmentNotFound %s", 404, payload) +} + +func (o *CreateEnvironmentNotFound) GetPayload() *models.ErrorPayload { + return o.Payload +} + +func (o *CreateEnvironmentNotFound) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + // hydrates response header Content-Length + hdrContentLength := response.GetHeader("Content-Length") + + if hdrContentLength != "" { + valcontentLength, err := swag.ConvertUint64(hdrContentLength) + if err != nil { + return errors.InvalidType("Content-Length", "header", "uint64", hdrContentLength) + } + o.ContentLength = valcontentLength + } + + o.Payload = new(models.ErrorPayload) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewCreateEnvironmentLengthRequired creates a CreateEnvironmentLengthRequired with default headers values +func NewCreateEnvironmentLengthRequired() *CreateEnvironmentLengthRequired { + return &CreateEnvironmentLengthRequired{} +} + +/* +CreateEnvironmentLengthRequired describes a response with status code 411, with default header values. + +The request has a body but it doesn't have a Content-Length header. +*/ +type CreateEnvironmentLengthRequired struct { +} + +// IsSuccess returns true when this create environment length required response has a 2xx status code +func (o *CreateEnvironmentLengthRequired) IsSuccess() bool { + return false +} + +// IsRedirect returns true when this create environment length required response has a 3xx status code +func (o *CreateEnvironmentLengthRequired) IsRedirect() bool { + return false +} + +// IsClientError returns true when this create environment length required response has a 4xx status code +func (o *CreateEnvironmentLengthRequired) IsClientError() bool { + return true +} + +// IsServerError returns true when this create environment length required response has a 5xx status code +func (o *CreateEnvironmentLengthRequired) IsServerError() bool { + return false +} + +// IsCode returns true when this create environment length required response a status code equal to that given +func (o *CreateEnvironmentLengthRequired) IsCode(code int) bool { + return code == 411 +} + +// Code gets the status code for the create environment length required response +func (o *CreateEnvironmentLengthRequired) Code() int { + return 411 +} + +func (o *CreateEnvironmentLengthRequired) Error() string { + return fmt.Sprintf("[POST /organizations/{organization_canonical}/projects/{project_canonical}/environments][%d] createEnvironmentLengthRequired", 411) +} + +func (o *CreateEnvironmentLengthRequired) String() string { + return fmt.Sprintf("[POST /organizations/{organization_canonical}/projects/{project_canonical}/environments][%d] createEnvironmentLengthRequired", 411) +} + +func (o *CreateEnvironmentLengthRequired) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + return nil +} + +// NewCreateEnvironmentUnprocessableEntity creates a CreateEnvironmentUnprocessableEntity with default headers values +func NewCreateEnvironmentUnprocessableEntity() *CreateEnvironmentUnprocessableEntity { + return &CreateEnvironmentUnprocessableEntity{} +} + +/* +CreateEnvironmentUnprocessableEntity describes a response with status code 422, with default header values. + +All the custom errors that are generated from the Cycloid API +*/ +type CreateEnvironmentUnprocessableEntity struct { + + /* The length of the response body in octets (8-bit bytes). + + Format: uint64 + */ + ContentLength uint64 + + Payload *models.ErrorPayload +} + +// IsSuccess returns true when this create environment unprocessable entity response has a 2xx status code +func (o *CreateEnvironmentUnprocessableEntity) IsSuccess() bool { + return false +} + +// IsRedirect returns true when this create environment unprocessable entity response has a 3xx status code +func (o *CreateEnvironmentUnprocessableEntity) IsRedirect() bool { + return false +} + +// IsClientError returns true when this create environment unprocessable entity response has a 4xx status code +func (o *CreateEnvironmentUnprocessableEntity) IsClientError() bool { + return true +} + +// IsServerError returns true when this create environment unprocessable entity response has a 5xx status code +func (o *CreateEnvironmentUnprocessableEntity) IsServerError() bool { + return false +} + +// IsCode returns true when this create environment unprocessable entity response a status code equal to that given +func (o *CreateEnvironmentUnprocessableEntity) IsCode(code int) bool { + return code == 422 +} + +// Code gets the status code for the create environment unprocessable entity response +func (o *CreateEnvironmentUnprocessableEntity) Code() int { + return 422 +} + +func (o *CreateEnvironmentUnprocessableEntity) Error() string { + payload, _ := json.Marshal(o.Payload) + return fmt.Sprintf("[POST /organizations/{organization_canonical}/projects/{project_canonical}/environments][%d] createEnvironmentUnprocessableEntity %s", 422, payload) +} + +func (o *CreateEnvironmentUnprocessableEntity) String() string { + payload, _ := json.Marshal(o.Payload) + return fmt.Sprintf("[POST /organizations/{organization_canonical}/projects/{project_canonical}/environments][%d] createEnvironmentUnprocessableEntity %s", 422, payload) +} + +func (o *CreateEnvironmentUnprocessableEntity) GetPayload() *models.ErrorPayload { + return o.Payload +} + +func (o *CreateEnvironmentUnprocessableEntity) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + // hydrates response header Content-Length + hdrContentLength := response.GetHeader("Content-Length") + + if hdrContentLength != "" { + valcontentLength, err := swag.ConvertUint64(hdrContentLength) + if err != nil { + return errors.InvalidType("Content-Length", "header", "uint64", hdrContentLength) + } + o.ContentLength = valcontentLength + } + + o.Payload = new(models.ErrorPayload) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewCreateEnvironmentDefault creates a CreateEnvironmentDefault with default headers values +func NewCreateEnvironmentDefault(code int) *CreateEnvironmentDefault { + return &CreateEnvironmentDefault{ + _statusCode: code, + } +} + +/* +CreateEnvironmentDefault describes a response with status code -1, with default header values. + +The response sent when an unexpected error happened, as known as an internal server error. +*/ +type CreateEnvironmentDefault struct { + _statusCode int + + /* The length of the response body in octets (8-bit bytes). + + Format: uint64 + */ + ContentLength uint64 + + Payload *models.ErrorPayload +} + +// IsSuccess returns true when this create environment default response has a 2xx status code +func (o *CreateEnvironmentDefault) IsSuccess() bool { + return o._statusCode/100 == 2 +} + +// IsRedirect returns true when this create environment default response has a 3xx status code +func (o *CreateEnvironmentDefault) IsRedirect() bool { + return o._statusCode/100 == 3 +} + +// IsClientError returns true when this create environment default response has a 4xx status code +func (o *CreateEnvironmentDefault) IsClientError() bool { + return o._statusCode/100 == 4 +} + +// IsServerError returns true when this create environment default response has a 5xx status code +func (o *CreateEnvironmentDefault) IsServerError() bool { + return o._statusCode/100 == 5 +} + +// IsCode returns true when this create environment default response a status code equal to that given +func (o *CreateEnvironmentDefault) IsCode(code int) bool { + return o._statusCode == code +} + +// Code gets the status code for the create environment default response +func (o *CreateEnvironmentDefault) Code() int { + return o._statusCode +} + +func (o *CreateEnvironmentDefault) Error() string { + payload, _ := json.Marshal(o.Payload) + return fmt.Sprintf("[POST /organizations/{organization_canonical}/projects/{project_canonical}/environments][%d] createEnvironment default %s", o._statusCode, payload) +} + +func (o *CreateEnvironmentDefault) String() string { + payload, _ := json.Marshal(o.Payload) + return fmt.Sprintf("[POST /organizations/{organization_canonical}/projects/{project_canonical}/environments][%d] createEnvironment default %s", o._statusCode, payload) +} + +func (o *CreateEnvironmentDefault) GetPayload() *models.ErrorPayload { + return o.Payload +} + +func (o *CreateEnvironmentDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + // hydrates response header Content-Length + hdrContentLength := response.GetHeader("Content-Length") + + if hdrContentLength != "" { + valcontentLength, err := swag.ConvertUint64(hdrContentLength) + if err != nil { + return errors.InvalidType("Content-Length", "header", "uint64", hdrContentLength) + } + o.ContentLength = valcontentLength + } + + o.Payload = new(models.ErrorPayload) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +/* +CreateEnvironmentOKBody create environment o k body +swagger:model CreateEnvironmentOKBody +*/ +type CreateEnvironmentOKBody struct { + + // data + // Required: true + Data *models.Environment `json:"data"` +} + +// Validate validates this create environment o k body +func (o *CreateEnvironmentOKBody) Validate(formats strfmt.Registry) error { + var res []error + + if err := o.validateData(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (o *CreateEnvironmentOKBody) validateData(formats strfmt.Registry) error { + + if err := validate.Required("createEnvironmentOK"+"."+"data", "body", o.Data); err != nil { + return err + } + + if o.Data != nil { + if err := o.Data.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("createEnvironmentOK" + "." + "data") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("createEnvironmentOK" + "." + "data") + } + return err + } + } + + return nil +} + +// ContextValidate validate this create environment o k body based on the context it is used +func (o *CreateEnvironmentOKBody) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + if err := o.contextValidateData(ctx, formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (o *CreateEnvironmentOKBody) contextValidateData(ctx context.Context, formats strfmt.Registry) error { + + if o.Data != nil { + + if err := o.Data.ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("createEnvironmentOK" + "." + "data") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("createEnvironmentOK" + "." + "data") + } + return err + } + } + + return nil +} + +// MarshalBinary interface implementation +func (o *CreateEnvironmentOKBody) MarshalBinary() ([]byte, error) { + if o == nil { + return nil, nil + } + return swag.WriteJSON(o) +} + +// UnmarshalBinary interface implementation +func (o *CreateEnvironmentOKBody) UnmarshalBinary(b []byte) error { + var res CreateEnvironmentOKBody + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *o = res + return nil +} diff --git a/client/client/organization_projects/delete_environment_parameters.go b/client/client/organization_projects/delete_environment_parameters.go new file mode 100644 index 00000000..b6b79322 --- /dev/null +++ b/client/client/organization_projects/delete_environment_parameters.go @@ -0,0 +1,195 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package organization_projects + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + "net/http" + "time" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + cr "github.com/go-openapi/runtime/client" + "github.com/go-openapi/strfmt" +) + +// NewDeleteEnvironmentParams creates a new DeleteEnvironmentParams object, +// with the default timeout for this client. +// +// Default values are not hydrated, since defaults are normally applied by the API server side. +// +// To enforce default values in parameter, use SetDefaults or WithDefaults. +func NewDeleteEnvironmentParams() *DeleteEnvironmentParams { + return &DeleteEnvironmentParams{ + timeout: cr.DefaultTimeout, + } +} + +// NewDeleteEnvironmentParamsWithTimeout creates a new DeleteEnvironmentParams object +// with the ability to set a timeout on a request. +func NewDeleteEnvironmentParamsWithTimeout(timeout time.Duration) *DeleteEnvironmentParams { + return &DeleteEnvironmentParams{ + timeout: timeout, + } +} + +// NewDeleteEnvironmentParamsWithContext creates a new DeleteEnvironmentParams object +// with the ability to set a context for a request. +func NewDeleteEnvironmentParamsWithContext(ctx context.Context) *DeleteEnvironmentParams { + return &DeleteEnvironmentParams{ + Context: ctx, + } +} + +// NewDeleteEnvironmentParamsWithHTTPClient creates a new DeleteEnvironmentParams object +// with the ability to set a custom HTTPClient for a request. +func NewDeleteEnvironmentParamsWithHTTPClient(client *http.Client) *DeleteEnvironmentParams { + return &DeleteEnvironmentParams{ + HTTPClient: client, + } +} + +/* +DeleteEnvironmentParams contains all the parameters to send to the API endpoint + + for the delete environment operation. + + Typically these are written to a http.Request. +*/ +type DeleteEnvironmentParams struct { + + /* EnvironmentCanonical. + + The environment canonical to use as part of a path + */ + EnvironmentCanonical string + + /* OrganizationCanonical. + + A canonical of an organization. + */ + OrganizationCanonical string + + /* ProjectCanonical. + + A canonical of a project. + */ + ProjectCanonical string + + timeout time.Duration + Context context.Context + HTTPClient *http.Client +} + +// WithDefaults hydrates default values in the delete environment params (not the query body). +// +// All values with no default are reset to their zero value. +func (o *DeleteEnvironmentParams) WithDefaults() *DeleteEnvironmentParams { + o.SetDefaults() + return o +} + +// SetDefaults hydrates default values in the delete environment params (not the query body). +// +// All values with no default are reset to their zero value. +func (o *DeleteEnvironmentParams) SetDefaults() { + // no default values defined for this parameter +} + +// WithTimeout adds the timeout to the delete environment params +func (o *DeleteEnvironmentParams) WithTimeout(timeout time.Duration) *DeleteEnvironmentParams { + o.SetTimeout(timeout) + return o +} + +// SetTimeout adds the timeout to the delete environment params +func (o *DeleteEnvironmentParams) SetTimeout(timeout time.Duration) { + o.timeout = timeout +} + +// WithContext adds the context to the delete environment params +func (o *DeleteEnvironmentParams) WithContext(ctx context.Context) *DeleteEnvironmentParams { + o.SetContext(ctx) + return o +} + +// SetContext adds the context to the delete environment params +func (o *DeleteEnvironmentParams) SetContext(ctx context.Context) { + o.Context = ctx +} + +// WithHTTPClient adds the HTTPClient to the delete environment params +func (o *DeleteEnvironmentParams) WithHTTPClient(client *http.Client) *DeleteEnvironmentParams { + o.SetHTTPClient(client) + return o +} + +// SetHTTPClient adds the HTTPClient to the delete environment params +func (o *DeleteEnvironmentParams) SetHTTPClient(client *http.Client) { + o.HTTPClient = client +} + +// WithEnvironmentCanonical adds the environmentCanonical to the delete environment params +func (o *DeleteEnvironmentParams) WithEnvironmentCanonical(environmentCanonical string) *DeleteEnvironmentParams { + o.SetEnvironmentCanonical(environmentCanonical) + return o +} + +// SetEnvironmentCanonical adds the environmentCanonical to the delete environment params +func (o *DeleteEnvironmentParams) SetEnvironmentCanonical(environmentCanonical string) { + o.EnvironmentCanonical = environmentCanonical +} + +// WithOrganizationCanonical adds the organizationCanonical to the delete environment params +func (o *DeleteEnvironmentParams) WithOrganizationCanonical(organizationCanonical string) *DeleteEnvironmentParams { + o.SetOrganizationCanonical(organizationCanonical) + return o +} + +// SetOrganizationCanonical adds the organizationCanonical to the delete environment params +func (o *DeleteEnvironmentParams) SetOrganizationCanonical(organizationCanonical string) { + o.OrganizationCanonical = organizationCanonical +} + +// WithProjectCanonical adds the projectCanonical to the delete environment params +func (o *DeleteEnvironmentParams) WithProjectCanonical(projectCanonical string) *DeleteEnvironmentParams { + o.SetProjectCanonical(projectCanonical) + return o +} + +// SetProjectCanonical adds the projectCanonical to the delete environment params +func (o *DeleteEnvironmentParams) SetProjectCanonical(projectCanonical string) { + o.ProjectCanonical = projectCanonical +} + +// WriteToRequest writes these params to a swagger request +func (o *DeleteEnvironmentParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { + + if err := r.SetTimeout(o.timeout); err != nil { + return err + } + var res []error + + // path param environment_canonical + if err := r.SetPathParam("environment_canonical", o.EnvironmentCanonical); err != nil { + return err + } + + // path param organization_canonical + if err := r.SetPathParam("organization_canonical", o.OrganizationCanonical); err != nil { + return err + } + + // path param project_canonical + if err := r.SetPathParam("project_canonical", o.ProjectCanonical); err != nil { + return err + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/client/client/organization_projects/delete_environment_responses.go b/client/client/organization_projects/delete_environment_responses.go new file mode 100644 index 00000000..b907708b --- /dev/null +++ b/client/client/organization_projects/delete_environment_responses.go @@ -0,0 +1,380 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package organization_projects + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "encoding/json" + "fmt" + "io" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" + + "github.com/cycloidio/cycloid-cli/client/models" +) + +// DeleteEnvironmentReader is a Reader for the DeleteEnvironment structure. +type DeleteEnvironmentReader struct { + formats strfmt.Registry +} + +// ReadResponse reads a server response into the received o. +func (o *DeleteEnvironmentReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + switch response.Code() { + case 204: + result := NewDeleteEnvironmentNoContent() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return result, nil + case 403: + result := NewDeleteEnvironmentForbidden() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + case 404: + result := NewDeleteEnvironmentNotFound() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + default: + result := NewDeleteEnvironmentDefault(response.Code()) + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + if response.Code()/100 == 2 { + return result, nil + } + return nil, result + } +} + +// NewDeleteEnvironmentNoContent creates a DeleteEnvironmentNoContent with default headers values +func NewDeleteEnvironmentNoContent() *DeleteEnvironmentNoContent { + return &DeleteEnvironmentNoContent{} +} + +/* +DeleteEnvironmentNoContent describes a response with status code 204, with default header values. + +Project environment has been deleted. +*/ +type DeleteEnvironmentNoContent struct { +} + +// IsSuccess returns true when this delete environment no content response has a 2xx status code +func (o *DeleteEnvironmentNoContent) IsSuccess() bool { + return true +} + +// IsRedirect returns true when this delete environment no content response has a 3xx status code +func (o *DeleteEnvironmentNoContent) IsRedirect() bool { + return false +} + +// IsClientError returns true when this delete environment no content response has a 4xx status code +func (o *DeleteEnvironmentNoContent) IsClientError() bool { + return false +} + +// IsServerError returns true when this delete environment no content response has a 5xx status code +func (o *DeleteEnvironmentNoContent) IsServerError() bool { + return false +} + +// IsCode returns true when this delete environment no content response a status code equal to that given +func (o *DeleteEnvironmentNoContent) IsCode(code int) bool { + return code == 204 +} + +// Code gets the status code for the delete environment no content response +func (o *DeleteEnvironmentNoContent) Code() int { + return 204 +} + +func (o *DeleteEnvironmentNoContent) Error() string { + return fmt.Sprintf("[DELETE /organizations/{organization_canonical}/projects/{project_canonical}/environments/{environment_canonical}][%d] deleteEnvironmentNoContent", 204) +} + +func (o *DeleteEnvironmentNoContent) String() string { + return fmt.Sprintf("[DELETE /organizations/{organization_canonical}/projects/{project_canonical}/environments/{environment_canonical}][%d] deleteEnvironmentNoContent", 204) +} + +func (o *DeleteEnvironmentNoContent) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + return nil +} + +// NewDeleteEnvironmentForbidden creates a DeleteEnvironmentForbidden with default headers values +func NewDeleteEnvironmentForbidden() *DeleteEnvironmentForbidden { + return &DeleteEnvironmentForbidden{} +} + +/* +DeleteEnvironmentForbidden describes a response with status code 403, with default header values. + +The authenticated user cannot perform the operation because, it doesn't have permissions for such operation. +*/ +type DeleteEnvironmentForbidden struct { + + /* The length of the response body in octets (8-bit bytes). + + Format: uint64 + */ + ContentLength uint64 + + Payload *models.ErrorPayload +} + +// IsSuccess returns true when this delete environment forbidden response has a 2xx status code +func (o *DeleteEnvironmentForbidden) IsSuccess() bool { + return false +} + +// IsRedirect returns true when this delete environment forbidden response has a 3xx status code +func (o *DeleteEnvironmentForbidden) IsRedirect() bool { + return false +} + +// IsClientError returns true when this delete environment forbidden response has a 4xx status code +func (o *DeleteEnvironmentForbidden) IsClientError() bool { + return true +} + +// IsServerError returns true when this delete environment forbidden response has a 5xx status code +func (o *DeleteEnvironmentForbidden) IsServerError() bool { + return false +} + +// IsCode returns true when this delete environment forbidden response a status code equal to that given +func (o *DeleteEnvironmentForbidden) IsCode(code int) bool { + return code == 403 +} + +// Code gets the status code for the delete environment forbidden response +func (o *DeleteEnvironmentForbidden) Code() int { + return 403 +} + +func (o *DeleteEnvironmentForbidden) Error() string { + payload, _ := json.Marshal(o.Payload) + return fmt.Sprintf("[DELETE /organizations/{organization_canonical}/projects/{project_canonical}/environments/{environment_canonical}][%d] deleteEnvironmentForbidden %s", 403, payload) +} + +func (o *DeleteEnvironmentForbidden) String() string { + payload, _ := json.Marshal(o.Payload) + return fmt.Sprintf("[DELETE /organizations/{organization_canonical}/projects/{project_canonical}/environments/{environment_canonical}][%d] deleteEnvironmentForbidden %s", 403, payload) +} + +func (o *DeleteEnvironmentForbidden) GetPayload() *models.ErrorPayload { + return o.Payload +} + +func (o *DeleteEnvironmentForbidden) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + // hydrates response header Content-Length + hdrContentLength := response.GetHeader("Content-Length") + + if hdrContentLength != "" { + valcontentLength, err := swag.ConvertUint64(hdrContentLength) + if err != nil { + return errors.InvalidType("Content-Length", "header", "uint64", hdrContentLength) + } + o.ContentLength = valcontentLength + } + + o.Payload = new(models.ErrorPayload) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewDeleteEnvironmentNotFound creates a DeleteEnvironmentNotFound with default headers values +func NewDeleteEnvironmentNotFound() *DeleteEnvironmentNotFound { + return &DeleteEnvironmentNotFound{} +} + +/* +DeleteEnvironmentNotFound describes a response with status code 404, with default header values. + +The response sent when any of the entities present in the path is not found. +*/ +type DeleteEnvironmentNotFound struct { + + /* The length of the response body in octets (8-bit bytes). + + Format: uint64 + */ + ContentLength uint64 + + Payload *models.ErrorPayload +} + +// IsSuccess returns true when this delete environment not found response has a 2xx status code +func (o *DeleteEnvironmentNotFound) IsSuccess() bool { + return false +} + +// IsRedirect returns true when this delete environment not found response has a 3xx status code +func (o *DeleteEnvironmentNotFound) IsRedirect() bool { + return false +} + +// IsClientError returns true when this delete environment not found response has a 4xx status code +func (o *DeleteEnvironmentNotFound) IsClientError() bool { + return true +} + +// IsServerError returns true when this delete environment not found response has a 5xx status code +func (o *DeleteEnvironmentNotFound) IsServerError() bool { + return false +} + +// IsCode returns true when this delete environment not found response a status code equal to that given +func (o *DeleteEnvironmentNotFound) IsCode(code int) bool { + return code == 404 +} + +// Code gets the status code for the delete environment not found response +func (o *DeleteEnvironmentNotFound) Code() int { + return 404 +} + +func (o *DeleteEnvironmentNotFound) Error() string { + payload, _ := json.Marshal(o.Payload) + return fmt.Sprintf("[DELETE /organizations/{organization_canonical}/projects/{project_canonical}/environments/{environment_canonical}][%d] deleteEnvironmentNotFound %s", 404, payload) +} + +func (o *DeleteEnvironmentNotFound) String() string { + payload, _ := json.Marshal(o.Payload) + return fmt.Sprintf("[DELETE /organizations/{organization_canonical}/projects/{project_canonical}/environments/{environment_canonical}][%d] deleteEnvironmentNotFound %s", 404, payload) +} + +func (o *DeleteEnvironmentNotFound) GetPayload() *models.ErrorPayload { + return o.Payload +} + +func (o *DeleteEnvironmentNotFound) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + // hydrates response header Content-Length + hdrContentLength := response.GetHeader("Content-Length") + + if hdrContentLength != "" { + valcontentLength, err := swag.ConvertUint64(hdrContentLength) + if err != nil { + return errors.InvalidType("Content-Length", "header", "uint64", hdrContentLength) + } + o.ContentLength = valcontentLength + } + + o.Payload = new(models.ErrorPayload) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewDeleteEnvironmentDefault creates a DeleteEnvironmentDefault with default headers values +func NewDeleteEnvironmentDefault(code int) *DeleteEnvironmentDefault { + return &DeleteEnvironmentDefault{ + _statusCode: code, + } +} + +/* +DeleteEnvironmentDefault describes a response with status code -1, with default header values. + +The response sent when an unexpected error happened, as known as an internal server error. +*/ +type DeleteEnvironmentDefault struct { + _statusCode int + + /* The length of the response body in octets (8-bit bytes). + + Format: uint64 + */ + ContentLength uint64 + + Payload *models.ErrorPayload +} + +// IsSuccess returns true when this delete environment default response has a 2xx status code +func (o *DeleteEnvironmentDefault) IsSuccess() bool { + return o._statusCode/100 == 2 +} + +// IsRedirect returns true when this delete environment default response has a 3xx status code +func (o *DeleteEnvironmentDefault) IsRedirect() bool { + return o._statusCode/100 == 3 +} + +// IsClientError returns true when this delete environment default response has a 4xx status code +func (o *DeleteEnvironmentDefault) IsClientError() bool { + return o._statusCode/100 == 4 +} + +// IsServerError returns true when this delete environment default response has a 5xx status code +func (o *DeleteEnvironmentDefault) IsServerError() bool { + return o._statusCode/100 == 5 +} + +// IsCode returns true when this delete environment default response a status code equal to that given +func (o *DeleteEnvironmentDefault) IsCode(code int) bool { + return o._statusCode == code +} + +// Code gets the status code for the delete environment default response +func (o *DeleteEnvironmentDefault) Code() int { + return o._statusCode +} + +func (o *DeleteEnvironmentDefault) Error() string { + payload, _ := json.Marshal(o.Payload) + return fmt.Sprintf("[DELETE /organizations/{organization_canonical}/projects/{project_canonical}/environments/{environment_canonical}][%d] deleteEnvironment default %s", o._statusCode, payload) +} + +func (o *DeleteEnvironmentDefault) String() string { + payload, _ := json.Marshal(o.Payload) + return fmt.Sprintf("[DELETE /organizations/{organization_canonical}/projects/{project_canonical}/environments/{environment_canonical}][%d] deleteEnvironment default %s", o._statusCode, payload) +} + +func (o *DeleteEnvironmentDefault) GetPayload() *models.ErrorPayload { + return o.Payload +} + +func (o *DeleteEnvironmentDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + // hydrates response header Content-Length + hdrContentLength := response.GetHeader("Content-Length") + + if hdrContentLength != "" { + valcontentLength, err := swag.ConvertUint64(hdrContentLength) + if err != nil { + return errors.InvalidType("Content-Length", "header", "uint64", hdrContentLength) + } + o.ContentLength = valcontentLength + } + + o.Payload = new(models.ErrorPayload) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} diff --git a/client/client/organization_projects/delete_project_environment_parameters.go b/client/client/organization_projects/delete_project_environment_parameters.go deleted file mode 100644 index f7b1b543..00000000 --- a/client/client/organization_projects/delete_project_environment_parameters.go +++ /dev/null @@ -1,195 +0,0 @@ -// Code generated by go-swagger; DO NOT EDIT. - -package organization_projects - -// This file was generated by the swagger tool. -// Editing this file might prove futile when you re-run the swagger generate command - -import ( - "context" - "net/http" - "time" - - "github.com/go-openapi/errors" - "github.com/go-openapi/runtime" - cr "github.com/go-openapi/runtime/client" - "github.com/go-openapi/strfmt" -) - -// NewDeleteProjectEnvironmentParams creates a new DeleteProjectEnvironmentParams object, -// with the default timeout for this client. -// -// Default values are not hydrated, since defaults are normally applied by the API server side. -// -// To enforce default values in parameter, use SetDefaults or WithDefaults. -func NewDeleteProjectEnvironmentParams() *DeleteProjectEnvironmentParams { - return &DeleteProjectEnvironmentParams{ - timeout: cr.DefaultTimeout, - } -} - -// NewDeleteProjectEnvironmentParamsWithTimeout creates a new DeleteProjectEnvironmentParams object -// with the ability to set a timeout on a request. -func NewDeleteProjectEnvironmentParamsWithTimeout(timeout time.Duration) *DeleteProjectEnvironmentParams { - return &DeleteProjectEnvironmentParams{ - timeout: timeout, - } -} - -// NewDeleteProjectEnvironmentParamsWithContext creates a new DeleteProjectEnvironmentParams object -// with the ability to set a context for a request. -func NewDeleteProjectEnvironmentParamsWithContext(ctx context.Context) *DeleteProjectEnvironmentParams { - return &DeleteProjectEnvironmentParams{ - Context: ctx, - } -} - -// NewDeleteProjectEnvironmentParamsWithHTTPClient creates a new DeleteProjectEnvironmentParams object -// with the ability to set a custom HTTPClient for a request. -func NewDeleteProjectEnvironmentParamsWithHTTPClient(client *http.Client) *DeleteProjectEnvironmentParams { - return &DeleteProjectEnvironmentParams{ - HTTPClient: client, - } -} - -/* -DeleteProjectEnvironmentParams contains all the parameters to send to the API endpoint - - for the delete project environment operation. - - Typically these are written to a http.Request. -*/ -type DeleteProjectEnvironmentParams struct { - - /* EnvironmentCanonical. - - The environment canonical to use as part of a path - */ - EnvironmentCanonical string - - /* OrganizationCanonical. - - A canonical of an organization. - */ - OrganizationCanonical string - - /* ProjectCanonical. - - A canonical of a project. - */ - ProjectCanonical string - - timeout time.Duration - Context context.Context - HTTPClient *http.Client -} - -// WithDefaults hydrates default values in the delete project environment params (not the query body). -// -// All values with no default are reset to their zero value. -func (o *DeleteProjectEnvironmentParams) WithDefaults() *DeleteProjectEnvironmentParams { - o.SetDefaults() - return o -} - -// SetDefaults hydrates default values in the delete project environment params (not the query body). -// -// All values with no default are reset to their zero value. -func (o *DeleteProjectEnvironmentParams) SetDefaults() { - // no default values defined for this parameter -} - -// WithTimeout adds the timeout to the delete project environment params -func (o *DeleteProjectEnvironmentParams) WithTimeout(timeout time.Duration) *DeleteProjectEnvironmentParams { - o.SetTimeout(timeout) - return o -} - -// SetTimeout adds the timeout to the delete project environment params -func (o *DeleteProjectEnvironmentParams) SetTimeout(timeout time.Duration) { - o.timeout = timeout -} - -// WithContext adds the context to the delete project environment params -func (o *DeleteProjectEnvironmentParams) WithContext(ctx context.Context) *DeleteProjectEnvironmentParams { - o.SetContext(ctx) - return o -} - -// SetContext adds the context to the delete project environment params -func (o *DeleteProjectEnvironmentParams) SetContext(ctx context.Context) { - o.Context = ctx -} - -// WithHTTPClient adds the HTTPClient to the delete project environment params -func (o *DeleteProjectEnvironmentParams) WithHTTPClient(client *http.Client) *DeleteProjectEnvironmentParams { - o.SetHTTPClient(client) - return o -} - -// SetHTTPClient adds the HTTPClient to the delete project environment params -func (o *DeleteProjectEnvironmentParams) SetHTTPClient(client *http.Client) { - o.HTTPClient = client -} - -// WithEnvironmentCanonical adds the environmentCanonical to the delete project environment params -func (o *DeleteProjectEnvironmentParams) WithEnvironmentCanonical(environmentCanonical string) *DeleteProjectEnvironmentParams { - o.SetEnvironmentCanonical(environmentCanonical) - return o -} - -// SetEnvironmentCanonical adds the environmentCanonical to the delete project environment params -func (o *DeleteProjectEnvironmentParams) SetEnvironmentCanonical(environmentCanonical string) { - o.EnvironmentCanonical = environmentCanonical -} - -// WithOrganizationCanonical adds the organizationCanonical to the delete project environment params -func (o *DeleteProjectEnvironmentParams) WithOrganizationCanonical(organizationCanonical string) *DeleteProjectEnvironmentParams { - o.SetOrganizationCanonical(organizationCanonical) - return o -} - -// SetOrganizationCanonical adds the organizationCanonical to the delete project environment params -func (o *DeleteProjectEnvironmentParams) SetOrganizationCanonical(organizationCanonical string) { - o.OrganizationCanonical = organizationCanonical -} - -// WithProjectCanonical adds the projectCanonical to the delete project environment params -func (o *DeleteProjectEnvironmentParams) WithProjectCanonical(projectCanonical string) *DeleteProjectEnvironmentParams { - o.SetProjectCanonical(projectCanonical) - return o -} - -// SetProjectCanonical adds the projectCanonical to the delete project environment params -func (o *DeleteProjectEnvironmentParams) SetProjectCanonical(projectCanonical string) { - o.ProjectCanonical = projectCanonical -} - -// WriteToRequest writes these params to a swagger request -func (o *DeleteProjectEnvironmentParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { - - if err := r.SetTimeout(o.timeout); err != nil { - return err - } - var res []error - - // path param environment_canonical - if err := r.SetPathParam("environment_canonical", o.EnvironmentCanonical); err != nil { - return err - } - - // path param organization_canonical - if err := r.SetPathParam("organization_canonical", o.OrganizationCanonical); err != nil { - return err - } - - // path param project_canonical - if err := r.SetPathParam("project_canonical", o.ProjectCanonical); err != nil { - return err - } - - if len(res) > 0 { - return errors.CompositeValidationError(res...) - } - return nil -} diff --git a/client/client/organization_projects/delete_project_environment_responses.go b/client/client/organization_projects/delete_project_environment_responses.go deleted file mode 100644 index 85dc2876..00000000 --- a/client/client/organization_projects/delete_project_environment_responses.go +++ /dev/null @@ -1,380 +0,0 @@ -// Code generated by go-swagger; DO NOT EDIT. - -package organization_projects - -// This file was generated by the swagger tool. -// Editing this file might prove futile when you re-run the swagger generate command - -import ( - "encoding/json" - "fmt" - "io" - - "github.com/go-openapi/errors" - "github.com/go-openapi/runtime" - "github.com/go-openapi/strfmt" - "github.com/go-openapi/swag" - - "github.com/cycloidio/cycloid-cli/client/models" -) - -// DeleteProjectEnvironmentReader is a Reader for the DeleteProjectEnvironment structure. -type DeleteProjectEnvironmentReader struct { - formats strfmt.Registry -} - -// ReadResponse reads a server response into the received o. -func (o *DeleteProjectEnvironmentReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { - switch response.Code() { - case 204: - result := NewDeleteProjectEnvironmentNoContent() - if err := result.readResponse(response, consumer, o.formats); err != nil { - return nil, err - } - return result, nil - case 403: - result := NewDeleteProjectEnvironmentForbidden() - if err := result.readResponse(response, consumer, o.formats); err != nil { - return nil, err - } - return nil, result - case 404: - result := NewDeleteProjectEnvironmentNotFound() - if err := result.readResponse(response, consumer, o.formats); err != nil { - return nil, err - } - return nil, result - default: - result := NewDeleteProjectEnvironmentDefault(response.Code()) - if err := result.readResponse(response, consumer, o.formats); err != nil { - return nil, err - } - if response.Code()/100 == 2 { - return result, nil - } - return nil, result - } -} - -// NewDeleteProjectEnvironmentNoContent creates a DeleteProjectEnvironmentNoContent with default headers values -func NewDeleteProjectEnvironmentNoContent() *DeleteProjectEnvironmentNoContent { - return &DeleteProjectEnvironmentNoContent{} -} - -/* -DeleteProjectEnvironmentNoContent describes a response with status code 204, with default header values. - -Project environment has been deleted. -*/ -type DeleteProjectEnvironmentNoContent struct { -} - -// IsSuccess returns true when this delete project environment no content response has a 2xx status code -func (o *DeleteProjectEnvironmentNoContent) IsSuccess() bool { - return true -} - -// IsRedirect returns true when this delete project environment no content response has a 3xx status code -func (o *DeleteProjectEnvironmentNoContent) IsRedirect() bool { - return false -} - -// IsClientError returns true when this delete project environment no content response has a 4xx status code -func (o *DeleteProjectEnvironmentNoContent) IsClientError() bool { - return false -} - -// IsServerError returns true when this delete project environment no content response has a 5xx status code -func (o *DeleteProjectEnvironmentNoContent) IsServerError() bool { - return false -} - -// IsCode returns true when this delete project environment no content response a status code equal to that given -func (o *DeleteProjectEnvironmentNoContent) IsCode(code int) bool { - return code == 204 -} - -// Code gets the status code for the delete project environment no content response -func (o *DeleteProjectEnvironmentNoContent) Code() int { - return 204 -} - -func (o *DeleteProjectEnvironmentNoContent) Error() string { - return fmt.Sprintf("[DELETE /organizations/{organization_canonical}/projects/{project_canonical}/environments/{environment_canonical}][%d] deleteProjectEnvironmentNoContent", 204) -} - -func (o *DeleteProjectEnvironmentNoContent) String() string { - return fmt.Sprintf("[DELETE /organizations/{organization_canonical}/projects/{project_canonical}/environments/{environment_canonical}][%d] deleteProjectEnvironmentNoContent", 204) -} - -func (o *DeleteProjectEnvironmentNoContent) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { - - return nil -} - -// NewDeleteProjectEnvironmentForbidden creates a DeleteProjectEnvironmentForbidden with default headers values -func NewDeleteProjectEnvironmentForbidden() *DeleteProjectEnvironmentForbidden { - return &DeleteProjectEnvironmentForbidden{} -} - -/* -DeleteProjectEnvironmentForbidden describes a response with status code 403, with default header values. - -The authenticated user cannot perform the operation because, it doesn't have permissions for such operation. -*/ -type DeleteProjectEnvironmentForbidden struct { - - /* The length of the response body in octets (8-bit bytes). - - Format: uint64 - */ - ContentLength uint64 - - Payload *models.ErrorPayload -} - -// IsSuccess returns true when this delete project environment forbidden response has a 2xx status code -func (o *DeleteProjectEnvironmentForbidden) IsSuccess() bool { - return false -} - -// IsRedirect returns true when this delete project environment forbidden response has a 3xx status code -func (o *DeleteProjectEnvironmentForbidden) IsRedirect() bool { - return false -} - -// IsClientError returns true when this delete project environment forbidden response has a 4xx status code -func (o *DeleteProjectEnvironmentForbidden) IsClientError() bool { - return true -} - -// IsServerError returns true when this delete project environment forbidden response has a 5xx status code -func (o *DeleteProjectEnvironmentForbidden) IsServerError() bool { - return false -} - -// IsCode returns true when this delete project environment forbidden response a status code equal to that given -func (o *DeleteProjectEnvironmentForbidden) IsCode(code int) bool { - return code == 403 -} - -// Code gets the status code for the delete project environment forbidden response -func (o *DeleteProjectEnvironmentForbidden) Code() int { - return 403 -} - -func (o *DeleteProjectEnvironmentForbidden) Error() string { - payload, _ := json.Marshal(o.Payload) - return fmt.Sprintf("[DELETE /organizations/{organization_canonical}/projects/{project_canonical}/environments/{environment_canonical}][%d] deleteProjectEnvironmentForbidden %s", 403, payload) -} - -func (o *DeleteProjectEnvironmentForbidden) String() string { - payload, _ := json.Marshal(o.Payload) - return fmt.Sprintf("[DELETE /organizations/{organization_canonical}/projects/{project_canonical}/environments/{environment_canonical}][%d] deleteProjectEnvironmentForbidden %s", 403, payload) -} - -func (o *DeleteProjectEnvironmentForbidden) GetPayload() *models.ErrorPayload { - return o.Payload -} - -func (o *DeleteProjectEnvironmentForbidden) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { - - // hydrates response header Content-Length - hdrContentLength := response.GetHeader("Content-Length") - - if hdrContentLength != "" { - valcontentLength, err := swag.ConvertUint64(hdrContentLength) - if err != nil { - return errors.InvalidType("Content-Length", "header", "uint64", hdrContentLength) - } - o.ContentLength = valcontentLength - } - - o.Payload = new(models.ErrorPayload) - - // response payload - if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { - return err - } - - return nil -} - -// NewDeleteProjectEnvironmentNotFound creates a DeleteProjectEnvironmentNotFound with default headers values -func NewDeleteProjectEnvironmentNotFound() *DeleteProjectEnvironmentNotFound { - return &DeleteProjectEnvironmentNotFound{} -} - -/* -DeleteProjectEnvironmentNotFound describes a response with status code 404, with default header values. - -The response sent when any of the entities present in the path is not found. -*/ -type DeleteProjectEnvironmentNotFound struct { - - /* The length of the response body in octets (8-bit bytes). - - Format: uint64 - */ - ContentLength uint64 - - Payload *models.ErrorPayload -} - -// IsSuccess returns true when this delete project environment not found response has a 2xx status code -func (o *DeleteProjectEnvironmentNotFound) IsSuccess() bool { - return false -} - -// IsRedirect returns true when this delete project environment not found response has a 3xx status code -func (o *DeleteProjectEnvironmentNotFound) IsRedirect() bool { - return false -} - -// IsClientError returns true when this delete project environment not found response has a 4xx status code -func (o *DeleteProjectEnvironmentNotFound) IsClientError() bool { - return true -} - -// IsServerError returns true when this delete project environment not found response has a 5xx status code -func (o *DeleteProjectEnvironmentNotFound) IsServerError() bool { - return false -} - -// IsCode returns true when this delete project environment not found response a status code equal to that given -func (o *DeleteProjectEnvironmentNotFound) IsCode(code int) bool { - return code == 404 -} - -// Code gets the status code for the delete project environment not found response -func (o *DeleteProjectEnvironmentNotFound) Code() int { - return 404 -} - -func (o *DeleteProjectEnvironmentNotFound) Error() string { - payload, _ := json.Marshal(o.Payload) - return fmt.Sprintf("[DELETE /organizations/{organization_canonical}/projects/{project_canonical}/environments/{environment_canonical}][%d] deleteProjectEnvironmentNotFound %s", 404, payload) -} - -func (o *DeleteProjectEnvironmentNotFound) String() string { - payload, _ := json.Marshal(o.Payload) - return fmt.Sprintf("[DELETE /organizations/{organization_canonical}/projects/{project_canonical}/environments/{environment_canonical}][%d] deleteProjectEnvironmentNotFound %s", 404, payload) -} - -func (o *DeleteProjectEnvironmentNotFound) GetPayload() *models.ErrorPayload { - return o.Payload -} - -func (o *DeleteProjectEnvironmentNotFound) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { - - // hydrates response header Content-Length - hdrContentLength := response.GetHeader("Content-Length") - - if hdrContentLength != "" { - valcontentLength, err := swag.ConvertUint64(hdrContentLength) - if err != nil { - return errors.InvalidType("Content-Length", "header", "uint64", hdrContentLength) - } - o.ContentLength = valcontentLength - } - - o.Payload = new(models.ErrorPayload) - - // response payload - if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { - return err - } - - return nil -} - -// NewDeleteProjectEnvironmentDefault creates a DeleteProjectEnvironmentDefault with default headers values -func NewDeleteProjectEnvironmentDefault(code int) *DeleteProjectEnvironmentDefault { - return &DeleteProjectEnvironmentDefault{ - _statusCode: code, - } -} - -/* -DeleteProjectEnvironmentDefault describes a response with status code -1, with default header values. - -The response sent when an unexpected error happened, as known as an internal server error. -*/ -type DeleteProjectEnvironmentDefault struct { - _statusCode int - - /* The length of the response body in octets (8-bit bytes). - - Format: uint64 - */ - ContentLength uint64 - - Payload *models.ErrorPayload -} - -// IsSuccess returns true when this delete project environment default response has a 2xx status code -func (o *DeleteProjectEnvironmentDefault) IsSuccess() bool { - return o._statusCode/100 == 2 -} - -// IsRedirect returns true when this delete project environment default response has a 3xx status code -func (o *DeleteProjectEnvironmentDefault) IsRedirect() bool { - return o._statusCode/100 == 3 -} - -// IsClientError returns true when this delete project environment default response has a 4xx status code -func (o *DeleteProjectEnvironmentDefault) IsClientError() bool { - return o._statusCode/100 == 4 -} - -// IsServerError returns true when this delete project environment default response has a 5xx status code -func (o *DeleteProjectEnvironmentDefault) IsServerError() bool { - return o._statusCode/100 == 5 -} - -// IsCode returns true when this delete project environment default response a status code equal to that given -func (o *DeleteProjectEnvironmentDefault) IsCode(code int) bool { - return o._statusCode == code -} - -// Code gets the status code for the delete project environment default response -func (o *DeleteProjectEnvironmentDefault) Code() int { - return o._statusCode -} - -func (o *DeleteProjectEnvironmentDefault) Error() string { - payload, _ := json.Marshal(o.Payload) - return fmt.Sprintf("[DELETE /organizations/{organization_canonical}/projects/{project_canonical}/environments/{environment_canonical}][%d] deleteProjectEnvironment default %s", o._statusCode, payload) -} - -func (o *DeleteProjectEnvironmentDefault) String() string { - payload, _ := json.Marshal(o.Payload) - return fmt.Sprintf("[DELETE /organizations/{organization_canonical}/projects/{project_canonical}/environments/{environment_canonical}][%d] deleteProjectEnvironment default %s", o._statusCode, payload) -} - -func (o *DeleteProjectEnvironmentDefault) GetPayload() *models.ErrorPayload { - return o.Payload -} - -func (o *DeleteProjectEnvironmentDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { - - // hydrates response header Content-Length - hdrContentLength := response.GetHeader("Content-Length") - - if hdrContentLength != "" { - valcontentLength, err := swag.ConvertUint64(hdrContentLength) - if err != nil { - return errors.InvalidType("Content-Length", "header", "uint64", hdrContentLength) - } - o.ContentLength = valcontentLength - } - - o.Payload = new(models.ErrorPayload) - - // response payload - if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { - return err - } - - return nil -} diff --git a/client/client/organization_projects/organization_projects_client.go b/client/client/organization_projects/organization_projects_client.go index 5ace38d1..b9fd2d06 100644 --- a/client/client/organization_projects/organization_projects_client.go +++ b/client/client/organization_projects/organization_projects_client.go @@ -103,13 +103,15 @@ func WithAcceptApplicationVndCycloidIoV1JSON(r *runtime.ClientOperation) { // ClientService is the interface for Client methods type ClientService interface { + CreateEnvironment(params *CreateEnvironmentParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*CreateEnvironmentOK, error) + CreateProject(params *CreateProjectParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*CreateProjectOK, error) CreateProjectFavorite(params *CreateProjectFavoriteParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*CreateProjectFavoriteNoContent, error) - DeleteProject(params *DeleteProjectParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*DeleteProjectNoContent, error) + DeleteEnvironment(params *DeleteEnvironmentParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*DeleteEnvironmentNoContent, error) - DeleteProjectEnvironment(params *DeleteProjectEnvironmentParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*DeleteProjectEnvironmentNoContent, error) + DeleteProject(params *DeleteProjectParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*DeleteProjectNoContent, error) DeleteProjectFavorite(params *DeleteProjectFavoriteParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*DeleteProjectFavoriteNoContent, error) @@ -119,11 +121,51 @@ type ClientService interface { GetProjects(params *GetProjectsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetProjectsOK, error) + UpdateEnvironment(params *UpdateEnvironmentParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*UpdateEnvironmentOK, error) + UpdateProject(params *UpdateProjectParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*UpdateProjectOK, error) SetTransport(transport runtime.ClientTransport) } +/* +CreateEnvironment Create a new environment with provider, icon and color in a project +*/ +func (a *Client) CreateEnvironment(params *CreateEnvironmentParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*CreateEnvironmentOK, error) { + // TODO: Validate the params before sending + if params == nil { + params = NewCreateEnvironmentParams() + } + op := &runtime.ClientOperation{ + ID: "createEnvironment", + Method: "POST", + PathPattern: "/organizations/{organization_canonical}/projects/{project_canonical}/environments", + ProducesMediaTypes: []string{"application/json"}, + ConsumesMediaTypes: []string{"application/vnd.cycloid.io.v1+json", "application/x-www-form-urlencoded"}, + Schemes: []string{"https"}, + Params: params, + Reader: &CreateEnvironmentReader{formats: a.formats}, + AuthInfo: authInfo, + Context: params.Context, + Client: params.HTTPClient, + } + for _, opt := range opts { + opt(op) + } + + result, err := a.transport.Submit(op) + if err != nil { + return nil, err + } + success, ok := result.(*CreateEnvironmentOK) + if ok { + return success, nil + } + // unexpected success response + unexpectedSuccess := result.(*CreateEnvironmentDefault) + return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code()) +} + /* CreateProject Create a new project with envs and pipelines in the organization. */ @@ -201,22 +243,22 @@ func (a *Client) CreateProjectFavorite(params *CreateProjectFavoriteParams, auth } /* -DeleteProject Delete a project of the organization. +DeleteEnvironment Delete a project environment. */ -func (a *Client) DeleteProject(params *DeleteProjectParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*DeleteProjectNoContent, error) { +func (a *Client) DeleteEnvironment(params *DeleteEnvironmentParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*DeleteEnvironmentNoContent, error) { // TODO: Validate the params before sending if params == nil { - params = NewDeleteProjectParams() + params = NewDeleteEnvironmentParams() } op := &runtime.ClientOperation{ - ID: "deleteProject", + ID: "deleteEnvironment", Method: "DELETE", - PathPattern: "/organizations/{organization_canonical}/projects/{project_canonical}", + PathPattern: "/organizations/{organization_canonical}/projects/{project_canonical}/environments/{environment_canonical}", ProducesMediaTypes: []string{"application/json"}, ConsumesMediaTypes: []string{"application/vnd.cycloid.io.v1+json", "application/x-www-form-urlencoded"}, Schemes: []string{"https"}, Params: params, - Reader: &DeleteProjectReader{formats: a.formats}, + Reader: &DeleteEnvironmentReader{formats: a.formats}, AuthInfo: authInfo, Context: params.Context, Client: params.HTTPClient, @@ -229,32 +271,32 @@ func (a *Client) DeleteProject(params *DeleteProjectParams, authInfo runtime.Cli if err != nil { return nil, err } - success, ok := result.(*DeleteProjectNoContent) + success, ok := result.(*DeleteEnvironmentNoContent) if ok { return success, nil } // unexpected success response - unexpectedSuccess := result.(*DeleteProjectDefault) + unexpectedSuccess := result.(*DeleteEnvironmentDefault) return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code()) } /* -DeleteProjectEnvironment Delete a project environment of the organization, and the project itself if it's the last environment. +DeleteProject Delete a project of the organization. */ -func (a *Client) DeleteProjectEnvironment(params *DeleteProjectEnvironmentParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*DeleteProjectEnvironmentNoContent, error) { +func (a *Client) DeleteProject(params *DeleteProjectParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*DeleteProjectNoContent, error) { // TODO: Validate the params before sending if params == nil { - params = NewDeleteProjectEnvironmentParams() + params = NewDeleteProjectParams() } op := &runtime.ClientOperation{ - ID: "deleteProjectEnvironment", + ID: "deleteProject", Method: "DELETE", - PathPattern: "/organizations/{organization_canonical}/projects/{project_canonical}/environments/{environment_canonical}", + PathPattern: "/organizations/{organization_canonical}/projects/{project_canonical}", ProducesMediaTypes: []string{"application/json"}, ConsumesMediaTypes: []string{"application/vnd.cycloid.io.v1+json", "application/x-www-form-urlencoded"}, Schemes: []string{"https"}, Params: params, - Reader: &DeleteProjectEnvironmentReader{formats: a.formats}, + Reader: &DeleteProjectReader{formats: a.formats}, AuthInfo: authInfo, Context: params.Context, Client: params.HTTPClient, @@ -267,12 +309,12 @@ func (a *Client) DeleteProjectEnvironment(params *DeleteProjectEnvironmentParams if err != nil { return nil, err } - success, ok := result.(*DeleteProjectEnvironmentNoContent) + success, ok := result.(*DeleteProjectNoContent) if ok { return success, nil } // unexpected success response - unexpectedSuccess := result.(*DeleteProjectEnvironmentDefault) + unexpectedSuccess := result.(*DeleteProjectDefault) return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code()) } @@ -428,6 +470,44 @@ func (a *Client) GetProjects(params *GetProjectsParams, authInfo runtime.ClientA return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code()) } +/* +UpdateEnvironment Update a project environment of the organization. +*/ +func (a *Client) UpdateEnvironment(params *UpdateEnvironmentParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*UpdateEnvironmentOK, error) { + // TODO: Validate the params before sending + if params == nil { + params = NewUpdateEnvironmentParams() + } + op := &runtime.ClientOperation{ + ID: "updateEnvironment", + Method: "PUT", + PathPattern: "/organizations/{organization_canonical}/projects/{project_canonical}/environments/{environment_canonical}", + ProducesMediaTypes: []string{"application/json"}, + ConsumesMediaTypes: []string{"application/vnd.cycloid.io.v1+json", "application/x-www-form-urlencoded"}, + Schemes: []string{"https"}, + Params: params, + Reader: &UpdateEnvironmentReader{formats: a.formats}, + AuthInfo: authInfo, + Context: params.Context, + Client: params.HTTPClient, + } + for _, opt := range opts { + opt(op) + } + + result, err := a.transport.Submit(op) + if err != nil { + return nil, err + } + success, ok := result.(*UpdateEnvironmentOK) + if ok { + return success, nil + } + // unexpected success response + unexpectedSuccess := result.(*UpdateEnvironmentDefault) + return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code()) +} + /* UpdateProject Update the information of a project of the organization. If the project has some information on the fields which aren't required and they are not sent or set to their default values, which depend of their types, the information will be removed. */ diff --git a/client/client/organization_projects/update_environment_parameters.go b/client/client/organization_projects/update_environment_parameters.go new file mode 100644 index 00000000..9730bc66 --- /dev/null +++ b/client/client/organization_projects/update_environment_parameters.go @@ -0,0 +1,219 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package organization_projects + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + "net/http" + "time" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + cr "github.com/go-openapi/runtime/client" + "github.com/go-openapi/strfmt" + + "github.com/cycloidio/cycloid-cli/client/models" +) + +// NewUpdateEnvironmentParams creates a new UpdateEnvironmentParams object, +// with the default timeout for this client. +// +// Default values are not hydrated, since defaults are normally applied by the API server side. +// +// To enforce default values in parameter, use SetDefaults or WithDefaults. +func NewUpdateEnvironmentParams() *UpdateEnvironmentParams { + return &UpdateEnvironmentParams{ + timeout: cr.DefaultTimeout, + } +} + +// NewUpdateEnvironmentParamsWithTimeout creates a new UpdateEnvironmentParams object +// with the ability to set a timeout on a request. +func NewUpdateEnvironmentParamsWithTimeout(timeout time.Duration) *UpdateEnvironmentParams { + return &UpdateEnvironmentParams{ + timeout: timeout, + } +} + +// NewUpdateEnvironmentParamsWithContext creates a new UpdateEnvironmentParams object +// with the ability to set a context for a request. +func NewUpdateEnvironmentParamsWithContext(ctx context.Context) *UpdateEnvironmentParams { + return &UpdateEnvironmentParams{ + Context: ctx, + } +} + +// NewUpdateEnvironmentParamsWithHTTPClient creates a new UpdateEnvironmentParams object +// with the ability to set a custom HTTPClient for a request. +func NewUpdateEnvironmentParamsWithHTTPClient(client *http.Client) *UpdateEnvironmentParams { + return &UpdateEnvironmentParams{ + HTTPClient: client, + } +} + +/* +UpdateEnvironmentParams contains all the parameters to send to the API endpoint + + for the update environment operation. + + Typically these are written to a http.Request. +*/ +type UpdateEnvironmentParams struct { + + /* Body. + + The canonical of the environment to update and its configuration. + */ + Body *models.UpdateEnvironment + + /* EnvironmentCanonical. + + The environment canonical to use as part of a path + */ + EnvironmentCanonical string + + /* OrganizationCanonical. + + A canonical of an organization. + */ + OrganizationCanonical string + + /* ProjectCanonical. + + A canonical of a project. + */ + ProjectCanonical string + + timeout time.Duration + Context context.Context + HTTPClient *http.Client +} + +// WithDefaults hydrates default values in the update environment params (not the query body). +// +// All values with no default are reset to their zero value. +func (o *UpdateEnvironmentParams) WithDefaults() *UpdateEnvironmentParams { + o.SetDefaults() + return o +} + +// SetDefaults hydrates default values in the update environment params (not the query body). +// +// All values with no default are reset to their zero value. +func (o *UpdateEnvironmentParams) SetDefaults() { + // no default values defined for this parameter +} + +// WithTimeout adds the timeout to the update environment params +func (o *UpdateEnvironmentParams) WithTimeout(timeout time.Duration) *UpdateEnvironmentParams { + o.SetTimeout(timeout) + return o +} + +// SetTimeout adds the timeout to the update environment params +func (o *UpdateEnvironmentParams) SetTimeout(timeout time.Duration) { + o.timeout = timeout +} + +// WithContext adds the context to the update environment params +func (o *UpdateEnvironmentParams) WithContext(ctx context.Context) *UpdateEnvironmentParams { + o.SetContext(ctx) + return o +} + +// SetContext adds the context to the update environment params +func (o *UpdateEnvironmentParams) SetContext(ctx context.Context) { + o.Context = ctx +} + +// WithHTTPClient adds the HTTPClient to the update environment params +func (o *UpdateEnvironmentParams) WithHTTPClient(client *http.Client) *UpdateEnvironmentParams { + o.SetHTTPClient(client) + return o +} + +// SetHTTPClient adds the HTTPClient to the update environment params +func (o *UpdateEnvironmentParams) SetHTTPClient(client *http.Client) { + o.HTTPClient = client +} + +// WithBody adds the body to the update environment params +func (o *UpdateEnvironmentParams) WithBody(body *models.UpdateEnvironment) *UpdateEnvironmentParams { + o.SetBody(body) + return o +} + +// SetBody adds the body to the update environment params +func (o *UpdateEnvironmentParams) SetBody(body *models.UpdateEnvironment) { + o.Body = body +} + +// WithEnvironmentCanonical adds the environmentCanonical to the update environment params +func (o *UpdateEnvironmentParams) WithEnvironmentCanonical(environmentCanonical string) *UpdateEnvironmentParams { + o.SetEnvironmentCanonical(environmentCanonical) + return o +} + +// SetEnvironmentCanonical adds the environmentCanonical to the update environment params +func (o *UpdateEnvironmentParams) SetEnvironmentCanonical(environmentCanonical string) { + o.EnvironmentCanonical = environmentCanonical +} + +// WithOrganizationCanonical adds the organizationCanonical to the update environment params +func (o *UpdateEnvironmentParams) WithOrganizationCanonical(organizationCanonical string) *UpdateEnvironmentParams { + o.SetOrganizationCanonical(organizationCanonical) + return o +} + +// SetOrganizationCanonical adds the organizationCanonical to the update environment params +func (o *UpdateEnvironmentParams) SetOrganizationCanonical(organizationCanonical string) { + o.OrganizationCanonical = organizationCanonical +} + +// WithProjectCanonical adds the projectCanonical to the update environment params +func (o *UpdateEnvironmentParams) WithProjectCanonical(projectCanonical string) *UpdateEnvironmentParams { + o.SetProjectCanonical(projectCanonical) + return o +} + +// SetProjectCanonical adds the projectCanonical to the update environment params +func (o *UpdateEnvironmentParams) SetProjectCanonical(projectCanonical string) { + o.ProjectCanonical = projectCanonical +} + +// WriteToRequest writes these params to a swagger request +func (o *UpdateEnvironmentParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { + + if err := r.SetTimeout(o.timeout); err != nil { + return err + } + var res []error + if o.Body != nil { + if err := r.SetBodyParam(o.Body); err != nil { + return err + } + } + + // path param environment_canonical + if err := r.SetPathParam("environment_canonical", o.EnvironmentCanonical); err != nil { + return err + } + + // path param organization_canonical + if err := r.SetPathParam("organization_canonical", o.OrganizationCanonical); err != nil { + return err + } + + // path param project_canonical + if err := r.SetPathParam("project_canonical", o.ProjectCanonical); err != nil { + return err + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/client/client/organization_projects/update_environment_responses.go b/client/client/organization_projects/update_environment_responses.go new file mode 100644 index 00000000..5d6d1b70 --- /dev/null +++ b/client/client/organization_projects/update_environment_responses.go @@ -0,0 +1,490 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package organization_projects + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + "encoding/json" + "fmt" + "io" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" + "github.com/go-openapi/validate" + + "github.com/cycloidio/cycloid-cli/client/models" +) + +// UpdateEnvironmentReader is a Reader for the UpdateEnvironment structure. +type UpdateEnvironmentReader struct { + formats strfmt.Registry +} + +// ReadResponse reads a server response into the received o. +func (o *UpdateEnvironmentReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + switch response.Code() { + case 200: + result := NewUpdateEnvironmentOK() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return result, nil + case 403: + result := NewUpdateEnvironmentForbidden() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + case 404: + result := NewUpdateEnvironmentNotFound() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + default: + result := NewUpdateEnvironmentDefault(response.Code()) + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + if response.Code()/100 == 2 { + return result, nil + } + return nil, result + } +} + +// NewUpdateEnvironmentOK creates a UpdateEnvironmentOK with default headers values +func NewUpdateEnvironmentOK() *UpdateEnvironmentOK { + return &UpdateEnvironmentOK{} +} + +/* +UpdateEnvironmentOK describes a response with status code 200, with default header values. + +Environment updated. The body contains the information of the updated environment. +*/ +type UpdateEnvironmentOK struct { + Payload *UpdateEnvironmentOKBody +} + +// IsSuccess returns true when this update environment o k response has a 2xx status code +func (o *UpdateEnvironmentOK) IsSuccess() bool { + return true +} + +// IsRedirect returns true when this update environment o k response has a 3xx status code +func (o *UpdateEnvironmentOK) IsRedirect() bool { + return false +} + +// IsClientError returns true when this update environment o k response has a 4xx status code +func (o *UpdateEnvironmentOK) IsClientError() bool { + return false +} + +// IsServerError returns true when this update environment o k response has a 5xx status code +func (o *UpdateEnvironmentOK) IsServerError() bool { + return false +} + +// IsCode returns true when this update environment o k response a status code equal to that given +func (o *UpdateEnvironmentOK) IsCode(code int) bool { + return code == 200 +} + +// Code gets the status code for the update environment o k response +func (o *UpdateEnvironmentOK) Code() int { + return 200 +} + +func (o *UpdateEnvironmentOK) Error() string { + payload, _ := json.Marshal(o.Payload) + return fmt.Sprintf("[PUT /organizations/{organization_canonical}/projects/{project_canonical}/environments/{environment_canonical}][%d] updateEnvironmentOK %s", 200, payload) +} + +func (o *UpdateEnvironmentOK) String() string { + payload, _ := json.Marshal(o.Payload) + return fmt.Sprintf("[PUT /organizations/{organization_canonical}/projects/{project_canonical}/environments/{environment_canonical}][%d] updateEnvironmentOK %s", 200, payload) +} + +func (o *UpdateEnvironmentOK) GetPayload() *UpdateEnvironmentOKBody { + return o.Payload +} + +func (o *UpdateEnvironmentOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(UpdateEnvironmentOKBody) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewUpdateEnvironmentForbidden creates a UpdateEnvironmentForbidden with default headers values +func NewUpdateEnvironmentForbidden() *UpdateEnvironmentForbidden { + return &UpdateEnvironmentForbidden{} +} + +/* +UpdateEnvironmentForbidden describes a response with status code 403, with default header values. + +The authenticated user cannot perform the operation because, it doesn't have permissions for such operation. +*/ +type UpdateEnvironmentForbidden struct { + + /* The length of the response body in octets (8-bit bytes). + + Format: uint64 + */ + ContentLength uint64 + + Payload *models.ErrorPayload +} + +// IsSuccess returns true when this update environment forbidden response has a 2xx status code +func (o *UpdateEnvironmentForbidden) IsSuccess() bool { + return false +} + +// IsRedirect returns true when this update environment forbidden response has a 3xx status code +func (o *UpdateEnvironmentForbidden) IsRedirect() bool { + return false +} + +// IsClientError returns true when this update environment forbidden response has a 4xx status code +func (o *UpdateEnvironmentForbidden) IsClientError() bool { + return true +} + +// IsServerError returns true when this update environment forbidden response has a 5xx status code +func (o *UpdateEnvironmentForbidden) IsServerError() bool { + return false +} + +// IsCode returns true when this update environment forbidden response a status code equal to that given +func (o *UpdateEnvironmentForbidden) IsCode(code int) bool { + return code == 403 +} + +// Code gets the status code for the update environment forbidden response +func (o *UpdateEnvironmentForbidden) Code() int { + return 403 +} + +func (o *UpdateEnvironmentForbidden) Error() string { + payload, _ := json.Marshal(o.Payload) + return fmt.Sprintf("[PUT /organizations/{organization_canonical}/projects/{project_canonical}/environments/{environment_canonical}][%d] updateEnvironmentForbidden %s", 403, payload) +} + +func (o *UpdateEnvironmentForbidden) String() string { + payload, _ := json.Marshal(o.Payload) + return fmt.Sprintf("[PUT /organizations/{organization_canonical}/projects/{project_canonical}/environments/{environment_canonical}][%d] updateEnvironmentForbidden %s", 403, payload) +} + +func (o *UpdateEnvironmentForbidden) GetPayload() *models.ErrorPayload { + return o.Payload +} + +func (o *UpdateEnvironmentForbidden) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + // hydrates response header Content-Length + hdrContentLength := response.GetHeader("Content-Length") + + if hdrContentLength != "" { + valcontentLength, err := swag.ConvertUint64(hdrContentLength) + if err != nil { + return errors.InvalidType("Content-Length", "header", "uint64", hdrContentLength) + } + o.ContentLength = valcontentLength + } + + o.Payload = new(models.ErrorPayload) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewUpdateEnvironmentNotFound creates a UpdateEnvironmentNotFound with default headers values +func NewUpdateEnvironmentNotFound() *UpdateEnvironmentNotFound { + return &UpdateEnvironmentNotFound{} +} + +/* +UpdateEnvironmentNotFound describes a response with status code 404, with default header values. + +The response sent when any of the entities present in the path is not found. +*/ +type UpdateEnvironmentNotFound struct { + + /* The length of the response body in octets (8-bit bytes). + + Format: uint64 + */ + ContentLength uint64 + + Payload *models.ErrorPayload +} + +// IsSuccess returns true when this update environment not found response has a 2xx status code +func (o *UpdateEnvironmentNotFound) IsSuccess() bool { + return false +} + +// IsRedirect returns true when this update environment not found response has a 3xx status code +func (o *UpdateEnvironmentNotFound) IsRedirect() bool { + return false +} + +// IsClientError returns true when this update environment not found response has a 4xx status code +func (o *UpdateEnvironmentNotFound) IsClientError() bool { + return true +} + +// IsServerError returns true when this update environment not found response has a 5xx status code +func (o *UpdateEnvironmentNotFound) IsServerError() bool { + return false +} + +// IsCode returns true when this update environment not found response a status code equal to that given +func (o *UpdateEnvironmentNotFound) IsCode(code int) bool { + return code == 404 +} + +// Code gets the status code for the update environment not found response +func (o *UpdateEnvironmentNotFound) Code() int { + return 404 +} + +func (o *UpdateEnvironmentNotFound) Error() string { + payload, _ := json.Marshal(o.Payload) + return fmt.Sprintf("[PUT /organizations/{organization_canonical}/projects/{project_canonical}/environments/{environment_canonical}][%d] updateEnvironmentNotFound %s", 404, payload) +} + +func (o *UpdateEnvironmentNotFound) String() string { + payload, _ := json.Marshal(o.Payload) + return fmt.Sprintf("[PUT /organizations/{organization_canonical}/projects/{project_canonical}/environments/{environment_canonical}][%d] updateEnvironmentNotFound %s", 404, payload) +} + +func (o *UpdateEnvironmentNotFound) GetPayload() *models.ErrorPayload { + return o.Payload +} + +func (o *UpdateEnvironmentNotFound) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + // hydrates response header Content-Length + hdrContentLength := response.GetHeader("Content-Length") + + if hdrContentLength != "" { + valcontentLength, err := swag.ConvertUint64(hdrContentLength) + if err != nil { + return errors.InvalidType("Content-Length", "header", "uint64", hdrContentLength) + } + o.ContentLength = valcontentLength + } + + o.Payload = new(models.ErrorPayload) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewUpdateEnvironmentDefault creates a UpdateEnvironmentDefault with default headers values +func NewUpdateEnvironmentDefault(code int) *UpdateEnvironmentDefault { + return &UpdateEnvironmentDefault{ + _statusCode: code, + } +} + +/* +UpdateEnvironmentDefault describes a response with status code -1, with default header values. + +The response sent when an unexpected error happened, as known as an internal server error. +*/ +type UpdateEnvironmentDefault struct { + _statusCode int + + /* The length of the response body in octets (8-bit bytes). + + Format: uint64 + */ + ContentLength uint64 + + Payload *models.ErrorPayload +} + +// IsSuccess returns true when this update environment default response has a 2xx status code +func (o *UpdateEnvironmentDefault) IsSuccess() bool { + return o._statusCode/100 == 2 +} + +// IsRedirect returns true when this update environment default response has a 3xx status code +func (o *UpdateEnvironmentDefault) IsRedirect() bool { + return o._statusCode/100 == 3 +} + +// IsClientError returns true when this update environment default response has a 4xx status code +func (o *UpdateEnvironmentDefault) IsClientError() bool { + return o._statusCode/100 == 4 +} + +// IsServerError returns true when this update environment default response has a 5xx status code +func (o *UpdateEnvironmentDefault) IsServerError() bool { + return o._statusCode/100 == 5 +} + +// IsCode returns true when this update environment default response a status code equal to that given +func (o *UpdateEnvironmentDefault) IsCode(code int) bool { + return o._statusCode == code +} + +// Code gets the status code for the update environment default response +func (o *UpdateEnvironmentDefault) Code() int { + return o._statusCode +} + +func (o *UpdateEnvironmentDefault) Error() string { + payload, _ := json.Marshal(o.Payload) + return fmt.Sprintf("[PUT /organizations/{organization_canonical}/projects/{project_canonical}/environments/{environment_canonical}][%d] updateEnvironment default %s", o._statusCode, payload) +} + +func (o *UpdateEnvironmentDefault) String() string { + payload, _ := json.Marshal(o.Payload) + return fmt.Sprintf("[PUT /organizations/{organization_canonical}/projects/{project_canonical}/environments/{environment_canonical}][%d] updateEnvironment default %s", o._statusCode, payload) +} + +func (o *UpdateEnvironmentDefault) GetPayload() *models.ErrorPayload { + return o.Payload +} + +func (o *UpdateEnvironmentDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + // hydrates response header Content-Length + hdrContentLength := response.GetHeader("Content-Length") + + if hdrContentLength != "" { + valcontentLength, err := swag.ConvertUint64(hdrContentLength) + if err != nil { + return errors.InvalidType("Content-Length", "header", "uint64", hdrContentLength) + } + o.ContentLength = valcontentLength + } + + o.Payload = new(models.ErrorPayload) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +/* +UpdateEnvironmentOKBody update environment o k body +swagger:model UpdateEnvironmentOKBody +*/ +type UpdateEnvironmentOKBody struct { + + // data + // Required: true + Data *models.UpdateEnvironment `json:"data"` +} + +// Validate validates this update environment o k body +func (o *UpdateEnvironmentOKBody) Validate(formats strfmt.Registry) error { + var res []error + + if err := o.validateData(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (o *UpdateEnvironmentOKBody) validateData(formats strfmt.Registry) error { + + if err := validate.Required("updateEnvironmentOK"+"."+"data", "body", o.Data); err != nil { + return err + } + + if o.Data != nil { + if err := o.Data.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("updateEnvironmentOK" + "." + "data") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("updateEnvironmentOK" + "." + "data") + } + return err + } + } + + return nil +} + +// ContextValidate validate this update environment o k body based on the context it is used +func (o *UpdateEnvironmentOKBody) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + if err := o.contextValidateData(ctx, formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (o *UpdateEnvironmentOKBody) contextValidateData(ctx context.Context, formats strfmt.Registry) error { + + if o.Data != nil { + + if err := o.Data.ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("updateEnvironmentOK" + "." + "data") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("updateEnvironmentOK" + "." + "data") + } + return err + } + } + + return nil +} + +// MarshalBinary interface implementation +func (o *UpdateEnvironmentOKBody) MarshalBinary() ([]byte, error) { + if o == nil { + return nil, nil + } + return swag.WriteJSON(o) +} + +// UnmarshalBinary interface implementation +func (o *UpdateEnvironmentOKBody) UnmarshalBinary(b []byte) error { + var res UpdateEnvironmentOKBody + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *o = res + return nil +} diff --git a/client/models/infrastructure_graph_node.go b/client/models/infrastructure_graph_node.go index c1317b0a..75fe9284 100644 --- a/client/models/infrastructure_graph_node.go +++ b/client/models/infrastructure_graph_node.go @@ -29,6 +29,9 @@ type InfrastructureGraphNode struct { // Required: true ID *string `json:"id"` + // name + Name string `json:"name,omitempty"` + // It holds [x,y] // Required: true Position []uint64 `json:"position"` diff --git a/client/models/new_environment.go b/client/models/new_environment.go index 21062c05..506cde2c 100644 --- a/client/models/new_environment.go +++ b/client/models/new_environment.go @@ -41,6 +41,12 @@ type NewEnvironment struct { // icon // Max Length: 64 Icon string `json:"icon,omitempty"` + + // use case + // Max Length: 100 + // Min Length: 3 + // Pattern: ^[a-z0-9]+[a-z0-9\-_]+[a-z0-9]+$ + UseCase string `json:"use_case,omitempty"` } // Validate validates this new environment @@ -63,6 +69,10 @@ func (m *NewEnvironment) Validate(formats strfmt.Registry) error { res = append(res, err) } + if err := m.validateUseCase(formats); err != nil { + res = append(res, err) + } + if len(res) > 0 { return errors.CompositeValidationError(res...) } @@ -134,6 +144,26 @@ func (m *NewEnvironment) validateIcon(formats strfmt.Registry) error { return nil } +func (m *NewEnvironment) validateUseCase(formats strfmt.Registry) error { + if swag.IsZero(m.UseCase) { // not required + return nil + } + + if err := validate.MinLength("use_case", "body", m.UseCase, 3); err != nil { + return err + } + + if err := validate.MaxLength("use_case", "body", m.UseCase, 100); err != nil { + return err + } + + if err := validate.Pattern("use_case", "body", m.UseCase, `^[a-z0-9]+[a-z0-9\-_]+[a-z0-9]+$`); err != nil { + return err + } + + return nil +} + // ContextValidate validates this new environment based on context it is used func (m *NewEnvironment) ContextValidate(ctx context.Context, formats strfmt.Registry) error { return nil diff --git a/client/models/update_environment.go b/client/models/update_environment.go new file mode 100644 index 00000000..73f3f94c --- /dev/null +++ b/client/models/update_environment.go @@ -0,0 +1,156 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + + "github.com/go-openapi/errors" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" + "github.com/go-openapi/validate" +) + +// UpdateEnvironment Update Environment +// +// # Represent an entity necessary for environment update +// +// swagger:model UpdateEnvironment +type UpdateEnvironment struct { + + // cloud provider canonical + // Max Length: 100 + // Min Length: 3 + // Pattern: ^[a-z0-9]+[a-z0-9\-_]+[a-z0-9]+$ + CloudProviderCanonical string `json:"cloud_provider_canonical,omitempty"` + + // color + // Max Length: 64 + Color string `json:"color,omitempty"` + + // icon + // Max Length: 64 + Icon string `json:"icon,omitempty"` + + // use case + // Max Length: 100 + // Min Length: 3 + // Pattern: ^[a-z0-9]+[a-z0-9\-_]+[a-z0-9]+$ + UseCase string `json:"use_case,omitempty"` +} + +// Validate validates this update environment +func (m *UpdateEnvironment) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateCloudProviderCanonical(formats); err != nil { + res = append(res, err) + } + + if err := m.validateColor(formats); err != nil { + res = append(res, err) + } + + if err := m.validateIcon(formats); err != nil { + res = append(res, err) + } + + if err := m.validateUseCase(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *UpdateEnvironment) validateCloudProviderCanonical(formats strfmt.Registry) error { + if swag.IsZero(m.CloudProviderCanonical) { // not required + return nil + } + + if err := validate.MinLength("cloud_provider_canonical", "body", m.CloudProviderCanonical, 3); err != nil { + return err + } + + if err := validate.MaxLength("cloud_provider_canonical", "body", m.CloudProviderCanonical, 100); err != nil { + return err + } + + if err := validate.Pattern("cloud_provider_canonical", "body", m.CloudProviderCanonical, `^[a-z0-9]+[a-z0-9\-_]+[a-z0-9]+$`); err != nil { + return err + } + + return nil +} + +func (m *UpdateEnvironment) validateColor(formats strfmt.Registry) error { + if swag.IsZero(m.Color) { // not required + return nil + } + + if err := validate.MaxLength("color", "body", m.Color, 64); err != nil { + return err + } + + return nil +} + +func (m *UpdateEnvironment) validateIcon(formats strfmt.Registry) error { + if swag.IsZero(m.Icon) { // not required + return nil + } + + if err := validate.MaxLength("icon", "body", m.Icon, 64); err != nil { + return err + } + + return nil +} + +func (m *UpdateEnvironment) validateUseCase(formats strfmt.Registry) error { + if swag.IsZero(m.UseCase) { // not required + return nil + } + + if err := validate.MinLength("use_case", "body", m.UseCase, 3); err != nil { + return err + } + + if err := validate.MaxLength("use_case", "body", m.UseCase, 100); err != nil { + return err + } + + if err := validate.Pattern("use_case", "body", m.UseCase, `^[a-z0-9]+[a-z0-9\-_]+[a-z0-9]+$`); err != nil { + return err + } + + return nil +} + +// ContextValidate validates this update environment based on context it is used +func (m *UpdateEnvironment) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *UpdateEnvironment) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *UpdateEnvironment) UnmarshalBinary(b []byte) error { + var res UpdateEnvironment + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/client/version b/client/version index 4abefd31..d9cff10e 100644 --- a/client/version +++ b/client/version @@ -1 +1 @@ -v5.1.9 +v5.1.43 From 77048af97bb400ac1db139f13e7458e886beec03 Mon Sep 17 00:00:00 2001 From: Cycloid Date: Mon, 9 Sep 2024 15:51:06 +0000 Subject: [PATCH 22/71] Changelog: Add entry for new version v5.1.43 --- changelog/unreleased/CLI-CHANGED-20240909-155106.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 changelog/unreleased/CLI-CHANGED-20240909-155106.yaml diff --git a/changelog/unreleased/CLI-CHANGED-20240909-155106.yaml b/changelog/unreleased/CLI-CHANGED-20240909-155106.yaml new file mode 100644 index 00000000..037db0dd --- /dev/null +++ b/changelog/unreleased/CLI-CHANGED-20240909-155106.yaml @@ -0,0 +1,8 @@ +component: CLI +kind: CHANGED +body: "Update client to version v5.1.43" +time: 2024-09-09T15:51:06.042148373+00:00 +custom: + DETAILS: "" + PR: "297" + TYPE: CLI From 9a911d6f337592f099da21693a2602b93ea78454 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20BARRAS=20HAMPEL?= Date: Thu, 12 Sep 2024 16:53:05 +0200 Subject: [PATCH 23/71] func: add new dependencies --- flake.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/flake.nix b/flake.nix index 13b31a19..89cfc2ce 100644 --- a/flake.nix +++ b/flake.nix @@ -24,6 +24,9 @@ go_1_22 go-swagger + gci + golangci-lint + golangci-lint-langserver ]); }; }); From 83df10e4b27f36e270dc173b3a142b2fff2839c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20BARRAS=20HAMPEL?= Date: Thu, 12 Sep 2024 16:57:58 +0200 Subject: [PATCH 24/71] misc: remove spammy debug log --- cmd/cycloid/common/flags.go | 7 ------- 1 file changed, 7 deletions(-) diff --git a/cmd/cycloid/common/flags.go b/cmd/cycloid/common/flags.go index b79ae388..76b6d945 100644 --- a/cmd/cycloid/common/flags.go +++ b/cmd/cycloid/common/flags.go @@ -1,9 +1,6 @@ package common import ( - "fmt" - "os" - "github.com/pkg/errors" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -20,10 +17,6 @@ func GetOrg(cmd *cobra.Command) (org string, err error) { return "", errors.New("org is not set, use --org flag or CY_ORG env var") } - if viper.GetString("verbosity") == "debug" { - fmt.Fprintln(os.Stderr, "\033[1;34mdebug:\033[0m using org:", org) - } - return org, nil } From 26d8f887a61027c7192ecc2a62b3674389d54e86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20BARRAS=20HAMPEL?= Date: Thu, 12 Sep 2024 18:04:24 +0200 Subject: [PATCH 25/71] fix: renamed middleware and model used for delete-env --- cmd/cycloid/middleware/middleware.go | 2 +- cmd/cycloid/middleware/project.go | 6 +++--- cmd/cycloid/projects/delete-env.go | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/cycloid/middleware/middleware.go b/cmd/cycloid/middleware/middleware.go index 71f74a6a..5e148af6 100644 --- a/cmd/cycloid/middleware/middleware.go +++ b/cmd/cycloid/middleware/middleware.go @@ -79,7 +79,7 @@ type Middleware interface { CreateProject(org, projectName, projectCanonical, env, pipelineTemplate, variables, description, stackRef, usecase, configRepo string) (*models.Project, error) CreateEmptyProject(org, projectName, projectCanonical, description, stackRef, configRepo string) (*models.Project, error) - DeleteProjectEnv(org, project, env string) error + DeleteEnv(org, project, env string) error DeleteProject(org, project string) error GetProject(org string, project string) (*models.Project, error) GetProjectConfig(org string, project string, environment string) (*models.ProjectEnvironmentConfig, error) diff --git a/cmd/cycloid/middleware/project.go b/cmd/cycloid/middleware/project.go index aaac101c..d3b50285 100644 --- a/cmd/cycloid/middleware/project.go +++ b/cmd/cycloid/middleware/project.go @@ -212,13 +212,13 @@ func (m *middleware) UpdateProject(org, projectName, projectCanonical string, en return d, err } -func (m *middleware) DeleteProjectEnv(org, project, env string) error { - params := organization_projects.NewDeleteProjectEnvironmentParams() +func (m *middleware) DeleteEnv(org, project, env string) error { + params := organization_projects.NewDeleteEnvironmentParams() params.SetOrganizationCanonical(org) params.SetProjectCanonical(project) params.SetEnvironmentCanonical(env) - _, err := m.api.OrganizationProjects.DeleteProjectEnvironment(params, m.api.Credentials(&org)) + _, err := m.api.OrganizationProjects.DeleteEnvironment(params, m.api.Credentials(&org)) if err != nil { return NewApiError(err) } diff --git a/cmd/cycloid/projects/delete-env.go b/cmd/cycloid/projects/delete-env.go index f51f86e6..bd8826df 100644 --- a/cmd/cycloid/projects/delete-env.go +++ b/cmd/cycloid/projects/delete-env.go @@ -55,6 +55,6 @@ func deleteEnv(cmd *cobra.Command, args []string) error { return errors.Wrap(err, "unable to get printer") } - err = m.DeleteProjectEnv(org, project, env) + err = m.DeleteEnv(org, project, env) return printer.SmartPrint(p, nil, err, "unable to delete environment", printer.Options{}, cmd.OutOrStdout()) } From df518b850c766f9e9698d22d136082528eb69194 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20BARRAS=20HAMPEL?= Date: Mon, 23 Sep 2024 14:58:50 +0200 Subject: [PATCH 26/71] fix#283: rename CY_API_TOKEN to CY_API_KEY --- cmd/cycloid.go | 2 +- cmd/cycloid/organizations/create.go | 2 +- cmd/cycloid/organizations/update.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/cycloid.go b/cmd/cycloid.go index f1eb4ff0..33aeed0f 100644 --- a/cmd/cycloid.go +++ b/cmd/cycloid.go @@ -54,7 +54,7 @@ Environment: CY_API_URL -> Specify the HTTP url of Cycloid API to use, default https://http-api.cycloid.io CY_ORG -> Set the current organization -CY_API_TOKEN -> Set the current API TOKEN +CY_API_KEY -> Set the current API Key to use CY_VERBOSITY -> Set the verbosity level (debug, info, warning, error), default warning `, } diff --git a/cmd/cycloid/organizations/create.go b/cmd/cycloid/organizations/create.go index c55406a2..27603d1c 100644 --- a/cmd/cycloid/organizations/create.go +++ b/cmd/cycloid/organizations/create.go @@ -12,7 +12,7 @@ import ( ) // This command have been Hidden because it is not compatible with API key login. -// Advanced user still can use it passing a user token in CY_TOKEN env var during a login. +// Advanced user still can use it passing a user token in CY_API_KEY env var during a login. func NewCreateCommand() *cobra.Command { var cmd = &cobra.Command{ Use: "create", diff --git a/cmd/cycloid/organizations/update.go b/cmd/cycloid/organizations/update.go index 8e062f7e..63699cbb 100644 --- a/cmd/cycloid/organizations/update.go +++ b/cmd/cycloid/organizations/update.go @@ -12,7 +12,7 @@ import ( ) // This command have been Hidden because it is not compatible with API key login. -// Advanced user still can use it passing a user token in CY_TOKEN env var during a login. +// Advanced user still can use it passing a user token in CY_API_KEY env var during a login. func NewUpdateCommand() *cobra.Command { var cmd = &cobra.Command{ Use: "update", From 39981a792fc586ee74ab4f98bfb3cb323ea3e683 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20BARRAS=20HAMPEL?= Date: Mon, 23 Sep 2024 14:59:51 +0200 Subject: [PATCH 27/71] func#283: fix env var selection by precedence. --- cmd/cycloid/common/helpers.go | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/cmd/cycloid/common/helpers.go b/cmd/cycloid/common/helpers.go index 4b1d303d..ef220f22 100644 --- a/cmd/cycloid/common/helpers.go +++ b/cmd/cycloid/common/helpers.go @@ -155,14 +155,20 @@ func NewAPI(opts ...APIOptions) *APIClient { func (a *APIClient) Credentials(org *string) runtime.ClientAuthInfoWriter { var token = a.Config.Token + + // we first try to get the token from the env variable if token == "" { - // we first try to get the token from the env variable - var ok bool - token, ok = os.LookupEnv("CY_API_TOKEN") - if !ok { - token, ok = os.LookupEnv("TOKEN") - if ok { - fmt.Println("TOKEN env var is deprecated, please use CY_API_TOKEN instead") + var ok = false + for _, env_var := range []string{"CY_API_KEY", "CY_API_TOKEN", "TOKEN"} { + token, ok = os.LookupEnv(env_var) + + // Still display warning for future deprecation + if ok && env_var == "TOKEN" { + fmt.Fprintln(os.Stderr, "TOKEN env var is deprecated, please use CY_API_KEY instead") + } + + if ok && len(token) != 0 { + break } } } @@ -186,6 +192,10 @@ func (a *APIClient) Credentials(org *string) runtime.ClientAuthInfoWriter { } return runtime.ClientAuthInfoWriterFunc(func(r runtime.ClientRequest, _ strfmt.Registry) error { + if token == "" { + return errors.New("No API_KEY was provided, please provide one by CY_API_KEY env var or using cy login.") + } + r.SetHeaderParam("Authorization", "Bearer "+token) return nil }) From e8c1dec5be62db87782189293cd2a161062c8c95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20BARRAS=20HAMPEL?= Date: Mon, 23 Sep 2024 15:00:10 +0200 Subject: [PATCH 28/71] tests: add tests for env var auth --- e2e/env_var_test.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 e2e/env_var_test.go diff --git a/e2e/env_var_test.go b/e2e/env_var_test.go new file mode 100644 index 00000000..88af6bf3 --- /dev/null +++ b/e2e/env_var_test.go @@ -0,0 +1,28 @@ +package e2e + +import ( + "os" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestAPIKeyEnvVar(t *testing.T) { + // Do not login + + for _, envVar := range []string{"CY_API_KEY", "CY_API_TOKEN", "TOKEN"} { + // We do a project list to check if we are authenticater + t.Run("SuccessProjectListWithEnvVarAuth", func(t *testing.T) { + os.Setenv(envVar, CY_TEST_ROOT_API_KEY) + _, err := executeCommand([]string{ + "--output", "json", + "--org", CY_TEST_ROOT_ORG, + "project", + "list", + }) + + assert.Nil(t, err, "Command should not fail using an env var for authentication") + os.Unsetenv(envVar) + }) + } +} From 21be0785e1170fb70965048b7fa83fd944d6c213 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20BARRAS=20HAMPEL?= Date: Mon, 23 Sep 2024 15:17:19 +0200 Subject: [PATCH 29/71] misc: add changelog --- changelog/unreleased/CLI-FIXED-20240923-131712.yaml | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 changelog/unreleased/CLI-FIXED-20240923-131712.yaml diff --git a/changelog/unreleased/CLI-FIXED-20240923-131712.yaml b/changelog/unreleased/CLI-FIXED-20240923-131712.yaml new file mode 100644 index 00000000..9a7c83be --- /dev/null +++ b/changelog/unreleased/CLI-FIXED-20240923-131712.yaml @@ -0,0 +1,9 @@ +component: CLI +kind: FIXED +body: Cycloid CLI now correctly uses CY_API_KEY env var instead of CY_API_TOKEN. +time: 2024-09-23T13:17:12.423881323Z +custom: + DETAILS: Old env vars still works, TOKEN and CY_API_TOKEN will be deprecated on + the future. + PR: "299" + TYPE: CLI From a7e70179c591bae240e0d2ac9b400b77c0155b50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20BARRAS=20HAMPEL?= Date: Mon, 23 Sep 2024 16:06:50 +0200 Subject: [PATCH 30/71] fix: add missing http:// for localhost:3001 urls and check for scheme in api config --- cmd/cycloid/common/helpers.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/cmd/cycloid/common/helpers.go b/cmd/cycloid/common/helpers.go index 4b1d303d..cec305b5 100644 --- a/cmd/cycloid/common/helpers.go +++ b/cmd/cycloid/common/helpers.go @@ -123,6 +123,17 @@ func NewAPI(opts ...APIOptions) *APIClient { o(&acfg) } + if !strings.HasPrefix(acfg.URL, "https://") { + if strings.Contains(acfg.URL, "localhost") { + // This handles the weird case of localhost:3001 + // being interpreted as scheme=localhost by url.Parse + acfg.URL = "http://" + acfg.URL + } else { + // Send warning + fmt.Fprintf(os.Stderr, "CLI is using a badly formatted API URL: %s, missing http scheme.\nPlease use https:// urls unless you know what you are doing.", acfg.URL) + } + } + apiUrl, err := url.Parse(acfg.URL) if err == nil && apiUrl.Host != "" { cfg = cfg.WithHost(apiUrl.Host) From 7aac44cd3a6bad387ca4ba3d3b4c6684c3b80873 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20BARRAS=20HAMPEL?= Date: Mon, 23 Sep 2024 16:55:59 +0200 Subject: [PATCH 31/71] misc: debug ci --- cmd/cycloid/common/helpers.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmd/cycloid/common/helpers.go b/cmd/cycloid/common/helpers.go index cec305b5..6d6352cd 100644 --- a/cmd/cycloid/common/helpers.go +++ b/cmd/cycloid/common/helpers.go @@ -141,6 +141,9 @@ func NewAPI(opts ...APIOptions) *APIClient { cfg = cfg.WithBasePath(apiUrl.Path) } + fmt.Fprintf(os.Stderr, "apiUrl: %v\n", apiUrl) + fmt.Fprintf(os.Stderr, "config: %v\n", cfg) + api := client.NewHTTPClientWithConfig(strfmt.Default, cfg) rt, err := httptransport.TLSTransport(httptransport.TLSClientOptions{InsecureSkipVerify: acfg.Insecure}) From cd64c9252a3d5df67556c30bd755e0b1cd5f898a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20BARRAS=20HAMPEL?= Date: Tue, 24 Sep 2024 15:22:23 +0200 Subject: [PATCH 32/71] misc: remove warning --- cmd/cycloid/common/helpers.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/cmd/cycloid/common/helpers.go b/cmd/cycloid/common/helpers.go index 6d6352cd..a4274535 100644 --- a/cmd/cycloid/common/helpers.go +++ b/cmd/cycloid/common/helpers.go @@ -128,9 +128,6 @@ func NewAPI(opts ...APIOptions) *APIClient { // This handles the weird case of localhost:3001 // being interpreted as scheme=localhost by url.Parse acfg.URL = "http://" + acfg.URL - } else { - // Send warning - fmt.Fprintf(os.Stderr, "CLI is using a badly formatted API URL: %s, missing http scheme.\nPlease use https:// urls unless you know what you are doing.", acfg.URL) } } From 0c60a061498b9c49f60cb3b4e28bda86822a3f42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20BARRAS=20HAMPEL?= Date: Tue, 24 Sep 2024 15:27:22 +0200 Subject: [PATCH 33/71] test: try to fix CI --- e2e/e2e.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/e2e.go b/e2e/e2e.go index 3c4261ea..b558dc12 100644 --- a/e2e/e2e.go +++ b/e2e/e2e.go @@ -7,7 +7,7 @@ import ( var ( CY_TEST_ROOT_API_KEY = "my secret api key" - CY_TEST_ROOT_ORG = "cycloidio" + CY_TEST_ROOT_ORG = "fake-cycloid" // Note, this url should be accessible by Cycloid API CY_TEST_GIT_CR_URL = "Url of the git repository used as config repository" CY_TEST_GIT_CR_BRANCH = "master" From 1942181bc66a402cde892d62e5225948cc6636be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20BARRAS=20HAMPEL?= Date: Tue, 24 Sep 2024 15:38:50 +0200 Subject: [PATCH 34/71] fix: make make test use root org env var --- Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 62e317b6..5a97f966 100644 --- a/Makefile +++ b/Makefile @@ -69,6 +69,7 @@ SWAGGER_DOCKER_GENERATE = rm -rf ./client; \ CY_API_URL ?= http://127.0.0.1:3001 # Env list specified in file /e2e/e2e.go CY_TEST_GIT_CR_URL ?= git@172.42.0.14:/git-server/repos/backend-test-config-repo.git +CY_TEST_ROOT_ORG ?= "fake-cycloid" # Local E2E tests # Note! Requires access to the private cycloid BE, only acessible within the organisation @@ -93,9 +94,10 @@ build: ## Builds the binary .PHONY: test test: ## Run end to end tests @echo "Using API url: $(CY_API_URL) (from \$$CY_API_URL)" + @echo "Using ORG: $(CY_TEST_ROOT_ORG) (from \$$CY_TEST_ROOT_ORG)" @echo "Using GIT: $(CY_TEST_GIT_CR_URL) (from \$$CY_TEST_GIT_CR_URL)" @if [ -z "$$CY_TEST_ROOT_API_KEY" ]; then echo "Unable to read API KEY from \$$CY_TEST_ROOT_API_KEY"; exit 1; fi; \ - CY_TEST_GIT_CR_URL="$(CY_TEST_GIT_CR_URL)" CY_API_URL="$(CY_API_URL)" go test ./... --tags e2e + CY_TEST_GIT_CR_URL="$(CY_TEST_GIT_CR_URL)" CY_API_URL="$(CY_API_URL)" CY_TEST_ROOT_ORG="$(CY_TEST_ROOT_ORG)" go test ./... --tags e2e .PHONY: delete-old-client reset-old-client: ## Resets old client folder From 6e4bbe44fcf0a7f78d0fa7c7216cafe1dfb8f8ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20BARRAS=20HAMPEL?= Date: Tue, 24 Sep 2024 15:48:30 +0200 Subject: [PATCH 35/71] misc: add debug logs --- e2e/catalog_repositories_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/catalog_repositories_test.go b/e2e/catalog_repositories_test.go index 663f7c12..f7e6cca8 100644 --- a/e2e/catalog_repositories_test.go +++ b/e2e/catalog_repositories_test.go @@ -33,7 +33,7 @@ func TestCatalogRepositories(t *testing.T) { "--name", "step-by-step", }) - require.Nil(t, cmdErr) + require.Nil(t, cmdErr, "more info, root org is: "+CY_TEST_ROOT_ORG) assert.Contains(t, cmdOut, "canonical\": \"stack-aws-sample") }) From 438aba90c9f699415bf31010d7bf26a8e5ff53dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20BARRAS=20HAMPEL?= Date: Tue, 24 Sep 2024 16:39:27 +0200 Subject: [PATCH 36/71] misc: remove debug shinanigans --- cmd/cycloid/common/helpers.go | 3 --- e2e/catalog_repositories_test.go | 5 +---- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/cmd/cycloid/common/helpers.go b/cmd/cycloid/common/helpers.go index a4274535..b61c6843 100644 --- a/cmd/cycloid/common/helpers.go +++ b/cmd/cycloid/common/helpers.go @@ -138,9 +138,6 @@ func NewAPI(opts ...APIOptions) *APIClient { cfg = cfg.WithBasePath(apiUrl.Path) } - fmt.Fprintf(os.Stderr, "apiUrl: %v\n", apiUrl) - fmt.Fprintf(os.Stderr, "config: %v\n", cfg) - api := client.NewHTTPClientWithConfig(strfmt.Default, cfg) rt, err := httptransport.TLSTransport(httptransport.TLSClientOptions{InsecureSkipVerify: acfg.Insecure}) diff --git a/e2e/catalog_repositories_test.go b/e2e/catalog_repositories_test.go index f7e6cca8..c7f91531 100644 --- a/e2e/catalog_repositories_test.go +++ b/e2e/catalog_repositories_test.go @@ -1,6 +1,3 @@ -//go:build e2e -// +build e2e - package e2e import ( @@ -33,7 +30,7 @@ func TestCatalogRepositories(t *testing.T) { "--name", "step-by-step", }) - require.Nil(t, cmdErr, "more info, root org is: "+CY_TEST_ROOT_ORG) + require.Nil(t, cmdErr) assert.Contains(t, cmdOut, "canonical\": \"stack-aws-sample") }) From 964c8835249d9d32bae269641cc7b05527babda3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20BARRAS=20HAMPEL?= Date: Tue, 24 Sep 2024 17:52:21 +0200 Subject: [PATCH 37/71] func: add owner param to create project --- cmd/cycloid/middleware/middleware.go | 4 ++-- cmd/cycloid/middleware/project.go | 6 ++++-- cmd/cycloid/projects/create-project.go | 14 ++++++++++---- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/cmd/cycloid/middleware/middleware.go b/cmd/cycloid/middleware/middleware.go index 5e148af6..e9401f92 100644 --- a/cmd/cycloid/middleware/middleware.go +++ b/cmd/cycloid/middleware/middleware.go @@ -77,8 +77,8 @@ type Middleware interface { GetPipeline(org, project, env string) (*models.Pipeline, error) SyncedPipeline(org, project, env string) (*models.PipelineStatus, error) - CreateProject(org, projectName, projectCanonical, env, pipelineTemplate, variables, description, stackRef, usecase, configRepo string) (*models.Project, error) - CreateEmptyProject(org, projectName, projectCanonical, description, stackRef, configRepo string) (*models.Project, error) + CreateProject(org, projectName, projectCanonical, env, pipelineTemplate, variables, description, stackRef, usecase, configRepo, owner string) (*models.Project, error) + CreateEmptyProject(org, projectName, projectCanonical, description, stackRef, configRepo, owner string) (*models.Project, error) DeleteEnv(org, project, env string) error DeleteProject(org, project string) error GetProject(org string, project string) (*models.Project, error) diff --git a/cmd/cycloid/middleware/project.go b/cmd/cycloid/middleware/project.go index d3b50285..5ec88777 100644 --- a/cmd/cycloid/middleware/project.go +++ b/cmd/cycloid/middleware/project.go @@ -74,7 +74,7 @@ func (m *middleware) GetProjectConfig(org string, project string, env string) (* return payload.Data, nil } -func (m *middleware) CreateEmptyProject(org, projectName, projectCanonical, description, stackRef, configRepo string) (*models.Project, error) { +func (m *middleware) CreateEmptyProject(org, projectName, projectCanonical, description, stackRef, configRepo, owner string) (*models.Project, error) { params := organization_projects.NewCreateProjectParams() params.WithOrganizationCanonical(org) @@ -84,6 +84,7 @@ func (m *middleware) CreateEmptyProject(org, projectName, projectCanonical, desc Canonical: projectCanonical, ServiceCatalogRef: &stackRef, ConfigRepositoryCanonical: &configRepo, + Owner: owner, } err := body.Validate(strfmt.Default) @@ -107,7 +108,7 @@ func (m *middleware) CreateEmptyProject(org, projectName, projectCanonical, desc return payload.Data, nil } -func (m *middleware) CreateProject(org, projectName, projectCanonical, env, pipelineTemplate, variables, description, stackRef, usecase, configRepo string) (*models.Project, error) { +func (m *middleware) CreateProject(org, projectName, projectCanonical, env, pipelineTemplate, variables, description, stackRef, usecase, configRepo, owner string) (*models.Project, error) { var body *models.NewProject var pipelines []*models.NewPipeline @@ -152,6 +153,7 @@ func (m *middleware) CreateProject(org, projectName, projectCanonical, env, pipe ServiceCatalogRef: &stackRef, ConfigRepositoryCanonical: &configRepo, Pipelines: pipelines, + Owner: owner, } err = body.Validate(strfmt.Default) diff --git a/cmd/cycloid/projects/create-project.go b/cmd/cycloid/projects/create-project.go index 889eba6e..4565fc6f 100644 --- a/cmd/cycloid/projects/create-project.go +++ b/cmd/cycloid/projects/create-project.go @@ -44,6 +44,7 @@ func NewCreateCommand() *cobra.Command { cmd.Flags().String("pipeline", "", "[deprecated] path to a pipeline file for the env creation") cmd.Flags().StringToString("config", nil, "[deprecated] path to a config file to inject in the config repo") cmd.Flags().String("usecase", "", "[deprecated] the usecase for the env creation") + cmd.Flags().String("owner", "", "the owner canonical") WithFlagDescription(cmd) WithFlagCanonical(cmd) @@ -84,6 +85,11 @@ func create(cmd *cobra.Command, args []string) error { return err } + ownerCanonical, err := cmd.Flags().GetString("owner") + if err != nil { + return err + } + env, err := cmd.Flags().GetString("env") if err != nil { return err @@ -123,15 +129,15 @@ func create(cmd *cobra.Command, args []string) error { if env+usecase+varsPath+pipelinePath != "" { // If any of the env provisioning vars is not empty, create the project with an env internal.Warning(cmd.ErrOrStderr(), "Creating an environment when creating a project is deprecated and will be removed in a future release. Please create your env separately using the 'cy project create-env' command.\n") - project, err := createProjectWithPipeline(org, name, canonical, description, stackRef, configRepo, env, usecase, varsPath, pipelinePath, configs) + project, err := createProjectWithPipeline(org, name, canonical, description, stackRef, configRepo, env, usecase, varsPath, pipelinePath, ownerCanonical, configs) return printer.SmartPrint(p, project, err, "", printer.Options{}, cmd.OutOrStdout()) } - project, err := m.CreateEmptyProject(org, name, canonical, description, stackRef, configRepo) + project, err := m.CreateEmptyProject(org, name, canonical, description, stackRef, configRepo, ownerCanonical) return printer.SmartPrint(p, project, err, "", printer.Options{}, cmd.OutOrStdout()) } -func createProjectWithPipeline(org, name, canonical, description, stackRef, configRepo, env, usecase, varsPath, pipelinePath string, configs map[string]string) (*models.Project, error) { +func createProjectWithPipeline(org, name, canonical, description, stackRef, configRepo, env, usecase, varsPath, pipelinePath, owner string, configs map[string]string) (*models.Project, error) { api := common.NewAPI() m := middleware.NewMiddleware(api) @@ -148,7 +154,7 @@ func createProjectWithPipeline(org, name, canonical, description, stackRef, conf vars := string(rawVars) - project, err := m.CreateProject(org, name, canonical, env, pipelineTemplate, vars, description, stackRef, usecase, configRepo) + project, err := m.CreateProject(org, name, canonical, env, pipelineTemplate, vars, description, stackRef, usecase, configRepo, owner) err = errors.Wrap(err, "unable to create project") if err != nil { return nil, err From f8eaec5e327a6e85153565e01f5c873af69cbd36 Mon Sep 17 00:00:00 2001 From: talset Date: Wed, 25 Sep 2024 10:15:52 +0200 Subject: [PATCH 38/71] project: update help owner --- cmd/cycloid/projects/common.go | 4 ++-- cmd/cycloid/projects/create-project.go | 10 +++------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/cmd/cycloid/projects/common.go b/cmd/cycloid/projects/common.go index afc1360e..c0927c36 100644 --- a/cmd/cycloid/projects/common.go +++ b/cmd/cycloid/projects/common.go @@ -43,7 +43,7 @@ func WithFlagUsecase(cmd *cobra.Command) string { } func WithFlagStackRef(cmd *cobra.Command) string { flagName := "stack-ref" - cmd.Flags().StringVar(&stackRefFlag, flagName, "", "") + cmd.Flags().StringVar(&stackRefFlag, flagName, "", "stack reference") return flagName } func WithFlagCanonical(cmd *cobra.Command) string { @@ -58,6 +58,6 @@ func WithFlagDescription(cmd *cobra.Command) string { } func WithFlagConfigRepository(cmd *cobra.Command) string { flagName := "config-repo" - cmd.Flags().StringVar(&configRepositoryFlag, flagName, "", "") + cmd.Flags().StringVar(&configRepositoryFlag, flagName, "", "Config repository canonical to save configuration") return flagName } diff --git a/cmd/cycloid/projects/create-project.go b/cmd/cycloid/projects/create-project.go index 4565fc6f..c11b8169 100644 --- a/cmd/cycloid/projects/create-project.go +++ b/cmd/cycloid/projects/create-project.go @@ -25,13 +25,9 @@ func NewCreateCommand() *cobra.Command { cy --org my-org project create \ --name my-project \ --description "an awesome project" \ + --owner "username" \ --stack-ref my-stack-ref \ - --config-repo config-repo-canonical \ - --env environment-name \ - --usecase usecase-1 \ - --vars /path/to/variables.yml \ - --pipeline /path/to/pipeline.yml \ - --config /path/to/config=/path/in/config_repo + --config-repo config-repo-canonical `, RunE: create, PreRunE: internal.CheckAPIAndCLIVersion, @@ -44,7 +40,7 @@ func NewCreateCommand() *cobra.Command { cmd.Flags().String("pipeline", "", "[deprecated] path to a pipeline file for the env creation") cmd.Flags().StringToString("config", nil, "[deprecated] path to a config file to inject in the config repo") cmd.Flags().String("usecase", "", "[deprecated] the usecase for the env creation") - cmd.Flags().String("owner", "", "the owner canonical") + cmd.Flags().String("owner", "", "the owner username") WithFlagDescription(cmd) WithFlagCanonical(cmd) From ab5aae82d7d06e73d5d71ba6b4eb21c70300af26 Mon Sep 17 00:00:00 2001 From: Cycloid Date: Wed, 25 Sep 2024 12:24:52 +0000 Subject: [PATCH 39/71] Bump swagger client to version v5.1.56 --- .../{forms_file_v2.go => forms_file_v3.go} | 26 +++++++++---------- client/models/forms_validation_result.go | 2 +- client/models/project_environment_config.go | 2 +- client/version | 2 +- 4 files changed, 16 insertions(+), 16 deletions(-) rename client/models/{forms_file_v2.go => forms_file_v3.go} (79%) diff --git a/client/models/forms_file_v2.go b/client/models/forms_file_v3.go similarity index 79% rename from client/models/forms_file_v2.go rename to client/models/forms_file_v3.go index 4407e1b6..021f7c11 100644 --- a/client/models/forms_file_v2.go +++ b/client/models/forms_file_v3.go @@ -15,10 +15,10 @@ import ( "github.com/go-openapi/validate" ) -// FormsFileV2 Forms File V2 +// FormsFileV3 Forms File V3 // -// swagger:model FormsFileV2 -type FormsFileV2 struct { +// swagger:model FormsFileV3 +type FormsFileV3 struct { // use cases // Required: true @@ -29,8 +29,8 @@ type FormsFileV2 struct { Version *string `json:"version"` } -// Validate validates this forms file v2 -func (m *FormsFileV2) Validate(formats strfmt.Registry) error { +// Validate validates this forms file v3 +func (m *FormsFileV3) Validate(formats strfmt.Registry) error { var res []error if err := m.validateUseCases(formats); err != nil { @@ -47,7 +47,7 @@ func (m *FormsFileV2) Validate(formats strfmt.Registry) error { return nil } -func (m *FormsFileV2) validateUseCases(formats strfmt.Registry) error { +func (m *FormsFileV3) validateUseCases(formats strfmt.Registry) error { if err := validate.Required("use_cases", "body", m.UseCases); err != nil { return err @@ -74,7 +74,7 @@ func (m *FormsFileV2) validateUseCases(formats strfmt.Registry) error { return nil } -func (m *FormsFileV2) validateVersion(formats strfmt.Registry) error { +func (m *FormsFileV3) validateVersion(formats strfmt.Registry) error { if err := validate.Required("version", "body", m.Version); err != nil { return err @@ -83,8 +83,8 @@ func (m *FormsFileV2) validateVersion(formats strfmt.Registry) error { return nil } -// ContextValidate validate this forms file v2 based on the context it is used -func (m *FormsFileV2) ContextValidate(ctx context.Context, formats strfmt.Registry) error { +// ContextValidate validate this forms file v3 based on the context it is used +func (m *FormsFileV3) ContextValidate(ctx context.Context, formats strfmt.Registry) error { var res []error if err := m.contextValidateUseCases(ctx, formats); err != nil { @@ -97,7 +97,7 @@ func (m *FormsFileV2) ContextValidate(ctx context.Context, formats strfmt.Regist return nil } -func (m *FormsFileV2) contextValidateUseCases(ctx context.Context, formats strfmt.Registry) error { +func (m *FormsFileV3) contextValidateUseCases(ctx context.Context, formats strfmt.Registry) error { for i := 0; i < len(m.UseCases); i++ { @@ -123,7 +123,7 @@ func (m *FormsFileV2) contextValidateUseCases(ctx context.Context, formats strfm } // MarshalBinary interface implementation -func (m *FormsFileV2) MarshalBinary() ([]byte, error) { +func (m *FormsFileV3) MarshalBinary() ([]byte, error) { if m == nil { return nil, nil } @@ -131,8 +131,8 @@ func (m *FormsFileV2) MarshalBinary() ([]byte, error) { } // UnmarshalBinary interface implementation -func (m *FormsFileV2) UnmarshalBinary(b []byte) error { - var res FormsFileV2 +func (m *FormsFileV3) UnmarshalBinary(b []byte) error { + var res FormsFileV3 if err := swag.ReadJSON(b, &res); err != nil { return err } diff --git a/client/models/forms_validation_result.go b/client/models/forms_validation_result.go index edec0402..cc3e8224 100644 --- a/client/models/forms_validation_result.go +++ b/client/models/forms_validation_result.go @@ -27,7 +27,7 @@ type FormsValidationResult struct { // forms // Required: true - Forms *FormsFileV2 `json:"forms"` + Forms *FormsFileV3 `json:"forms"` } // Validate validates this forms validation result diff --git a/client/models/project_environment_config.go b/client/models/project_environment_config.go index f1469f09..652652c0 100644 --- a/client/models/project_environment_config.go +++ b/client/models/project_environment_config.go @@ -25,7 +25,7 @@ type ProjectEnvironmentConfig struct { // forms // Required: true - Forms *FormsFileV2 `json:"forms"` + Forms *FormsFileV3 `json:"forms"` // The resource pool canonical, only require when using Quotas ResourcePoolCanonical string `json:"resource_pool_canonical,omitempty"` diff --git a/client/version b/client/version index d9cff10e..0bb240d1 100644 --- a/client/version +++ b/client/version @@ -1 +1 @@ -v5.1.43 +v5.1.56 From 566b471ad8a06909378f56d4503ee97b8b1c46bc Mon Sep 17 00:00:00 2001 From: Cycloid Date: Wed, 25 Sep 2024 12:25:21 +0000 Subject: [PATCH 40/71] Changelog: Add entry for new version v5.1.56 --- changelog/unreleased/CLI-CHANGED-20240925-122521.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 changelog/unreleased/CLI-CHANGED-20240925-122521.yaml diff --git a/changelog/unreleased/CLI-CHANGED-20240925-122521.yaml b/changelog/unreleased/CLI-CHANGED-20240925-122521.yaml new file mode 100644 index 00000000..2c037ea7 --- /dev/null +++ b/changelog/unreleased/CLI-CHANGED-20240925-122521.yaml @@ -0,0 +1,8 @@ +component: CLI +kind: CHANGED +body: "Update client to version v5.1.56" +time: 2024-09-25T12:25:21.465390378+00:00 +custom: + DETAILS: "" + PR: "302" + TYPE: CLI From 0c1805e55949554ca3de059c293edcfeb012b1a3 Mon Sep 17 00:00:00 2001 From: Cycloid Date: Thu, 26 Sep 2024 06:56:50 +0000 Subject: [PATCH 41/71] Bump swagger client to version v5.1.58 --- .../{forms_file_v2.go => forms_file_v3.go} | 26 +++++++++---------- client/models/forms_validation_result.go | 2 +- client/models/project_environment_config.go | 2 +- client/version | 2 +- 4 files changed, 16 insertions(+), 16 deletions(-) rename client/models/{forms_file_v2.go => forms_file_v3.go} (79%) diff --git a/client/models/forms_file_v2.go b/client/models/forms_file_v3.go similarity index 79% rename from client/models/forms_file_v2.go rename to client/models/forms_file_v3.go index 4407e1b6..021f7c11 100644 --- a/client/models/forms_file_v2.go +++ b/client/models/forms_file_v3.go @@ -15,10 +15,10 @@ import ( "github.com/go-openapi/validate" ) -// FormsFileV2 Forms File V2 +// FormsFileV3 Forms File V3 // -// swagger:model FormsFileV2 -type FormsFileV2 struct { +// swagger:model FormsFileV3 +type FormsFileV3 struct { // use cases // Required: true @@ -29,8 +29,8 @@ type FormsFileV2 struct { Version *string `json:"version"` } -// Validate validates this forms file v2 -func (m *FormsFileV2) Validate(formats strfmt.Registry) error { +// Validate validates this forms file v3 +func (m *FormsFileV3) Validate(formats strfmt.Registry) error { var res []error if err := m.validateUseCases(formats); err != nil { @@ -47,7 +47,7 @@ func (m *FormsFileV2) Validate(formats strfmt.Registry) error { return nil } -func (m *FormsFileV2) validateUseCases(formats strfmt.Registry) error { +func (m *FormsFileV3) validateUseCases(formats strfmt.Registry) error { if err := validate.Required("use_cases", "body", m.UseCases); err != nil { return err @@ -74,7 +74,7 @@ func (m *FormsFileV2) validateUseCases(formats strfmt.Registry) error { return nil } -func (m *FormsFileV2) validateVersion(formats strfmt.Registry) error { +func (m *FormsFileV3) validateVersion(formats strfmt.Registry) error { if err := validate.Required("version", "body", m.Version); err != nil { return err @@ -83,8 +83,8 @@ func (m *FormsFileV2) validateVersion(formats strfmt.Registry) error { return nil } -// ContextValidate validate this forms file v2 based on the context it is used -func (m *FormsFileV2) ContextValidate(ctx context.Context, formats strfmt.Registry) error { +// ContextValidate validate this forms file v3 based on the context it is used +func (m *FormsFileV3) ContextValidate(ctx context.Context, formats strfmt.Registry) error { var res []error if err := m.contextValidateUseCases(ctx, formats); err != nil { @@ -97,7 +97,7 @@ func (m *FormsFileV2) ContextValidate(ctx context.Context, formats strfmt.Regist return nil } -func (m *FormsFileV2) contextValidateUseCases(ctx context.Context, formats strfmt.Registry) error { +func (m *FormsFileV3) contextValidateUseCases(ctx context.Context, formats strfmt.Registry) error { for i := 0; i < len(m.UseCases); i++ { @@ -123,7 +123,7 @@ func (m *FormsFileV2) contextValidateUseCases(ctx context.Context, formats strfm } // MarshalBinary interface implementation -func (m *FormsFileV2) MarshalBinary() ([]byte, error) { +func (m *FormsFileV3) MarshalBinary() ([]byte, error) { if m == nil { return nil, nil } @@ -131,8 +131,8 @@ func (m *FormsFileV2) MarshalBinary() ([]byte, error) { } // UnmarshalBinary interface implementation -func (m *FormsFileV2) UnmarshalBinary(b []byte) error { - var res FormsFileV2 +func (m *FormsFileV3) UnmarshalBinary(b []byte) error { + var res FormsFileV3 if err := swag.ReadJSON(b, &res); err != nil { return err } diff --git a/client/models/forms_validation_result.go b/client/models/forms_validation_result.go index edec0402..cc3e8224 100644 --- a/client/models/forms_validation_result.go +++ b/client/models/forms_validation_result.go @@ -27,7 +27,7 @@ type FormsValidationResult struct { // forms // Required: true - Forms *FormsFileV2 `json:"forms"` + Forms *FormsFileV3 `json:"forms"` } // Validate validates this forms validation result diff --git a/client/models/project_environment_config.go b/client/models/project_environment_config.go index f1469f09..652652c0 100644 --- a/client/models/project_environment_config.go +++ b/client/models/project_environment_config.go @@ -25,7 +25,7 @@ type ProjectEnvironmentConfig struct { // forms // Required: true - Forms *FormsFileV2 `json:"forms"` + Forms *FormsFileV3 `json:"forms"` // The resource pool canonical, only require when using Quotas ResourcePoolCanonical string `json:"resource_pool_canonical,omitempty"` diff --git a/client/version b/client/version index d9cff10e..44ebf688 100644 --- a/client/version +++ b/client/version @@ -1 +1 @@ -v5.1.43 +v5.1.58 From 628258befcc5ac983f2c37e1c920a6df8f0782bc Mon Sep 17 00:00:00 2001 From: Cycloid Date: Thu, 26 Sep 2024 06:57:16 +0000 Subject: [PATCH 42/71] Changelog: Add entry for new version v5.1.58 --- changelog/unreleased/CLI-CHANGED-20240926-065716.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 changelog/unreleased/CLI-CHANGED-20240926-065716.yaml diff --git a/changelog/unreleased/CLI-CHANGED-20240926-065716.yaml b/changelog/unreleased/CLI-CHANGED-20240926-065716.yaml new file mode 100644 index 00000000..1ebb5312 --- /dev/null +++ b/changelog/unreleased/CLI-CHANGED-20240926-065716.yaml @@ -0,0 +1,8 @@ +component: CLI +kind: CHANGED +body: "Update client to version v5.1.58" +time: 2024-09-26T06:57:16.888834935+00:00 +custom: + DETAILS: "" + PR: "303" + TYPE: CLI From c4979e1888b6f54c5cc8a60ec764918d807c74b5 Mon Sep 17 00:00:00 2001 From: Cycloid Date: Thu, 3 Oct 2024 12:24:25 +0000 Subject: [PATCH 43/71] Bump swagger client to version v5.1.61 --- .../{forms_file_v2.go => forms_file_v3.go} | 26 ++-- client/models/forms_validation_result.go | 2 +- client/models/new_environment.go | 143 +++++++++++++++++- client/models/project_environment_config.go | 2 +- client/models/update_environment.go | 72 ++++++++- client/version | 2 +- 6 files changed, 229 insertions(+), 18 deletions(-) rename client/models/{forms_file_v2.go => forms_file_v3.go} (79%) diff --git a/client/models/forms_file_v2.go b/client/models/forms_file_v3.go similarity index 79% rename from client/models/forms_file_v2.go rename to client/models/forms_file_v3.go index 4407e1b6..021f7c11 100644 --- a/client/models/forms_file_v2.go +++ b/client/models/forms_file_v3.go @@ -15,10 +15,10 @@ import ( "github.com/go-openapi/validate" ) -// FormsFileV2 Forms File V2 +// FormsFileV3 Forms File V3 // -// swagger:model FormsFileV2 -type FormsFileV2 struct { +// swagger:model FormsFileV3 +type FormsFileV3 struct { // use cases // Required: true @@ -29,8 +29,8 @@ type FormsFileV2 struct { Version *string `json:"version"` } -// Validate validates this forms file v2 -func (m *FormsFileV2) Validate(formats strfmt.Registry) error { +// Validate validates this forms file v3 +func (m *FormsFileV3) Validate(formats strfmt.Registry) error { var res []error if err := m.validateUseCases(formats); err != nil { @@ -47,7 +47,7 @@ func (m *FormsFileV2) Validate(formats strfmt.Registry) error { return nil } -func (m *FormsFileV2) validateUseCases(formats strfmt.Registry) error { +func (m *FormsFileV3) validateUseCases(formats strfmt.Registry) error { if err := validate.Required("use_cases", "body", m.UseCases); err != nil { return err @@ -74,7 +74,7 @@ func (m *FormsFileV2) validateUseCases(formats strfmt.Registry) error { return nil } -func (m *FormsFileV2) validateVersion(formats strfmt.Registry) error { +func (m *FormsFileV3) validateVersion(formats strfmt.Registry) error { if err := validate.Required("version", "body", m.Version); err != nil { return err @@ -83,8 +83,8 @@ func (m *FormsFileV2) validateVersion(formats strfmt.Registry) error { return nil } -// ContextValidate validate this forms file v2 based on the context it is used -func (m *FormsFileV2) ContextValidate(ctx context.Context, formats strfmt.Registry) error { +// ContextValidate validate this forms file v3 based on the context it is used +func (m *FormsFileV3) ContextValidate(ctx context.Context, formats strfmt.Registry) error { var res []error if err := m.contextValidateUseCases(ctx, formats); err != nil { @@ -97,7 +97,7 @@ func (m *FormsFileV2) ContextValidate(ctx context.Context, formats strfmt.Regist return nil } -func (m *FormsFileV2) contextValidateUseCases(ctx context.Context, formats strfmt.Registry) error { +func (m *FormsFileV3) contextValidateUseCases(ctx context.Context, formats strfmt.Registry) error { for i := 0; i < len(m.UseCases); i++ { @@ -123,7 +123,7 @@ func (m *FormsFileV2) contextValidateUseCases(ctx context.Context, formats strfm } // MarshalBinary interface implementation -func (m *FormsFileV2) MarshalBinary() ([]byte, error) { +func (m *FormsFileV3) MarshalBinary() ([]byte, error) { if m == nil { return nil, nil } @@ -131,8 +131,8 @@ func (m *FormsFileV2) MarshalBinary() ([]byte, error) { } // UnmarshalBinary interface implementation -func (m *FormsFileV2) UnmarshalBinary(b []byte) error { - var res FormsFileV2 +func (m *FormsFileV3) UnmarshalBinary(b []byte) error { + var res FormsFileV3 if err := swag.ReadJSON(b, &res); err != nil { return err } diff --git a/client/models/forms_validation_result.go b/client/models/forms_validation_result.go index edec0402..cc3e8224 100644 --- a/client/models/forms_validation_result.go +++ b/client/models/forms_validation_result.go @@ -27,7 +27,7 @@ type FormsValidationResult struct { // forms // Required: true - Forms *FormsFileV2 `json:"forms"` + Forms *FormsFileV3 `json:"forms"` } // Validate validates this forms validation result diff --git a/client/models/new_environment.go b/client/models/new_environment.go index 506cde2c..66c69d29 100644 --- a/client/models/new_environment.go +++ b/client/models/new_environment.go @@ -7,6 +7,7 @@ package models import ( "context" + "strconv" "github.com/go-openapi/errors" "github.com/go-openapi/strfmt" @@ -42,6 +43,17 @@ type NewEnvironment struct { // Max Length: 64 Icon string `json:"icon,omitempty"` + // The variables set within a form with the corresponding environment + // canonical and use case + // + Inputs []*FormInput `json:"inputs"` + + // Each instance should include passed_config if no inputs are sent on + // environment creation, otherwise it will be inferred internally. + // + // Min Items: 1 + Pipelines []*NewPipeline `json:"pipelines"` + // use case // Max Length: 100 // Min Length: 3 @@ -69,6 +81,14 @@ func (m *NewEnvironment) Validate(formats strfmt.Registry) error { res = append(res, err) } + if err := m.validateInputs(formats); err != nil { + res = append(res, err) + } + + if err := m.validatePipelines(formats); err != nil { + res = append(res, err) + } + if err := m.validateUseCase(formats); err != nil { res = append(res, err) } @@ -144,6 +164,64 @@ func (m *NewEnvironment) validateIcon(formats strfmt.Registry) error { return nil } +func (m *NewEnvironment) validateInputs(formats strfmt.Registry) error { + if swag.IsZero(m.Inputs) { // not required + return nil + } + + for i := 0; i < len(m.Inputs); i++ { + if swag.IsZero(m.Inputs[i]) { // not required + continue + } + + if m.Inputs[i] != nil { + if err := m.Inputs[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("inputs" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("inputs" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +func (m *NewEnvironment) validatePipelines(formats strfmt.Registry) error { + if swag.IsZero(m.Pipelines) { // not required + return nil + } + + iPipelinesSize := int64(len(m.Pipelines)) + + if err := validate.MinItems("pipelines", "body", iPipelinesSize, 1); err != nil { + return err + } + + for i := 0; i < len(m.Pipelines); i++ { + if swag.IsZero(m.Pipelines[i]) { // not required + continue + } + + if m.Pipelines[i] != nil { + if err := m.Pipelines[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("pipelines" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("pipelines" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + func (m *NewEnvironment) validateUseCase(formats strfmt.Registry) error { if swag.IsZero(m.UseCase) { // not required return nil @@ -164,8 +242,71 @@ func (m *NewEnvironment) validateUseCase(formats strfmt.Registry) error { return nil } -// ContextValidate validates this new environment based on context it is used +// ContextValidate validate this new environment based on the context it is used func (m *NewEnvironment) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + if err := m.contextValidateInputs(ctx, formats); err != nil { + res = append(res, err) + } + + if err := m.contextValidatePipelines(ctx, formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *NewEnvironment) contextValidateInputs(ctx context.Context, formats strfmt.Registry) error { + + for i := 0; i < len(m.Inputs); i++ { + + if m.Inputs[i] != nil { + + if swag.IsZero(m.Inputs[i]) { // not required + return nil + } + + if err := m.Inputs[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("inputs" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("inputs" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +func (m *NewEnvironment) contextValidatePipelines(ctx context.Context, formats strfmt.Registry) error { + + for i := 0; i < len(m.Pipelines); i++ { + + if m.Pipelines[i] != nil { + + if swag.IsZero(m.Pipelines[i]) { // not required + return nil + } + + if err := m.Pipelines[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("pipelines" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("pipelines" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + return nil } diff --git a/client/models/project_environment_config.go b/client/models/project_environment_config.go index f1469f09..652652c0 100644 --- a/client/models/project_environment_config.go +++ b/client/models/project_environment_config.go @@ -25,7 +25,7 @@ type ProjectEnvironmentConfig struct { // forms // Required: true - Forms *FormsFileV2 `json:"forms"` + Forms *FormsFileV3 `json:"forms"` // The resource pool canonical, only require when using Quotas ResourcePoolCanonical string `json:"resource_pool_canonical,omitempty"` diff --git a/client/models/update_environment.go b/client/models/update_environment.go index 73f3f94c..642f8886 100644 --- a/client/models/update_environment.go +++ b/client/models/update_environment.go @@ -7,6 +7,7 @@ package models import ( "context" + "strconv" "github.com/go-openapi/errors" "github.com/go-openapi/strfmt" @@ -35,6 +36,11 @@ type UpdateEnvironment struct { // Max Length: 64 Icon string `json:"icon,omitempty"` + // The variables set within a form with the corresponding environment + // canonical and use case + // + Inputs []*FormInput `json:"inputs"` + // use case // Max Length: 100 // Min Length: 3 @@ -58,6 +64,10 @@ func (m *UpdateEnvironment) Validate(formats strfmt.Registry) error { res = append(res, err) } + if err := m.validateInputs(formats); err != nil { + res = append(res, err) + } + if err := m.validateUseCase(formats); err != nil { res = append(res, err) } @@ -112,6 +122,32 @@ func (m *UpdateEnvironment) validateIcon(formats strfmt.Registry) error { return nil } +func (m *UpdateEnvironment) validateInputs(formats strfmt.Registry) error { + if swag.IsZero(m.Inputs) { // not required + return nil + } + + for i := 0; i < len(m.Inputs); i++ { + if swag.IsZero(m.Inputs[i]) { // not required + continue + } + + if m.Inputs[i] != nil { + if err := m.Inputs[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("inputs" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("inputs" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + func (m *UpdateEnvironment) validateUseCase(formats strfmt.Registry) error { if swag.IsZero(m.UseCase) { // not required return nil @@ -132,8 +168,42 @@ func (m *UpdateEnvironment) validateUseCase(formats strfmt.Registry) error { return nil } -// ContextValidate validates this update environment based on context it is used +// ContextValidate validate this update environment based on the context it is used func (m *UpdateEnvironment) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + if err := m.contextValidateInputs(ctx, formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *UpdateEnvironment) contextValidateInputs(ctx context.Context, formats strfmt.Registry) error { + + for i := 0; i < len(m.Inputs); i++ { + + if m.Inputs[i] != nil { + + if swag.IsZero(m.Inputs[i]) { // not required + return nil + } + + if err := m.Inputs[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("inputs" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("inputs" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + return nil } diff --git a/client/version b/client/version index d9cff10e..6249f709 100644 --- a/client/version +++ b/client/version @@ -1 +1 @@ -v5.1.43 +v5.1.61 From de40eaffd9097a19973a1f342ac062ff7bcf8cd0 Mon Sep 17 00:00:00 2001 From: Cycloid Date: Thu, 3 Oct 2024 12:24:56 +0000 Subject: [PATCH 44/71] Changelog: Add entry for new version v5.1.61 --- changelog/unreleased/CLI-CHANGED-20241003-122456.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 changelog/unreleased/CLI-CHANGED-20241003-122456.yaml diff --git a/changelog/unreleased/CLI-CHANGED-20241003-122456.yaml b/changelog/unreleased/CLI-CHANGED-20241003-122456.yaml new file mode 100644 index 00000000..b82e7e45 --- /dev/null +++ b/changelog/unreleased/CLI-CHANGED-20241003-122456.yaml @@ -0,0 +1,8 @@ +component: CLI +kind: CHANGED +body: "Update client to version v5.1.61" +time: 2024-10-03T12:24:56.681460044+00:00 +custom: + DETAILS: "" + PR: "304" + TYPE: CLI From a89007f8e224c96f85d9b92bb2443dbb542c7f28 Mon Sep 17 00:00:00 2001 From: Cycloid Date: Thu, 3 Oct 2024 16:08:15 +0000 Subject: [PATCH 45/71] Bump swagger client to version v5.1.67 --- .../{forms_file_v2.go => forms_file_v3.go} | 26 ++-- client/models/forms_validation_result.go | 2 +- client/models/new_environment.go | 143 +++++++++++++++++- client/models/project_environment_config.go | 2 +- client/models/update_environment.go | 72 ++++++++- client/version | 2 +- 6 files changed, 229 insertions(+), 18 deletions(-) rename client/models/{forms_file_v2.go => forms_file_v3.go} (79%) diff --git a/client/models/forms_file_v2.go b/client/models/forms_file_v3.go similarity index 79% rename from client/models/forms_file_v2.go rename to client/models/forms_file_v3.go index 4407e1b6..021f7c11 100644 --- a/client/models/forms_file_v2.go +++ b/client/models/forms_file_v3.go @@ -15,10 +15,10 @@ import ( "github.com/go-openapi/validate" ) -// FormsFileV2 Forms File V2 +// FormsFileV3 Forms File V3 // -// swagger:model FormsFileV2 -type FormsFileV2 struct { +// swagger:model FormsFileV3 +type FormsFileV3 struct { // use cases // Required: true @@ -29,8 +29,8 @@ type FormsFileV2 struct { Version *string `json:"version"` } -// Validate validates this forms file v2 -func (m *FormsFileV2) Validate(formats strfmt.Registry) error { +// Validate validates this forms file v3 +func (m *FormsFileV3) Validate(formats strfmt.Registry) error { var res []error if err := m.validateUseCases(formats); err != nil { @@ -47,7 +47,7 @@ func (m *FormsFileV2) Validate(formats strfmt.Registry) error { return nil } -func (m *FormsFileV2) validateUseCases(formats strfmt.Registry) error { +func (m *FormsFileV3) validateUseCases(formats strfmt.Registry) error { if err := validate.Required("use_cases", "body", m.UseCases); err != nil { return err @@ -74,7 +74,7 @@ func (m *FormsFileV2) validateUseCases(formats strfmt.Registry) error { return nil } -func (m *FormsFileV2) validateVersion(formats strfmt.Registry) error { +func (m *FormsFileV3) validateVersion(formats strfmt.Registry) error { if err := validate.Required("version", "body", m.Version); err != nil { return err @@ -83,8 +83,8 @@ func (m *FormsFileV2) validateVersion(formats strfmt.Registry) error { return nil } -// ContextValidate validate this forms file v2 based on the context it is used -func (m *FormsFileV2) ContextValidate(ctx context.Context, formats strfmt.Registry) error { +// ContextValidate validate this forms file v3 based on the context it is used +func (m *FormsFileV3) ContextValidate(ctx context.Context, formats strfmt.Registry) error { var res []error if err := m.contextValidateUseCases(ctx, formats); err != nil { @@ -97,7 +97,7 @@ func (m *FormsFileV2) ContextValidate(ctx context.Context, formats strfmt.Regist return nil } -func (m *FormsFileV2) contextValidateUseCases(ctx context.Context, formats strfmt.Registry) error { +func (m *FormsFileV3) contextValidateUseCases(ctx context.Context, formats strfmt.Registry) error { for i := 0; i < len(m.UseCases); i++ { @@ -123,7 +123,7 @@ func (m *FormsFileV2) contextValidateUseCases(ctx context.Context, formats strfm } // MarshalBinary interface implementation -func (m *FormsFileV2) MarshalBinary() ([]byte, error) { +func (m *FormsFileV3) MarshalBinary() ([]byte, error) { if m == nil { return nil, nil } @@ -131,8 +131,8 @@ func (m *FormsFileV2) MarshalBinary() ([]byte, error) { } // UnmarshalBinary interface implementation -func (m *FormsFileV2) UnmarshalBinary(b []byte) error { - var res FormsFileV2 +func (m *FormsFileV3) UnmarshalBinary(b []byte) error { + var res FormsFileV3 if err := swag.ReadJSON(b, &res); err != nil { return err } diff --git a/client/models/forms_validation_result.go b/client/models/forms_validation_result.go index edec0402..cc3e8224 100644 --- a/client/models/forms_validation_result.go +++ b/client/models/forms_validation_result.go @@ -27,7 +27,7 @@ type FormsValidationResult struct { // forms // Required: true - Forms *FormsFileV2 `json:"forms"` + Forms *FormsFileV3 `json:"forms"` } // Validate validates this forms validation result diff --git a/client/models/new_environment.go b/client/models/new_environment.go index 506cde2c..66c69d29 100644 --- a/client/models/new_environment.go +++ b/client/models/new_environment.go @@ -7,6 +7,7 @@ package models import ( "context" + "strconv" "github.com/go-openapi/errors" "github.com/go-openapi/strfmt" @@ -42,6 +43,17 @@ type NewEnvironment struct { // Max Length: 64 Icon string `json:"icon,omitempty"` + // The variables set within a form with the corresponding environment + // canonical and use case + // + Inputs []*FormInput `json:"inputs"` + + // Each instance should include passed_config if no inputs are sent on + // environment creation, otherwise it will be inferred internally. + // + // Min Items: 1 + Pipelines []*NewPipeline `json:"pipelines"` + // use case // Max Length: 100 // Min Length: 3 @@ -69,6 +81,14 @@ func (m *NewEnvironment) Validate(formats strfmt.Registry) error { res = append(res, err) } + if err := m.validateInputs(formats); err != nil { + res = append(res, err) + } + + if err := m.validatePipelines(formats); err != nil { + res = append(res, err) + } + if err := m.validateUseCase(formats); err != nil { res = append(res, err) } @@ -144,6 +164,64 @@ func (m *NewEnvironment) validateIcon(formats strfmt.Registry) error { return nil } +func (m *NewEnvironment) validateInputs(formats strfmt.Registry) error { + if swag.IsZero(m.Inputs) { // not required + return nil + } + + for i := 0; i < len(m.Inputs); i++ { + if swag.IsZero(m.Inputs[i]) { // not required + continue + } + + if m.Inputs[i] != nil { + if err := m.Inputs[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("inputs" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("inputs" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +func (m *NewEnvironment) validatePipelines(formats strfmt.Registry) error { + if swag.IsZero(m.Pipelines) { // not required + return nil + } + + iPipelinesSize := int64(len(m.Pipelines)) + + if err := validate.MinItems("pipelines", "body", iPipelinesSize, 1); err != nil { + return err + } + + for i := 0; i < len(m.Pipelines); i++ { + if swag.IsZero(m.Pipelines[i]) { // not required + continue + } + + if m.Pipelines[i] != nil { + if err := m.Pipelines[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("pipelines" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("pipelines" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + func (m *NewEnvironment) validateUseCase(formats strfmt.Registry) error { if swag.IsZero(m.UseCase) { // not required return nil @@ -164,8 +242,71 @@ func (m *NewEnvironment) validateUseCase(formats strfmt.Registry) error { return nil } -// ContextValidate validates this new environment based on context it is used +// ContextValidate validate this new environment based on the context it is used func (m *NewEnvironment) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + if err := m.contextValidateInputs(ctx, formats); err != nil { + res = append(res, err) + } + + if err := m.contextValidatePipelines(ctx, formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *NewEnvironment) contextValidateInputs(ctx context.Context, formats strfmt.Registry) error { + + for i := 0; i < len(m.Inputs); i++ { + + if m.Inputs[i] != nil { + + if swag.IsZero(m.Inputs[i]) { // not required + return nil + } + + if err := m.Inputs[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("inputs" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("inputs" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +func (m *NewEnvironment) contextValidatePipelines(ctx context.Context, formats strfmt.Registry) error { + + for i := 0; i < len(m.Pipelines); i++ { + + if m.Pipelines[i] != nil { + + if swag.IsZero(m.Pipelines[i]) { // not required + return nil + } + + if err := m.Pipelines[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("pipelines" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("pipelines" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + return nil } diff --git a/client/models/project_environment_config.go b/client/models/project_environment_config.go index f1469f09..652652c0 100644 --- a/client/models/project_environment_config.go +++ b/client/models/project_environment_config.go @@ -25,7 +25,7 @@ type ProjectEnvironmentConfig struct { // forms // Required: true - Forms *FormsFileV2 `json:"forms"` + Forms *FormsFileV3 `json:"forms"` // The resource pool canonical, only require when using Quotas ResourcePoolCanonical string `json:"resource_pool_canonical,omitempty"` diff --git a/client/models/update_environment.go b/client/models/update_environment.go index 73f3f94c..642f8886 100644 --- a/client/models/update_environment.go +++ b/client/models/update_environment.go @@ -7,6 +7,7 @@ package models import ( "context" + "strconv" "github.com/go-openapi/errors" "github.com/go-openapi/strfmt" @@ -35,6 +36,11 @@ type UpdateEnvironment struct { // Max Length: 64 Icon string `json:"icon,omitempty"` + // The variables set within a form with the corresponding environment + // canonical and use case + // + Inputs []*FormInput `json:"inputs"` + // use case // Max Length: 100 // Min Length: 3 @@ -58,6 +64,10 @@ func (m *UpdateEnvironment) Validate(formats strfmt.Registry) error { res = append(res, err) } + if err := m.validateInputs(formats); err != nil { + res = append(res, err) + } + if err := m.validateUseCase(formats); err != nil { res = append(res, err) } @@ -112,6 +122,32 @@ func (m *UpdateEnvironment) validateIcon(formats strfmt.Registry) error { return nil } +func (m *UpdateEnvironment) validateInputs(formats strfmt.Registry) error { + if swag.IsZero(m.Inputs) { // not required + return nil + } + + for i := 0; i < len(m.Inputs); i++ { + if swag.IsZero(m.Inputs[i]) { // not required + continue + } + + if m.Inputs[i] != nil { + if err := m.Inputs[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("inputs" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("inputs" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + func (m *UpdateEnvironment) validateUseCase(formats strfmt.Registry) error { if swag.IsZero(m.UseCase) { // not required return nil @@ -132,8 +168,42 @@ func (m *UpdateEnvironment) validateUseCase(formats strfmt.Registry) error { return nil } -// ContextValidate validates this update environment based on context it is used +// ContextValidate validate this update environment based on the context it is used func (m *UpdateEnvironment) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + if err := m.contextValidateInputs(ctx, formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *UpdateEnvironment) contextValidateInputs(ctx context.Context, formats strfmt.Registry) error { + + for i := 0; i < len(m.Inputs); i++ { + + if m.Inputs[i] != nil { + + if swag.IsZero(m.Inputs[i]) { // not required + return nil + } + + if err := m.Inputs[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("inputs" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("inputs" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + return nil } diff --git a/client/version b/client/version index d9cff10e..2e5d457c 100644 --- a/client/version +++ b/client/version @@ -1 +1 @@ -v5.1.43 +v5.1.67 From cba508bf06a1ec0e393da93f2813e69e762ead3e Mon Sep 17 00:00:00 2001 From: Cycloid Date: Thu, 3 Oct 2024 16:08:47 +0000 Subject: [PATCH 46/71] Changelog: Add entry for new version v5.1.67 --- changelog/unreleased/CLI-CHANGED-20241003-160847.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 changelog/unreleased/CLI-CHANGED-20241003-160847.yaml diff --git a/changelog/unreleased/CLI-CHANGED-20241003-160847.yaml b/changelog/unreleased/CLI-CHANGED-20241003-160847.yaml new file mode 100644 index 00000000..f696fcb5 --- /dev/null +++ b/changelog/unreleased/CLI-CHANGED-20241003-160847.yaml @@ -0,0 +1,8 @@ +component: CLI +kind: CHANGED +body: "Update client to version v5.1.67" +time: 2024-10-03T16:08:47.699256654+00:00 +custom: + DETAILS: "" + PR: "305" + TYPE: CLI From 66f9d870bd11bd2b39cf23fbd8755f96c2f2f047 Mon Sep 17 00:00:00 2001 From: Cycloid Date: Tue, 15 Oct 2024 08:44:06 +0000 Subject: [PATCH 47/71] Bump swagger client to version v5.1.76 --- .../{forms_file_v2.go => forms_file_v3.go} | 26 ++-- client/models/forms_validation_result.go | 2 +- client/models/new_environment.go | 143 +++++++++++++++++- client/models/project_environment_config.go | 2 +- client/models/update_environment.go | 72 ++++++++- client/version | 2 +- 6 files changed, 229 insertions(+), 18 deletions(-) rename client/models/{forms_file_v2.go => forms_file_v3.go} (79%) diff --git a/client/models/forms_file_v2.go b/client/models/forms_file_v3.go similarity index 79% rename from client/models/forms_file_v2.go rename to client/models/forms_file_v3.go index 4407e1b6..021f7c11 100644 --- a/client/models/forms_file_v2.go +++ b/client/models/forms_file_v3.go @@ -15,10 +15,10 @@ import ( "github.com/go-openapi/validate" ) -// FormsFileV2 Forms File V2 +// FormsFileV3 Forms File V3 // -// swagger:model FormsFileV2 -type FormsFileV2 struct { +// swagger:model FormsFileV3 +type FormsFileV3 struct { // use cases // Required: true @@ -29,8 +29,8 @@ type FormsFileV2 struct { Version *string `json:"version"` } -// Validate validates this forms file v2 -func (m *FormsFileV2) Validate(formats strfmt.Registry) error { +// Validate validates this forms file v3 +func (m *FormsFileV3) Validate(formats strfmt.Registry) error { var res []error if err := m.validateUseCases(formats); err != nil { @@ -47,7 +47,7 @@ func (m *FormsFileV2) Validate(formats strfmt.Registry) error { return nil } -func (m *FormsFileV2) validateUseCases(formats strfmt.Registry) error { +func (m *FormsFileV3) validateUseCases(formats strfmt.Registry) error { if err := validate.Required("use_cases", "body", m.UseCases); err != nil { return err @@ -74,7 +74,7 @@ func (m *FormsFileV2) validateUseCases(formats strfmt.Registry) error { return nil } -func (m *FormsFileV2) validateVersion(formats strfmt.Registry) error { +func (m *FormsFileV3) validateVersion(formats strfmt.Registry) error { if err := validate.Required("version", "body", m.Version); err != nil { return err @@ -83,8 +83,8 @@ func (m *FormsFileV2) validateVersion(formats strfmt.Registry) error { return nil } -// ContextValidate validate this forms file v2 based on the context it is used -func (m *FormsFileV2) ContextValidate(ctx context.Context, formats strfmt.Registry) error { +// ContextValidate validate this forms file v3 based on the context it is used +func (m *FormsFileV3) ContextValidate(ctx context.Context, formats strfmt.Registry) error { var res []error if err := m.contextValidateUseCases(ctx, formats); err != nil { @@ -97,7 +97,7 @@ func (m *FormsFileV2) ContextValidate(ctx context.Context, formats strfmt.Regist return nil } -func (m *FormsFileV2) contextValidateUseCases(ctx context.Context, formats strfmt.Registry) error { +func (m *FormsFileV3) contextValidateUseCases(ctx context.Context, formats strfmt.Registry) error { for i := 0; i < len(m.UseCases); i++ { @@ -123,7 +123,7 @@ func (m *FormsFileV2) contextValidateUseCases(ctx context.Context, formats strfm } // MarshalBinary interface implementation -func (m *FormsFileV2) MarshalBinary() ([]byte, error) { +func (m *FormsFileV3) MarshalBinary() ([]byte, error) { if m == nil { return nil, nil } @@ -131,8 +131,8 @@ func (m *FormsFileV2) MarshalBinary() ([]byte, error) { } // UnmarshalBinary interface implementation -func (m *FormsFileV2) UnmarshalBinary(b []byte) error { - var res FormsFileV2 +func (m *FormsFileV3) UnmarshalBinary(b []byte) error { + var res FormsFileV3 if err := swag.ReadJSON(b, &res); err != nil { return err } diff --git a/client/models/forms_validation_result.go b/client/models/forms_validation_result.go index edec0402..cc3e8224 100644 --- a/client/models/forms_validation_result.go +++ b/client/models/forms_validation_result.go @@ -27,7 +27,7 @@ type FormsValidationResult struct { // forms // Required: true - Forms *FormsFileV2 `json:"forms"` + Forms *FormsFileV3 `json:"forms"` } // Validate validates this forms validation result diff --git a/client/models/new_environment.go b/client/models/new_environment.go index 506cde2c..66c69d29 100644 --- a/client/models/new_environment.go +++ b/client/models/new_environment.go @@ -7,6 +7,7 @@ package models import ( "context" + "strconv" "github.com/go-openapi/errors" "github.com/go-openapi/strfmt" @@ -42,6 +43,17 @@ type NewEnvironment struct { // Max Length: 64 Icon string `json:"icon,omitempty"` + // The variables set within a form with the corresponding environment + // canonical and use case + // + Inputs []*FormInput `json:"inputs"` + + // Each instance should include passed_config if no inputs are sent on + // environment creation, otherwise it will be inferred internally. + // + // Min Items: 1 + Pipelines []*NewPipeline `json:"pipelines"` + // use case // Max Length: 100 // Min Length: 3 @@ -69,6 +81,14 @@ func (m *NewEnvironment) Validate(formats strfmt.Registry) error { res = append(res, err) } + if err := m.validateInputs(formats); err != nil { + res = append(res, err) + } + + if err := m.validatePipelines(formats); err != nil { + res = append(res, err) + } + if err := m.validateUseCase(formats); err != nil { res = append(res, err) } @@ -144,6 +164,64 @@ func (m *NewEnvironment) validateIcon(formats strfmt.Registry) error { return nil } +func (m *NewEnvironment) validateInputs(formats strfmt.Registry) error { + if swag.IsZero(m.Inputs) { // not required + return nil + } + + for i := 0; i < len(m.Inputs); i++ { + if swag.IsZero(m.Inputs[i]) { // not required + continue + } + + if m.Inputs[i] != nil { + if err := m.Inputs[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("inputs" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("inputs" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +func (m *NewEnvironment) validatePipelines(formats strfmt.Registry) error { + if swag.IsZero(m.Pipelines) { // not required + return nil + } + + iPipelinesSize := int64(len(m.Pipelines)) + + if err := validate.MinItems("pipelines", "body", iPipelinesSize, 1); err != nil { + return err + } + + for i := 0; i < len(m.Pipelines); i++ { + if swag.IsZero(m.Pipelines[i]) { // not required + continue + } + + if m.Pipelines[i] != nil { + if err := m.Pipelines[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("pipelines" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("pipelines" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + func (m *NewEnvironment) validateUseCase(formats strfmt.Registry) error { if swag.IsZero(m.UseCase) { // not required return nil @@ -164,8 +242,71 @@ func (m *NewEnvironment) validateUseCase(formats strfmt.Registry) error { return nil } -// ContextValidate validates this new environment based on context it is used +// ContextValidate validate this new environment based on the context it is used func (m *NewEnvironment) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + if err := m.contextValidateInputs(ctx, formats); err != nil { + res = append(res, err) + } + + if err := m.contextValidatePipelines(ctx, formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *NewEnvironment) contextValidateInputs(ctx context.Context, formats strfmt.Registry) error { + + for i := 0; i < len(m.Inputs); i++ { + + if m.Inputs[i] != nil { + + if swag.IsZero(m.Inputs[i]) { // not required + return nil + } + + if err := m.Inputs[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("inputs" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("inputs" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +func (m *NewEnvironment) contextValidatePipelines(ctx context.Context, formats strfmt.Registry) error { + + for i := 0; i < len(m.Pipelines); i++ { + + if m.Pipelines[i] != nil { + + if swag.IsZero(m.Pipelines[i]) { // not required + return nil + } + + if err := m.Pipelines[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("pipelines" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("pipelines" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + return nil } diff --git a/client/models/project_environment_config.go b/client/models/project_environment_config.go index f1469f09..652652c0 100644 --- a/client/models/project_environment_config.go +++ b/client/models/project_environment_config.go @@ -25,7 +25,7 @@ type ProjectEnvironmentConfig struct { // forms // Required: true - Forms *FormsFileV2 `json:"forms"` + Forms *FormsFileV3 `json:"forms"` // The resource pool canonical, only require when using Quotas ResourcePoolCanonical string `json:"resource_pool_canonical,omitempty"` diff --git a/client/models/update_environment.go b/client/models/update_environment.go index 73f3f94c..642f8886 100644 --- a/client/models/update_environment.go +++ b/client/models/update_environment.go @@ -7,6 +7,7 @@ package models import ( "context" + "strconv" "github.com/go-openapi/errors" "github.com/go-openapi/strfmt" @@ -35,6 +36,11 @@ type UpdateEnvironment struct { // Max Length: 64 Icon string `json:"icon,omitempty"` + // The variables set within a form with the corresponding environment + // canonical and use case + // + Inputs []*FormInput `json:"inputs"` + // use case // Max Length: 100 // Min Length: 3 @@ -58,6 +64,10 @@ func (m *UpdateEnvironment) Validate(formats strfmt.Registry) error { res = append(res, err) } + if err := m.validateInputs(formats); err != nil { + res = append(res, err) + } + if err := m.validateUseCase(formats); err != nil { res = append(res, err) } @@ -112,6 +122,32 @@ func (m *UpdateEnvironment) validateIcon(formats strfmt.Registry) error { return nil } +func (m *UpdateEnvironment) validateInputs(formats strfmt.Registry) error { + if swag.IsZero(m.Inputs) { // not required + return nil + } + + for i := 0; i < len(m.Inputs); i++ { + if swag.IsZero(m.Inputs[i]) { // not required + continue + } + + if m.Inputs[i] != nil { + if err := m.Inputs[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("inputs" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("inputs" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + func (m *UpdateEnvironment) validateUseCase(formats strfmt.Registry) error { if swag.IsZero(m.UseCase) { // not required return nil @@ -132,8 +168,42 @@ func (m *UpdateEnvironment) validateUseCase(formats strfmt.Registry) error { return nil } -// ContextValidate validates this update environment based on context it is used +// ContextValidate validate this update environment based on the context it is used func (m *UpdateEnvironment) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + if err := m.contextValidateInputs(ctx, formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *UpdateEnvironment) contextValidateInputs(ctx context.Context, formats strfmt.Registry) error { + + for i := 0; i < len(m.Inputs); i++ { + + if m.Inputs[i] != nil { + + if swag.IsZero(m.Inputs[i]) { // not required + return nil + } + + if err := m.Inputs[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("inputs" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("inputs" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + return nil } diff --git a/client/version b/client/version index d9cff10e..90b540fb 100644 --- a/client/version +++ b/client/version @@ -1 +1 @@ -v5.1.43 +v5.1.76 From 81714faea52ba4374ce4ac0bfdb99701a32eaeed Mon Sep 17 00:00:00 2001 From: Cycloid Date: Tue, 15 Oct 2024 08:44:36 +0000 Subject: [PATCH 48/71] Changelog: Add entry for new version v5.1.76 --- changelog/unreleased/CLI-CHANGED-20241015-084435.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 changelog/unreleased/CLI-CHANGED-20241015-084435.yaml diff --git a/changelog/unreleased/CLI-CHANGED-20241015-084435.yaml b/changelog/unreleased/CLI-CHANGED-20241015-084435.yaml new file mode 100644 index 00000000..d5bd74c0 --- /dev/null +++ b/changelog/unreleased/CLI-CHANGED-20241015-084435.yaml @@ -0,0 +1,8 @@ +component: CLI +kind: CHANGED +body: "Update client to version v5.1.76" +time: 2024-10-15T08:44:35.988961269+00:00 +custom: + DETAILS: "" + PR: "306" + TYPE: CLI From 7ba61336c229e5f84cddb86bd1086840bdc47fc7 Mon Sep 17 00:00:00 2001 From: talset Date: Wed, 23 Oct 2024 12:48:57 +0200 Subject: [PATCH 49/71] org: display org delete --- cmd/cycloid/organizations/delete.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/cycloid/organizations/delete.go b/cmd/cycloid/organizations/delete.go index e91e5db6..1511f520 100644 --- a/cmd/cycloid/organizations/delete.go +++ b/cmd/cycloid/organizations/delete.go @@ -13,11 +13,11 @@ import ( func NewDeleteCommand() *cobra.Command { var cmd = &cobra.Command{ - Use: "delete", - Short: "delete an organization", - Hidden: true, + Use: "delete", + Short: "delete an organization (require root API_KEY)", Example: ` # delete an organization with canonical name my-org + # The API_KEY must be obtained from the root organization cy organization delete --org my-org `, RunE: del, From a3a9399261e4456654909ca9a7c768cc550486c1 Mon Sep 17 00:00:00 2001 From: Cycloid Date: Tue, 5 Nov 2024 13:42:51 +0000 Subject: [PATCH 50/71] Bump swagger client to version v5.1.98 --- .../{forms_file_v2.go => forms_file_v3.go} | 26 ++-- client/models/forms_validation_result.go | 2 +- client/models/new_environment.go | 143 +++++++++++++++++- client/models/project_environment_config.go | 2 +- client/models/update_environment.go | 72 ++++++++- client/version | 2 +- 6 files changed, 229 insertions(+), 18 deletions(-) rename client/models/{forms_file_v2.go => forms_file_v3.go} (79%) diff --git a/client/models/forms_file_v2.go b/client/models/forms_file_v3.go similarity index 79% rename from client/models/forms_file_v2.go rename to client/models/forms_file_v3.go index 4407e1b6..021f7c11 100644 --- a/client/models/forms_file_v2.go +++ b/client/models/forms_file_v3.go @@ -15,10 +15,10 @@ import ( "github.com/go-openapi/validate" ) -// FormsFileV2 Forms File V2 +// FormsFileV3 Forms File V3 // -// swagger:model FormsFileV2 -type FormsFileV2 struct { +// swagger:model FormsFileV3 +type FormsFileV3 struct { // use cases // Required: true @@ -29,8 +29,8 @@ type FormsFileV2 struct { Version *string `json:"version"` } -// Validate validates this forms file v2 -func (m *FormsFileV2) Validate(formats strfmt.Registry) error { +// Validate validates this forms file v3 +func (m *FormsFileV3) Validate(formats strfmt.Registry) error { var res []error if err := m.validateUseCases(formats); err != nil { @@ -47,7 +47,7 @@ func (m *FormsFileV2) Validate(formats strfmt.Registry) error { return nil } -func (m *FormsFileV2) validateUseCases(formats strfmt.Registry) error { +func (m *FormsFileV3) validateUseCases(formats strfmt.Registry) error { if err := validate.Required("use_cases", "body", m.UseCases); err != nil { return err @@ -74,7 +74,7 @@ func (m *FormsFileV2) validateUseCases(formats strfmt.Registry) error { return nil } -func (m *FormsFileV2) validateVersion(formats strfmt.Registry) error { +func (m *FormsFileV3) validateVersion(formats strfmt.Registry) error { if err := validate.Required("version", "body", m.Version); err != nil { return err @@ -83,8 +83,8 @@ func (m *FormsFileV2) validateVersion(formats strfmt.Registry) error { return nil } -// ContextValidate validate this forms file v2 based on the context it is used -func (m *FormsFileV2) ContextValidate(ctx context.Context, formats strfmt.Registry) error { +// ContextValidate validate this forms file v3 based on the context it is used +func (m *FormsFileV3) ContextValidate(ctx context.Context, formats strfmt.Registry) error { var res []error if err := m.contextValidateUseCases(ctx, formats); err != nil { @@ -97,7 +97,7 @@ func (m *FormsFileV2) ContextValidate(ctx context.Context, formats strfmt.Regist return nil } -func (m *FormsFileV2) contextValidateUseCases(ctx context.Context, formats strfmt.Registry) error { +func (m *FormsFileV3) contextValidateUseCases(ctx context.Context, formats strfmt.Registry) error { for i := 0; i < len(m.UseCases); i++ { @@ -123,7 +123,7 @@ func (m *FormsFileV2) contextValidateUseCases(ctx context.Context, formats strfm } // MarshalBinary interface implementation -func (m *FormsFileV2) MarshalBinary() ([]byte, error) { +func (m *FormsFileV3) MarshalBinary() ([]byte, error) { if m == nil { return nil, nil } @@ -131,8 +131,8 @@ func (m *FormsFileV2) MarshalBinary() ([]byte, error) { } // UnmarshalBinary interface implementation -func (m *FormsFileV2) UnmarshalBinary(b []byte) error { - var res FormsFileV2 +func (m *FormsFileV3) UnmarshalBinary(b []byte) error { + var res FormsFileV3 if err := swag.ReadJSON(b, &res); err != nil { return err } diff --git a/client/models/forms_validation_result.go b/client/models/forms_validation_result.go index edec0402..cc3e8224 100644 --- a/client/models/forms_validation_result.go +++ b/client/models/forms_validation_result.go @@ -27,7 +27,7 @@ type FormsValidationResult struct { // forms // Required: true - Forms *FormsFileV2 `json:"forms"` + Forms *FormsFileV3 `json:"forms"` } // Validate validates this forms validation result diff --git a/client/models/new_environment.go b/client/models/new_environment.go index 506cde2c..66c69d29 100644 --- a/client/models/new_environment.go +++ b/client/models/new_environment.go @@ -7,6 +7,7 @@ package models import ( "context" + "strconv" "github.com/go-openapi/errors" "github.com/go-openapi/strfmt" @@ -42,6 +43,17 @@ type NewEnvironment struct { // Max Length: 64 Icon string `json:"icon,omitempty"` + // The variables set within a form with the corresponding environment + // canonical and use case + // + Inputs []*FormInput `json:"inputs"` + + // Each instance should include passed_config if no inputs are sent on + // environment creation, otherwise it will be inferred internally. + // + // Min Items: 1 + Pipelines []*NewPipeline `json:"pipelines"` + // use case // Max Length: 100 // Min Length: 3 @@ -69,6 +81,14 @@ func (m *NewEnvironment) Validate(formats strfmt.Registry) error { res = append(res, err) } + if err := m.validateInputs(formats); err != nil { + res = append(res, err) + } + + if err := m.validatePipelines(formats); err != nil { + res = append(res, err) + } + if err := m.validateUseCase(formats); err != nil { res = append(res, err) } @@ -144,6 +164,64 @@ func (m *NewEnvironment) validateIcon(formats strfmt.Registry) error { return nil } +func (m *NewEnvironment) validateInputs(formats strfmt.Registry) error { + if swag.IsZero(m.Inputs) { // not required + return nil + } + + for i := 0; i < len(m.Inputs); i++ { + if swag.IsZero(m.Inputs[i]) { // not required + continue + } + + if m.Inputs[i] != nil { + if err := m.Inputs[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("inputs" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("inputs" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +func (m *NewEnvironment) validatePipelines(formats strfmt.Registry) error { + if swag.IsZero(m.Pipelines) { // not required + return nil + } + + iPipelinesSize := int64(len(m.Pipelines)) + + if err := validate.MinItems("pipelines", "body", iPipelinesSize, 1); err != nil { + return err + } + + for i := 0; i < len(m.Pipelines); i++ { + if swag.IsZero(m.Pipelines[i]) { // not required + continue + } + + if m.Pipelines[i] != nil { + if err := m.Pipelines[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("pipelines" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("pipelines" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + func (m *NewEnvironment) validateUseCase(formats strfmt.Registry) error { if swag.IsZero(m.UseCase) { // not required return nil @@ -164,8 +242,71 @@ func (m *NewEnvironment) validateUseCase(formats strfmt.Registry) error { return nil } -// ContextValidate validates this new environment based on context it is used +// ContextValidate validate this new environment based on the context it is used func (m *NewEnvironment) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + if err := m.contextValidateInputs(ctx, formats); err != nil { + res = append(res, err) + } + + if err := m.contextValidatePipelines(ctx, formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *NewEnvironment) contextValidateInputs(ctx context.Context, formats strfmt.Registry) error { + + for i := 0; i < len(m.Inputs); i++ { + + if m.Inputs[i] != nil { + + if swag.IsZero(m.Inputs[i]) { // not required + return nil + } + + if err := m.Inputs[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("inputs" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("inputs" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +func (m *NewEnvironment) contextValidatePipelines(ctx context.Context, formats strfmt.Registry) error { + + for i := 0; i < len(m.Pipelines); i++ { + + if m.Pipelines[i] != nil { + + if swag.IsZero(m.Pipelines[i]) { // not required + return nil + } + + if err := m.Pipelines[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("pipelines" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("pipelines" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + return nil } diff --git a/client/models/project_environment_config.go b/client/models/project_environment_config.go index f1469f09..652652c0 100644 --- a/client/models/project_environment_config.go +++ b/client/models/project_environment_config.go @@ -25,7 +25,7 @@ type ProjectEnvironmentConfig struct { // forms // Required: true - Forms *FormsFileV2 `json:"forms"` + Forms *FormsFileV3 `json:"forms"` // The resource pool canonical, only require when using Quotas ResourcePoolCanonical string `json:"resource_pool_canonical,omitempty"` diff --git a/client/models/update_environment.go b/client/models/update_environment.go index 73f3f94c..642f8886 100644 --- a/client/models/update_environment.go +++ b/client/models/update_environment.go @@ -7,6 +7,7 @@ package models import ( "context" + "strconv" "github.com/go-openapi/errors" "github.com/go-openapi/strfmt" @@ -35,6 +36,11 @@ type UpdateEnvironment struct { // Max Length: 64 Icon string `json:"icon,omitempty"` + // The variables set within a form with the corresponding environment + // canonical and use case + // + Inputs []*FormInput `json:"inputs"` + // use case // Max Length: 100 // Min Length: 3 @@ -58,6 +64,10 @@ func (m *UpdateEnvironment) Validate(formats strfmt.Registry) error { res = append(res, err) } + if err := m.validateInputs(formats); err != nil { + res = append(res, err) + } + if err := m.validateUseCase(formats); err != nil { res = append(res, err) } @@ -112,6 +122,32 @@ func (m *UpdateEnvironment) validateIcon(formats strfmt.Registry) error { return nil } +func (m *UpdateEnvironment) validateInputs(formats strfmt.Registry) error { + if swag.IsZero(m.Inputs) { // not required + return nil + } + + for i := 0; i < len(m.Inputs); i++ { + if swag.IsZero(m.Inputs[i]) { // not required + continue + } + + if m.Inputs[i] != nil { + if err := m.Inputs[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("inputs" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("inputs" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + func (m *UpdateEnvironment) validateUseCase(formats strfmt.Registry) error { if swag.IsZero(m.UseCase) { // not required return nil @@ -132,8 +168,42 @@ func (m *UpdateEnvironment) validateUseCase(formats strfmt.Registry) error { return nil } -// ContextValidate validates this update environment based on context it is used +// ContextValidate validate this update environment based on the context it is used func (m *UpdateEnvironment) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + if err := m.contextValidateInputs(ctx, formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *UpdateEnvironment) contextValidateInputs(ctx context.Context, formats strfmt.Registry) error { + + for i := 0; i < len(m.Inputs); i++ { + + if m.Inputs[i] != nil { + + if swag.IsZero(m.Inputs[i]) { // not required + return nil + } + + if err := m.Inputs[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("inputs" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("inputs" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + return nil } diff --git a/client/version b/client/version index d9cff10e..d55181ba 100644 --- a/client/version +++ b/client/version @@ -1 +1 @@ -v5.1.43 +v5.1.98 From 8952dbf724afc7c232055f69aa43f18fd151b7d5 Mon Sep 17 00:00:00 2001 From: Cycloid Date: Tue, 5 Nov 2024 13:43:19 +0000 Subject: [PATCH 51/71] Changelog: Add entry for new version v5.1.98 --- changelog/unreleased/CLI-CHANGED-20241105-134319.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 changelog/unreleased/CLI-CHANGED-20241105-134319.yaml diff --git a/changelog/unreleased/CLI-CHANGED-20241105-134319.yaml b/changelog/unreleased/CLI-CHANGED-20241105-134319.yaml new file mode 100644 index 00000000..7e1d6c8e --- /dev/null +++ b/changelog/unreleased/CLI-CHANGED-20241105-134319.yaml @@ -0,0 +1,8 @@ +component: CLI +kind: CHANGED +body: "Update client to version v5.1.98" +time: 2024-11-05T13:43:19.058980911+00:00 +custom: + DETAILS: "" + PR: "308" + TYPE: CLI From a8ea3ef07a0f22a42ad451df340c9c1d2504b6f4 Mon Sep 17 00:00:00 2001 From: Cycloid Date: Wed, 6 Nov 2024 11:49:03 +0000 Subject: [PATCH 52/71] Bump swagger client to version v5.1.102 --- .../{forms_file_v2.go => forms_file_v3.go} | 26 ++-- client/models/forms_validation_result.go | 2 +- client/models/new_environment.go | 143 +++++++++++++++++- client/models/project_environment_config.go | 2 +- client/models/update_environment.go | 72 ++++++++- client/version | 2 +- 6 files changed, 229 insertions(+), 18 deletions(-) rename client/models/{forms_file_v2.go => forms_file_v3.go} (79%) diff --git a/client/models/forms_file_v2.go b/client/models/forms_file_v3.go similarity index 79% rename from client/models/forms_file_v2.go rename to client/models/forms_file_v3.go index 4407e1b6..021f7c11 100644 --- a/client/models/forms_file_v2.go +++ b/client/models/forms_file_v3.go @@ -15,10 +15,10 @@ import ( "github.com/go-openapi/validate" ) -// FormsFileV2 Forms File V2 +// FormsFileV3 Forms File V3 // -// swagger:model FormsFileV2 -type FormsFileV2 struct { +// swagger:model FormsFileV3 +type FormsFileV3 struct { // use cases // Required: true @@ -29,8 +29,8 @@ type FormsFileV2 struct { Version *string `json:"version"` } -// Validate validates this forms file v2 -func (m *FormsFileV2) Validate(formats strfmt.Registry) error { +// Validate validates this forms file v3 +func (m *FormsFileV3) Validate(formats strfmt.Registry) error { var res []error if err := m.validateUseCases(formats); err != nil { @@ -47,7 +47,7 @@ func (m *FormsFileV2) Validate(formats strfmt.Registry) error { return nil } -func (m *FormsFileV2) validateUseCases(formats strfmt.Registry) error { +func (m *FormsFileV3) validateUseCases(formats strfmt.Registry) error { if err := validate.Required("use_cases", "body", m.UseCases); err != nil { return err @@ -74,7 +74,7 @@ func (m *FormsFileV2) validateUseCases(formats strfmt.Registry) error { return nil } -func (m *FormsFileV2) validateVersion(formats strfmt.Registry) error { +func (m *FormsFileV3) validateVersion(formats strfmt.Registry) error { if err := validate.Required("version", "body", m.Version); err != nil { return err @@ -83,8 +83,8 @@ func (m *FormsFileV2) validateVersion(formats strfmt.Registry) error { return nil } -// ContextValidate validate this forms file v2 based on the context it is used -func (m *FormsFileV2) ContextValidate(ctx context.Context, formats strfmt.Registry) error { +// ContextValidate validate this forms file v3 based on the context it is used +func (m *FormsFileV3) ContextValidate(ctx context.Context, formats strfmt.Registry) error { var res []error if err := m.contextValidateUseCases(ctx, formats); err != nil { @@ -97,7 +97,7 @@ func (m *FormsFileV2) ContextValidate(ctx context.Context, formats strfmt.Regist return nil } -func (m *FormsFileV2) contextValidateUseCases(ctx context.Context, formats strfmt.Registry) error { +func (m *FormsFileV3) contextValidateUseCases(ctx context.Context, formats strfmt.Registry) error { for i := 0; i < len(m.UseCases); i++ { @@ -123,7 +123,7 @@ func (m *FormsFileV2) contextValidateUseCases(ctx context.Context, formats strfm } // MarshalBinary interface implementation -func (m *FormsFileV2) MarshalBinary() ([]byte, error) { +func (m *FormsFileV3) MarshalBinary() ([]byte, error) { if m == nil { return nil, nil } @@ -131,8 +131,8 @@ func (m *FormsFileV2) MarshalBinary() ([]byte, error) { } // UnmarshalBinary interface implementation -func (m *FormsFileV2) UnmarshalBinary(b []byte) error { - var res FormsFileV2 +func (m *FormsFileV3) UnmarshalBinary(b []byte) error { + var res FormsFileV3 if err := swag.ReadJSON(b, &res); err != nil { return err } diff --git a/client/models/forms_validation_result.go b/client/models/forms_validation_result.go index edec0402..cc3e8224 100644 --- a/client/models/forms_validation_result.go +++ b/client/models/forms_validation_result.go @@ -27,7 +27,7 @@ type FormsValidationResult struct { // forms // Required: true - Forms *FormsFileV2 `json:"forms"` + Forms *FormsFileV3 `json:"forms"` } // Validate validates this forms validation result diff --git a/client/models/new_environment.go b/client/models/new_environment.go index 506cde2c..66c69d29 100644 --- a/client/models/new_environment.go +++ b/client/models/new_environment.go @@ -7,6 +7,7 @@ package models import ( "context" + "strconv" "github.com/go-openapi/errors" "github.com/go-openapi/strfmt" @@ -42,6 +43,17 @@ type NewEnvironment struct { // Max Length: 64 Icon string `json:"icon,omitempty"` + // The variables set within a form with the corresponding environment + // canonical and use case + // + Inputs []*FormInput `json:"inputs"` + + // Each instance should include passed_config if no inputs are sent on + // environment creation, otherwise it will be inferred internally. + // + // Min Items: 1 + Pipelines []*NewPipeline `json:"pipelines"` + // use case // Max Length: 100 // Min Length: 3 @@ -69,6 +81,14 @@ func (m *NewEnvironment) Validate(formats strfmt.Registry) error { res = append(res, err) } + if err := m.validateInputs(formats); err != nil { + res = append(res, err) + } + + if err := m.validatePipelines(formats); err != nil { + res = append(res, err) + } + if err := m.validateUseCase(formats); err != nil { res = append(res, err) } @@ -144,6 +164,64 @@ func (m *NewEnvironment) validateIcon(formats strfmt.Registry) error { return nil } +func (m *NewEnvironment) validateInputs(formats strfmt.Registry) error { + if swag.IsZero(m.Inputs) { // not required + return nil + } + + for i := 0; i < len(m.Inputs); i++ { + if swag.IsZero(m.Inputs[i]) { // not required + continue + } + + if m.Inputs[i] != nil { + if err := m.Inputs[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("inputs" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("inputs" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +func (m *NewEnvironment) validatePipelines(formats strfmt.Registry) error { + if swag.IsZero(m.Pipelines) { // not required + return nil + } + + iPipelinesSize := int64(len(m.Pipelines)) + + if err := validate.MinItems("pipelines", "body", iPipelinesSize, 1); err != nil { + return err + } + + for i := 0; i < len(m.Pipelines); i++ { + if swag.IsZero(m.Pipelines[i]) { // not required + continue + } + + if m.Pipelines[i] != nil { + if err := m.Pipelines[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("pipelines" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("pipelines" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + func (m *NewEnvironment) validateUseCase(formats strfmt.Registry) error { if swag.IsZero(m.UseCase) { // not required return nil @@ -164,8 +242,71 @@ func (m *NewEnvironment) validateUseCase(formats strfmt.Registry) error { return nil } -// ContextValidate validates this new environment based on context it is used +// ContextValidate validate this new environment based on the context it is used func (m *NewEnvironment) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + if err := m.contextValidateInputs(ctx, formats); err != nil { + res = append(res, err) + } + + if err := m.contextValidatePipelines(ctx, formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *NewEnvironment) contextValidateInputs(ctx context.Context, formats strfmt.Registry) error { + + for i := 0; i < len(m.Inputs); i++ { + + if m.Inputs[i] != nil { + + if swag.IsZero(m.Inputs[i]) { // not required + return nil + } + + if err := m.Inputs[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("inputs" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("inputs" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +func (m *NewEnvironment) contextValidatePipelines(ctx context.Context, formats strfmt.Registry) error { + + for i := 0; i < len(m.Pipelines); i++ { + + if m.Pipelines[i] != nil { + + if swag.IsZero(m.Pipelines[i]) { // not required + return nil + } + + if err := m.Pipelines[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("pipelines" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("pipelines" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + return nil } diff --git a/client/models/project_environment_config.go b/client/models/project_environment_config.go index f1469f09..652652c0 100644 --- a/client/models/project_environment_config.go +++ b/client/models/project_environment_config.go @@ -25,7 +25,7 @@ type ProjectEnvironmentConfig struct { // forms // Required: true - Forms *FormsFileV2 `json:"forms"` + Forms *FormsFileV3 `json:"forms"` // The resource pool canonical, only require when using Quotas ResourcePoolCanonical string `json:"resource_pool_canonical,omitempty"` diff --git a/client/models/update_environment.go b/client/models/update_environment.go index 73f3f94c..642f8886 100644 --- a/client/models/update_environment.go +++ b/client/models/update_environment.go @@ -7,6 +7,7 @@ package models import ( "context" + "strconv" "github.com/go-openapi/errors" "github.com/go-openapi/strfmt" @@ -35,6 +36,11 @@ type UpdateEnvironment struct { // Max Length: 64 Icon string `json:"icon,omitempty"` + // The variables set within a form with the corresponding environment + // canonical and use case + // + Inputs []*FormInput `json:"inputs"` + // use case // Max Length: 100 // Min Length: 3 @@ -58,6 +64,10 @@ func (m *UpdateEnvironment) Validate(formats strfmt.Registry) error { res = append(res, err) } + if err := m.validateInputs(formats); err != nil { + res = append(res, err) + } + if err := m.validateUseCase(formats); err != nil { res = append(res, err) } @@ -112,6 +122,32 @@ func (m *UpdateEnvironment) validateIcon(formats strfmt.Registry) error { return nil } +func (m *UpdateEnvironment) validateInputs(formats strfmt.Registry) error { + if swag.IsZero(m.Inputs) { // not required + return nil + } + + for i := 0; i < len(m.Inputs); i++ { + if swag.IsZero(m.Inputs[i]) { // not required + continue + } + + if m.Inputs[i] != nil { + if err := m.Inputs[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("inputs" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("inputs" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + func (m *UpdateEnvironment) validateUseCase(formats strfmt.Registry) error { if swag.IsZero(m.UseCase) { // not required return nil @@ -132,8 +168,42 @@ func (m *UpdateEnvironment) validateUseCase(formats strfmt.Registry) error { return nil } -// ContextValidate validates this update environment based on context it is used +// ContextValidate validate this update environment based on the context it is used func (m *UpdateEnvironment) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + if err := m.contextValidateInputs(ctx, formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *UpdateEnvironment) contextValidateInputs(ctx context.Context, formats strfmt.Registry) error { + + for i := 0; i < len(m.Inputs); i++ { + + if m.Inputs[i] != nil { + + if swag.IsZero(m.Inputs[i]) { // not required + return nil + } + + if err := m.Inputs[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("inputs" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("inputs" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + return nil } diff --git a/client/version b/client/version index d9cff10e..3aeef0d1 100644 --- a/client/version +++ b/client/version @@ -1 +1 @@ -v5.1.43 +v5.1.102 From 58b725cf0d3c858ca32743b8d8ba6f327a7dc1fa Mon Sep 17 00:00:00 2001 From: Cycloid Date: Wed, 6 Nov 2024 11:49:34 +0000 Subject: [PATCH 53/71] Changelog: Add entry for new version v5.1.102 --- changelog/unreleased/CLI-CHANGED-20241106-114934.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 changelog/unreleased/CLI-CHANGED-20241106-114934.yaml diff --git a/changelog/unreleased/CLI-CHANGED-20241106-114934.yaml b/changelog/unreleased/CLI-CHANGED-20241106-114934.yaml new file mode 100644 index 00000000..56e7a03e --- /dev/null +++ b/changelog/unreleased/CLI-CHANGED-20241106-114934.yaml @@ -0,0 +1,8 @@ +component: CLI +kind: CHANGED +body: "Update client to version v5.1.102" +time: 2024-11-06T11:49:34.079304206+00:00 +custom: + DETAILS: "" + PR: "309" + TYPE: CLI From 65e1bb6fc4921ff2dcdfc23ce812d80e6960fac6 Mon Sep 17 00:00:00 2001 From: Cycloid Date: Mon, 18 Nov 2024 13:24:40 +0000 Subject: [PATCH 54/71] Bump swagger client to version v5.1.116 --- client/version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/version b/client/version index 3aeef0d1..dfbc6fda 100644 --- a/client/version +++ b/client/version @@ -1 +1 @@ -v5.1.102 +v5.1.116 From 8aa8de8cbf69e491fded0ad76a46cc1a3ba6825f Mon Sep 17 00:00:00 2001 From: Cycloid Date: Mon, 18 Nov 2024 13:25:11 +0000 Subject: [PATCH 55/71] Changelog: Add entry for new version v5.1.116 --- changelog/unreleased/CLI-CHANGED-20241118-132511.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 changelog/unreleased/CLI-CHANGED-20241118-132511.yaml diff --git a/changelog/unreleased/CLI-CHANGED-20241118-132511.yaml b/changelog/unreleased/CLI-CHANGED-20241118-132511.yaml new file mode 100644 index 00000000..2ce9a46c --- /dev/null +++ b/changelog/unreleased/CLI-CHANGED-20241118-132511.yaml @@ -0,0 +1,8 @@ +component: CLI +kind: CHANGED +body: "Update client to version v5.1.116" +time: 2024-11-18T13:25:11.005175895+00:00 +custom: + DETAILS: "" + PR: "311" + TYPE: CLI From 88281d03e942f11042536a90d2b26e7aa9e71c23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20BARRAS=20HAMPEL?= Date: Tue, 19 Nov 2024 18:07:33 +0100 Subject: [PATCH 56/71] fix: fix tests default org --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 5a97f966..fd027654 100644 --- a/Makefile +++ b/Makefile @@ -69,7 +69,7 @@ SWAGGER_DOCKER_GENERATE = rm -rf ./client; \ CY_API_URL ?= http://127.0.0.1:3001 # Env list specified in file /e2e/e2e.go CY_TEST_GIT_CR_URL ?= git@172.42.0.14:/git-server/repos/backend-test-config-repo.git -CY_TEST_ROOT_ORG ?= "fake-cycloid" +CY_TEST_ROOT_ORG ?= "cycloidio" # Local E2E tests # Note! Requires access to the private cycloid BE, only acessible within the organisation From 2f91d063b9c84f9af0b8aef7fa10a9c68ccb21b3 Mon Sep 17 00:00:00 2001 From: Cycloid Date: Mon, 25 Nov 2024 14:24:50 +0000 Subject: [PATCH 57/71] Bump swagger client to version v5.1.124 --- .../create_project_parameters.go | 3 +- .../organization_projects_client.go | 2 +- client/models/new_environment.go | 71 --------- client/models/new_project.go | 143 +----------------- client/models/update_project.go | 141 +---------------- client/version | 2 +- 6 files changed, 5 insertions(+), 357 deletions(-) diff --git a/client/client/organization_projects/create_project_parameters.go b/client/client/organization_projects/create_project_parameters.go index c4452dc5..d56811e6 100644 --- a/client/client/organization_projects/create_project_parameters.go +++ b/client/client/organization_projects/create_project_parameters.go @@ -65,8 +65,7 @@ type CreateProjectParams struct { /* Body. - The information of the project to create and optionally its configuration inputs. - If the configuration inputs are not sent the project configuration is not generated and should be generated separately. + The information of the project to create. */ Body *models.NewProject diff --git a/client/client/organization_projects/organization_projects_client.go b/client/client/organization_projects/organization_projects_client.go index b9fd2d06..2aa75389 100644 --- a/client/client/organization_projects/organization_projects_client.go +++ b/client/client/organization_projects/organization_projects_client.go @@ -167,7 +167,7 @@ func (a *Client) CreateEnvironment(params *CreateEnvironmentParams, authInfo run } /* -CreateProject Create a new project with envs and pipelines in the organization. +CreateProject Create a new project with pipelines in the organization. */ func (a *Client) CreateProject(params *CreateProjectParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*CreateProjectOK, error) { // TODO: Validate the params before sending diff --git a/client/models/new_environment.go b/client/models/new_environment.go index 66c69d29..e862d267 100644 --- a/client/models/new_environment.go +++ b/client/models/new_environment.go @@ -48,12 +48,6 @@ type NewEnvironment struct { // Inputs []*FormInput `json:"inputs"` - // Each instance should include passed_config if no inputs are sent on - // environment creation, otherwise it will be inferred internally. - // - // Min Items: 1 - Pipelines []*NewPipeline `json:"pipelines"` - // use case // Max Length: 100 // Min Length: 3 @@ -85,10 +79,6 @@ func (m *NewEnvironment) Validate(formats strfmt.Registry) error { res = append(res, err) } - if err := m.validatePipelines(formats); err != nil { - res = append(res, err) - } - if err := m.validateUseCase(formats); err != nil { res = append(res, err) } @@ -190,38 +180,6 @@ func (m *NewEnvironment) validateInputs(formats strfmt.Registry) error { return nil } -func (m *NewEnvironment) validatePipelines(formats strfmt.Registry) error { - if swag.IsZero(m.Pipelines) { // not required - return nil - } - - iPipelinesSize := int64(len(m.Pipelines)) - - if err := validate.MinItems("pipelines", "body", iPipelinesSize, 1); err != nil { - return err - } - - for i := 0; i < len(m.Pipelines); i++ { - if swag.IsZero(m.Pipelines[i]) { // not required - continue - } - - if m.Pipelines[i] != nil { - if err := m.Pipelines[i].Validate(formats); err != nil { - if ve, ok := err.(*errors.Validation); ok { - return ve.ValidateName("pipelines" + "." + strconv.Itoa(i)) - } else if ce, ok := err.(*errors.CompositeError); ok { - return ce.ValidateName("pipelines" + "." + strconv.Itoa(i)) - } - return err - } - } - - } - - return nil -} - func (m *NewEnvironment) validateUseCase(formats strfmt.Registry) error { if swag.IsZero(m.UseCase) { // not required return nil @@ -250,10 +208,6 @@ func (m *NewEnvironment) ContextValidate(ctx context.Context, formats strfmt.Reg res = append(res, err) } - if err := m.contextValidatePipelines(ctx, formats); err != nil { - res = append(res, err) - } - if len(res) > 0 { return errors.CompositeValidationError(res...) } @@ -285,31 +239,6 @@ func (m *NewEnvironment) contextValidateInputs(ctx context.Context, formats strf return nil } -func (m *NewEnvironment) contextValidatePipelines(ctx context.Context, formats strfmt.Registry) error { - - for i := 0; i < len(m.Pipelines); i++ { - - if m.Pipelines[i] != nil { - - if swag.IsZero(m.Pipelines[i]) { // not required - return nil - } - - if err := m.Pipelines[i].ContextValidate(ctx, formats); err != nil { - if ve, ok := err.(*errors.Validation); ok { - return ve.ValidateName("pipelines" + "." + strconv.Itoa(i)) - } else if ce, ok := err.(*errors.CompositeError); ok { - return ce.ValidateName("pipelines" + "." + strconv.Itoa(i)) - } - return err - } - } - - } - - return nil -} - // MarshalBinary interface implementation func (m *NewEnvironment) MarshalBinary() ([]byte, error) { if m == nil { diff --git a/client/models/new_project.go b/client/models/new_project.go index 3c339be1..0356c69e 100644 --- a/client/models/new_project.go +++ b/client/models/new_project.go @@ -7,7 +7,6 @@ package models import ( "context" - "strconv" "github.com/go-openapi/errors" "github.com/go-openapi/strfmt" @@ -40,11 +39,6 @@ type NewProject struct { // Description string `json:"description,omitempty"` - // The variables set within a form with the corresponding environment - // canonical and use case - // - Inputs []*FormInput `json:"inputs"` - // name // Required: true // Min Length: 1 @@ -56,12 +50,6 @@ type NewProject struct { // Owner string `json:"owner,omitempty"` - // Each instance should include passed_config if no inputs are sent on - // project creation, otherwise it will be inferred internally. - // - // Min Items: 1 - Pipelines []*NewPipeline `json:"pipelines"` - // It's the ref of the Service Catalog, like 'cycloidio:stack-magento' // Required: true ServiceCatalogRef *string `json:"service_catalog_ref"` @@ -87,18 +75,10 @@ func (m *NewProject) Validate(formats strfmt.Registry) error { res = append(res, err) } - if err := m.validateInputs(formats); err != nil { - res = append(res, err) - } - if err := m.validateName(formats); err != nil { res = append(res, err) } - if err := m.validatePipelines(formats); err != nil { - res = append(res, err) - } - if err := m.validateServiceCatalogRef(formats); err != nil { res = append(res, err) } @@ -154,32 +134,6 @@ func (m *NewProject) validateConfigRepositoryCanonical(formats strfmt.Registry) return nil } -func (m *NewProject) validateInputs(formats strfmt.Registry) error { - if swag.IsZero(m.Inputs) { // not required - return nil - } - - for i := 0; i < len(m.Inputs); i++ { - if swag.IsZero(m.Inputs[i]) { // not required - continue - } - - if m.Inputs[i] != nil { - if err := m.Inputs[i].Validate(formats); err != nil { - if ve, ok := err.(*errors.Validation); ok { - return ve.ValidateName("inputs" + "." + strconv.Itoa(i)) - } else if ce, ok := err.(*errors.CompositeError); ok { - return ce.ValidateName("inputs" + "." + strconv.Itoa(i)) - } - return err - } - } - - } - - return nil -} - func (m *NewProject) validateName(formats strfmt.Registry) error { if err := validate.Required("name", "body", m.Name); err != nil { @@ -193,38 +147,6 @@ func (m *NewProject) validateName(formats strfmt.Registry) error { return nil } -func (m *NewProject) validatePipelines(formats strfmt.Registry) error { - if swag.IsZero(m.Pipelines) { // not required - return nil - } - - iPipelinesSize := int64(len(m.Pipelines)) - - if err := validate.MinItems("pipelines", "body", iPipelinesSize, 1); err != nil { - return err - } - - for i := 0; i < len(m.Pipelines); i++ { - if swag.IsZero(m.Pipelines[i]) { // not required - continue - } - - if m.Pipelines[i] != nil { - if err := m.Pipelines[i].Validate(formats); err != nil { - if ve, ok := err.(*errors.Validation); ok { - return ve.ValidateName("pipelines" + "." + strconv.Itoa(i)) - } else if ce, ok := err.(*errors.CompositeError); ok { - return ce.ValidateName("pipelines" + "." + strconv.Itoa(i)) - } - return err - } - } - - } - - return nil -} - func (m *NewProject) validateServiceCatalogRef(formats strfmt.Registry) error { if err := validate.Required("service_catalog_ref", "body", m.ServiceCatalogRef); err != nil { @@ -254,71 +176,8 @@ func (m *NewProject) validateTeamCanonical(formats strfmt.Registry) error { return nil } -// ContextValidate validate this new project based on the context it is used +// ContextValidate validates this new project based on context it is used func (m *NewProject) ContextValidate(ctx context.Context, formats strfmt.Registry) error { - var res []error - - if err := m.contextValidateInputs(ctx, formats); err != nil { - res = append(res, err) - } - - if err := m.contextValidatePipelines(ctx, formats); err != nil { - res = append(res, err) - } - - if len(res) > 0 { - return errors.CompositeValidationError(res...) - } - return nil -} - -func (m *NewProject) contextValidateInputs(ctx context.Context, formats strfmt.Registry) error { - - for i := 0; i < len(m.Inputs); i++ { - - if m.Inputs[i] != nil { - - if swag.IsZero(m.Inputs[i]) { // not required - return nil - } - - if err := m.Inputs[i].ContextValidate(ctx, formats); err != nil { - if ve, ok := err.(*errors.Validation); ok { - return ve.ValidateName("inputs" + "." + strconv.Itoa(i)) - } else if ce, ok := err.(*errors.CompositeError); ok { - return ce.ValidateName("inputs" + "." + strconv.Itoa(i)) - } - return err - } - } - - } - - return nil -} - -func (m *NewProject) contextValidatePipelines(ctx context.Context, formats strfmt.Registry) error { - - for i := 0; i < len(m.Pipelines); i++ { - - if m.Pipelines[i] != nil { - - if swag.IsZero(m.Pipelines[i]) { // not required - return nil - } - - if err := m.Pipelines[i].ContextValidate(ctx, formats); err != nil { - if ve, ok := err.(*errors.Validation); ok { - return ve.ValidateName("pipelines" + "." + strconv.Itoa(i)) - } else if ce, ok := err.(*errors.CompositeError); ok { - return ce.ValidateName("pipelines" + "." + strconv.Itoa(i)) - } - return err - } - } - - } - return nil } diff --git a/client/models/update_project.go b/client/models/update_project.go index 9677641e..76cdaa9c 100644 --- a/client/models/update_project.go +++ b/client/models/update_project.go @@ -8,7 +8,6 @@ package models import ( "context" "encoding/json" - "strconv" "github.com/go-openapi/errors" "github.com/go-openapi/strfmt" @@ -51,15 +50,6 @@ type UpdateProject struct { // description Description string `json:"description,omitempty"` - // environments - // Min Items: 0 - Environments []*NewEnvironment `json:"environments"` - - // The variables set within a form with the corresponding environment - // canonical and use case - // - Inputs []*FormInput `json:"inputs"` - // name // Required: true // Min Length: 1 @@ -97,14 +87,6 @@ func (m *UpdateProject) Validate(formats strfmt.Registry) error { res = append(res, err) } - if err := m.validateEnvironments(formats); err != nil { - res = append(res, err) - } - - if err := m.validateInputs(formats); err != nil { - res = append(res, err) - } - if err := m.validateName(formats); err != nil { res = append(res, err) } @@ -194,64 +176,6 @@ func (m *UpdateProject) validateConfigRepositoryCanonical(formats strfmt.Registr return nil } -func (m *UpdateProject) validateEnvironments(formats strfmt.Registry) error { - if swag.IsZero(m.Environments) { // not required - return nil - } - - iEnvironmentsSize := int64(len(m.Environments)) - - if err := validate.MinItems("environments", "body", iEnvironmentsSize, 0); err != nil { - return err - } - - for i := 0; i < len(m.Environments); i++ { - if swag.IsZero(m.Environments[i]) { // not required - continue - } - - if m.Environments[i] != nil { - if err := m.Environments[i].Validate(formats); err != nil { - if ve, ok := err.(*errors.Validation); ok { - return ve.ValidateName("environments" + "." + strconv.Itoa(i)) - } else if ce, ok := err.(*errors.CompositeError); ok { - return ce.ValidateName("environments" + "." + strconv.Itoa(i)) - } - return err - } - } - - } - - return nil -} - -func (m *UpdateProject) validateInputs(formats strfmt.Registry) error { - if swag.IsZero(m.Inputs) { // not required - return nil - } - - for i := 0; i < len(m.Inputs); i++ { - if swag.IsZero(m.Inputs[i]) { // not required - continue - } - - if m.Inputs[i] != nil { - if err := m.Inputs[i].Validate(formats); err != nil { - if ve, ok := err.(*errors.Validation); ok { - return ve.ValidateName("inputs" + "." + strconv.Itoa(i)) - } else if ce, ok := err.(*errors.CompositeError); ok { - return ce.ValidateName("inputs" + "." + strconv.Itoa(i)) - } - return err - } - } - - } - - return nil -} - func (m *UpdateProject) validateName(formats strfmt.Registry) error { if err := validate.Required("name", "body", m.Name); err != nil { @@ -291,71 +215,8 @@ func (m *UpdateProject) validateUpdatedAt(formats strfmt.Registry) error { return nil } -// ContextValidate validate this update project based on the context it is used +// ContextValidate validates this update project based on context it is used func (m *UpdateProject) ContextValidate(ctx context.Context, formats strfmt.Registry) error { - var res []error - - if err := m.contextValidateEnvironments(ctx, formats); err != nil { - res = append(res, err) - } - - if err := m.contextValidateInputs(ctx, formats); err != nil { - res = append(res, err) - } - - if len(res) > 0 { - return errors.CompositeValidationError(res...) - } - return nil -} - -func (m *UpdateProject) contextValidateEnvironments(ctx context.Context, formats strfmt.Registry) error { - - for i := 0; i < len(m.Environments); i++ { - - if m.Environments[i] != nil { - - if swag.IsZero(m.Environments[i]) { // not required - return nil - } - - if err := m.Environments[i].ContextValidate(ctx, formats); err != nil { - if ve, ok := err.(*errors.Validation); ok { - return ve.ValidateName("environments" + "." + strconv.Itoa(i)) - } else if ce, ok := err.(*errors.CompositeError); ok { - return ce.ValidateName("environments" + "." + strconv.Itoa(i)) - } - return err - } - } - - } - - return nil -} - -func (m *UpdateProject) contextValidateInputs(ctx context.Context, formats strfmt.Registry) error { - - for i := 0; i < len(m.Inputs); i++ { - - if m.Inputs[i] != nil { - - if swag.IsZero(m.Inputs[i]) { // not required - return nil - } - - if err := m.Inputs[i].ContextValidate(ctx, formats); err != nil { - if ve, ok := err.(*errors.Validation); ok { - return ve.ValidateName("inputs" + "." + strconv.Itoa(i)) - } else if ce, ok := err.(*errors.CompositeError); ok { - return ce.ValidateName("inputs" + "." + strconv.Itoa(i)) - } - return err - } - } - - } - return nil } diff --git a/client/version b/client/version index dfbc6fda..5594fd37 100644 --- a/client/version +++ b/client/version @@ -1 +1 @@ -v5.1.116 +v5.1.124 From 9a241fe04691a6149e2eb4f0b12ed057ab7cf8ac Mon Sep 17 00:00:00 2001 From: Cycloid Date: Mon, 25 Nov 2024 14:25:21 +0000 Subject: [PATCH 58/71] Changelog: Add entry for new version v5.1.124 --- changelog/unreleased/CLI-CHANGED-20241125-142521.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 changelog/unreleased/CLI-CHANGED-20241125-142521.yaml diff --git a/changelog/unreleased/CLI-CHANGED-20241125-142521.yaml b/changelog/unreleased/CLI-CHANGED-20241125-142521.yaml new file mode 100644 index 00000000..9e7162b7 --- /dev/null +++ b/changelog/unreleased/CLI-CHANGED-20241125-142521.yaml @@ -0,0 +1,8 @@ +component: CLI +kind: CHANGED +body: "Update client to version v5.1.124" +time: 2024-11-25T14:25:21.065186728+00:00 +custom: + DETAILS: "" + PR: "312" + TYPE: CLI From f8153ab0f5a398b9d59419a899b5a48115992a5c Mon Sep 17 00:00:00 2001 From: Cycloid Date: Thu, 28 Nov 2024 14:23:08 +0000 Subject: [PATCH 59/71] Bump swagger client to version v5.1.129 --- .../list_service_catalogs_parameters.go | 69 ---- .../update_service_catalog_parameters.go | 6 +- client/models/new_service_catalog.go | 71 ++-- .../new_service_catalog_from_template.go | 50 ++- client/models/new_service_catalog_source.go | 36 ++ client/models/service_catalog.go | 166 +++++++- client/models/update_service_catalog.go | 370 ++++++++++++++++++ client/version | 2 +- 8 files changed, 627 insertions(+), 143 deletions(-) create mode 100644 client/models/update_service_catalog.go diff --git a/client/client/service_catalogs/list_service_catalogs_parameters.go b/client/client/service_catalogs/list_service_catalogs_parameters.go index bf06ab18..365a789e 100644 --- a/client/client/service_catalogs/list_service_catalogs_parameters.go +++ b/client/client/service_catalogs/list_service_catalogs_parameters.go @@ -93,12 +93,6 @@ type ListServiceCatalogsParams struct { */ ServiceCatalogOwn *bool - /* ServiceCatalogStatus. - - The status of the catalog service used for filtering. - */ - ServiceCatalogStatus *string - /* ServiceCatalogTemplate. Filters the Service Catalogs to only show the ones that are templates @@ -106,13 +100,6 @@ type ListServiceCatalogsParams struct { */ ServiceCatalogTemplate *bool - /* ServiceCatalogTrusted. - - Filters the Service Catalogs to only show the ones that are from trusted source (Cycloid) - - */ - ServiceCatalogTrusted *bool - timeout time.Duration Context context.Context HTTPClient *http.Client @@ -227,17 +214,6 @@ func (o *ListServiceCatalogsParams) SetServiceCatalogOwn(serviceCatalogOwn *bool o.ServiceCatalogOwn = serviceCatalogOwn } -// WithServiceCatalogStatus adds the serviceCatalogStatus to the list service catalogs params -func (o *ListServiceCatalogsParams) WithServiceCatalogStatus(serviceCatalogStatus *string) *ListServiceCatalogsParams { - o.SetServiceCatalogStatus(serviceCatalogStatus) - return o -} - -// SetServiceCatalogStatus adds the serviceCatalogStatus to the list service catalogs params -func (o *ListServiceCatalogsParams) SetServiceCatalogStatus(serviceCatalogStatus *string) { - o.ServiceCatalogStatus = serviceCatalogStatus -} - // WithServiceCatalogTemplate adds the serviceCatalogTemplate to the list service catalogs params func (o *ListServiceCatalogsParams) WithServiceCatalogTemplate(serviceCatalogTemplate *bool) *ListServiceCatalogsParams { o.SetServiceCatalogTemplate(serviceCatalogTemplate) @@ -249,17 +225,6 @@ func (o *ListServiceCatalogsParams) SetServiceCatalogTemplate(serviceCatalogTemp o.ServiceCatalogTemplate = serviceCatalogTemplate } -// WithServiceCatalogTrusted adds the serviceCatalogTrusted to the list service catalogs params -func (o *ListServiceCatalogsParams) WithServiceCatalogTrusted(serviceCatalogTrusted *bool) *ListServiceCatalogsParams { - o.SetServiceCatalogTrusted(serviceCatalogTrusted) - return o -} - -// SetServiceCatalogTrusted adds the serviceCatalogTrusted to the list service catalogs params -func (o *ListServiceCatalogsParams) SetServiceCatalogTrusted(serviceCatalogTrusted *bool) { - o.ServiceCatalogTrusted = serviceCatalogTrusted -} - // WriteToRequest writes these params to a swagger request func (o *ListServiceCatalogsParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { @@ -324,23 +289,6 @@ func (o *ListServiceCatalogsParams) WriteToRequest(r runtime.ClientRequest, reg } } - if o.ServiceCatalogStatus != nil { - - // query param service_catalog_status - var qrServiceCatalogStatus string - - if o.ServiceCatalogStatus != nil { - qrServiceCatalogStatus = *o.ServiceCatalogStatus - } - qServiceCatalogStatus := qrServiceCatalogStatus - if qServiceCatalogStatus != "" { - - if err := r.SetQueryParam("service_catalog_status", qServiceCatalogStatus); err != nil { - return err - } - } - } - if o.ServiceCatalogTemplate != nil { // query param service_catalog_template @@ -358,23 +306,6 @@ func (o *ListServiceCatalogsParams) WriteToRequest(r runtime.ClientRequest, reg } } - if o.ServiceCatalogTrusted != nil { - - // query param service_catalog_trusted - var qrServiceCatalogTrusted bool - - if o.ServiceCatalogTrusted != nil { - qrServiceCatalogTrusted = *o.ServiceCatalogTrusted - } - qServiceCatalogTrusted := swag.FormatBool(qrServiceCatalogTrusted) - if qServiceCatalogTrusted != "" { - - if err := r.SetQueryParam("service_catalog_trusted", qServiceCatalogTrusted); err != nil { - return err - } - } - } - if len(res) > 0 { return errors.CompositeValidationError(res...) } diff --git a/client/client/service_catalogs/update_service_catalog_parameters.go b/client/client/service_catalogs/update_service_catalog_parameters.go index c8e5c0fd..8b15c286 100644 --- a/client/client/service_catalogs/update_service_catalog_parameters.go +++ b/client/client/service_catalogs/update_service_catalog_parameters.go @@ -67,7 +67,7 @@ type UpdateServiceCatalogParams struct { The information of the ServiceCatalog Terraform. */ - Body *models.NewServiceCatalog + Body *models.UpdateServiceCatalog /* OrganizationCanonical. @@ -135,13 +135,13 @@ func (o *UpdateServiceCatalogParams) SetHTTPClient(client *http.Client) { } // WithBody adds the body to the update service catalog params -func (o *UpdateServiceCatalogParams) WithBody(body *models.NewServiceCatalog) *UpdateServiceCatalogParams { +func (o *UpdateServiceCatalogParams) WithBody(body *models.UpdateServiceCatalog) *UpdateServiceCatalogParams { o.SetBody(body) return o } // SetBody adds the body to the update service catalog params -func (o *UpdateServiceCatalogParams) SetBody(body *models.NewServiceCatalog) { +func (o *UpdateServiceCatalogParams) SetBody(body *models.UpdateServiceCatalog) { o.Body = body } diff --git a/client/models/new_service_catalog.go b/client/models/new_service_catalog.go index ee3ed5ad..0639d4a4 100644 --- a/client/models/new_service_catalog.go +++ b/client/models/new_service_catalog.go @@ -15,7 +15,7 @@ import ( "github.com/go-openapi/validate" ) -// NewServiceCatalog Service Catalog +// NewServiceCatalog NewServiceCatalog // // # Represents the Service Catalog item // @@ -32,10 +32,6 @@ type NewServiceCatalog struct { // Pattern: ^[a-z0-9]+[a-z0-9\-_]+[a-z0-9]+$ Canonical string `json:"canonical,omitempty"` - // created at - // Minimum: 0 - CreatedAt *uint64 `json:"created_at,omitempty"` - // dependencies Dependencies []*ServiceCatalogDependency `json:"dependencies"` @@ -62,15 +58,18 @@ type NewServiceCatalog struct { // Pattern: ^[a-z0-9]+[a-z0-9\-_]+[a-z0-9]+$ ServiceCatalogSourceCanonical *string `json:"service_catalog_source_canonical"` - // status - Status string `json:"status,omitempty"` + // Team responsible for the maintenance of the underlying service catalogs + // + // Max Length: 100 + // Min Length: 3 + // Pattern: ^[a-z0-9]+[a-z0-9\-_]+[a-z0-9]+$ + TeamCanonical string `json:"team_canonical,omitempty"` // technologies Technologies []*ServiceCatalogTechnology `json:"technologies"` - // updated at - // Minimum: 0 - UpdatedAt *uint64 `json:"updated_at,omitempty"` + // visibility + Visibility string `json:"visibility,omitempty"` } // Validate validates this new service catalog @@ -85,10 +84,6 @@ func (m *NewServiceCatalog) Validate(formats strfmt.Registry) error { res = append(res, err) } - if err := m.validateCreatedAt(formats); err != nil { - res = append(res, err) - } - if err := m.validateDependencies(formats); err != nil { res = append(res, err) } @@ -113,11 +108,11 @@ func (m *NewServiceCatalog) Validate(formats strfmt.Registry) error { res = append(res, err) } - if err := m.validateTechnologies(formats); err != nil { + if err := m.validateTeamCanonical(formats); err != nil { res = append(res, err) } - if err := m.validateUpdatedAt(formats); err != nil { + if err := m.validateTechnologies(formats); err != nil { res = append(res, err) } @@ -156,18 +151,6 @@ func (m *NewServiceCatalog) validateCanonical(formats strfmt.Registry) error { return nil } -func (m *NewServiceCatalog) validateCreatedAt(formats strfmt.Registry) error { - if swag.IsZero(m.CreatedAt) { // not required - return nil - } - - if err := validate.MinimumUint("created_at", "body", *m.CreatedAt, 0, false); err != nil { - return err - } - - return nil -} - func (m *NewServiceCatalog) validateDependencies(formats strfmt.Registry) error { if swag.IsZero(m.Dependencies) { // not required return nil @@ -254,6 +237,26 @@ func (m *NewServiceCatalog) validateServiceCatalogSourceCanonical(formats strfmt return nil } +func (m *NewServiceCatalog) validateTeamCanonical(formats strfmt.Registry) error { + if swag.IsZero(m.TeamCanonical) { // not required + return nil + } + + if err := validate.MinLength("team_canonical", "body", m.TeamCanonical, 3); err != nil { + return err + } + + if err := validate.MaxLength("team_canonical", "body", m.TeamCanonical, 100); err != nil { + return err + } + + if err := validate.Pattern("team_canonical", "body", m.TeamCanonical, `^[a-z0-9]+[a-z0-9\-_]+[a-z0-9]+$`); err != nil { + return err + } + + return nil +} + func (m *NewServiceCatalog) validateTechnologies(formats strfmt.Registry) error { if swag.IsZero(m.Technologies) { // not required return nil @@ -280,18 +283,6 @@ func (m *NewServiceCatalog) validateTechnologies(formats strfmt.Registry) error return nil } -func (m *NewServiceCatalog) validateUpdatedAt(formats strfmt.Registry) error { - if swag.IsZero(m.UpdatedAt) { // not required - return nil - } - - if err := validate.MinimumUint("updated_at", "body", *m.UpdatedAt, 0, false); err != nil { - return err - } - - return nil -} - // ContextValidate validate this new service catalog based on the context it is used func (m *NewServiceCatalog) ContextValidate(ctx context.Context, formats strfmt.Registry) error { var res []error diff --git a/client/models/new_service_catalog_from_template.go b/client/models/new_service_catalog_from_template.go index 30916bb3..a2f50894 100644 --- a/client/models/new_service_catalog_from_template.go +++ b/client/models/new_service_catalog_from_template.go @@ -14,7 +14,7 @@ import ( "github.com/go-openapi/validate" ) -// NewServiceCatalogFromTemplate Service Catalog +// NewServiceCatalogFromTemplate NewServiceCatalogFromTemplate // // # Represents the Service Catalog item // @@ -31,10 +31,6 @@ type NewServiceCatalogFromTemplate struct { // Pattern: ^[a-z0-9]+[a-z0-9\-_]+[a-z0-9]+$ Canonical *string `json:"canonical"` - // created at - // Minimum: 0 - CreatedAt *uint64 `json:"created_at,omitempty"` - // name // Required: true Name *string `json:"name"` @@ -46,13 +42,19 @@ type NewServiceCatalogFromTemplate struct { // Pattern: ^[a-z0-9]+[a-z0-9\-_]+[a-z0-9]+$ ServiceCatalogSourceCanonical *string `json:"service_catalog_source_canonical"` - // updated at - // Minimum: 0 - UpdatedAt *uint64 `json:"updated_at,omitempty"` + // Team responsible for the maintenance of the underlying service catalogs + // + // Max Length: 100 + // Min Length: 3 + // Pattern: ^[a-z0-9]+[a-z0-9\-_]+[a-z0-9]+$ + TeamCanonical string `json:"team_canonical,omitempty"` // use case // Required: true UseCase *string `json:"use_case"` + + // visibility + Visibility string `json:"visibility,omitempty"` } // Validate validates this new service catalog from template @@ -63,10 +65,6 @@ func (m *NewServiceCatalogFromTemplate) Validate(formats strfmt.Registry) error res = append(res, err) } - if err := m.validateCreatedAt(formats); err != nil { - res = append(res, err) - } - if err := m.validateName(formats); err != nil { res = append(res, err) } @@ -75,7 +73,7 @@ func (m *NewServiceCatalogFromTemplate) Validate(formats strfmt.Registry) error res = append(res, err) } - if err := m.validateUpdatedAt(formats); err != nil { + if err := m.validateTeamCanonical(formats); err != nil { res = append(res, err) } @@ -110,18 +108,6 @@ func (m *NewServiceCatalogFromTemplate) validateCanonical(formats strfmt.Registr return nil } -func (m *NewServiceCatalogFromTemplate) validateCreatedAt(formats strfmt.Registry) error { - if swag.IsZero(m.CreatedAt) { // not required - return nil - } - - if err := validate.MinimumUint("created_at", "body", *m.CreatedAt, 0, false); err != nil { - return err - } - - return nil -} - func (m *NewServiceCatalogFromTemplate) validateName(formats strfmt.Registry) error { if err := validate.Required("name", "body", m.Name); err != nil { @@ -152,12 +138,20 @@ func (m *NewServiceCatalogFromTemplate) validateServiceCatalogSourceCanonical(fo return nil } -func (m *NewServiceCatalogFromTemplate) validateUpdatedAt(formats strfmt.Registry) error { - if swag.IsZero(m.UpdatedAt) { // not required +func (m *NewServiceCatalogFromTemplate) validateTeamCanonical(formats strfmt.Registry) error { + if swag.IsZero(m.TeamCanonical) { // not required return nil } - if err := validate.MinimumUint("updated_at", "body", *m.UpdatedAt, 0, false); err != nil { + if err := validate.MinLength("team_canonical", "body", m.TeamCanonical, 3); err != nil { + return err + } + + if err := validate.MaxLength("team_canonical", "body", m.TeamCanonical, 100); err != nil { + return err + } + + if err := validate.Pattern("team_canonical", "body", m.TeamCanonical, `^[a-z0-9]+[a-z0-9\-_]+[a-z0-9]+$`); err != nil { return err } diff --git a/client/models/new_service_catalog_source.go b/client/models/new_service_catalog_source.go index 9a7c32bf..cab9fde2 100644 --- a/client/models/new_service_catalog_source.go +++ b/client/models/new_service_catalog_source.go @@ -45,10 +45,22 @@ type NewServiceCatalogSource struct { // Owner string `json:"owner,omitempty"` + // Team responsible for the maintenance of the underlying service catalogs + // + // Max Length: 100 + // Min Length: 3 + // Pattern: ^[a-z0-9]+[a-z0-9\-_]+[a-z0-9]+$ + TeamCanonical string `json:"team_canonical,omitempty"` + // url // Required: true // Pattern: ^((/|~)[^/]*)+.(\.git)|(([\w\]+@[\w\.]+))(:(//)?)([\w\.@\:/\-~]+)(/)? URL *string `json:"url"` + + // The visibility setting allows to specify which visibility will be applied to stacks in this catalog repository. + // This option is only applied during initial catalog repository creation, not for subsequent updates. + // + Visibility string `json:"visibility,omitempty"` } // Validate validates this new service catalog source @@ -71,6 +83,10 @@ func (m *NewServiceCatalogSource) Validate(formats strfmt.Registry) error { res = append(res, err) } + if err := m.validateTeamCanonical(formats); err != nil { + res = append(res, err) + } + if err := m.validateURL(formats); err != nil { res = append(res, err) } @@ -139,6 +155,26 @@ func (m *NewServiceCatalogSource) validateName(formats strfmt.Registry) error { return nil } +func (m *NewServiceCatalogSource) validateTeamCanonical(formats strfmt.Registry) error { + if swag.IsZero(m.TeamCanonical) { // not required + return nil + } + + if err := validate.MinLength("team_canonical", "body", m.TeamCanonical, 3); err != nil { + return err + } + + if err := validate.MaxLength("team_canonical", "body", m.TeamCanonical, 100); err != nil { + return err + } + + if err := validate.Pattern("team_canonical", "body", m.TeamCanonical, `^[a-z0-9]+[a-z0-9\-_]+[a-z0-9]+$`); err != nil { + return err + } + + return nil +} + func (m *NewServiceCatalogSource) validateURL(formats strfmt.Registry) error { if err := validate.Required("url", "body", m.URL); err != nil { diff --git a/client/models/service_catalog.go b/client/models/service_catalog.go index 6331aabd..0ed57625 100644 --- a/client/models/service_catalog.go +++ b/client/models/service_catalog.go @@ -27,6 +27,9 @@ type ServiceCatalog struct { // Required: true Author *string `json:"author"` + // Determines if given stack is a blueprint + Blueprint bool `json:"blueprint,omitempty"` + // canonical // Required: true // Max Length: 100 @@ -34,6 +37,9 @@ type ServiceCatalog struct { // Pattern: ^[a-z0-9]+[a-z0-9\-_]+[a-z0-9]+$ Canonical *string `json:"canonical"` + // Cloud providers supported by the stack + CloudProviders []*CloudProvider `json:"cloud_providers"` + // created at // Minimum: 0 CreatedAt *uint64 `json:"created_at,omitempty"` @@ -74,6 +80,13 @@ type ServiceCatalog struct { // Required: true Name *string `json:"name"` + // Organization that the stack belongs to + // Required: true + // Max Length: 100 + // Min Length: 3 + // Pattern: ^[a-z0-9]+[a-z0-9\-_]+[a-z0-9]+$ + OrganizationCanonical *string `json:"organization_canonical"` + // Indicates if this stack can be configured with form's and has a Quota configuration. // Required: true QuotaEnabled *bool `json:"quota_enabled"` @@ -91,8 +104,8 @@ type ServiceCatalog struct { // Pattern: ^[a-z0-9]+[a-z0-9\-_]+[a-z0-9]+$ ServiceCatalogSourceCanonical string `json:"service_catalog_source_canonical,omitempty"` - // status - Status string `json:"status,omitempty"` + // Team that maintains the stack + Team *SimpleTeam `json:"team,omitempty"` // technologies Technologies []*ServiceCatalogTechnology `json:"technologies"` @@ -104,6 +117,10 @@ type ServiceCatalog struct { // updated at // Minimum: 0 UpdatedAt *uint64 `json:"updated_at,omitempty"` + + // visibility + // Required: true + Visibility *string `json:"visibility"` } // Validate validates this service catalog @@ -118,6 +135,10 @@ func (m *ServiceCatalog) Validate(formats strfmt.Registry) error { res = append(res, err) } + if err := m.validateCloudProviders(formats); err != nil { + res = append(res, err) + } + if err := m.validateCreatedAt(formats); err != nil { res = append(res, err) } @@ -158,6 +179,10 @@ func (m *ServiceCatalog) Validate(formats strfmt.Registry) error { res = append(res, err) } + if err := m.validateOrganizationCanonical(formats); err != nil { + res = append(res, err) + } + if err := m.validateQuotaEnabled(formats); err != nil { res = append(res, err) } @@ -170,6 +195,10 @@ func (m *ServiceCatalog) Validate(formats strfmt.Registry) error { res = append(res, err) } + if err := m.validateTeam(formats); err != nil { + res = append(res, err) + } + if err := m.validateTechnologies(formats); err != nil { res = append(res, err) } @@ -182,6 +211,10 @@ func (m *ServiceCatalog) Validate(formats strfmt.Registry) error { res = append(res, err) } + if err := m.validateVisibility(formats); err != nil { + res = append(res, err) + } + if len(res) > 0 { return errors.CompositeValidationError(res...) } @@ -218,6 +251,32 @@ func (m *ServiceCatalog) validateCanonical(formats strfmt.Registry) error { return nil } +func (m *ServiceCatalog) validateCloudProviders(formats strfmt.Registry) error { + if swag.IsZero(m.CloudProviders) { // not required + return nil + } + + for i := 0; i < len(m.CloudProviders); i++ { + if swag.IsZero(m.CloudProviders[i]) { // not required + continue + } + + if m.CloudProviders[i] != nil { + if err := m.CloudProviders[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("cloud_providers" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("cloud_providers" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + func (m *ServiceCatalog) validateCreatedAt(formats strfmt.Registry) error { if swag.IsZero(m.CreatedAt) { // not required return nil @@ -371,6 +430,27 @@ func (m *ServiceCatalog) validateName(formats strfmt.Registry) error { return nil } +func (m *ServiceCatalog) validateOrganizationCanonical(formats strfmt.Registry) error { + + if err := validate.Required("organization_canonical", "body", m.OrganizationCanonical); err != nil { + return err + } + + if err := validate.MinLength("organization_canonical", "body", *m.OrganizationCanonical, 3); err != nil { + return err + } + + if err := validate.MaxLength("organization_canonical", "body", *m.OrganizationCanonical, 100); err != nil { + return err + } + + if err := validate.Pattern("organization_canonical", "body", *m.OrganizationCanonical, `^[a-z0-9]+[a-z0-9\-_]+[a-z0-9]+$`); err != nil { + return err + } + + return nil +} + func (m *ServiceCatalog) validateQuotaEnabled(formats strfmt.Registry) error { if err := validate.Required("quota_enabled", "body", m.QuotaEnabled); err != nil { @@ -409,6 +489,25 @@ func (m *ServiceCatalog) validateServiceCatalogSourceCanonical(formats strfmt.Re return nil } +func (m *ServiceCatalog) validateTeam(formats strfmt.Registry) error { + if swag.IsZero(m.Team) { // not required + return nil + } + + if m.Team != nil { + if err := m.Team.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("team") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("team") + } + return err + } + } + + return nil +} + func (m *ServiceCatalog) validateTechnologies(formats strfmt.Registry) error { if swag.IsZero(m.Technologies) { // not required return nil @@ -456,14 +555,31 @@ func (m *ServiceCatalog) validateUpdatedAt(formats strfmt.Registry) error { return nil } +func (m *ServiceCatalog) validateVisibility(formats strfmt.Registry) error { + + if err := validate.Required("visibility", "body", m.Visibility); err != nil { + return err + } + + return nil +} + // ContextValidate validate this service catalog based on the context it is used func (m *ServiceCatalog) ContextValidate(ctx context.Context, formats strfmt.Registry) error { var res []error + if err := m.contextValidateCloudProviders(ctx, formats); err != nil { + res = append(res, err) + } + if err := m.contextValidateDependencies(ctx, formats); err != nil { res = append(res, err) } + if err := m.contextValidateTeam(ctx, formats); err != nil { + res = append(res, err) + } + if err := m.contextValidateTechnologies(ctx, formats); err != nil { res = append(res, err) } @@ -474,6 +590,31 @@ func (m *ServiceCatalog) ContextValidate(ctx context.Context, formats strfmt.Reg return nil } +func (m *ServiceCatalog) contextValidateCloudProviders(ctx context.Context, formats strfmt.Registry) error { + + for i := 0; i < len(m.CloudProviders); i++ { + + if m.CloudProviders[i] != nil { + + if swag.IsZero(m.CloudProviders[i]) { // not required + return nil + } + + if err := m.CloudProviders[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("cloud_providers" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("cloud_providers" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + func (m *ServiceCatalog) contextValidateDependencies(ctx context.Context, formats strfmt.Registry) error { for i := 0; i < len(m.Dependencies); i++ { @@ -499,6 +640,27 @@ func (m *ServiceCatalog) contextValidateDependencies(ctx context.Context, format return nil } +func (m *ServiceCatalog) contextValidateTeam(ctx context.Context, formats strfmt.Registry) error { + + if m.Team != nil { + + if swag.IsZero(m.Team) { // not required + return nil + } + + if err := m.Team.ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("team") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("team") + } + return err + } + } + + return nil +} + func (m *ServiceCatalog) contextValidateTechnologies(ctx context.Context, formats strfmt.Registry) error { for i := 0; i < len(m.Technologies); i++ { diff --git a/client/models/update_service_catalog.go b/client/models/update_service_catalog.go new file mode 100644 index 00000000..82622974 --- /dev/null +++ b/client/models/update_service_catalog.go @@ -0,0 +1,370 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + "strconv" + + "github.com/go-openapi/errors" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" + "github.com/go-openapi/validate" +) + +// UpdateServiceCatalog UpdateServiceCatalog +// +// # Represents the Service Catalog item +// +// swagger:model UpdateServiceCatalog +type UpdateServiceCatalog struct { + + // author + // Required: true + Author *string `json:"author"` + + // canonical + // Max Length: 100 + // Min Length: 3 + // Pattern: ^[a-z0-9]+[a-z0-9\-_]+[a-z0-9]+$ + Canonical string `json:"canonical,omitempty"` + + // dependencies + Dependencies []*ServiceCatalogDependency `json:"dependencies"` + + // description + // Required: true + Description *string `json:"description"` + + // image + // Format: uri + Image strfmt.URI `json:"image,omitempty"` + + // keywords + // Required: true + Keywords []string `json:"keywords"` + + // name + // Required: true + Name *string `json:"name"` + + // service catalog source canonical + // Required: true + // Max Length: 100 + // Min Length: 3 + // Pattern: ^[a-z0-9]+[a-z0-9\-_]+[a-z0-9]+$ + ServiceCatalogSourceCanonical *string `json:"service_catalog_source_canonical"` + + // Team responsible for the maintenance of the underlying service catalogs + // + // Max Length: 100 + // Min Length: 3 + // Pattern: ^[a-z0-9]+[a-z0-9\-_]+[a-z0-9]+$ + TeamCanonical string `json:"team_canonical,omitempty"` + + // technologies + Technologies []*ServiceCatalogTechnology `json:"technologies"` + + // visibility + Visibility string `json:"visibility,omitempty"` +} + +// Validate validates this update service catalog +func (m *UpdateServiceCatalog) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateAuthor(formats); err != nil { + res = append(res, err) + } + + if err := m.validateCanonical(formats); err != nil { + res = append(res, err) + } + + if err := m.validateDependencies(formats); err != nil { + res = append(res, err) + } + + if err := m.validateDescription(formats); err != nil { + res = append(res, err) + } + + if err := m.validateImage(formats); err != nil { + res = append(res, err) + } + + if err := m.validateKeywords(formats); err != nil { + res = append(res, err) + } + + if err := m.validateName(formats); err != nil { + res = append(res, err) + } + + if err := m.validateServiceCatalogSourceCanonical(formats); err != nil { + res = append(res, err) + } + + if err := m.validateTeamCanonical(formats); err != nil { + res = append(res, err) + } + + if err := m.validateTechnologies(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *UpdateServiceCatalog) validateAuthor(formats strfmt.Registry) error { + + if err := validate.Required("author", "body", m.Author); err != nil { + return err + } + + return nil +} + +func (m *UpdateServiceCatalog) validateCanonical(formats strfmt.Registry) error { + if swag.IsZero(m.Canonical) { // not required + return nil + } + + if err := validate.MinLength("canonical", "body", m.Canonical, 3); err != nil { + return err + } + + if err := validate.MaxLength("canonical", "body", m.Canonical, 100); err != nil { + return err + } + + if err := validate.Pattern("canonical", "body", m.Canonical, `^[a-z0-9]+[a-z0-9\-_]+[a-z0-9]+$`); err != nil { + return err + } + + return nil +} + +func (m *UpdateServiceCatalog) validateDependencies(formats strfmt.Registry) error { + if swag.IsZero(m.Dependencies) { // not required + return nil + } + + for i := 0; i < len(m.Dependencies); i++ { + if swag.IsZero(m.Dependencies[i]) { // not required + continue + } + + if m.Dependencies[i] != nil { + if err := m.Dependencies[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("dependencies" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("dependencies" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +func (m *UpdateServiceCatalog) validateDescription(formats strfmt.Registry) error { + + if err := validate.Required("description", "body", m.Description); err != nil { + return err + } + + return nil +} + +func (m *UpdateServiceCatalog) validateImage(formats strfmt.Registry) error { + if swag.IsZero(m.Image) { // not required + return nil + } + + if err := validate.FormatOf("image", "body", "uri", m.Image.String(), formats); err != nil { + return err + } + + return nil +} + +func (m *UpdateServiceCatalog) validateKeywords(formats strfmt.Registry) error { + + if err := validate.Required("keywords", "body", m.Keywords); err != nil { + return err + } + + return nil +} + +func (m *UpdateServiceCatalog) validateName(formats strfmt.Registry) error { + + if err := validate.Required("name", "body", m.Name); err != nil { + return err + } + + return nil +} + +func (m *UpdateServiceCatalog) validateServiceCatalogSourceCanonical(formats strfmt.Registry) error { + + if err := validate.Required("service_catalog_source_canonical", "body", m.ServiceCatalogSourceCanonical); err != nil { + return err + } + + if err := validate.MinLength("service_catalog_source_canonical", "body", *m.ServiceCatalogSourceCanonical, 3); err != nil { + return err + } + + if err := validate.MaxLength("service_catalog_source_canonical", "body", *m.ServiceCatalogSourceCanonical, 100); err != nil { + return err + } + + if err := validate.Pattern("service_catalog_source_canonical", "body", *m.ServiceCatalogSourceCanonical, `^[a-z0-9]+[a-z0-9\-_]+[a-z0-9]+$`); err != nil { + return err + } + + return nil +} + +func (m *UpdateServiceCatalog) validateTeamCanonical(formats strfmt.Registry) error { + if swag.IsZero(m.TeamCanonical) { // not required + return nil + } + + if err := validate.MinLength("team_canonical", "body", m.TeamCanonical, 3); err != nil { + return err + } + + if err := validate.MaxLength("team_canonical", "body", m.TeamCanonical, 100); err != nil { + return err + } + + if err := validate.Pattern("team_canonical", "body", m.TeamCanonical, `^[a-z0-9]+[a-z0-9\-_]+[a-z0-9]+$`); err != nil { + return err + } + + return nil +} + +func (m *UpdateServiceCatalog) validateTechnologies(formats strfmt.Registry) error { + if swag.IsZero(m.Technologies) { // not required + return nil + } + + for i := 0; i < len(m.Technologies); i++ { + if swag.IsZero(m.Technologies[i]) { // not required + continue + } + + if m.Technologies[i] != nil { + if err := m.Technologies[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("technologies" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("technologies" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +// ContextValidate validate this update service catalog based on the context it is used +func (m *UpdateServiceCatalog) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + if err := m.contextValidateDependencies(ctx, formats); err != nil { + res = append(res, err) + } + + if err := m.contextValidateTechnologies(ctx, formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *UpdateServiceCatalog) contextValidateDependencies(ctx context.Context, formats strfmt.Registry) error { + + for i := 0; i < len(m.Dependencies); i++ { + + if m.Dependencies[i] != nil { + + if swag.IsZero(m.Dependencies[i]) { // not required + return nil + } + + if err := m.Dependencies[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("dependencies" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("dependencies" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +func (m *UpdateServiceCatalog) contextValidateTechnologies(ctx context.Context, formats strfmt.Registry) error { + + for i := 0; i < len(m.Technologies); i++ { + + if m.Technologies[i] != nil { + + if swag.IsZero(m.Technologies[i]) { // not required + return nil + } + + if err := m.Technologies[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("technologies" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("technologies" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +// MarshalBinary interface implementation +func (m *UpdateServiceCatalog) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *UpdateServiceCatalog) UnmarshalBinary(b []byte) error { + var res UpdateServiceCatalog + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/client/version b/client/version index 5594fd37..d9383f90 100644 --- a/client/version +++ b/client/version @@ -1 +1 @@ -v5.1.124 +v5.1.129 From 6fe3751a66b42d0a4f4b9386438541c79e4f1efb Mon Sep 17 00:00:00 2001 From: Cycloid Date: Thu, 28 Nov 2024 14:23:38 +0000 Subject: [PATCH 60/71] Changelog: Add entry for new version v5.1.129 --- changelog/unreleased/CLI-CHANGED-20241128-142338.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 changelog/unreleased/CLI-CHANGED-20241128-142338.yaml diff --git a/changelog/unreleased/CLI-CHANGED-20241128-142338.yaml b/changelog/unreleased/CLI-CHANGED-20241128-142338.yaml new file mode 100644 index 00000000..ddd8fecf --- /dev/null +++ b/changelog/unreleased/CLI-CHANGED-20241128-142338.yaml @@ -0,0 +1,8 @@ +component: CLI +kind: CHANGED +body: "Update client to version v5.1.129" +time: 2024-11-28T14:23:38.714004010+00:00 +custom: + DETAILS: "" + PR: "314" + TYPE: CLI From 34451dda3a6022477b707e4bd19743cb7226635b Mon Sep 17 00:00:00 2001 From: Cycloid Date: Tue, 3 Dec 2024 08:49:39 +0000 Subject: [PATCH 61/71] Bump swagger client to version v5.1.130 --- client/version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/version b/client/version index d9383f90..70e2a159 100644 --- a/client/version +++ b/client/version @@ -1 +1 @@ -v5.1.129 +v5.1.130 From bfedff0bce3240f199822f18830a4b7efdb01e3b Mon Sep 17 00:00:00 2001 From: Cycloid Date: Tue, 3 Dec 2024 08:50:11 +0000 Subject: [PATCH 62/71] Changelog: Add entry for new version v5.1.130 --- changelog/unreleased/CLI-CHANGED-20241203-085011.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 changelog/unreleased/CLI-CHANGED-20241203-085011.yaml diff --git a/changelog/unreleased/CLI-CHANGED-20241203-085011.yaml b/changelog/unreleased/CLI-CHANGED-20241203-085011.yaml new file mode 100644 index 00000000..515d7a74 --- /dev/null +++ b/changelog/unreleased/CLI-CHANGED-20241203-085011.yaml @@ -0,0 +1,8 @@ +component: CLI +kind: CHANGED +body: "Update client to version v5.1.130" +time: 2024-12-03T08:50:11.170131109+00:00 +custom: + DETAILS: "" + PR: "315" + TYPE: CLI From d235271d31725754336b2e460acedbe42030c226 Mon Sep 17 00:00:00 2001 From: Cycloid Date: Tue, 3 Dec 2024 11:07:13 +0000 Subject: [PATCH 63/71] Bump swagger client to version v5.1.134 --- .../get_environment_parameters.go | 195 +++++++ .../get_environment_responses.go | 490 ++++++++++++++++++ .../organization_projects_client.go | 40 ++ .../update_environment_responses.go | 2 +- client/version | 2 +- 5 files changed, 727 insertions(+), 2 deletions(-) create mode 100644 client/client/organization_projects/get_environment_parameters.go create mode 100644 client/client/organization_projects/get_environment_responses.go diff --git a/client/client/organization_projects/get_environment_parameters.go b/client/client/organization_projects/get_environment_parameters.go new file mode 100644 index 00000000..6248f042 --- /dev/null +++ b/client/client/organization_projects/get_environment_parameters.go @@ -0,0 +1,195 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package organization_projects + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + "net/http" + "time" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + cr "github.com/go-openapi/runtime/client" + "github.com/go-openapi/strfmt" +) + +// NewGetEnvironmentParams creates a new GetEnvironmentParams object, +// with the default timeout for this client. +// +// Default values are not hydrated, since defaults are normally applied by the API server side. +// +// To enforce default values in parameter, use SetDefaults or WithDefaults. +func NewGetEnvironmentParams() *GetEnvironmentParams { + return &GetEnvironmentParams{ + timeout: cr.DefaultTimeout, + } +} + +// NewGetEnvironmentParamsWithTimeout creates a new GetEnvironmentParams object +// with the ability to set a timeout on a request. +func NewGetEnvironmentParamsWithTimeout(timeout time.Duration) *GetEnvironmentParams { + return &GetEnvironmentParams{ + timeout: timeout, + } +} + +// NewGetEnvironmentParamsWithContext creates a new GetEnvironmentParams object +// with the ability to set a context for a request. +func NewGetEnvironmentParamsWithContext(ctx context.Context) *GetEnvironmentParams { + return &GetEnvironmentParams{ + Context: ctx, + } +} + +// NewGetEnvironmentParamsWithHTTPClient creates a new GetEnvironmentParams object +// with the ability to set a custom HTTPClient for a request. +func NewGetEnvironmentParamsWithHTTPClient(client *http.Client) *GetEnvironmentParams { + return &GetEnvironmentParams{ + HTTPClient: client, + } +} + +/* +GetEnvironmentParams contains all the parameters to send to the API endpoint + + for the get environment operation. + + Typically these are written to a http.Request. +*/ +type GetEnvironmentParams struct { + + /* EnvironmentCanonical. + + The environment canonical to use as part of a path + */ + EnvironmentCanonical string + + /* OrganizationCanonical. + + A canonical of an organization. + */ + OrganizationCanonical string + + /* ProjectCanonical. + + A canonical of a project. + */ + ProjectCanonical string + + timeout time.Duration + Context context.Context + HTTPClient *http.Client +} + +// WithDefaults hydrates default values in the get environment params (not the query body). +// +// All values with no default are reset to their zero value. +func (o *GetEnvironmentParams) WithDefaults() *GetEnvironmentParams { + o.SetDefaults() + return o +} + +// SetDefaults hydrates default values in the get environment params (not the query body). +// +// All values with no default are reset to their zero value. +func (o *GetEnvironmentParams) SetDefaults() { + // no default values defined for this parameter +} + +// WithTimeout adds the timeout to the get environment params +func (o *GetEnvironmentParams) WithTimeout(timeout time.Duration) *GetEnvironmentParams { + o.SetTimeout(timeout) + return o +} + +// SetTimeout adds the timeout to the get environment params +func (o *GetEnvironmentParams) SetTimeout(timeout time.Duration) { + o.timeout = timeout +} + +// WithContext adds the context to the get environment params +func (o *GetEnvironmentParams) WithContext(ctx context.Context) *GetEnvironmentParams { + o.SetContext(ctx) + return o +} + +// SetContext adds the context to the get environment params +func (o *GetEnvironmentParams) SetContext(ctx context.Context) { + o.Context = ctx +} + +// WithHTTPClient adds the HTTPClient to the get environment params +func (o *GetEnvironmentParams) WithHTTPClient(client *http.Client) *GetEnvironmentParams { + o.SetHTTPClient(client) + return o +} + +// SetHTTPClient adds the HTTPClient to the get environment params +func (o *GetEnvironmentParams) SetHTTPClient(client *http.Client) { + o.HTTPClient = client +} + +// WithEnvironmentCanonical adds the environmentCanonical to the get environment params +func (o *GetEnvironmentParams) WithEnvironmentCanonical(environmentCanonical string) *GetEnvironmentParams { + o.SetEnvironmentCanonical(environmentCanonical) + return o +} + +// SetEnvironmentCanonical adds the environmentCanonical to the get environment params +func (o *GetEnvironmentParams) SetEnvironmentCanonical(environmentCanonical string) { + o.EnvironmentCanonical = environmentCanonical +} + +// WithOrganizationCanonical adds the organizationCanonical to the get environment params +func (o *GetEnvironmentParams) WithOrganizationCanonical(organizationCanonical string) *GetEnvironmentParams { + o.SetOrganizationCanonical(organizationCanonical) + return o +} + +// SetOrganizationCanonical adds the organizationCanonical to the get environment params +func (o *GetEnvironmentParams) SetOrganizationCanonical(organizationCanonical string) { + o.OrganizationCanonical = organizationCanonical +} + +// WithProjectCanonical adds the projectCanonical to the get environment params +func (o *GetEnvironmentParams) WithProjectCanonical(projectCanonical string) *GetEnvironmentParams { + o.SetProjectCanonical(projectCanonical) + return o +} + +// SetProjectCanonical adds the projectCanonical to the get environment params +func (o *GetEnvironmentParams) SetProjectCanonical(projectCanonical string) { + o.ProjectCanonical = projectCanonical +} + +// WriteToRequest writes these params to a swagger request +func (o *GetEnvironmentParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { + + if err := r.SetTimeout(o.timeout); err != nil { + return err + } + var res []error + + // path param environment_canonical + if err := r.SetPathParam("environment_canonical", o.EnvironmentCanonical); err != nil { + return err + } + + // path param organization_canonical + if err := r.SetPathParam("organization_canonical", o.OrganizationCanonical); err != nil { + return err + } + + // path param project_canonical + if err := r.SetPathParam("project_canonical", o.ProjectCanonical); err != nil { + return err + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/client/client/organization_projects/get_environment_responses.go b/client/client/organization_projects/get_environment_responses.go new file mode 100644 index 00000000..0e0329ee --- /dev/null +++ b/client/client/organization_projects/get_environment_responses.go @@ -0,0 +1,490 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package organization_projects + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + "encoding/json" + "fmt" + "io" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" + "github.com/go-openapi/validate" + + "github.com/cycloidio/cycloid-cli/client/models" +) + +// GetEnvironmentReader is a Reader for the GetEnvironment structure. +type GetEnvironmentReader struct { + formats strfmt.Registry +} + +// ReadResponse reads a server response into the received o. +func (o *GetEnvironmentReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + switch response.Code() { + case 200: + result := NewGetEnvironmentOK() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return result, nil + case 403: + result := NewGetEnvironmentForbidden() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + case 404: + result := NewGetEnvironmentNotFound() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + default: + result := NewGetEnvironmentDefault(response.Code()) + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + if response.Code()/100 == 2 { + return result, nil + } + return nil, result + } +} + +// NewGetEnvironmentOK creates a GetEnvironmentOK with default headers values +func NewGetEnvironmentOK() *GetEnvironmentOK { + return &GetEnvironmentOK{} +} + +/* +GetEnvironmentOK describes a response with status code 200, with default header values. + +The body contains the environment. +*/ +type GetEnvironmentOK struct { + Payload *GetEnvironmentOKBody +} + +// IsSuccess returns true when this get environment o k response has a 2xx status code +func (o *GetEnvironmentOK) IsSuccess() bool { + return true +} + +// IsRedirect returns true when this get environment o k response has a 3xx status code +func (o *GetEnvironmentOK) IsRedirect() bool { + return false +} + +// IsClientError returns true when this get environment o k response has a 4xx status code +func (o *GetEnvironmentOK) IsClientError() bool { + return false +} + +// IsServerError returns true when this get environment o k response has a 5xx status code +func (o *GetEnvironmentOK) IsServerError() bool { + return false +} + +// IsCode returns true when this get environment o k response a status code equal to that given +func (o *GetEnvironmentOK) IsCode(code int) bool { + return code == 200 +} + +// Code gets the status code for the get environment o k response +func (o *GetEnvironmentOK) Code() int { + return 200 +} + +func (o *GetEnvironmentOK) Error() string { + payload, _ := json.Marshal(o.Payload) + return fmt.Sprintf("[GET /organizations/{organization_canonical}/projects/{project_canonical}/environments/{environment_canonical}][%d] getEnvironmentOK %s", 200, payload) +} + +func (o *GetEnvironmentOK) String() string { + payload, _ := json.Marshal(o.Payload) + return fmt.Sprintf("[GET /organizations/{organization_canonical}/projects/{project_canonical}/environments/{environment_canonical}][%d] getEnvironmentOK %s", 200, payload) +} + +func (o *GetEnvironmentOK) GetPayload() *GetEnvironmentOKBody { + return o.Payload +} + +func (o *GetEnvironmentOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(GetEnvironmentOKBody) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewGetEnvironmentForbidden creates a GetEnvironmentForbidden with default headers values +func NewGetEnvironmentForbidden() *GetEnvironmentForbidden { + return &GetEnvironmentForbidden{} +} + +/* +GetEnvironmentForbidden describes a response with status code 403, with default header values. + +The authenticated user cannot perform the operation because, it doesn't have permissions for such operation. +*/ +type GetEnvironmentForbidden struct { + + /* The length of the response body in octets (8-bit bytes). + + Format: uint64 + */ + ContentLength uint64 + + Payload *models.ErrorPayload +} + +// IsSuccess returns true when this get environment forbidden response has a 2xx status code +func (o *GetEnvironmentForbidden) IsSuccess() bool { + return false +} + +// IsRedirect returns true when this get environment forbidden response has a 3xx status code +func (o *GetEnvironmentForbidden) IsRedirect() bool { + return false +} + +// IsClientError returns true when this get environment forbidden response has a 4xx status code +func (o *GetEnvironmentForbidden) IsClientError() bool { + return true +} + +// IsServerError returns true when this get environment forbidden response has a 5xx status code +func (o *GetEnvironmentForbidden) IsServerError() bool { + return false +} + +// IsCode returns true when this get environment forbidden response a status code equal to that given +func (o *GetEnvironmentForbidden) IsCode(code int) bool { + return code == 403 +} + +// Code gets the status code for the get environment forbidden response +func (o *GetEnvironmentForbidden) Code() int { + return 403 +} + +func (o *GetEnvironmentForbidden) Error() string { + payload, _ := json.Marshal(o.Payload) + return fmt.Sprintf("[GET /organizations/{organization_canonical}/projects/{project_canonical}/environments/{environment_canonical}][%d] getEnvironmentForbidden %s", 403, payload) +} + +func (o *GetEnvironmentForbidden) String() string { + payload, _ := json.Marshal(o.Payload) + return fmt.Sprintf("[GET /organizations/{organization_canonical}/projects/{project_canonical}/environments/{environment_canonical}][%d] getEnvironmentForbidden %s", 403, payload) +} + +func (o *GetEnvironmentForbidden) GetPayload() *models.ErrorPayload { + return o.Payload +} + +func (o *GetEnvironmentForbidden) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + // hydrates response header Content-Length + hdrContentLength := response.GetHeader("Content-Length") + + if hdrContentLength != "" { + valcontentLength, err := swag.ConvertUint64(hdrContentLength) + if err != nil { + return errors.InvalidType("Content-Length", "header", "uint64", hdrContentLength) + } + o.ContentLength = valcontentLength + } + + o.Payload = new(models.ErrorPayload) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewGetEnvironmentNotFound creates a GetEnvironmentNotFound with default headers values +func NewGetEnvironmentNotFound() *GetEnvironmentNotFound { + return &GetEnvironmentNotFound{} +} + +/* +GetEnvironmentNotFound describes a response with status code 404, with default header values. + +The response sent when any of the entities present in the path is not found. +*/ +type GetEnvironmentNotFound struct { + + /* The length of the response body in octets (8-bit bytes). + + Format: uint64 + */ + ContentLength uint64 + + Payload *models.ErrorPayload +} + +// IsSuccess returns true when this get environment not found response has a 2xx status code +func (o *GetEnvironmentNotFound) IsSuccess() bool { + return false +} + +// IsRedirect returns true when this get environment not found response has a 3xx status code +func (o *GetEnvironmentNotFound) IsRedirect() bool { + return false +} + +// IsClientError returns true when this get environment not found response has a 4xx status code +func (o *GetEnvironmentNotFound) IsClientError() bool { + return true +} + +// IsServerError returns true when this get environment not found response has a 5xx status code +func (o *GetEnvironmentNotFound) IsServerError() bool { + return false +} + +// IsCode returns true when this get environment not found response a status code equal to that given +func (o *GetEnvironmentNotFound) IsCode(code int) bool { + return code == 404 +} + +// Code gets the status code for the get environment not found response +func (o *GetEnvironmentNotFound) Code() int { + return 404 +} + +func (o *GetEnvironmentNotFound) Error() string { + payload, _ := json.Marshal(o.Payload) + return fmt.Sprintf("[GET /organizations/{organization_canonical}/projects/{project_canonical}/environments/{environment_canonical}][%d] getEnvironmentNotFound %s", 404, payload) +} + +func (o *GetEnvironmentNotFound) String() string { + payload, _ := json.Marshal(o.Payload) + return fmt.Sprintf("[GET /organizations/{organization_canonical}/projects/{project_canonical}/environments/{environment_canonical}][%d] getEnvironmentNotFound %s", 404, payload) +} + +func (o *GetEnvironmentNotFound) GetPayload() *models.ErrorPayload { + return o.Payload +} + +func (o *GetEnvironmentNotFound) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + // hydrates response header Content-Length + hdrContentLength := response.GetHeader("Content-Length") + + if hdrContentLength != "" { + valcontentLength, err := swag.ConvertUint64(hdrContentLength) + if err != nil { + return errors.InvalidType("Content-Length", "header", "uint64", hdrContentLength) + } + o.ContentLength = valcontentLength + } + + o.Payload = new(models.ErrorPayload) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewGetEnvironmentDefault creates a GetEnvironmentDefault with default headers values +func NewGetEnvironmentDefault(code int) *GetEnvironmentDefault { + return &GetEnvironmentDefault{ + _statusCode: code, + } +} + +/* +GetEnvironmentDefault describes a response with status code -1, with default header values. + +The response sent when an unexpected error happened, as known as an internal server error. +*/ +type GetEnvironmentDefault struct { + _statusCode int + + /* The length of the response body in octets (8-bit bytes). + + Format: uint64 + */ + ContentLength uint64 + + Payload *models.ErrorPayload +} + +// IsSuccess returns true when this get environment default response has a 2xx status code +func (o *GetEnvironmentDefault) IsSuccess() bool { + return o._statusCode/100 == 2 +} + +// IsRedirect returns true when this get environment default response has a 3xx status code +func (o *GetEnvironmentDefault) IsRedirect() bool { + return o._statusCode/100 == 3 +} + +// IsClientError returns true when this get environment default response has a 4xx status code +func (o *GetEnvironmentDefault) IsClientError() bool { + return o._statusCode/100 == 4 +} + +// IsServerError returns true when this get environment default response has a 5xx status code +func (o *GetEnvironmentDefault) IsServerError() bool { + return o._statusCode/100 == 5 +} + +// IsCode returns true when this get environment default response a status code equal to that given +func (o *GetEnvironmentDefault) IsCode(code int) bool { + return o._statusCode == code +} + +// Code gets the status code for the get environment default response +func (o *GetEnvironmentDefault) Code() int { + return o._statusCode +} + +func (o *GetEnvironmentDefault) Error() string { + payload, _ := json.Marshal(o.Payload) + return fmt.Sprintf("[GET /organizations/{organization_canonical}/projects/{project_canonical}/environments/{environment_canonical}][%d] getEnvironment default %s", o._statusCode, payload) +} + +func (o *GetEnvironmentDefault) String() string { + payload, _ := json.Marshal(o.Payload) + return fmt.Sprintf("[GET /organizations/{organization_canonical}/projects/{project_canonical}/environments/{environment_canonical}][%d] getEnvironment default %s", o._statusCode, payload) +} + +func (o *GetEnvironmentDefault) GetPayload() *models.ErrorPayload { + return o.Payload +} + +func (o *GetEnvironmentDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + // hydrates response header Content-Length + hdrContentLength := response.GetHeader("Content-Length") + + if hdrContentLength != "" { + valcontentLength, err := swag.ConvertUint64(hdrContentLength) + if err != nil { + return errors.InvalidType("Content-Length", "header", "uint64", hdrContentLength) + } + o.ContentLength = valcontentLength + } + + o.Payload = new(models.ErrorPayload) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +/* +GetEnvironmentOKBody get environment o k body +swagger:model GetEnvironmentOKBody +*/ +type GetEnvironmentOKBody struct { + + // data + // Required: true + Data *models.Environment `json:"data"` +} + +// Validate validates this get environment o k body +func (o *GetEnvironmentOKBody) Validate(formats strfmt.Registry) error { + var res []error + + if err := o.validateData(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (o *GetEnvironmentOKBody) validateData(formats strfmt.Registry) error { + + if err := validate.Required("getEnvironmentOK"+"."+"data", "body", o.Data); err != nil { + return err + } + + if o.Data != nil { + if err := o.Data.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("getEnvironmentOK" + "." + "data") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("getEnvironmentOK" + "." + "data") + } + return err + } + } + + return nil +} + +// ContextValidate validate this get environment o k body based on the context it is used +func (o *GetEnvironmentOKBody) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + if err := o.contextValidateData(ctx, formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (o *GetEnvironmentOKBody) contextValidateData(ctx context.Context, formats strfmt.Registry) error { + + if o.Data != nil { + + if err := o.Data.ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("getEnvironmentOK" + "." + "data") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("getEnvironmentOK" + "." + "data") + } + return err + } + } + + return nil +} + +// MarshalBinary interface implementation +func (o *GetEnvironmentOKBody) MarshalBinary() ([]byte, error) { + if o == nil { + return nil, nil + } + return swag.WriteJSON(o) +} + +// UnmarshalBinary interface implementation +func (o *GetEnvironmentOKBody) UnmarshalBinary(b []byte) error { + var res GetEnvironmentOKBody + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *o = res + return nil +} diff --git a/client/client/organization_projects/organization_projects_client.go b/client/client/organization_projects/organization_projects_client.go index 2aa75389..e7147cc0 100644 --- a/client/client/organization_projects/organization_projects_client.go +++ b/client/client/organization_projects/organization_projects_client.go @@ -115,6 +115,8 @@ type ClientService interface { DeleteProjectFavorite(params *DeleteProjectFavoriteParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*DeleteProjectFavoriteNoContent, error) + GetEnvironment(params *GetEnvironmentParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetEnvironmentOK, error) + GetProject(params *GetProjectParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetProjectOK, error) GetProjectConfig(params *GetProjectConfigParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetProjectConfigOK, error) @@ -356,6 +358,44 @@ func (a *Client) DeleteProjectFavorite(params *DeleteProjectFavoriteParams, auth return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code()) } +/* +GetEnvironment Get a project environment of the organization. +*/ +func (a *Client) GetEnvironment(params *GetEnvironmentParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetEnvironmentOK, error) { + // TODO: Validate the params before sending + if params == nil { + params = NewGetEnvironmentParams() + } + op := &runtime.ClientOperation{ + ID: "getEnvironment", + Method: "GET", + PathPattern: "/organizations/{organization_canonical}/projects/{project_canonical}/environments/{environment_canonical}", + ProducesMediaTypes: []string{"application/json"}, + ConsumesMediaTypes: []string{"application/vnd.cycloid.io.v1+json", "application/x-www-form-urlencoded"}, + Schemes: []string{"https"}, + Params: params, + Reader: &GetEnvironmentReader{formats: a.formats}, + AuthInfo: authInfo, + Context: params.Context, + Client: params.HTTPClient, + } + for _, opt := range opts { + opt(op) + } + + result, err := a.transport.Submit(op) + if err != nil { + return nil, err + } + success, ok := result.(*GetEnvironmentOK) + if ok { + return success, nil + } + // unexpected success response + unexpectedSuccess := result.(*GetEnvironmentDefault) + return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code()) +} + /* GetProject Get a project of the organization. */ diff --git a/client/client/organization_projects/update_environment_responses.go b/client/client/organization_projects/update_environment_responses.go index 5d6d1b70..42e89013 100644 --- a/client/client/organization_projects/update_environment_responses.go +++ b/client/client/organization_projects/update_environment_responses.go @@ -403,7 +403,7 @@ type UpdateEnvironmentOKBody struct { // data // Required: true - Data *models.UpdateEnvironment `json:"data"` + Data *models.Environment `json:"data"` } // Validate validates this update environment o k body diff --git a/client/version b/client/version index 70e2a159..83c48cde 100644 --- a/client/version +++ b/client/version @@ -1 +1 @@ -v5.1.130 +v5.1.134 From eecfc61910e4b2d3e34bdb7b1d5fca468e3f2afe Mon Sep 17 00:00:00 2001 From: Cycloid Date: Tue, 3 Dec 2024 11:07:37 +0000 Subject: [PATCH 64/71] Changelog: Add entry for new version v5.1.134 --- changelog/unreleased/CLI-CHANGED-20241203-110737.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 changelog/unreleased/CLI-CHANGED-20241203-110737.yaml diff --git a/changelog/unreleased/CLI-CHANGED-20241203-110737.yaml b/changelog/unreleased/CLI-CHANGED-20241203-110737.yaml new file mode 100644 index 00000000..12b4c5e2 --- /dev/null +++ b/changelog/unreleased/CLI-CHANGED-20241203-110737.yaml @@ -0,0 +1,8 @@ +component: CLI +kind: CHANGED +body: "Update client to version v5.1.134" +time: 2024-12-03T11:07:37.671899158+00:00 +custom: + DETAILS: "" + PR: "316" + TYPE: CLI From b299c36b71f8ed8a0bb16b30c655f491b13404cd Mon Sep 17 00:00:00 2001 From: fhacloid <148750436+fhacloid@users.noreply.github.com> Date: Wed, 4 Dec 2024 10:08:48 +0100 Subject: [PATCH 65/71] Implement environments CRUD and fix broken tests. * fix: make members tests parse json output * deprecation: `cy project create` will no longer allow project creation with an env * func: implement createEnv and updateEnv in the middleware * func: add log error function * func: refactor form config data parsing * func: update get-config to new parsing * wip: refactor create env to merge the CLI in one endpoint * misc: update middleware * func: update get-env-config * fix: find tests result using json * func: update forms data handler (until API fix itself) * fix: fix update env * misc: fix make file * misc: rename func * fix: fix create --update env * fix: patch bad http reponse code locally * func: add update env command * fix: fix FormInput keys casing * misc: remove useless comment * temp: remove flaky test * fix: fix middleware with new updateProject route * fix: remove bad os.exit() and use error instead * fix: fix a lot of broken test preparations with the new CRUD * fix: bad typing for variable merge * func: add verbosity in tests execution * misc: remove legacy test * misc: rename create-raw-env to create-legacy-env * misc: add legacy project create in tests * fix: remove payload validation and fix buildup tests * fix: fix middleware signature and get forms vars after create/update env * misc: add changelog * misc: remove commented useless code --- Makefile | 8 +- .../CLI-BREAKING-20241203-163923.yaml | 9 + .../unreleased/CLI-FIXED-20241203-164023.yaml | 10 + .../unreleased/CLI-FIXED-20241203-164125.yaml | 9 + cmd/cycloid/common/formsUtils.go | 65 ++++ cmd/cycloid/common/helpers.go | 78 +---- cmd/cycloid/common/helpers_test.go | 46 --- cmd/cycloid/internal/version.go | 11 + .../middleware/catalog-repositories.go | 32 +- cmd/cycloid/middleware/middleware.go | 9 +- cmd/cycloid/middleware/project.go | 194 ++++++----- cmd/cycloid/middleware/stacks.go | 32 +- cmd/cycloid/projects/cmd.go | 2 +- cmd/cycloid/projects/create-env.go | 301 +++++++++--------- cmd/cycloid/projects/create-legacy-env.go | 97 ++++++ cmd/cycloid/projects/create-project.go | 97 ++---- cmd/cycloid/projects/create-raw-env.go | 211 ------------ cmd/cycloid/projects/delete.go | 4 +- cmd/cycloid/projects/get-env.go | 16 +- cmd/cycloid/projects/update-env.go | 218 +++++++++++++ cmd/cycloid/projects/update.go | 4 - cmd/cycloid/stacks/get-config.go | 57 +--- e2e/external_backends_test.go | 10 +- e2e/helpers.go | 10 + e2e/kpis_test.go | 10 +- e2e/members_test.go | 32 +- e2e/pipelines_test.go | 13 +- e2e/projects_test.go | 90 ++++-- 28 files changed, 917 insertions(+), 758 deletions(-) create mode 100644 changelog/unreleased/CLI-BREAKING-20241203-163923.yaml create mode 100644 changelog/unreleased/CLI-FIXED-20241203-164023.yaml create mode 100644 changelog/unreleased/CLI-FIXED-20241203-164125.yaml create mode 100644 cmd/cycloid/common/formsUtils.go create mode 100644 cmd/cycloid/projects/create-legacy-env.go delete mode 100644 cmd/cycloid/projects/create-raw-env.go create mode 100644 cmd/cycloid/projects/update-env.go diff --git a/Makefile b/Makefile index fd027654..77498597 100644 --- a/Makefile +++ b/Makefile @@ -69,15 +69,15 @@ SWAGGER_DOCKER_GENERATE = rm -rf ./client; \ CY_API_URL ?= http://127.0.0.1:3001 # Env list specified in file /e2e/e2e.go CY_TEST_GIT_CR_URL ?= git@172.42.0.14:/git-server/repos/backend-test-config-repo.git -CY_TEST_ROOT_ORG ?= "cycloidio" +CY_TEST_ROOT_ORG ?= "fake-cycloid" # Local E2E tests # Note! Requires access to the private cycloid BE, only acessible within the organisation # AWS - ECR login export AWS_ACCESS_KEY_ID ?= $(shell vault read -field=access_key secret/cycloid/aws) export AWS_SECRET_ACCESS_KEY ?= $(shell vault read -field=secret_key secret/cycloid/aws) -AWS_DEFAULT_REGION ?= eu-west-1 -AWS_ACCOUNT_ID ?= $(shell vault read -field=account_id secret/cycloid/aws) +export AWS_DEFAULT_REGION ?= eu-west-1 +export AWS_ACCOUNT_ID ?= $(shell vault read -field=account_id secret/cycloid/aws) # Local BE LOCAL_BE_GIT_PATH ?= ../youdeploy-http-api YD_API_TAG ?= staging @@ -97,7 +97,7 @@ test: ## Run end to end tests @echo "Using ORG: $(CY_TEST_ROOT_ORG) (from \$$CY_TEST_ROOT_ORG)" @echo "Using GIT: $(CY_TEST_GIT_CR_URL) (from \$$CY_TEST_GIT_CR_URL)" @if [ -z "$$CY_TEST_ROOT_API_KEY" ]; then echo "Unable to read API KEY from \$$CY_TEST_ROOT_API_KEY"; exit 1; fi; \ - CY_TEST_GIT_CR_URL="$(CY_TEST_GIT_CR_URL)" CY_API_URL="$(CY_API_URL)" CY_TEST_ROOT_ORG="$(CY_TEST_ROOT_ORG)" go test ./... --tags e2e + CY_TEST_GIT_CR_URL="$(CY_TEST_GIT_CR_URL)" CY_API_URL="$(CY_API_URL)" CY_TEST_ROOT_ORG="$(CY_TEST_ROOT_ORG)" go test ./... --tags e2e -v .PHONY: delete-old-client reset-old-client: ## Resets old client folder diff --git a/changelog/unreleased/CLI-BREAKING-20241203-163923.yaml b/changelog/unreleased/CLI-BREAKING-20241203-163923.yaml new file mode 100644 index 00000000..b8cdb25f --- /dev/null +++ b/changelog/unreleased/CLI-BREAKING-20241203-163923.yaml @@ -0,0 +1,9 @@ +component: CLI +kind: BREAKING +body: create-env uses now stackforms by default +time: 2024-12-03T16:39:23.199719606Z +custom: + DETAILS: the old create-env logic will apply if you give the legacy flags, but they + won't be advertised anymore on the CLI. + PR: "313" + TYPE: CLI diff --git a/changelog/unreleased/CLI-FIXED-20241203-164023.yaml b/changelog/unreleased/CLI-FIXED-20241203-164023.yaml new file mode 100644 index 00000000..59448128 --- /dev/null +++ b/changelog/unreleased/CLI-FIXED-20241203-164023.yaml @@ -0,0 +1,10 @@ +--- +component: "CLI" +kind: "FIXED" +body: "Fixed bugs related to the API update" +time: 2024-12-03T16:40:23.517487Z + +custom: + DETAILS: "CLI should behave as expected now." + PR: "313" + TYPE: "CLI" diff --git a/changelog/unreleased/CLI-FIXED-20241203-164125.yaml b/changelog/unreleased/CLI-FIXED-20241203-164125.yaml new file mode 100644 index 00000000..7f86a7cf --- /dev/null +++ b/changelog/unreleased/CLI-FIXED-20241203-164125.yaml @@ -0,0 +1,9 @@ +component: CLI +kind: FIXED +body: Fixed an issue where stackforms vars input precedence was not respected on certain + types +time: 2024-12-03T16:41:25.336872265Z +custom: + DETAILS: "" + PR: "313" + TYPE: CLI diff --git a/cmd/cycloid/common/formsUtils.go b/cmd/cycloid/common/formsUtils.go new file mode 100644 index 00000000..0ad995cb --- /dev/null +++ b/cmd/cycloid/common/formsUtils.go @@ -0,0 +1,65 @@ +package common + +import "strings" + +// Define what we need to extract only +type Widget struct { + Widget string `json:"widget,omitempty"` + Default interface{} `json:"default"` + Type string `json:"type,omitempty"` + Description string `json:"description,omitempty"` + Key string `json:"key,omitempty"` + Name string `json:"name,omitempty"` + Current interface{} `json:"current,omitempty"` +} + +// Retrieve the value from a Stackforms widget definition +func (w *Widget) GetValue(useDefaults bool) interface{} { + if w.Current == nil && useDefaults { + return w.Default + } else { + return w.Current + } +} + +type UseCase struct { + Name string `json:"name"` + Sections []Section `json:"sections"` +} + +type Section struct { + Name string `json:"name"` + Groups []Group `json:"groups"` +} + +type Group struct { + Name string `json:"name"` + Technologies []string `json:"technologies,omitempty"` + Vars []Widget `json:"vars"` +} + +// Convert a UseCase to a suitable Stackforms Input for create/update env API call +func UseCaseToFormInput(useCase UseCase, useDefaults bool) map[string]map[string]map[string]interface{} { + result := make(map[string]map[string]map[string]interface{}) + + for _, useCase := range useCase.Sections { + useCaseName := strings.ToLower(useCase.Name) + if result[useCaseName] == nil { + result[useCaseName] = make(map[string]map[string]interface{}) + } + + for _, group := range useCase.Groups { + groupName := strings.ToLower(group.Name) + if result[useCaseName][groupName] == nil { + result[useCaseName][groupName] = make(map[string]interface{}) + } + + for _, widget := range group.Vars { + widgetName := strings.ToLower(widget.Name) + result[useCaseName][groupName][widgetName] = widget.GetValue(useDefaults) + } + } + } + + return result +} diff --git a/cmd/cycloid/common/helpers.go b/cmd/cycloid/common/helpers.go index 3ee75203..6110dfb8 100644 --- a/cmd/cycloid/common/helpers.go +++ b/cmd/cycloid/common/helpers.go @@ -4,7 +4,6 @@ import ( "fmt" "net/url" "os" - "reflect" "regexp" "strings" @@ -333,85 +332,22 @@ func EntityGetValue(entity *models.FormEntity, getCurrent bool) any { } } -func ParseFormsConfig(form *models.FormUseCase, getCurrent bool) (vars map[string]map[string]map[string]any, err error) { - vars = make(map[string]map[string]map[string]any) - for _, section := range form.Sections { - if section == nil { - continue - } - - var groups = make(map[string]map[string]any) - for _, group := range section.Groups { - if group == nil { - continue - } - - vars := make(map[string]any) - - for _, varEntity := range group.Vars { - if varEntity == nil { - continue - } - - value := EntityGetValue(varEntity, getCurrent) - vars[*varEntity.Key] = value - } - - groups[strings.ToLower(*group.Name)] = vars - } - - vars[strings.ToLower(*section.Name)] = groups - } - - return vars, nil -} - -func GetFormsUseCase(formsUseCases []*models.FormUseCase, useCase string) (*models.FormUseCase, error) { - if formsUseCases == nil { - return nil, fmt.Errorf("got empty forms use case") - } - - for _, form := range formsUseCases { - if *form.Name == useCase { - return form, nil - } - } - - return nil, errors.New(fmt.Sprint("failed to find usecase:", useCase, "in form input:", formsUseCases)) -} - // Update map 'm' with field 'field' to 'value' // the field must be in dot notation // e.g. field='one.nested.key' value='myValue' // If the map is nil, it will be created -func UpdateMapField(field string, value any, m map[string]any) error { - keys := strings.Split(field, ".") +func UpdateMapField(field string, value interface{}, m map[string]map[string]map[string]interface{}) error { + keys := strings.Split(strings.ToLower(field), ".") - if m == nil { - m = make(map[string]any) + if len(keys) != 3 { + return errors.New("key=val update failed, you can only update a value using `section.group.var=value` syntax") } - if len(keys) == 1 { - m[keys[0]] = value - return nil - } - - child, exists := m[keys[0]] - if exists && reflect.ValueOf(child).Kind() == reflect.Map { - childMap, ok := child.(map[string]any) - if !ok { - return fmt.Errorf("failed to parse nested map: %v\n%v", child, childMap) - } - return UpdateMapField(strings.Join(keys[1:], "."), value, childMap) - } - - child = make(map[string]any) - err := UpdateMapField(strings.Join(keys[1:], "."), value, child.(map[string]any)) - if err != nil { - return err + if m == nil { + m = make(map[string]map[string]map[string]any) } - m[keys[0]] = child + m[keys[0]][keys[1]][keys[2]] = value return nil } diff --git a/cmd/cycloid/common/helpers_test.go b/cmd/cycloid/common/helpers_test.go index ad811fa3..d5dadac6 100644 --- a/cmd/cycloid/common/helpers_test.go +++ b/cmd/cycloid/common/helpers_test.go @@ -39,49 +39,3 @@ func TestGenerateCanonical(t *testing.T) { assert.Equal(t, input.Canonical, common.GenerateCanonical(input.Name)) } } - -func TestUpdateMapField(t *testing.T) { - inputs := []struct { - Field string - Value any - Base map[string]any - Expected map[string]any - }{ - { - Field: "test", - Value: "value", - Base: make(map[string]any), - Expected: map[string]any{ - "test": "value", - }, - }, - { - Field: "test.nested.value", - Value: "hello", - Base: make(map[string]any), - Expected: map[string]any{ - "test": map[string]any{ - "nested": map[string]any{ - "value": "hello", - }, - }, - }, - }, - { - Field: "changed", - Value: "yes", - Base: map[string]any{ - "changed": "notChanged", - }, - Expected: map[string]any{ - "changed": "yes", - }, - }, - } - - for _, input := range inputs { - err := common.UpdateMapField(input.Field, input.Value, input.Base) - assert.Nil(t, err) - assert.Equal(t, input.Expected, input.Base) - } -} diff --git a/cmd/cycloid/internal/version.go b/cmd/cycloid/internal/version.go index a5d9aaac..81d52d6f 100644 --- a/cmd/cycloid/internal/version.go +++ b/cmd/cycloid/internal/version.go @@ -14,6 +14,17 @@ import ( "github.com/cycloidio/cycloid-cli/internal/version" ) +func Error(out io.Writer, msg string) { + switch viper.GetString("verbosity") { + case "info", "debug", "warning": + // This is still dirty, we should detect if the current + // terminal is able to support colors + // But that would be for another PR. + fmt.Fprintf(out, "\033[1;31merror:\033[0m %s", msg) + default: + } +} + func Warning(out io.Writer, msg string) { switch viper.GetString("verbosity") { case "info", "debug", "warning": diff --git a/cmd/cycloid/middleware/catalog-repositories.go b/cmd/cycloid/middleware/catalog-repositories.go index f6fb9648..46c3c07e 100644 --- a/cmd/cycloid/middleware/catalog-repositories.go +++ b/cmd/cycloid/middleware/catalog-repositories.go @@ -18,10 +18,10 @@ func (m *middleware) ListCatalogRepositories(org string) ([]*models.ServiceCatal } p := resp.GetPayload() - err = p.Validate(strfmt.Default) - if err != nil { - return nil, err - } + // err = p.Validate(strfmt.Default) + // if err != nil { + // return nil, err + // } d := p.Data @@ -40,10 +40,10 @@ func (m *middleware) GetCatalogRepository(org, catalogRepo string) (*models.Serv } p := resp.GetPayload() - err = p.Validate(strfmt.Default) - if err != nil { - return nil, err - } + // err = p.Validate(strfmt.Default) + // if err != nil { + // return nil, err + // } d := p.Data @@ -96,10 +96,10 @@ func (m *middleware) CreateCatalogRepository(org, name, url, branch, cred string p := resp.GetPayload() - err = p.Validate(strfmt.Default) - if err != nil { - return nil, err - } + // err = p.Validate(strfmt.Default) + // if err != nil { + // return nil, err + // } d := p.Data @@ -131,10 +131,10 @@ func (m *middleware) UpdateCatalogRepository(org, catalogRepo string, name, url, } p := resp.GetPayload() - err = p.Validate(strfmt.Default) - if err != nil { - return nil, err - } + // err = p.Validate(strfmt.Default) + // if err != nil { + // return nil, err + // } d := p.Data diff --git a/cmd/cycloid/middleware/middleware.go b/cmd/cycloid/middleware/middleware.go index e9401f92..a317156e 100644 --- a/cmd/cycloid/middleware/middleware.go +++ b/cmd/cycloid/middleware/middleware.go @@ -77,14 +77,15 @@ type Middleware interface { GetPipeline(org, project, env string) (*models.Pipeline, error) SyncedPipeline(org, project, env string) (*models.PipelineStatus, error) - CreateProject(org, projectName, projectCanonical, env, pipelineTemplate, variables, description, stackRef, usecase, configRepo, owner string) (*models.Project, error) - CreateEmptyProject(org, projectName, projectCanonical, description, stackRef, configRepo, owner string) (*models.Project, error) - DeleteEnv(org, project, env string) error + CreateProject(org, projectName, projectCanonical, description, stackRef, configRepo, owner string) (*models.Project, error) + CreateEnv(org, project, envCanonical, useCase, cloudProviderCanonical, color, icon string, inputs *models.FormInput) error + UpdateEnv(org, project, envCanonical, useCase, cloudProviderCanonical, color, icon string, inputs *models.FormInput) (*models.Environment, error) + DeleteEnv(org, project, envCanonical string) error DeleteProject(org, project string) error GetProject(org string, project string) (*models.Project, error) GetProjectConfig(org string, project string, environment string) (*models.ProjectEnvironmentConfig, error) ListProjects(org string) ([]*models.Project, error) - UpdateProject(org, projectName, projectCanonical string, envs []*models.NewEnvironment, description, stackRef, owner, configRepo string, inputs []*models.FormInput, updatedAt uint64) (*models.Project, error) + UpdateProject(org, projectName, projectCanonical string, description, stackRef, owner, configRepo string, updatedAt uint64) (*models.Project, error) DeleteRole(org, role string) error GetRole(org, role string) (*models.Role, error) diff --git a/cmd/cycloid/middleware/project.go b/cmd/cycloid/middleware/project.go index 5ec88777..ed739610 100644 --- a/cmd/cycloid/middleware/project.go +++ b/cmd/cycloid/middleware/project.go @@ -1,15 +1,13 @@ package middleware import ( - "regexp" - "strings" + "fmt" strfmt "github.com/go-openapi/strfmt" "github.com/pkg/errors" "github.com/cycloidio/cycloid-cli/client/client/organization_projects" "github.com/cycloidio/cycloid-cli/client/models" - "github.com/cycloidio/cycloid-cli/cmd/cycloid/common" ) func (m *middleware) ListProjects(org string) ([]*models.Project, error) { @@ -43,10 +41,10 @@ func (m *middleware) GetProject(org, project string) (*models.Project, error) { } p := resp.GetPayload() - err = p.Validate(strfmt.Default) - if err != nil { - return nil, err - } + // err = p.Validate(strfmt.Default) + // if err != nil { + // return nil, err + // } d := p.Data @@ -60,7 +58,13 @@ func (m *middleware) GetProjectConfig(org string, project string, env string) (* params.WithEnvironmentCanonical(env) params.WithDefaults() - resp, err := m.api.OrganizationProjects.GetProjectConfig(params, m.api.Credentials(&org)) + resp, err := m.api.OrganizationProjects.GetProjectConfig( + params, + m.api.Credentials(&org), + // organization_projects.WithContentType("application/vnd.cycloid.io.v1+json"), + // organization_projects.WithAccept("application/json"), + ) + if err != nil { return nil, NewApiError(err) } @@ -74,7 +78,7 @@ func (m *middleware) GetProjectConfig(org string, project string, env string) (* return payload.Data, nil } -func (m *middleware) CreateEmptyProject(org, projectName, projectCanonical, description, stackRef, configRepo, owner string) (*models.Project, error) { +func (m *middleware) CreateProject(org, projectName, projectCanonical, description, stackRef, configRepo, owner string) (*models.Project, error) { params := organization_projects.NewCreateProjectParams() params.WithOrganizationCanonical(org) @@ -100,69 +104,43 @@ func (m *middleware) CreateEmptyProject(org, projectName, projectCanonical, desc } payload := response.GetPayload() - err = payload.Validate(strfmt.Default) - if err != nil { - return nil, errors.Wrap(err, "failed to validate response from API after project creation.") - } + // err = payload.Validate(strfmt.Default) + // if err != nil { + // return nil, errors.Wrap(err, "failed to validate response from API after project creation.") + // } return payload.Data, nil } -func (m *middleware) CreateProject(org, projectName, projectCanonical, env, pipelineTemplate, variables, description, stackRef, usecase, configRepo, owner string) (*models.Project, error) { - var body *models.NewProject - var pipelines []*models.NewPipeline - - if projectCanonical == "" { - re := regexp.MustCompile(`[^a-z0-9\-_]`) - projectCanonical = re.ReplaceAllString(strings.ToLower(projectName), "-") - } - - cyCtx := common.CycloidContext{Env: env, - Org: org, - Project: projectCanonical} - - params := organization_projects.NewCreateProjectParams() - params.SetOrganizationCanonical(org) - - pipelineName := common.GetPipelineName(projectCanonical, env) - - vars := common.ReplaceCycloidVarsString(cyCtx, variables) - - pipeline := &models.NewPipeline{ - Environment: &models.NewEnvironment{ - // TODO: https://github.com/cycloidio/cycloid-cli/issues/67 - Canonical: &env, - }, - PipelineName: &pipelineName, - UseCase: usecase, - PassedConfig: pipelineTemplate, - YamlVars: vars, - } - - err := pipeline.Validate(strfmt.Default) - if err != nil { - return nil, err - } - - pipelines = append(pipelines, pipeline) +/* +Warning: This method is deprecated. You can't create envs from this route anymore, use the env CRUD +*/ +func (m *middleware) UpdateProject(org, projectName, projectCanonical string, description, stackRef, owner, configRepo string, updatedAt uint64) (*models.Project, error) { + params := organization_projects.NewUpdateProjectParams() + params.WithOrganizationCanonical(org) + params.WithProjectCanonical(projectCanonical) - body = &models.NewProject{ + body := &models.UpdateProject{ Name: &projectName, Description: description, - Canonical: projectCanonical, ServiceCatalogRef: &stackRef, - ConfigRepositoryCanonical: &configRepo, - Pipelines: pipelines, + ConfigRepositoryCanonical: configRepo, Owner: owner, + UpdatedAt: &updatedAt, } - err = body.Validate(strfmt.Default) + err := body.Validate(strfmt.Default) if err != nil { return nil, err } params.SetBody(body) - resp, err := m.api.OrganizationProjects.CreateProject(params, m.api.Credentials(&org)) + resp, err := m.api.OrganizationProjects.UpdateProject( + params, + m.api.Credentials(&org), + // organization_projects.WithContentType("application/vnd.cycloid.io.v1+json"), + // organization_projects.WithAccept("application/json"), + ) if err != nil { return nil, NewApiError(err) } @@ -177,41 +155,101 @@ func (m *middleware) CreateProject(org, projectName, projectCanonical, env, pipe return d, err } -func (m *middleware) UpdateProject(org, projectName, projectCanonical string, envs []*models.NewEnvironment, description, stackRef, owner, configRepo string, inputs []*models.FormInput, updatedAt uint64) (*models.Project, error) { - params := organization_projects.NewUpdateProjectParams() +func (m *middleware) CreateEnv(org, project, envCanonical, useCase, cloudProviderCanonical, color, icon string, inputs *models.FormInput) error { + params := organization_projects.NewCreateEnvironmentParams() params.WithOrganizationCanonical(org) - params.WithProjectCanonical(projectCanonical) + params.WithProjectCanonical(project) - body := &models.UpdateProject{ - Name: &projectName, - Description: description, - ServiceCatalogRef: &stackRef, - ConfigRepositoryCanonical: configRepo, - Environments: envs, - Owner: owner, - Inputs: inputs, - UpdatedAt: &updatedAt, + if color == "" { + color = "default" } - err := body.Validate(strfmt.Default) + if icon == "" { + icon = "extension" + } + + var envBody models.NewEnvironment + if inputs == nil { + envBody = models.NewEnvironment{ + Canonical: &envCanonical, + UseCase: useCase, + Icon: icon, + Color: color, + CloudProviderCanonical: cloudProviderCanonical, + } + } else { + envBody = models.NewEnvironment{ + Canonical: &envCanonical, + UseCase: useCase, + Inputs: []*models.FormInput{inputs}, + Icon: icon, + Color: color, + CloudProviderCanonical: cloudProviderCanonical, + } + } + + err := envBody.Validate(strfmt.Default) if err != nil { - return nil, err + return errors.Wrap(err, "Validation failed for createEnv argument, check API docs for allow values in createEnv") + } + + params.WithBody(&envBody) + + response, err := m.api.OrganizationProjects.CreateEnvironment(params, m.api.Credentials(&org)) + + if response.Code() == 409 { + // Careful before changing the error message, it's matched insite create-env.go + return errors.New(fmt.Sprintf("environment %s already exists.", envCanonical)) + } + + // Fix for bad http response code in API + if response.Code() == 200 { + return nil } - params.SetBody(body) - resp, err := m.api.OrganizationProjects.UpdateProject(params, m.api.Credentials(&org)) if err != nil { - return nil, NewApiError(err) + return errors.Wrap(err, "an error occurred while calling Cycloid API for createEnv.") } - p := resp.GetPayload() - err = p.Validate(strfmt.Default) + return nil +} + +func (m *middleware) UpdateEnv(org, project, envCanonical, useCase, cloudProviderCanonical, color, icon string, inputs *models.FormInput) (*models.Environment, error) { + params := organization_projects.NewUpdateEnvironmentParams() + params.WithOrganizationCanonical(org) + params.WithProjectCanonical(project) + params.WithEnvironmentCanonical(envCanonical) + + if color == "" { + color = "default" + } + + if icon == "" { + icon = "extension" + } + + envBody := models.UpdateEnvironment{ + UseCase: useCase, + Inputs: []*models.FormInput{inputs}, + Icon: icon, + Color: color, + CloudProviderCanonical: cloudProviderCanonical, + } + + // err := envBody.Validate(strfmt.Default) + // if err != nil { + // return nil, errors.Wrap(err, "Validation failed for updateEnv argument, check API docs for allow values in createEnv") + // } + // + params.WithBody(&envBody) + + response, err := m.api.OrganizationProjects.UpdateEnvironment(params, m.api.Credentials(&org)) + if err != nil { - return nil, err + return nil, errors.Wrap(err, "an error occurred while calling Cycloid API for updateEnv.") } - d := p.Data - return d, err + return response.Payload.Data, nil } func (m *middleware) DeleteEnv(org, project, env string) error { diff --git a/cmd/cycloid/middleware/stacks.go b/cmd/cycloid/middleware/stacks.go index 013325c3..95275d9f 100644 --- a/cmd/cycloid/middleware/stacks.go +++ b/cmd/cycloid/middleware/stacks.go @@ -21,10 +21,10 @@ func (m *middleware) ListStacks(org string) ([]*models.ServiceCatalog, error) { } p := resp.GetPayload() - err = p.Validate(strfmt.Default) - if err != nil { - return nil, err - } + // err = p.Validate(strfmt.Default) + // if err != nil { + // return nil, err + // } d := p.Data @@ -42,10 +42,10 @@ func (m *middleware) GetStack(org, ref string) (*models.ServiceCatalog, error) { } p := resp.GetPayload() - err = p.Validate(strfmt.Default) - if err != nil { - return nil, err - } + // err = p.Validate(strfmt.Default) + // if err != nil { + // return nil, err + // } d := p.Data @@ -63,10 +63,10 @@ func (m *middleware) GetStackConfig(org, ref string) (interface{}, error) { } p := resp.GetPayload() - err = p.Validate(strfmt.Default) - if err != nil { - return nil, err - } + // err = p.Validate(strfmt.Default) + // if err != nil { + // return nil, err + // } d := p.Data @@ -140,10 +140,10 @@ func (m *middleware) ValidateForm(org string, rawForms []byte) (*models.FormsVal } p := resp.GetPayload() - err = p.Validate(strfmt.Default) - if err != nil { - return nil, err - } + // err = p.Validate(strfmt.Default) + // if err != nil { + // return nil, err + // } d := p.Data return d, nil diff --git a/cmd/cycloid/projects/cmd.go b/cmd/cycloid/projects/cmd.go index 78f51b9c..fb7f987a 100644 --- a/cmd/cycloid/projects/cmd.go +++ b/cmd/cycloid/projects/cmd.go @@ -19,9 +19,9 @@ func NewCommands() *cobra.Command { NewListCommand(), NewDeleteEnvCommand(), NewCreateEnvCommand(), - NewCreateRawEnvCommand(), NewGetCommand(), NewGetEnvCommand(), + NewUpdateEnvCommand(), ) return cmd diff --git a/cmd/cycloid/projects/create-env.go b/cmd/cycloid/projects/create-env.go index 08c809c9..3c258639 100644 --- a/cmd/cycloid/projects/create-env.go +++ b/cmd/cycloid/projects/create-env.go @@ -15,15 +15,15 @@ import ( "github.com/cycloidio/cycloid-cli/cmd/cycloid/common" "github.com/cycloidio/cycloid-cli/cmd/cycloid/internal" "github.com/cycloidio/cycloid-cli/cmd/cycloid/middleware" - "github.com/cycloidio/cycloid-cli/cmd/cycloid/stacks" "github.com/cycloidio/cycloid-cli/printer" "github.com/cycloidio/cycloid-cli/printer/factory" ) func NewCreateEnvCommand() *cobra.Command { var cmd = &cobra.Command{ - Use: "create-stackforms-env", - Short: "create an environment within a project using StackForms.", + Use: "create-env", + Aliases: []string{"create-stackforms-env", "create-raw-env"}, + Short: "create an environment within a project using StackForms.", Long: `Create or update (with --update) an environment within a project using StackForms. By default, the command will fetch the stack's default value for you to override. @@ -38,7 +38,7 @@ You can use the following ways to fill in the stackforms configuration (in the o The output will be the generated configuration of the project.`, Example: ` # create 'prod' environment in 'my-project' -cy project create-stackforms-env \ +cy project create-env \ --org my-org \ --project my-project \ --env prod \ @@ -50,18 +50,13 @@ cy project create-stackforms-env \ # Update a project with some values from another environement # using -V to override some variables. cy project get-env-config --org my-org --project my-project --env prod \ - | cy project create-stackforms-env --update \ + | cy project create-env --update \ --project my-project --env staging --use-case aws \ --var-file "-" \ -V "pipeline.database.dump_version=staging"`, - PreRunE: func(cmd *cobra.Command, args []string) error { - internal.Warning(cmd.ErrOrStderr(), - "This command will replace `cy project create-env` soon.\n"+ - "Please see https://github.com/cycloidio/cycloid-cli/issues/268 for more information.\n") - return internal.CheckAPIAndCLIVersion(cmd, args) - }, - - RunE: createEnv, + PreRunE: internal.CheckAPIAndCLIVersion, + + RunE: createEnvParseArgs, } cmd.PersistentFlags().StringP("project", "p", "", "project name") @@ -72,19 +67,24 @@ cy project get-env-config --org my-org --project my-project --env prod \ cmd.MarkFlagRequired("use-case") cmd.PersistentFlags().StringArrayP("var-file", "f", nil, "path to a JSON file containing variables, can be '-' for stdin, can be set multiple times.") cmd.PersistentFlags().StringArrayP("json-vars", "j", nil, "JSON string containing variables, can be set multiple times.") - cmd.PersistentFlags().StringToStringP("var", "V", nil, `update a variable using a field=value syntax (e.g. -V section.group.key=value)`) + cmd.PersistentFlags().StringToStringP("var", "V", nil, `update a variable using a section.group.var=value syntax`) cmd.PersistentFlags().Bool("update", false, "allow to override existing environment") cmd.PersistentFlags().Bool("no-fetch-defaults", false, "disable the fetching of the stacks default values") + // TODO + // Handle legacy createEnv, we create the flags to detect + // env creation without stackforms and redirect user to the old command + cmd.Flags().String("pipeline", "", "[deprecated] path to a pipeline file.") + cmd.Flags().MarkHidden("pipeline") + cmd.Flags().String("vars", "", "[deprecated] path to a pipeline config file.") + cmd.Flags().MarkHidden("vars") + cmd.Flags().StringToString("config", nil, "[deprecated] config key=val for legacy stacks") + cmd.Flags().MarkHidden("config") + return cmd } -func createEnv(cmd *cobra.Command, args []string) error { - api := common.NewAPI() - m := middleware.NewMiddleware(api) - - var err error - +func createEnvParseArgs(cmd *cobra.Command, args []string) error { org, err := common.GetOrg(cmd) if err != nil { return err @@ -137,56 +137,65 @@ func createEnv(cmd *cobra.Command, args []string) error { return err } - // - // Variable merge - // - var vars = make(map[string]interface{}) + output, err := cmd.Flags().GetString("output") + if err != nil { + return errors.Wrap(err, "unable to get output flag") + } - // We need the project data first to get the stack ref - projectData, err := m.GetProject(org, project) + // Handle legacy flags + // We will detect the stacks V2 flags and use the legacy function here + legacyPipeline, err := cmd.Flags().GetString("pipeline") if err != nil { return err } - if !noFetchDefault { - // First we fetch the stack's default - stack, err := m.GetStackConfig(org, *projectData.ServiceCatalog.Ref) - if err != nil { - return errors.Wrap(err, "failed to retrieve stack's defaults values") - } - - data, err := stacks.ExtractFormsFromStackConfig(stack, useCase) - if err != nil { - return err - } + legacyVars, err := cmd.Flags().GetString("vars") + if err != nil { + return err + } - defaultValues, err := common.ParseFormsConfig(data, false) - if err != nil { - return err - } + legacyConfig, err := cmd.Flags().GetStringToString("config") + if err != nil { + return err + } - // We merge default values first - mergo.Merge(&vars, defaultValues, mergo.WithOverride) + if (legacyPipeline + legacyVars) != "" { + internal.Warning(cmd.ErrOrStderr(), "You are using a legacy V2 stack and should migrate to use stackforms.") + internal.Warning(cmd.ErrOrStderr(), "This way of creating env will be deprecated in the future") + return createLegacyEnv(cmd, org, project, env, useCase, legacyVars, legacyPipeline, output, legacyConfig) } + return createEnv(cmd, org, project, env, useCase, output, update, noFetchDefault, varsFiles, extraVar) +} + +type FormVars = map[string]map[string]map[string]interface{} + +// Merge variable in correct order of precedence for createEnv and updateEnv +func mergeVars(defaultValues FormVars, varsFiles []string, jsonVars []string, keyValVars map[string]string) (FormVars, error) { + var vars = make(FormVars) + + // We merge default values first + mergo.Merge(&vars, defaultValues, mergo.WithOverride) + // Fetch vars from files and stdin for _, varFile := range varsFiles { - internal.Debug("found var file", varFile) var decoder *json.Decoder + if varFile == "-" { decoder = json.NewDecoder(os.Stdin) } else { reader, err := os.Open(varFile) if err != nil { - return fmt.Errorf("failed to read input vars from stdin: %v", err) + return nil, errors.Errorf("failed to read input vars from stdin: %v", err) } + defer reader.Close() decoder = json.NewDecoder(reader) } // Files can contain one or more object, so we scan for all with a decoder for { - var extractedVars = make(map[string]interface{}) + var extractedVars = make(FormVars) err := decoder.Decode(&extractedVars) if err == io.EOF { internal.Debug("finished reading input vars from", varFile) @@ -197,104 +206,104 @@ func createEnv(cmd *cobra.Command, args []string) error { if varFile == "-" { varFile = "stdin" } - return fmt.Errorf("failed to read input vars from "+varFile+": %v", err) + + return nil, fmt.Errorf("failed to read input vars from "+varFile+": %v", err) } if err := mergo.Merge(&vars, extractedVars, mergo.WithOverride); err != nil { - return fmt.Errorf("failed to merge input vars from "+varFile+": %v", err) + return nil, errors.Errorf("failed to merge input vars from "+varFile+": %v", err) } } } - // Get vars via the CY_STACKFORMS_VARS env var - envConfig, exists := os.LookupEnv("CY_STACKFORMS_VARS") - if exists { - internal.Debug("found config via env var", envConfig) - var envVars = make(map[string]interface{}) - err := json.Unmarshal([]byte(envConfig), &envVars) + for _, varInput := range jsonVars { + var extractedVars = make(FormVars) - // TODO: does this should error if parsing fail, of should we just put a warning ? + err := json.Unmarshal([]byte(varInput), &extractedVars) if err != nil { - return fmt.Errorf("failed to parse env var config '"+envConfig+"' as JSON: %s", err) + return nil, errors.Errorf("failed to parse json-var input '"+varInput+"' as JSON: %s", err) } - if err := mergo.Merge(&vars, envVars, mergo.WithOverride); err != nil { - return fmt.Errorf("failed to merge input vars from environment: %v", err) + if err := mergo.Merge(&vars, extractedVars, mergo.WithOverride); err != nil { + return nil, errors.Errorf("failed to merge input vars from json-var input: %v\nerr: %v", extractedVars, err) } } - // Get variables via CLI arguments --json-vars - cliVars, err := cmd.Flags().GetStringArray("json-vars") + // Merge key/val from --var + for k, v := range keyValVars { + common.UpdateMapField(k, v, vars) + } + + return vars, nil +} + +func createEnv(cmd *cobra.Command, org, project, env, useCase, output string, update, noFetchDefault bool, varsFiles []string, extraVar map[string]string) error { + api := common.NewAPI() + m := middleware.NewMiddleware(api) + + // We need the project data first to get the stack ref + projectData, err := m.GetProject(org, project) if err != nil { return err } - for _, varInput := range cliVars { - internal.Debug("found var input", varInput) - var extractedVars = make(map[string]interface{}) - err = json.Unmarshal([]byte(varInput), &extractedVars) + var defaultValues FormVars + + if !noFetchDefault { + // First we fetch the stack's default + stack, err := m.GetStackConfig(org, *projectData.ServiceCatalog.Ref) if err != nil { - return fmt.Errorf("failed to parse json-var input '"+varInput+"' as JSON: %s", err) + return errors.Wrap(err, "failed to retrieve stack's defaults values") } - if err := mergo.Merge(&vars, extractedVars, mergo.WithOverride); err != nil { - return fmt.Errorf("failed to merge input vars from json-var input: %v\nerr: %v", extractedVars, err) + var stackConfig map[string]struct { + Forms common.UseCase `json:"forms"` + } + + errMsg := `failed to serialize API response for stack default value fetched with getServiceCatalogConfig.` + stackJson, err := json.MarshalIndent(stack, "", " ") + if err != nil { + return errors.Wrap(err, errMsg) + } + + err = json.Unmarshal(stackJson, &stackConfig) + if err != nil { + return errors.Wrap(err, errMsg) } + + defaultValues = common.UseCaseToFormInput(stackConfig[useCase].Forms, true) + } - // Merge key/val from --var - for k, v := range extraVar { - common.UpdateMapField(k, v, vars) + // Get variables via CLI arguments --json-vars + cliVars, err := cmd.Flags().GetStringArray("json-vars") + if err != nil { + return err } - output, err := cmd.Flags().GetString("output") + var jsonVars []string + + envConfig, exists := os.LookupEnv("CY_STACKFORMS_VARS") + if exists { + jsonVars = append(jsonVars, envConfig) + } + + jsonVars = append(jsonVars, cliVars...) + vars, err := mergeVars(defaultValues, varsFiles, jsonVars, extraVar) if err != nil { - return errors.Wrap(err, "unable to get output flag") + return errors.Wrapf(err, "Failed to merge variables: %v", vars) } // fetch the printer from the factory if output == "table" { output = "json" } + p, err := factory.GetPrinter(output) if err != nil { return errors.Wrap(err, "unable to get printer") } - envs := make([]*models.NewEnvironment, len(projectData.Environments)) - - for i, e := range projectData.Environments { - if *e.Canonical == env && !update { - return fmt.Errorf("environment %s exists already in %s\nIf you want to update it, add the --update flag.", env, project) - } - - if e.Canonical == nil { - return fmt.Errorf("missing canonical for environment %v", e) - } - - cloudProviderCanonical := "" - if e.CloudProvider != nil { - cloudProviderCanonical = *e.CloudProvider.Canonical - } - - color := "default" - if e.Color != nil { - color = *e.Color - } - - icon := "extension" - if e.Icon != nil { - icon = *e.Icon - } - - envs[i] = &models.NewEnvironment{ - Canonical: e.Canonical, - CloudProviderCanonical: cloudProviderCanonical, - Color: color, - Icon: icon, - } - } - // Infer icon and color based on usecase var cloudProviderCanonical, icon, color string switch strings.ToLower(useCase) { @@ -317,56 +326,52 @@ func createEnv(cmd *cobra.Command, args []string) error { } // TODO: add the same color/icon as frontend for prod/prd staging/stg/preprod - - // finally add the new environment - envs = append(envs, &models.NewEnvironment{ - // TODO: https://github.com/cycloidio/cycloid-cli/issues/67 - Canonical: &env, - CloudProviderCanonical: cloudProviderCanonical, - Color: color, - Icon: icon, - }) - - inputs := []*models.FormInput{ - { - EnvironmentCanonical: &env, - UseCase: &useCase, - Vars: vars, - }, + inputs := models.FormInput{ + EnvironmentCanonical: &env, + UseCase: &useCase, + Vars: vars, } - // Send the updateProject call // TODO: Add support for resource pool canonical in case of resource quotas - _, err = m.UpdateProject(org, - *projectData.Name, + err = m.CreateEnv( + org, project, - envs, - projectData.Description, - *projectData.ServiceCatalog.Ref, - *projectData.Owner.Username, - projectData.ConfigRepositoryCanonical, - inputs, - *projectData.UpdatedAt, + env, + useCase, + cloudProviderCanonical, + color, + icon, + &inputs, ) - if err != nil { - return errors.Wrap(err, "failed to send config to backend") - } - errMsg := "failed to send config accepted by backend, returning inputs instead." - config, err := m.GetProjectConfig(org, project, env) - if err != nil { - return printer.SmartPrint(p, inputs[0].Vars, errors.Wrap(err, errMsg), "", printer.Options{}, cmd.OutOrStdout()) - } + if errors.Is(err, errors.Errorf("environment %s already exists.", env)) && update { + _, err := m.UpdateEnv( + org, + project, + env, + useCase, + cloudProviderCanonical, + color, + icon, + &inputs, + ) + + // return the config understood by the backend + resp, err := m.GetProjectConfig(org, project, env) + data, err := json.Marshal(resp.Forms.UseCases[0]) + if err != nil { + return errors.New("failed to marshall API response.") + } - form, err := common.GetFormsUseCase(config.Forms.UseCases, useCase) - if err != nil { - return errors.Wrap(err, "failed to extract forms data from project config.") - } + var useCase common.UseCase + err = json.Unmarshal(data, &useCase) + if err != nil { + // we didn't got correct response from backend but we can return our inputs + return printer.SmartPrint(p, inputs, err, "", printer.Options{}, cmd.OutOrStdout()) + } - formsConfig, err := common.ParseFormsConfig(form, true) - if err != nil { - return printer.SmartPrint(p, inputs[0].Vars, errors.Wrap(err, errMsg), "", printer.Options{}, cmd.OutOrStdout()) + return printer.SmartPrint(p, common.UseCaseToFormInput(useCase, false), err, "failed to update environment "+env, printer.Options{}, cmd.OutOrStdout()) } - return printer.SmartPrint(p, formsConfig, nil, "", printer.Options{}, cmd.OutOrStdout()) + return printer.SmartPrint(p, inputs.Vars, err, "", printer.Options{}, cmd.OutOrStdout()) } diff --git a/cmd/cycloid/projects/create-legacy-env.go b/cmd/cycloid/projects/create-legacy-env.go new file mode 100644 index 00000000..5ee0ef7b --- /dev/null +++ b/cmd/cycloid/projects/create-legacy-env.go @@ -0,0 +1,97 @@ +package projects + +import ( + "os" + + strfmt "github.com/go-openapi/strfmt" + "github.com/pkg/errors" + "github.com/spf13/cobra" + + "github.com/cycloidio/cycloid-cli/cmd/cycloid/common" + "github.com/cycloidio/cycloid-cli/cmd/cycloid/middleware" + "github.com/cycloidio/cycloid-cli/cmd/cycloid/pipelines" + "github.com/cycloidio/cycloid-cli/printer" + "github.com/cycloidio/cycloid-cli/printer/factory" +) + +func createLegacyEnv(cmd *cobra.Command, org, project, env, useCase, varsPath, pipelinePath, output string, configs map[string]string) error { + api := common.NewAPI() + m := middleware.NewMiddleware(api) + + // fetch the printer from the factory + p, err := factory.GetPrinter(output) + if err != nil { + return errors.Wrap(err, "unable to get printer") + } + + err = m.CreateEnv( + org, + project, + env, + useCase, + "", // color + "", // icon // TODO add color and icon handling + "", // cloudProviderCanonical + nil, // inputs + ) + + if err != nil { + return printer.SmartPrint(p, nil, err, "unable to create env "+env, printer.Options{}, cmd.OutOrStdout()) + } + + // + // CREATE PIPELINE + // + rawPipeline, err := os.ReadFile(pipelinePath) + if err != nil { + return errors.Wrap(err, "unable to read pipeline file") + } + pipelineTemplate := string(rawPipeline) + + rawVars, err := os.ReadFile(varsPath) + if err != nil { + return errors.Wrap(err, "unable to read variables file") + } + + variables := string(rawVars) + + newPP, err := m.CreatePipeline(org, project, env, pipelineTemplate, variables, useCase) + err = printer.SmartPrint(p, nil, err, "unable to create pipeline", printer.Options{}, cmd.OutOrStdout()) + if err != nil { + return err + } + + // + // PUSH CONFIG If project creation succeeded we push the config files + // + // Pipeline vars file + crVarsPath, err := pipelines.GetPipelineVarsPath(m, org, project, *newPP.UseCase) + if err != nil { + printer.SmartPrint(p, nil, err, "unable to get pipeline variables destination path", printer.Options{}, cmd.OutOrStdout()) + } + cfs := make(map[string]strfmt.Base64) + cfs[crVarsPath] = rawVars + + // Additionals config files + if len(configs) > 0 { + for fp, dest := range configs { + var c strfmt.Base64 + c, err = os.ReadFile(fp) + if err != nil { + return errors.Wrap(err, "unable to read config file") + } + cfs[dest] = c + } + } + + err = m.PushConfig(org, project, env, cfs) + if err != nil { + return printer.SmartPrint(p, nil, err, "unable to push config", printer.Options{}, cmd.OutOrStdout()) + } + + // + // PIPELINE UNPAUSE + // + err = m.UnpausePipeline(org, project, env) + return printer.SmartPrint(p, nil, err, "unable to unpause pipeline", printer.Options{}, cmd.OutOrStdout()) +} diff --git a/cmd/cycloid/projects/create-project.go b/cmd/cycloid/projects/create-project.go index c11b8169..048e702d 100644 --- a/cmd/cycloid/projects/create-project.go +++ b/cmd/cycloid/projects/create-project.go @@ -1,17 +1,12 @@ package projects import ( - "os" - - strfmt "github.com/go-openapi/strfmt" "github.com/pkg/errors" "github.com/spf13/cobra" - "github.com/cycloidio/cycloid-cli/client/models" "github.com/cycloidio/cycloid-cli/cmd/cycloid/common" "github.com/cycloidio/cycloid-cli/cmd/cycloid/internal" "github.com/cycloidio/cycloid-cli/cmd/cycloid/middleware" - "github.com/cycloidio/cycloid-cli/cmd/cycloid/pipelines" "github.com/cycloidio/cycloid-cli/printer" "github.com/cycloidio/cycloid-cli/printer/factory" ) @@ -36,10 +31,15 @@ func NewCreateCommand() *cobra.Command { common.RequiredFlag(WithFlagStackRef, cmd) common.RequiredFlag(WithFlagConfigRepository, cmd) cmd.Flags().StringP("env", "e", "", "[deprecated] add an environment with project creation") + cmd.Flags().MarkHidden("env") cmd.Flags().String("vars", "", "[deprecated] path to a variable file for the env creation") + cmd.Flags().MarkHidden("vars") cmd.Flags().String("pipeline", "", "[deprecated] path to a pipeline file for the env creation") + cmd.Flags().MarkHidden("pipeline") cmd.Flags().StringToString("config", nil, "[deprecated] path to a config file to inject in the config repo") + cmd.Flags().MarkHidden("config") cmd.Flags().String("usecase", "", "[deprecated] the usecase for the env creation") + cmd.Flags().MarkHidden("usecase") cmd.Flags().String("owner", "", "the owner username") WithFlagDescription(cmd) @@ -86,104 +86,49 @@ func create(cmd *cobra.Command, args []string) error { return err } - env, err := cmd.Flags().GetString("env") + output, err := cmd.Flags().GetString("output") if err != nil { - return err + return errors.Wrap(err, "unable to get output flag") } - usecase, err := cmd.Flags().GetString("usecase") + // fetch the printer from the factory + p, err := factory.GetPrinter(output) if err != nil { - return err + return errors.Wrap(err, "unable to get printer") } - varsPath, err := cmd.Flags().GetString("vars") + // Deprecated flags, we still collect them to give a correct error message to the user + _, err = cmd.Flags().GetStringToString("config") if err != nil { return err } - pipelinePath, err := cmd.Flags().GetString("pipeline") + env, err := cmd.Flags().GetString("env") if err != nil { return err } - configs, err := cmd.Flags().GetStringToString("config") + usecase, err := cmd.Flags().GetString("usecase") if err != nil { return err } - output, err := cmd.Flags().GetString("output") + varsPath, err := cmd.Flags().GetString("vars") if err != nil { - return errors.Wrap(err, "unable to get output flag") + return err } - // fetch the printer from the factory - p, err := factory.GetPrinter(output) + pipelinePath, err := cmd.Flags().GetString("pipeline") if err != nil { - return errors.Wrap(err, "unable to get printer") + return err } + // Handle deprecation if env+usecase+varsPath+pipelinePath != "" { // If any of the env provisioning vars is not empty, create the project with an env - internal.Warning(cmd.ErrOrStderr(), "Creating an environment when creating a project is deprecated and will be removed in a future release. Please create your env separately using the 'cy project create-env' command.\n") - project, err := createProjectWithPipeline(org, name, canonical, description, stackRef, configRepo, env, usecase, varsPath, pipelinePath, ownerCanonical, configs) - return printer.SmartPrint(p, project, err, "", printer.Options{}, cmd.OutOrStdout()) + return errors.New("Creating an environment when creating a project is not possible anymore. Please create your env separately using the 'cy project create-env' command.") } - project, err := m.CreateEmptyProject(org, name, canonical, description, stackRef, configRepo, ownerCanonical) + project, err := m.CreateProject(org, name, canonical, description, stackRef, configRepo, ownerCanonical) return printer.SmartPrint(p, project, err, "", printer.Options{}, cmd.OutOrStdout()) } - -func createProjectWithPipeline(org, name, canonical, description, stackRef, configRepo, env, usecase, varsPath, pipelinePath, owner string, configs map[string]string) (*models.Project, error) { - api := common.NewAPI() - m := middleware.NewMiddleware(api) - - rawPipeline, err := os.ReadFile(pipelinePath) - if err != nil { - return nil, errors.Wrap(err, "unable to read pipeline file") - } - pipelineTemplate := string(rawPipeline) - - rawVars, err := os.ReadFile(varsPath) - if err != nil { - return nil, errors.Wrap(err, "unable to read variables file") - } - - vars := string(rawVars) - - project, err := m.CreateProject(org, name, canonical, env, pipelineTemplate, vars, description, stackRef, usecase, configRepo, owner) - err = errors.Wrap(err, "unable to create project") - if err != nil { - return nil, err - } - - // - // PUSH CONFIG If project creation succeeded we push the config files - // - // Pipeline vars file - crVarsPath, err := pipelines.GetPipelineVarsPath(m, org, *project.Canonical, usecase) - if err != nil { - errors.Wrap(err, "unable to get pipeline variables destination path") - } - cfs := make(map[string]strfmt.Base64) - cfs[crVarsPath] = rawVars - - // Additionals config files - if len(configs) > 0 { - for fp, dest := range configs { - var c strfmt.Base64 - c, err = os.ReadFile(fp) - if err != nil { - return nil, errors.Wrap(err, "unable to read config file") - } - cfs[dest] = c - } - } - - err = m.PushConfig(org, *project.Canonical, env, cfs) - err = errors.Wrap(err, "unable to push config") - if err != nil { - return nil, err - } - - return project, nil -} diff --git a/cmd/cycloid/projects/create-raw-env.go b/cmd/cycloid/projects/create-raw-env.go deleted file mode 100644 index 74a276b3..00000000 --- a/cmd/cycloid/projects/create-raw-env.go +++ /dev/null @@ -1,211 +0,0 @@ -package projects - -import ( - "fmt" - "os" - - strfmt "github.com/go-openapi/strfmt" - "github.com/pkg/errors" - "github.com/spf13/cobra" - - "github.com/cycloidio/cycloid-cli/client/models" - "github.com/cycloidio/cycloid-cli/cmd/cycloid/common" - "github.com/cycloidio/cycloid-cli/cmd/cycloid/internal" - "github.com/cycloidio/cycloid-cli/cmd/cycloid/middleware" - "github.com/cycloidio/cycloid-cli/cmd/cycloid/pipelines" - "github.com/cycloidio/cycloid-cli/printer" - "github.com/cycloidio/cycloid-cli/printer/factory" -) - -func NewCreateRawEnvCommand() *cobra.Command { - var cmd = &cobra.Command{ - Use: "create-raw-env", - Short: "create an environment within a project with the old configuration format.", - Aliases: []string{"create-env"}, - Example: ` - # create 'prod' environment in 'my-project' - cy --org my-org project create-raw-env \ - --project my-project \ - --env prod \ - --usecase usecase-1 \ - --pipeline /my/pipeline.yml \ - --vars /my/pipeline/vars.yml \ - --config /path/to/config=/path/in/config_repo -`, - Hidden: false, - // TODO: Bring back deprecation when switch will be operated - // If we depreciate it, it will disappear from the help - //Deprecated: "This command will be changed to use stackforms in the future.\n" + - // "If your still want to use this command as is, use `cy project create-env` instead.\n" + - // "Please see https://github.com/cycloidio/cycloid-cli/issues/268 for more information.", - PreRunE: func(cmd *cobra.Command, args []string) error { - internal.Warning(cmd.ErrOrStderr(), - "This command will be changed to use stackforms in the future.\n"+ - "If your still want to use this command as is, use `cy project create-raw-env` instead.\n"+ - "Please see https://github.com/cycloidio/cycloid-cli/issues/268 for more information.\n") - return internal.CheckAPIAndCLIVersion(cmd, args) - }, - RunE: createRawEnv, - } - common.RequiredPersistentFlag(common.WithFlagProject, cmd) - common.RequiredPersistentFlag(common.WithFlagEnv, cmd) - common.RequiredFlag(WithFlagPipeline, cmd) - common.RequiredFlag(WithFlagVars, cmd) - WithFlagConfig(cmd) - WithFlagUsecase(cmd) - - return cmd -} - -func createRawEnv(cmd *cobra.Command, args []string) error { - api := common.NewAPI() - m := middleware.NewMiddleware(api) - - var err error - - org, err := common.GetOrg(cmd) - if err != nil { - return err - } - project, err := cmd.Flags().GetString("project") - if err != nil { - return err - } - env, err := cmd.Flags().GetString("env") - if err != nil { - return err - } - usecase, err := cmd.Flags().GetString("usecase") - if err != nil { - return err - } - varsPath, err := cmd.Flags().GetString("vars") - if err != nil { - return err - } - pipelinePath, err := cmd.Flags().GetString("pipeline") - if err != nil { - return err - } - configs, err := cmd.Flags().GetStringToString("config") - if err != nil { - return err - } - - projectData, err := m.GetProject(org, project) - if err != nil { - return err - } - output, err := cmd.Flags().GetString("output") - if err != nil { - return errors.Wrap(err, "unable to get output flag") - } - - // fetch the printer from the factory - p, err := factory.GetPrinter(output) - if err != nil { - return errors.Wrap(err, "unable to get printer") - } - - // need to conver the environment to "new environment" as required - // by the API - envs := make([]*models.NewEnvironment, len(projectData.Environments)) - - for i, e := range projectData.Environments { - if *e.Canonical == env { - return fmt.Errorf("environment %s exists already in %s", env, project) - } - envs[i] = &models.NewEnvironment{ - Canonical: e.Canonical, - } - } - - // finally add the new environment - envs = append(envs, &models.NewEnvironment{ - // TODO: https://github.com/cycloidio/cycloid-cli/issues/67 - Canonical: &env, - }) - - // - // UPDATE PROJECT - // - resp, err := m.UpdateProject(org, - *projectData.Name, - project, - envs, - projectData.Description, - *projectData.ServiceCatalog.Ref, - *projectData.Owner.Username, - projectData.ConfigRepositoryCanonical, - nil, - *projectData.UpdatedAt) - - err = printer.SmartPrint(p, nil, err, "unable to update project", printer.Options{}, cmd.OutOrStdout()) - if err != nil { - return err - } - - // - // CREATE PIPELINE - // - - rawPipeline, err := os.ReadFile(pipelinePath) - if err != nil { - return errors.Wrap(err, "unable to read pipeline file") - } - pipelineTemplate := string(rawPipeline) - - rawVars, err := os.ReadFile(varsPath) - if err != nil { - return errors.Wrap(err, "unable to read variables file") - } - - variables := string(rawVars) - - newPP, err := m.CreatePipeline(org, project, env, pipelineTemplate, variables, usecase) - err = printer.SmartPrint(p, nil, err, "unable to create pipeline", printer.Options{}, cmd.OutOrStdout()) - if err != nil { - return err - } - - // - // PUSH CONFIG If project creation succeeded we push the config files - // - // Pipeline vars file - crVarsPath, err := pipelines.GetPipelineVarsPath(m, org, project, *newPP.UseCase) - if err != nil { - printer.SmartPrint(p, nil, err, "unable to get pipeline variables destination path", printer.Options{}, cmd.OutOrStdout()) - } - cfs := make(map[string]strfmt.Base64) - cfs[crVarsPath] = rawVars - - // Additionals config files - if len(configs) > 0 { - - for fp, dest := range configs { - var c strfmt.Base64 - c, err = os.ReadFile(fp) - if err != nil { - return errors.Wrap(err, "unable to read config file") - } - cfs[dest] = c - } - } - - err = m.PushConfig(org, project, env, cfs) - err = printer.SmartPrint(p, nil, err, "unable to push config", printer.Options{}, cmd.OutOrStdout()) - if err != nil { - return err - } - - // - // PIPELINE UNPAUSE - // - err = m.UnpausePipeline(org, project, env) - err = printer.SmartPrint(p, nil, err, "unable to unpause pipeline", printer.Options{}, cmd.OutOrStdout()) - if err != nil { - return err - } - - return printer.SmartPrint(p, resp, err, "", printer.Options{}, cmd.OutOrStdout()) -} diff --git a/cmd/cycloid/projects/delete.go b/cmd/cycloid/projects/delete.go index 5051ede4..859ee1e9 100644 --- a/cmd/cycloid/projects/delete.go +++ b/cmd/cycloid/projects/delete.go @@ -19,7 +19,7 @@ func NewDeleteCommand() *cobra.Command { # delete a project in 'my-org' organization cy --org my-org project delete --project my-project `, - RunE: del, + RunE: deleteProject, PreRunE: internal.CheckAPIAndCLIVersion, } @@ -27,7 +27,7 @@ func NewDeleteCommand() *cobra.Command { return cmd } -func del(cmd *cobra.Command, args []string) error { +func deleteProject(cmd *cobra.Command, args []string) error { api := common.NewAPI() m := middleware.NewMiddleware(api) diff --git a/cmd/cycloid/projects/get-env.go b/cmd/cycloid/projects/get-env.go index cfccb37b..038febb9 100644 --- a/cmd/cycloid/projects/get-env.go +++ b/cmd/cycloid/projects/get-env.go @@ -1,6 +1,7 @@ package projects import ( + "encoding/json" "fmt" "github.com/pkg/errors" @@ -75,7 +76,7 @@ func getEnvConfig(cmd *cobra.Command, args []string) error { return fmt.Errorf("missing use case argument") } - getDefault, err := cmd.Flags().GetBool("default") + useDefaults, err := cmd.Flags().GetBool("default") if err != nil { return err } @@ -111,15 +112,14 @@ func getEnvConfig(cmd *cobra.Command, args []string) error { return printer.SmartPrint(p, nil, err, fmt.Sprint("failed to fetch project '", project, "' config for env '", env, "' in org '", org, "'"), printer.Options{}, cmd.OutOrStderr()) } - form, err := common.GetFormsUseCase(resp.Forms.UseCases, *resp.UseCase) + data, err := json.Marshal(resp.Forms.UseCases[0]) if err != nil { - return errors.Wrap(err, "failed to extract forms data from project config.") + return errors.New("failed to marshall API response.") } - formData, err := common.ParseFormsConfig(form, !getDefault) - if err != nil { - return printer.SmartPrint(p, nil, err, "failed to get stack config, parsing failed.", printer.Options{}, cmd.OutOrStdout()) - } + var useCase common.UseCase + err = json.Unmarshal(data, &useCase) - return printer.SmartPrint(p, formData, err, "failed to get stack config", printer.Options{}, cmd.OutOrStdout()) + // Yes, it's always one -_o_- + return printer.SmartPrint(p, common.UseCaseToFormInput(useCase, useDefaults), err, "failed to get stack config", printer.Options{}, cmd.OutOrStdout()) } diff --git a/cmd/cycloid/projects/update-env.go b/cmd/cycloid/projects/update-env.go new file mode 100644 index 00000000..badd87ca --- /dev/null +++ b/cmd/cycloid/projects/update-env.go @@ -0,0 +1,218 @@ +package projects + +import ( + "encoding/json" + "fmt" + "os" + + "github.com/pkg/errors" + "github.com/spf13/cobra" + + "github.com/cycloidio/cycloid-cli/client/models" + "github.com/cycloidio/cycloid-cli/cmd/cycloid/common" + "github.com/cycloidio/cycloid-cli/cmd/cycloid/internal" + "github.com/cycloidio/cycloid-cli/cmd/cycloid/middleware" + "github.com/cycloidio/cycloid-cli/printer" + "github.com/cycloidio/cycloid-cli/printer/factory" +) + +func NewUpdateEnvCommand() *cobra.Command { + var cmd = &cobra.Command{ + Use: "update-env", + Short: "update an environment within a project using StackForms.", + Long: `Create or update (with --update) an environment within a project using StackForms. + +By default, the command will fetch the stack's default value for you to override. +You can cancel this with the --no-fetch-defaults flag + +You can use the following ways to fill in the stackforms configuration (in the order of precedence): +1. --var-file (-f) flag -> accept any valid JSON file, if the filename is "-", read from stdin (can be set multiple times) +2. CY_STACKFORMS_VAR env var -> accept any valid JSON string (can be multiple json objects) +3. --json-vars (-j) flag -> accept any valid JSON string (can be set multiple times) +4. --var (-V) flag -> update a variable using a field=value syntax (e.g. -V section.group.key=value) + +The output will be the generated configuration of the project.`, + Example: ` +# create 'prod' environment in 'my-project' +cy project update \ + --org my-org \ + --project my-project \ + --env prod \ + --use-case usecase-1 \ + --var-file vars.yml \ + --json-vars '{"myRaw": "vars"}' \ + --var section.group.key=value +`, + PreRunE: internal.CheckAPIAndCLIVersion, + + RunE: updateEnv, + } + + cmd.PersistentFlags().StringP("project", "p", "", "project name") + cmd.MarkFlagRequired("project") + cmd.PersistentFlags().StringP("env", "e", "", "environment name") + cmd.MarkFlagRequired("env") + cmd.PersistentFlags().StringP("use-case", "u", "", "the selected use case of the stack") + cmd.MarkFlagRequired("use-case") + cmd.PersistentFlags().StringArrayP("var-file", "f", nil, "path to a JSON file containing variables, can be '-' for stdin, can be set multiple times.") + cmd.PersistentFlags().StringArrayP("json-vars", "j", nil, "JSON string containing variables, can be set multiple times.") + cmd.PersistentFlags().StringToStringP("var", "V", nil, `update a variable using a section.group.var=value syntax`) + cmd.PersistentFlags().Bool("no-fetch-defaults", false, "disable the fetching of the stacks default values") + + return cmd +} + +func updateEnv(cmd *cobra.Command, args []string) error { + org, err := common.GetOrg(cmd) + if err != nil { + return err + } + + project, err := cmd.Flags().GetString("project") + if err != nil { + return err + } + + if len(project) < 2 { + return errors.New("project must be at least 2 characters long") + } + + env, err := cmd.Flags().GetString("env") + if err != nil { + return err + } + + if len(env) < 2 { + return errors.New("env must be at least 2 characters long") + } + + useCase, err := cmd.Flags().GetString("use-case") + if err != nil { + return err + } + + if useCase == "" { + return errors.New("use-case is empty, please specify an use-case with --use-case") + } + + varsFiles, err := cmd.Flags().GetStringArray("var-file") + if err != nil { + return err + } + + extraVar, err := cmd.Flags().GetStringToString("var") + if err != nil { + return err + } + + noFetchDefault, err := cmd.Flags().GetBool("no-fetch-defaults") + if err != nil { + return err + } + + api := common.NewAPI() + m := middleware.NewMiddleware(api) + + // We need the project data first to get the stack ref + projectData, err := m.GetProject(org, project) + if err != nil { + return err + } + + var defaultValues FormVars + + if !noFetchDefault { + // First we fetch the stack's default + stack, err := m.GetStackConfig(org, *projectData.ServiceCatalog.Ref) + if err != nil { + return errors.Wrap(err, "failed to retrieve stack's defaults values") + } + + var stackConfig map[string]struct { + Forms common.UseCase `json:"forms"` + } + + errMsg := `failed to serialize API response for stack default value fetched with getServiceCatalogConfig.` + stackJson, err := json.MarshalIndent(stack, "", " ") + if err != nil { + return errors.Wrap(err, errMsg) + } + + err = json.Unmarshal(stackJson, &stackConfig) + if err != nil { + return errors.Wrap(err, errMsg) + } + + defaultValues = common.UseCaseToFormInput(stackConfig[useCase].Forms, true) + + } + + // Get variables via CLI arguments --json-vars + cliVars, err := cmd.Flags().GetStringArray("json-vars") + if err != nil { + return err + } + + // Get vars via the CY_STACKFORMS_VARS env var + envConfig, exists := os.LookupEnv("CY_STACKFORMS_VARS") + if exists { + internal.Debug("found config via env var", envConfig) + var envVars = make(map[string]interface{}) + err := json.Unmarshal([]byte(envConfig), &envVars) + + // TODO: does this should error if parsing fail, of should we just put a warning ? + if err != nil { + return fmt.Errorf("failed to parse env var config '"+envConfig+"' as JSON: %s", err) + } + } + + vars, err := mergeVars(defaultValues, varsFiles, append([]string{envConfig}, cliVars...), extraVar) + + // Handle output options + output, err := cmd.Flags().GetString("output") + if err != nil { + return errors.Wrap(err, "unable to get output flag") + } + + if output == "table" { + output = "json" + } + + p, err := factory.GetPrinter(output) + if err != nil { + return errors.Wrap(err, "unable to get printer") + } + + inputs := models.FormInput{ + EnvironmentCanonical: &env, + UseCase: &useCase, + Vars: vars, + } + + _, err = m.UpdateEnv( + org, + project, + env, + useCase, + "", + "", + "", + &inputs, + ) + + // return the config understood by the backend + resp, err := m.GetProjectConfig(org, project, env) + data, err := json.Marshal(resp.Forms.UseCases[0]) + if err != nil { + return errors.New("failed to marshall API response.") + } + + var envData common.UseCase + err = json.Unmarshal(data, &envData) + if err != nil { + // we didn't got correct response from backend but we can return our inputs + return printer.SmartPrint(p, inputs, err, "", printer.Options{}, cmd.OutOrStdout()) + } + + return printer.SmartPrint(p, common.UseCaseToFormInput(envData, false), err, "", printer.Options{}, cmd.OutOrStdout()) +} diff --git a/cmd/cycloid/projects/update.go b/cmd/cycloid/projects/update.go index 1e1acd94..e6a567c8 100644 --- a/cmd/cycloid/projects/update.go +++ b/cmd/cycloid/projects/update.go @@ -20,7 +20,3 @@ func NewUpdateCommand() *cobra.Command { } return cmd } - -// /organizations/{organization_canonical}/projects/{project_canonical} -// put: updateProject -// Update the information of a project of the organization. If the project has some information on the fields which aren't required and they are not sent or set to their default vaules, which depend of their types, the information will be removed. diff --git a/cmd/cycloid/stacks/get-config.go b/cmd/cycloid/stacks/get-config.go index 9aa114d6..6f895fe8 100644 --- a/cmd/cycloid/stacks/get-config.go +++ b/cmd/cycloid/stacks/get-config.go @@ -7,7 +7,6 @@ import ( "github.com/pkg/errors" "github.com/spf13/cobra" - "github.com/cycloidio/cycloid-cli/client/models" "github.com/cycloidio/cycloid-cli/cmd/cycloid/common" "github.com/cycloidio/cycloid-cli/cmd/cycloid/internal" "github.com/cycloidio/cycloid-cli/cmd/cycloid/middleware" @@ -26,46 +25,14 @@ cy --org my-org stacks get-config my:stack-ref stack-usecase RunE: getConfig, Args: cobra.RangeArgs(0, 2), } - cmd.Flags().String("org", "", "organization") - cmd.MarkFlagRequired("org") cmd.Flags().StringP("ref", "r", "", "referential of the stack") cmd.Flags().StringP("use-case", "u", "", "usecase you want") return cmd } -func ExtractFormsFromStackConfig(data interface{}, useCase string) (*models.FormUseCase, error) { - formData, ok := data.(map[string]interface{}) - if !ok { - return nil, errors.New("failed to cast forms data") - } - - useCaseData, ok := formData[useCase].(map[string]interface{}) - if !ok { - return nil, errors.New("failed to extract selected use-case: " + useCase) - } - - // Type casting is not working but marshall/unmashall works - // TODO: Clean this or ask backend to return a typed response - jsonData, err := json.Marshal(useCaseData["forms"]) - if err != nil { - return nil, errors.Wrap(err, "failed to marshall config") - } - - var d *models.FormUseCase - err = json.Unmarshal(jsonData, &d) - if err != nil { - return nil, errors.Wrap(err, "failed to parse forms usecase, struct invalid.") - } - - return d, nil -} - func getConfig(cmd *cobra.Command, args []string) error { - api := common.NewAPI() - m := middleware.NewMiddleware(api) - - org, err := cmd.Flags().GetString("org") + org, err := common.GetOrg(cmd) if err != nil { return err } @@ -102,20 +69,30 @@ func getConfig(cmd *cobra.Command, args []string) error { return errors.Wrap(err, "unable to get printer") } - s, err := m.GetStackConfig(org, ref) + api := common.NewAPI() + m := middleware.NewMiddleware(api) + + data, err := m.GetStackConfig(org, ref) if err != nil { return printer.SmartPrint(p, nil, err, "unable to get the stack configuration", printer.Options{}, cmd.OutOrStdout()) } - data, err := ExtractFormsFromStackConfig(s, useCase) + var mappedData map[string]struct { + Forms common.UseCase `json:"forms"` + } + + // Type casting is not working but marshall/unmashall works + // TODO: Clean this or ask backend to return a typed response + jsonData, err := json.Marshal(data) if err != nil { - return printer.SmartPrint(p, nil, err, "failed to parse config from API response", printer.Options{}, cmd.OutOrStdout()) + return errors.Wrap(err, "failed to parse config from API.") } - formConfig, err := common.ParseFormsConfig(data, false) + err = json.Unmarshal(jsonData, &mappedData) if err != nil { - return printer.SmartPrint(p, nil, err, "unable to parse stack config", printer.Options{}, cmd.OutOrStdout()) + return errors.Wrap(err, "failed to parse forms usecase from API.") } - return printer.SmartPrint(p, formConfig, err, "unable to get stack", printer.Options{}, cmd.OutOrStdout()) + formConfig := common.UseCaseToFormInput(mappedData[useCase].Forms, true) + return printer.SmartPrint(p, formConfig, err, "unable to get stack config", printer.Options{}, cmd.OutOrStdout()) } diff --git a/e2e/external_backends_test.go b/e2e/external_backends_test.go index ab8b98fa..dbf44c60 100644 --- a/e2e/external_backends_test.go +++ b/e2e/external_backends_test.go @@ -96,8 +96,16 @@ func TestExternalBackends(t *testing.T) { "--description", "this is a test project", "--stack-ref", fmt.Sprintf("%s:stack-dummy", CY_TEST_ROOT_ORG), "--config-repo", "project-config", + }) + + executeCommand([]string{ + "--output", "json", + "--org", CY_TEST_ROOT_ORG, + "project", + "create-env", + "--project", "eb-test", "--env", "test", - "--usecase", "default", + "--use-case", "default", "--vars", "/tmp/test_cli-pp-vars", "--pipeline", "/tmp/test_cli-pp", "--config", "/tmp/test_cli-pp=/snowy/test/test_cli-pp", diff --git a/e2e/helpers.go b/e2e/helpers.go index dfd4801c..60c22ce8 100644 --- a/e2e/helpers.go +++ b/e2e/helpers.go @@ -155,6 +155,16 @@ func JsonListExtractFields(js string, field, filterField, filterRegex string) ([ return out, nil } +func JsonListFindObjectValue(list []map[string]interface{}, key, value string) bool { + for _, item := range list { + if item[key] == value { + return true + } + } + + return false +} + // // JsonExtractField Extract a field from a json entity // func JsonExtractField(js []byte, field string) (interface{}, error) { // var e interface{} diff --git a/e2e/kpis_test.go b/e2e/kpis_test.go index 5c26fd7a..e2202c3c 100644 --- a/e2e/kpis_test.go +++ b/e2e/kpis_test.go @@ -88,8 +88,16 @@ func TestKpis(t *testing.T) { "--description", "this is a test project", "--stack-ref", fmt.Sprintf("%s:stack-dummy", CY_TEST_ROOT_ORG), "--config-repo", "project-config", + }) + + executeCommand([]string{ + "--output", "json", + "--org", CY_TEST_ROOT_ORG, + "project", + "create-env", + "--project", "kpi-test", "--env", "test", - "--usecase", "default", + "--use-case", "default", "--vars", "/tmp/test_cli-pp-vars", "--pipeline", "/tmp/test_cli-pp", "--config", "/tmp/test_cli-pp=/snowy/test/test_cli-pp", diff --git a/e2e/members_test.go b/e2e/members_test.go index 9d1d6e4b..379fb48f 100644 --- a/e2e/members_test.go +++ b/e2e/members_test.go @@ -1,9 +1,8 @@ -//go:build e2e -// +build e2e - package e2e import ( + "encoding/json" + "fmt" "testing" "github.com/stretchr/testify/assert" @@ -46,7 +45,13 @@ func TestMembers(t *testing.T) { }) require.Nil(t, cmdErr) - assert.Contains(t, cmdOut, "email\": \"cycloidio@cycloid.io") + + var memberList []map[string]interface{} + err := json.Unmarshal([]byte(cmdOut), &memberList) + require.Nil(t, err, "unmarshalling cli json output") + + ok := JsonListFindObjectValue(memberList, "email", "cycloidio@cycloid.io") + assert.True(t, ok, fmt.Sprint("member with cycloidio@cycloid.io email address not found in json:\n", cmdOut)) }) t.Run("SuccessMembersGet", func(t *testing.T) { @@ -58,8 +63,14 @@ func TestMembers(t *testing.T) { "--id", "1", }) - require.Nil(t, cmdErr) - assert.Contains(t, cmdOut, "email\": \"cycloidio@cycloid.io") + require.Nil(t, cmdErr, "CLI should not error on this action.") + + var member map[string]any + err := json.Unmarshal([]byte(cmdOut), &member) + require.Nil(t, err, "we should be able to serialized the CLI json output: ", cmdOut) + + assert.Equal(t, member["email"], "cycloidio@cycloid.io", + "member with cycloidio@cycloid.io email address not found in json:\n", cmdOut) }) t.Run("SuccessMembersInvite", func(t *testing.T) { @@ -74,6 +85,7 @@ func TestMembers(t *testing.T) { require.Nil(t, cmdErr) assert.Equal(t, "", cmdOut) + }) t.Run("SuccessMembersListInvite", func(t *testing.T) { @@ -85,6 +97,12 @@ func TestMembers(t *testing.T) { }) require.Nil(t, cmdErr) - assert.Contains(t, cmdOut, "email\": \"foo@bli.fr") + + var memberList []map[string]interface{} + err := json.Unmarshal([]byte(cmdOut), &memberList) + require.Nil(t, err, "unmarshalling cli json output") + + ok := JsonListFindObjectValue(memberList, "invitation_email", "foo@bli.fr") + assert.True(t, ok, fmt.Sprint("member with foo@bli.fr email address not found in json:\n", cmdOut)) }) } diff --git a/e2e/pipelines_test.go b/e2e/pipelines_test.go index f6c1a04c..7c065222 100644 --- a/e2e/pipelines_test.go +++ b/e2e/pipelines_test.go @@ -1,6 +1,3 @@ -//go:build e2e -// +build e2e - package e2e import ( @@ -63,8 +60,16 @@ func TestPipelines(t *testing.T) { "--description", "this is a test project", "--stack-ref", fmt.Sprintf("%s:stack-dummy", CY_TEST_ROOT_ORG), "--config-repo", "project-config", + }) + + executeCommand([]string{ + "--output", "json", + "--org", CY_TEST_ROOT_ORG, + "project", + "create-env", + "--project", "pipeline-test", "--env", "test", - "--usecase", "default", + "--use-case", "default", "--vars", "/tmp/test_cli-pp-vars", "--pipeline", "/tmp/test_cli-pp", "--config", "/tmp/test_cli-pp=/snowy/test/test_cli-pp", diff --git a/e2e/projects_test.go b/e2e/projects_test.go index ab5f804f..572b4034 100644 --- a/e2e/projects_test.go +++ b/e2e/projects_test.go @@ -66,20 +66,17 @@ func TestProjects(t *testing.T) { // require.Contains(t, cmdOut, "canonical\": \"dummy") }) - t.Run("SuccessLegacyProjectsCreate", func(t *testing.T) { - WriteFile("/tmp/test_cli-pp-vars", TestPipelineVariables) - WriteFile("/tmp/test_cli-pp", TestPipelineSample) - + t.Run("CreateProjectWithEnvShouldFail", func(t *testing.T) { // Cleanup executeCommand([]string{ "--output", "json", "--org", CY_TEST_ROOT_ORG, "project", "delete", - "--project", "snowy", + "--project", "snowy-invalid", }) - cmdOut, cmdErr := executeCommand([]string{ + _, cmdErr := executeCommand([]string{ "--output", "json", "--org", CY_TEST_ROOT_ORG, "project", @@ -95,29 +92,40 @@ func TestProjects(t *testing.T) { "--config", "/tmp/test_cli-pp=/snowy/test/test_cli-pp", }) - assert.Nil(t, cmdErr) - require.Contains(t, cmdOut, "canonical\": \"snowy") + assert.ErrorContains(t, cmdErr, "Creating an environment when creating a project is not possible anymore", "Creating a project with an env is prohibited now.") }) - t.Run("SuccessLegacyProjectsCreateEnv", func(t *testing.T) { - WriteFile("/tmp/test_cli-pp-vars", TestPipelineVariables) - WriteFile("/tmp/test_cli-pp", TestPipelineSample) + t.Run("SuccessLegacyProjectsCreate", func(t *testing.T) { + // Cleanup + executeCommand([]string{ + "--output", "json", + "--org", CY_TEST_ROOT_ORG, + "project", + "delete", + "--project", "snowy", + }) cmdOut, cmdErr := executeCommand([]string{ "--output", "json", "--org", CY_TEST_ROOT_ORG, "project", - "create-env", - "--project", "snowy", - "--env", "test2", - "--usecase", "default", - "--vars", "/tmp/test_cli-pp-vars", - "--pipeline", "/tmp/test_cli-pp", - "--config", "/tmp/test_cli-pp=/snowy/test/test_cli-pp", + "create", + "--name", "snowy", + "--description", "this is a test project", + "--stack-ref", fmt.Sprintf("%s:stack-dummy", CY_TEST_ROOT_ORG), + "--config-repo", "project-config", + "--output", "json", }) assert.Nil(t, cmdErr) - require.Contains(t, cmdOut, "canonical\": \"snowy") + + var expectedData map[string]any + err := json.Unmarshal([]byte(cmdOut), &expectedData) + assert.Nil(t, err, "whe should be able to parse json output") + require.Equal(t, + "snowy", + expectedData["canonical"], + "project canonical should be in json output: ", cmdOut) }) t.Run("SuccessProjectsList", func(t *testing.T) { @@ -138,7 +146,7 @@ func TestProjects(t *testing.T) { "--output", "json", "--org", CY_TEST_ROOT_ORG, "project", - "create-stackforms-env", + "create-env", "--project", "snowy", "--env", "sf-vars", "--use-case", "default", @@ -227,4 +235,46 @@ func TestProjects(t *testing.T) { require.Equal(t, "", cmdOut) }) + t.Run("SuccessCreateEnvLegacy", func(t *testing.T) { + WriteFile("/tmp/test_cli-pp-vars", TestPipelineVariables) + WriteFile("/tmp/test_cli-pp", TestPipelineSample) + + // Cleanup + executeCommand([]string{ + "--output", "json", + "--org", CY_TEST_ROOT_ORG, + "project", + "delete", + "--project", "snowy-legacy", + }) + + cmdOut, cmdErr := executeCommand([]string{ + "--output", "json", + "--org", CY_TEST_ROOT_ORG, + "project", + "create", + "--name", "snowy-legacy", + "--description", "this is a test project", + "--stack-ref", fmt.Sprintf("%s:stack-dummy", CY_TEST_ROOT_ORG), + "--config-repo", "project-config", + "--output", "json", + }) + + assert.Nil(t, cmdErr, "project creation should have succeeded: ", cmdOut) + + cmdOut, cmdErr = executeCommand([]string{ + "--output", "json", + "--org", CY_TEST_ROOT_ORG, + "project", + "create-env", + "--project", "snowy-legacy", + "--env", "test", + "--pipeline", "/tmp/test_cli-pp", + "--vars", "/tmp/test_cli-pp-vars", + "--config", "/tmp/test_cli-pp=/snowy/test/test_cli-pp", + "--use-case", "default", + }) + + assert.Nil(t, cmdErr, "createEnv should handle legacy env creation, error: ", cmdOut) + }) } From af3b3fc49ffb9fbd862ececd8e17d054c2e7ad68 Mon Sep 17 00:00:00 2001 From: fhacloid <148750436+fhacloid@users.noreply.github.com> Date: Thu, 5 Dec 2024 10:06:42 +0100 Subject: [PATCH 66/71] Feat stack visibility (#317) * func: add visiblity parameter to middleware * func: add stack visibility parameter for catalog creation * func: add stack update command --- cmd/cycloid/catalog-repositories/create.go | 16 +- .../middleware/catalog-repositories.go | 42 ++--- cmd/cycloid/middleware/middleware.go | 3 +- cmd/cycloid/middleware/stacks.go | 74 +++++++-- cmd/cycloid/stacks/cmd.go | 1 + cmd/cycloid/stacks/update.go | 155 ++++++++++++++++++ e2e/stacks_test.go | 19 ++- 7 files changed, 263 insertions(+), 47 deletions(-) create mode 100644 cmd/cycloid/stacks/update.go diff --git a/cmd/cycloid/catalog-repositories/create.go b/cmd/cycloid/catalog-repositories/create.go index acb3c4d7..f362ae06 100644 --- a/cmd/cycloid/catalog-repositories/create.go +++ b/cmd/cycloid/catalog-repositories/create.go @@ -26,11 +26,13 @@ func NewCreateCommand() *cobra.Command { // create --branch test --cred my-cred --url "git@github.com:foo/bla.git" --name catalogname common.WithFlagCred(cmd) - common.RequiredFlag(WithFlagName, cmd) common.RequiredFlag(WithFlagBranch, cmd) common.RequiredFlag(WithFlagURL, cmd) + cmd.Flags().String("visibility", "", "set the stacks base visibility in the catalog. accepted values are 'local', 'share' or 'hidden' default to 'local'") + cmd.Flags().String("team", "", "set the team canonical to be set as maintener of the stacks") + return cmd } @@ -73,12 +75,22 @@ func createCatalogRepository(cmd *cobra.Command, args []string) error { return errors.Wrap(err, "unable to get output flag") } + visibility, err := cmd.Flags().GetString("visibility") + if err != nil { + return errors.Wrap(err, "unable to get visibility flag") + } + + teamCanonical, err := cmd.Flags().GetString("team") + if err != nil { + return errors.Wrap(err, "unable to get team flag") + } + // fetch the printer from the factory p, err := factory.GetPrinter(output) if err != nil { return errors.Wrap(err, "unable to get printer") } - cr, err := m.CreateCatalogRepository(org, name, url, branch, cred) + cr, err := m.CreateCatalogRepository(org, name, url, branch, cred, visibility, teamCanonical) return printer.SmartPrint(p, cr, err, "unable to create catalog repository", printer.Options{}, cmd.OutOrStdout()) } diff --git a/cmd/cycloid/middleware/catalog-repositories.go b/cmd/cycloid/middleware/catalog-repositories.go index 46c3c07e..544cf383 100644 --- a/cmd/cycloid/middleware/catalog-repositories.go +++ b/cmd/cycloid/middleware/catalog-repositories.go @@ -2,6 +2,7 @@ package middleware import ( strfmt "github.com/go-openapi/strfmt" + "github.com/pkg/errors" "github.com/cycloidio/cycloid-cli/client/client/organization_service_catalog_sources" "github.com/cycloidio/cycloid-cli/client/models" @@ -18,10 +19,6 @@ func (m *middleware) ListCatalogRepositories(org string) ([]*models.ServiceCatal } p := resp.GetPayload() - // err = p.Validate(strfmt.Default) - // if err != nil { - // return nil, err - // } d := p.Data @@ -40,10 +37,6 @@ func (m *middleware) GetCatalogRepository(org, catalogRepo string) (*models.Serv } p := resp.GetPayload() - // err = p.Validate(strfmt.Default) - // if err != nil { - // return nil, err - // } d := p.Data @@ -62,7 +55,7 @@ func (m *middleware) DeleteCatalogRepository(org, catalogRepo string) error { return nil } -func (m *middleware) CreateCatalogRepository(org, name, url, branch, cred string) (*models.ServiceCatalogSource, error) { +func (m *middleware) CreateCatalogRepository(org, name, url, branch, cred, visibility, teamCanonical string) (*models.ServiceCatalogSource, error) { params := organization_service_catalog_sources.NewCreateServiceCatalogSourceParams() params.SetOrganizationCanonical(org) @@ -83,6 +76,19 @@ func (m *middleware) CreateCatalogRepository(org, name, url, branch, cred string } } + switch visibility { + case "shared", "local", "hidden": + body.Visibility = visibility + case "": + break + default: + return nil, errors.New("invalid visibility parameter for CreateCatalogRepository, accepted values are 'local', 'shared' or 'hidden'") + } + + if teamCanonical != "" { + body.TeamCanonical = teamCanonical + } + params.SetBody(body) err := body.Validate(strfmt.Default) if err != nil { @@ -96,18 +102,13 @@ func (m *middleware) CreateCatalogRepository(org, name, url, branch, cred string p := resp.GetPayload() - // err = p.Validate(strfmt.Default) - // if err != nil { - // return nil, err - // } - d := p.Data return d, nil } -func (m *middleware) UpdateCatalogRepository(org, catalogRepo string, name, url, branch, cred string) (*models.ServiceCatalogSource, error) { - +func (m *middleware) UpdateCatalogRepository(org, catalogRepo string, name, url, branch, cred string, +) (*models.ServiceCatalogSource, error) { params := organization_service_catalog_sources.NewUpdateServiceCatalogSourceParams() params.SetOrganizationCanonical(org) params.SetServiceCatalogSourceCanonical(catalogRepo) @@ -131,10 +132,6 @@ func (m *middleware) UpdateCatalogRepository(org, catalogRepo string, name, url, } p := resp.GetPayload() - // err = p.Validate(strfmt.Default) - // if err != nil { - // return nil, err - // } d := p.Data @@ -152,11 +149,6 @@ func (m *middleware) RefreshCatalogRepository(org, catalogRepo string) (*models. } p := resp.GetPayload() - // TODO: Put back validation when backend fix it - //err = p.Validate(strfmt.Default) - //if err != nil { - // return nil, err - //} d := p.Data diff --git a/cmd/cycloid/middleware/middleware.go b/cmd/cycloid/middleware/middleware.go index a317156e..8f87728e 100644 --- a/cmd/cycloid/middleware/middleware.go +++ b/cmd/cycloid/middleware/middleware.go @@ -11,7 +11,7 @@ type Middleware interface { GetAppVersion() (*models.AppVersion, error) GetStatus() (*models.GeneralStatus, error) - CreateCatalogRepository(org, name, url, branch, cred string) (*models.ServiceCatalogSource, error) + CreateCatalogRepository(org, name, url, branch, cred, visibility, teamCanonical string) (*models.ServiceCatalogSource, error) DeleteCatalogRepository(org, catalogRepo string) error GetCatalogRepository(org, catalogRepo string) (*models.ServiceCatalogSource, error) ListCatalogRepositories(org string) ([]*models.ServiceCatalogSource, error) @@ -92,6 +92,7 @@ type Middleware interface { ListRoles(org string) ([]*models.Role, error) GetStack(org, ref string) (*models.ServiceCatalog, error) + UpdateStack(org, ref, name, canonical, author, description, visibility, catalogRepoCanonical, teamCanonical string, image strfmt.URI, keywords []string, technologies []*models.ServiceCatalogTechnology, dependencies []*models.ServiceCatalogDependency) (*models.ServiceCatalog, error) ListStacks(org string) ([]*models.ServiceCatalog, error) CreateKpi(name, kpiType, widget, org, project, job, env, config string) (*models.KPI, error) diff --git a/cmd/cycloid/middleware/stacks.go b/cmd/cycloid/middleware/stacks.go index 95275d9f..c432ea61 100644 --- a/cmd/cycloid/middleware/stacks.go +++ b/cmd/cycloid/middleware/stacks.go @@ -4,6 +4,7 @@ import ( "fmt" strfmt "github.com/go-openapi/strfmt" + "github.com/pkg/errors" "gopkg.in/yaml.v3" "github.com/cycloidio/cycloid-cli/client/client/organization_forms" @@ -21,10 +22,6 @@ func (m *middleware) ListStacks(org string) ([]*models.ServiceCatalog, error) { } p := resp.GetPayload() - // err = p.Validate(strfmt.Default) - // if err != nil { - // return nil, err - // } d := p.Data @@ -42,16 +39,69 @@ func (m *middleware) GetStack(org, ref string) (*models.ServiceCatalog, error) { } p := resp.GetPayload() - // err = p.Validate(strfmt.Default) - // if err != nil { - // return nil, err - // } d := p.Data return d, nil } +func (m *middleware) UpdateStack( + org, ref, name, canonical, author, description, visibility, catalogRepoCanonical, teamCanonical string, + image strfmt.URI, + keywords []string, + technologies []*models.ServiceCatalogTechnology, + dependencies []*models.ServiceCatalogDependency, +) (*models.ServiceCatalog, error) { + params := service_catalogs.NewUpdateServiceCatalogParams() + params.WithOrganizationCanonical(org) + params.WithServiceCatalogRef(ref) + + body := &models.UpdateServiceCatalog{ + Name: &name, + Author: &author, + Description: &description, + Keywords: keywords, + ServiceCatalogSourceCanonical: &catalogRepoCanonical, + } + + if canonical != "" { + body.Canonical = canonical + } + + if image != "" { + body.Image = image + } + + switch visibility { + case "shared", "local", "hidden": + body.Visibility = visibility + case "": + break + default: + return nil, errors.New("invalid visibility parameter for CreateCatalogRepository, accepted values are 'local', 'shared' or 'hidden'") + } + + if teamCanonical != "" { + body.TeamCanonical = teamCanonical + } + + err := body.Validate(strfmt.Default) + if err != nil { + return nil, errors.Wrap(err, "validation failed for updateServiceCatalog input") + } + + params.WithBody(body) + + response, err := m.api.ServiceCatalogs.UpdateServiceCatalog(params, m.api.Credentials(&org)) + if err != nil { + return nil, NewApiError(err) + } + + payload := response.GetPayload() + + return payload.Data, nil +} + func (m *middleware) GetStackConfig(org, ref string) (interface{}, error) { params := service_catalogs.NewGetServiceCatalogConfigParams() params.SetOrganizationCanonical(org) @@ -63,10 +113,6 @@ func (m *middleware) GetStackConfig(org, ref string) (interface{}, error) { } p := resp.GetPayload() - // err = p.Validate(strfmt.Default) - // if err != nil { - // return nil, err - // } d := p.Data @@ -140,10 +186,6 @@ func (m *middleware) ValidateForm(org string, rawForms []byte) (*models.FormsVal } p := resp.GetPayload() - // err = p.Validate(strfmt.Default) - // if err != nil { - // return nil, err - // } d := p.Data return d, nil diff --git a/cmd/cycloid/stacks/cmd.go b/cmd/cycloid/stacks/cmd.go index 827cf1fd..01ec7d0c 100644 --- a/cmd/cycloid/stacks/cmd.go +++ b/cmd/cycloid/stacks/cmd.go @@ -17,6 +17,7 @@ func NewCommands() *cobra.Command { cmd.AddCommand( NewListCommand(), NewGetCommand(), + NewUpdateCommand(), NewGetConfigCommand(), NewValidateFormCmd(), ) diff --git a/cmd/cycloid/stacks/update.go b/cmd/cycloid/stacks/update.go new file mode 100644 index 00000000..863d3271 --- /dev/null +++ b/cmd/cycloid/stacks/update.go @@ -0,0 +1,155 @@ +package stacks + +import ( + "fmt" + + "github.com/go-openapi/strfmt" + "github.com/pkg/errors" + "github.com/spf13/cobra" + + "github.com/cycloidio/cycloid-cli/cmd/cycloid/common" + "github.com/cycloidio/cycloid-cli/cmd/cycloid/internal" + "github.com/cycloidio/cycloid-cli/cmd/cycloid/middleware" + "github.com/cycloidio/cycloid-cli/printer" + "github.com/cycloidio/cycloid-cli/printer/factory" +) + +func NewUpdateCommand() *cobra.Command { + var cmd = &cobra.Command{ + Use: "update", + Short: "update a stack", + Long: "The CLI will fetch the current value of the --stack-ref and update with the field you will provide", + Example: `# Update one stack visibility +cy stacks update --stack-ref org:myStack --visibility shared + +# Full args example +cy stacks update \ + --stack-ref my:stack-ref \ + --name "Stack display name" \ + --author "authorCanonical" \ + --description "" \ + --keyword "keyword1,keyword2" \ + --keyword "keyword3" \ + --image "https://url-to-img.example.com/img" \ + --visibility "local" \ + --team "teamCanonical" +`, + RunE: update, + PreRunE: internal.CheckAPIAndCLIVersion, + } + + cmd.Flags().String("stack-ref", "", "stack reference, format 'org:stack-canonical'") + cmd.MarkFlagRequired("stack-ref") + + cmd.Flags().String("name", "", "update the stack display name") + cmd.Flags().String("author", "", "update the stack author") + cmd.Flags().String("description", "", "update the stack description") + cmd.Flags().StringSlice("keyword", []string{}, "update the stack keywords (will replace keywords, not append them.)") + cmd.Flags().String("image", "", "update the stack image, must be a valid URL") + cmd.Flags().String("visibility", "", "update stack visibility") + cmd.Flags().String("team", "", "update the maintainer team canonical") + + return cmd +} + +func update(cmd *cobra.Command, args []string) error { + api := common.NewAPI() + m := middleware.NewMiddleware(api) + + org, err := common.GetOrg(cmd) + if err != nil { + return err + } + + stackRef, err := cmd.Flags().GetString("stack-ref") + if err != nil { + return err + } + + output, err := cmd.Flags().GetString("output") + if err != nil { + return errors.Wrap(err, "unable to get output flag") + } + + // fetch the printer from the factory + p, err := factory.GetPrinter(output) + if err != nil { + return errors.Wrap(err, "unable to get printer") + } + + // Fetch the current stack state + stack, err := m.GetStack(org, stackRef) + if err != nil { + return printer.SmartPrint(p, nil, err, fmt.Sprintf("failed to retrieve the stack with stack ref: %s", stackRef), printer.Options{}, cmd.OutOrStderr()) + } + + // Manage optional parameters + name, err := cmd.Flags().GetString("name") + if err != nil { + return err + } + + if name == "" { + name = *stack.Name + } + + author, err := cmd.Flags().GetString("author") + if err != nil { + return err + } + + if author == "" { + author = *stack.Author + } + + description, err := cmd.Flags().GetString("description") + if err != nil { + return err + } + + if description == "" { + description = *stack.Description + } + + var imageUrl strfmt.URI + image, err := cmd.Flags().GetString("image") + if err != nil { + return err + } + + if image == "" { + imageUrl = stack.Image + } else { + imageUrl = strfmt.URI(image) + } + + visibility, err := cmd.Flags().GetString("visibility") + if err != nil { + return err + } + + if visibility == "" { + visibility = *stack.Visibility + } + + team, err := cmd.Flags().GetString("team") + if err != nil { + return err + } + + if team == "" { + team = *stack.Team.Canonical + } + + keywords, err := cmd.Flags().GetStringSlice("keyword") + if err != nil { + return err + } + + if keywords == nil { + keywords = stack.Keywords + } + + s, err := m.UpdateStack(org, stackRef, name, *stack.Canonical, author, description, visibility, stack.ServiceCatalogSourceCanonical, team, imageUrl, keywords, stack.Technologies, stack.Dependencies) + return printer.SmartPrint(p, s, err, fmt.Sprintf("fail to update stack with ref: %s", stackRef), printer.Options{}, cmd.OutOrStdout()) +} diff --git a/e2e/stacks_test.go b/e2e/stacks_test.go index 0265ca4f..086b9b41 100644 --- a/e2e/stacks_test.go +++ b/e2e/stacks_test.go @@ -1,6 +1,3 @@ -//go:build e2e -// +build e2e - package e2e import ( @@ -50,6 +47,7 @@ func TestStacks(t *testing.T) { require.Nil(t, cmdErr) assert.Contains(t, cmdOut, "canonical\": \"stack-dummy") }) + t.Run("SuccessStacksGet", func(t *testing.T) { cmdOut, cmdErr := executeCommand([]string{ "--output", "json", @@ -90,4 +88,19 @@ default: require.Nil(t, cmdErr) assert.Contains(t, cmdOut, "errors\": []") }) + + t.Run("SuccessStacksUpdateVisibilty", func(t *testing.T) { + cmdOut, cmdErr := executeCommand([]string{ + "--output", "json", + "--org", CY_TEST_ROOT_ORG, + "stack", + "update", + "--stack-ref", fmt.Sprintf("%s:stack-dummy", CY_TEST_ROOT_ORG), + "--visibility", "shared", + }) + + require.Nil(t, cmdErr) + assert.Contains(t, cmdOut, "canonical\": \"stack-dummy") + assert.Contains(t, cmdOut, "visibility\": \"shared") + }) } From a31ec74b60719a79f9e24aa4a037387ed206f4ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20BARRAS=20HAMPEL?= Date: Thu, 5 Dec 2024 10:46:17 +0100 Subject: [PATCH 67/71] misc: add missing changelog --- changelog/unreleased/CLI-FIXED-20241205-094611.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 changelog/unreleased/CLI-FIXED-20241205-094611.yaml diff --git a/changelog/unreleased/CLI-FIXED-20241205-094611.yaml b/changelog/unreleased/CLI-FIXED-20241205-094611.yaml new file mode 100644 index 00000000..551cd1cd --- /dev/null +++ b/changelog/unreleased/CLI-FIXED-20241205-094611.yaml @@ -0,0 +1,8 @@ +component: CLI +kind: FIXED +body: Fixed inconsistency on --org and CY_ORG parameter +time: 2024-12-05T09:46:11.017703786Z +custom: + DETAILS: "" + PR: "313" + TYPE: CLI From fec60d443833de7569a785307cfcb347fc828bdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20BARRAS=20HAMPEL?= Date: Thu, 5 Dec 2024 11:54:13 +0100 Subject: [PATCH 68/71] fix: fix panic on nil map assignment for teams --- cmd/cycloid/stacks/update.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/cycloid/stacks/update.go b/cmd/cycloid/stacks/update.go index 863d3271..e23c91fb 100644 --- a/cmd/cycloid/stacks/update.go +++ b/cmd/cycloid/stacks/update.go @@ -137,7 +137,7 @@ func update(cmd *cobra.Command, args []string) error { return err } - if team == "" { + if team == "" && stack.Team != nil { team = *stack.Team.Canonical } From 288fe8c4f028b6fe04fe627d8819a71c5d70fb48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20BARRAS=20HAMPEL?= Date: Mon, 9 Dec 2024 17:45:18 +0100 Subject: [PATCH 69/71] fix: fix team parameter update on stacks --- cmd/cycloid/middleware/stacks.go | 39 +++++------- cmd/cycloid/stacks/update.go | 103 ++++++++++++++++++------------- 2 files changed, 76 insertions(+), 66 deletions(-) diff --git a/cmd/cycloid/middleware/stacks.go b/cmd/cycloid/middleware/stacks.go index c432ea61..35e437bd 100644 --- a/cmd/cycloid/middleware/stacks.go +++ b/cmd/cycloid/middleware/stacks.go @@ -57,32 +57,17 @@ func (m *middleware) UpdateStack( params.WithServiceCatalogRef(ref) body := &models.UpdateServiceCatalog{ - Name: &name, Author: &author, + Canonical: canonical, + Dependencies: dependencies, Description: &description, + Image: image, Keywords: keywords, + Name: &name, ServiceCatalogSourceCanonical: &catalogRepoCanonical, - } - - if canonical != "" { - body.Canonical = canonical - } - - if image != "" { - body.Image = image - } - - switch visibility { - case "shared", "local", "hidden": - body.Visibility = visibility - case "": - break - default: - return nil, errors.New("invalid visibility parameter for CreateCatalogRepository, accepted values are 'local', 'shared' or 'hidden'") - } - - if teamCanonical != "" { - body.TeamCanonical = teamCanonical + TeamCanonical: teamCanonical, + Technologies: technologies, + Visibility: visibility, } err := body.Validate(strfmt.Default) @@ -99,6 +84,16 @@ func (m *middleware) UpdateStack( payload := response.GetPayload() + // TODO: This is a local fix for https://github.com/cycloidio/youdeploy-http-api/issues/5020 + // Remove this condition when backend will be fixed + // If the team attribute is nil, this means that the backend did not found the maitainer canonical + if teamCanonical != "" && payload.Data.Team == nil { + return payload.Data, errors.Errorf( + "maintainer with canonical '%s' may not exists, maintainer on stack ref '%s' has been removed, please check you team canonical argument and ensure that the team exists.", + teamCanonical, ref, + ) + } + return payload.Data, nil } diff --git a/cmd/cycloid/stacks/update.go b/cmd/cycloid/stacks/update.go index e23c91fb..1d18c502 100644 --- a/cmd/cycloid/stacks/update.go +++ b/cmd/cycloid/stacks/update.go @@ -77,6 +77,11 @@ func update(cmd *cobra.Command, args []string) error { return errors.Wrap(err, "unable to get printer") } + // We will make the CLI work like a PATCH request + // 1. we fetch the current stack values + // 2. we update values when the flag is set explicitly + // 3. we send the request + // Fetch the current stack state stack, err := m.GetStack(org, stackRef) if err != nil { @@ -84,72 +89,82 @@ func update(cmd *cobra.Command, args []string) error { } // Manage optional parameters - name, err := cmd.Flags().GetString("name") - if err != nil { - return err - } + var name, author, description, image, visibility, team string + var keywords []string - if name == "" { - name = *stack.Name - } + flagSet := cmd.Flags() - author, err := cmd.Flags().GetString("author") - if err != nil { - return err + if flagSet.Changed("name") { + name, err = flagSet.GetString("name") + if err != nil { + return err + } + } else { + name = *stack.Name } - if author == "" { + if flagSet.Changed("author") { + author, err = flagSet.GetString("author") + if err != nil { + return err + } + } else { author = *stack.Author } - description, err := cmd.Flags().GetString("description") - if err != nil { - return err - } - - if description == "" { + if flagSet.Changed("description") { + description, err = flagSet.GetString("description") + if err != nil { + return err + } + } else { description = *stack.Description } var imageUrl strfmt.URI - image, err := cmd.Flags().GetString("image") - if err != nil { - return err - } + if flagSet.Changed("image") { + image, err = flagSet.GetString("image") + if err != nil { + return err + } - if image == "" { - imageUrl = stack.Image - } else { imageUrl = strfmt.URI(image) + } else { + imageUrl = stack.Image } - visibility, err := cmd.Flags().GetString("visibility") - if err != nil { - return err - } - - if visibility == "" { + if flagSet.Changed("visibility") { + visibility, err = flagSet.GetString("visibility") + if err != nil { + return err + } + } else { visibility = *stack.Visibility } - team, err := cmd.Flags().GetString("team") - if err != nil { - return err - } - - if team == "" && stack.Team != nil { - team = *stack.Team.Canonical - } - - keywords, err := cmd.Flags().GetStringSlice("keyword") - if err != nil { - return err + if flagSet.Changed("team") { + team, err = flagSet.GetString("team") + if err != nil { + return err + } + } else { + if stack.Team != nil { + team = *stack.Team.Canonical + } } - if keywords == nil { - keywords = stack.Keywords + if flagSet.Changed("keyword") { + keywords, err = flagSet.GetStringSlice("keyword") + if err != nil { + return err + } + } else { + if stack.Keywords != nil { + keywords = stack.Keywords + } } + // Send request s, err := m.UpdateStack(org, stackRef, name, *stack.Canonical, author, description, visibility, stack.ServiceCatalogSourceCanonical, team, imageUrl, keywords, stack.Technologies, stack.Dependencies) return printer.SmartPrint(p, s, err, fmt.Sprintf("fail to update stack with ref: %s", stackRef), printer.Options{}, cmd.OutOrStdout()) } From 5c98dadd88a07d1fa4eddc6a5f35a0e41f163a14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20BARRAS=20HAMPEL?= Date: Mon, 9 Dec 2024 17:45:31 +0100 Subject: [PATCH 70/71] func: add tests on team parameter --- e2e/e2e.go | 6 +++++ e2e/stacks_test.go | 66 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/e2e/e2e.go b/e2e/e2e.go index b558dc12..afdd834d 100644 --- a/e2e/e2e.go +++ b/e2e/e2e.go @@ -11,6 +11,7 @@ var ( // Note, this url should be accessible by Cycloid API CY_TEST_GIT_CR_URL = "Url of the git repository used as config repository" CY_TEST_GIT_CR_BRANCH = "master" + CY_API_URL = "http://127.0.0.1:3001" // default for local tests ) func init() { @@ -33,6 +34,11 @@ func init() { if len(gitBranch) > 0 { CY_TEST_GIT_CR_BRANCH = gitBranch } + + apiUrl, ok := os.LookupEnv("CY_API_URL") + if ok { + CY_API_URL = apiUrl + } } const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" diff --git a/e2e/stacks_test.go b/e2e/stacks_test.go index 086b9b41..ba074d88 100644 --- a/e2e/stacks_test.go +++ b/e2e/stacks_test.go @@ -1,7 +1,10 @@ package e2e import ( + "bytes" + "encoding/json" "fmt" + "net/http" "testing" "github.com/stretchr/testify/assert" @@ -103,4 +106,67 @@ default: assert.Contains(t, cmdOut, "canonical\": \"stack-dummy") assert.Contains(t, cmdOut, "visibility\": \"shared") }) + + t.Run("SuccessAddStackMaintainer", func(t *testing.T) { + t.Setenv("CY_ORG", CY_TEST_ROOT_ORG) + var teamCanonical = "test-team" + body := map[string]any{ + "canonical": teamCanonical, + "name": teamCanonical, + "roles_canonical": []string{ + "default-project-viewer", + }, + } + jsonBody, err := json.Marshal(body) + assert.Nil(t, err, "[preparation]: json serialization shouldn't fail.") + + // team management is not implemented on the CLI, so making the call ourselves + request, err := http.NewRequest("POST", fmt.Sprintf("%s/organizations/%s/teams", CY_API_URL, CY_TEST_ROOT_ORG), bytes.NewBuffer(jsonBody)) + assert.Nil(t, err, "[preparation]: request creationg shoudn't fail") + + request.Header.Add("Authorization", fmt.Sprintf("Bearer %s", CY_TEST_ROOT_API_KEY)) + request.Header.Add("Content-Type", "application/vnd.cycloid.io.v1+json") + + client := &http.Client{} + _, err = client.Do(request) + assert.Nil(t, err, "[Preparation]: request to create teams shouldn't fail") + + // At this point we should have a team, I assume CR and stacks are present too + cmdOut, cmdErr := executeCommand([]string{ + "--output", "json", + "stack", "update", + "--stack-ref", fmt.Sprintf("%s:stack-dummy", CY_TEST_ROOT_ORG), + "--team", teamCanonical, + }) + + assert.Nil(t, cmdErr, "CLI should be able to update the correct team without error") + assert.Contains(t, cmdOut, teamCanonical, "team canonical should be in the JSON response.") + }) + + t.Run("SuccessRemoveMaintainer", func(t *testing.T) { + t.Setenv("CY_ORG", CY_TEST_ROOT_ORG) + // We assume that the team exists from the previous test + var teamCanonical = "test-team" + cmdOut, cmdErr := executeCommand([]string{ + "--output", "json", + "stack", "update", + "--stack-ref", fmt.Sprintf("%s:stack-dummy", CY_TEST_ROOT_ORG), + "--team", "", // setting the flag with empty string should remove the maintainer + }) + + assert.Nil(t, cmdErr, "CLI should be able to update the correct team without error") + assert.NotContains(t, cmdOut, teamCanonical, "team canonical should not be in json response") + }) + + t.Run("InvalidMaintainerShouldError", func(t *testing.T) { + t.Setenv("CY_ORG", CY_TEST_ROOT_ORG) + _, cmdErr := executeCommand([]string{ + "--output", "json", + "stack", "update", + "--stack-ref", fmt.Sprintf("%s:stack-dummy", CY_TEST_ROOT_ORG), + "--team", "invalidteam", + }) + + assert.Error(t, cmdErr, "CLI should output an error if we try to update a stack with a team that doesn't exists") + }) } From 128ae23c6c9685764f3b6639c407c2406fc7d24d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20BARRAS=20HAMPEL?= Date: Tue, 10 Dec 2024 09:51:52 +0100 Subject: [PATCH 71/71] [ci skip] remove changelog that doesn't belong here --- changelog/releases/v5.0.66.md | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 changelog/releases/v5.0.66.md diff --git a/changelog/releases/v5.0.66.md b/changelog/releases/v5.0.66.md deleted file mode 100644 index 137a7442..00000000 --- a/changelog/releases/v5.0.66.md +++ /dev/null @@ -1,5 +0,0 @@ -## [v5.0.66] _2024-07-04_ - -Cycloid CLI changelog: - -