Skip to content

Commit 9551c3b

Browse files
committed
prepare cli for the versioning feature
1 parent 821f8be commit 9551c3b

40 files changed

+1052
-207
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*.dll
88
*.so
99
*.dylib
10+
cycloid-cli
1011

1112
# Test binary, built with `go test -c`
1213
*.test
@@ -30,4 +31,3 @@ gst
3031
# direnv
3132
.direnv
3233

33-
cycloid-cli

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,4 +152,3 @@ ci-test:
152152

153153
.git/hooks/pre-commit:
154154
pre-commit-install
155-

cmd/cycloid/beta/config/interpolate.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ func NewInterpolateCmd() *cobra.Command {
2525
cyargs.AddStackRefFlag(cmd)
2626
cyargs.AddCyContext(cmd)
2727
cyargs.AddStackFormsInputFlags(cmd)
28+
cyargs.AddStackVersionFlags(cmd)
2829
return cmd
2930
}
3031

@@ -57,8 +58,14 @@ func interpolate(cmd *cobra.Command, args []string) error {
5758
api := common.NewAPI()
5859
m := middleware.NewMiddleware(api)
5960

61+
// Get the stack version flags
62+
tag, branch, hash, err := cyargs.GetStackVersionFlags(cmd)
63+
if err != nil {
64+
return errors.Wrap(err, "failed to read stack version flags")
65+
}
66+
6067
// Get default to stacks
61-
stackConfig, err := m.GetComponentStackConfig(org, project, env, component, useCase)
68+
stackConfig, err := m.GetComponentStackConfig(org, project, env, component, useCase, tag, branch, hash)
6269
if err != nil {
6370
return err
6471
}

cmd/cycloid/components/create.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ func NewCreateComponentCommand() *cobra.Command {
2727
cyargs.AddNameFlag(cmd)
2828
cyargs.AddComponentDescriptionFlag(cmd)
2929
cmd.MarkFlagRequired(cyargs.AddUseCaseFlag(cmd))
30+
cyargs.AddStackVersionFlags(cmd)
3031
cyargs.AddCloudProviderFlag(cmd)
31-
cyargs.AddComponentStackRefFlag(cmd)
32+
cmd.MarkFlagRequired(cyargs.AddComponentStackRefFlag(cmd))
3233
cyargs.AddStackFormsInputFlags(cmd)
3334
cmd.Flags().Bool("update", false, "If the component exists, update it.")
3435
return cmd
@@ -83,6 +84,12 @@ func createComponent(cmd *cobra.Command, args []string) error {
8384
api := common.NewAPI()
8485
m := middleware.NewMiddleware(api)
8586

87+
// Get the stack version flags
88+
tag, branch, hash, err := cyargs.GetStackVersionFlags(cmd)
89+
if err != nil {
90+
return errors.Wrap(err, "failed to read stack version flags")
91+
}
92+
8693
p, err := factory.GetPrinter(output)
8794
if err != nil {
8895
return errors.Wrap(err, "unable to get printer")
@@ -115,7 +122,7 @@ func createComponent(cmd *cobra.Command, args []string) error {
115122
}
116123

117124
// ConfigureComponent will reconfigure the component
118-
componentOutput, err := m.CreateAndConfigureComponent(org, project, env, component, *description, &name, stackRef, useCase, *cloudProvider, inputs)
125+
componentOutput, err := m.CreateAndConfigureComponent(org, project, env, component, *description, name, stackRef, tag, branch, hash, useCase, *cloudProvider, inputs)
119126
if err != nil {
120127
return printer.SmartPrint(p, nil, err, "failed to configure component '"+component+"'", printer.Options{}, cmd.OutOrStderr())
121128
}
@@ -134,7 +141,7 @@ func createComponent(cmd *cobra.Command, args []string) error {
134141
return err
135142
}
136143

137-
componentOutput, err := m.CreateAndConfigureComponent(org, project, env, component, *description, &name, stackRef, useCase, *cloudProvider, inputs)
144+
componentOutput, err := m.CreateAndConfigureComponent(org, project, env, component, *description, name, stackRef, tag, branch, hash, useCase, *cloudProvider, inputs)
138145
if err != nil {
139146
return printer.SmartPrint(p, nil, err, "failed to create and configure component '"+component+"'", printer.Options{}, cmd.OutOrStderr())
140147
}

cmd/cycloid/components/update.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ func NewUpdateComponentCommand() *cobra.Command {
2525
cyargs.AddNameFlag(cmd)
2626
cyargs.AddComponentDescriptionFlag(cmd)
2727
cyargs.AddUseCaseFlag(cmd)
28+
cyargs.AddStackVersionFlags(cmd)
2829
cyargs.AddStackFormsInputFlags(cmd)
2930
cyargs.AddStackRefFlag(cmd)
3031
cyargs.AddCloudProviderFlag(cmd)
32+
3133
return cmd
3234
}
3335

@@ -42,6 +44,11 @@ func updateComponent(cmd *cobra.Command, args []string) error {
4244
return err
4345
}
4446

47+
if name == "" {
48+
// if name is empty, use the canonical
49+
name = component
50+
}
51+
4552
description, err := cyargs.GetComponentDescription(cmd)
4653
if err != nil {
4754
return err
@@ -90,6 +97,12 @@ func updateComponent(cmd *cobra.Command, args []string) error {
9097
useCase = currentComponent.UseCase
9198
}
9299

100+
// Get the stack version flags
101+
tag, branch, hash, err := cyargs.GetStackVersionFlags(cmd)
102+
if err != nil {
103+
return errors.Wrap(err, "failed to read stack version flags")
104+
}
105+
93106
var currentConfig = make(models.FormVariables)
94107
if currentComponent.IsConfigured {
95108
currentConfig, err = m.GetComponentConfig(org, project, env, component)
@@ -104,7 +117,7 @@ func updateComponent(cmd *cobra.Command, args []string) error {
104117
}
105118

106119
// CreateComponent will reconfigure the component if it already exists
107-
updatedComponent, err := m.CreateAndConfigureComponent(org, project, env, component, *description, &name, stackRef, useCase, *cloudProvider, inputs)
120+
updatedComponent, err := m.CreateAndConfigureComponent(org, project, env, component, *description, name, stackRef, tag, branch, hash, useCase, *cloudProvider, inputs)
108121
if err != nil {
109122
return printer.SmartPrint(p, nil, err, "failed to configure component '"+component+"'", printer.Options{}, cmd.OutOrStderr())
110123
}

cmd/cycloid/middleware/component_pipelines_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@ package middleware_test
22

33
import (
44
"fmt"
5-
"reflect"
65
"strconv"
76
"testing"
87
"time"
8+
9+
"github.com/stretchr/testify/require"
910
)
1011

1112
func TestComponentPipeline(t *testing.T) {
1213
m := config.Middleware
1314

1415
component, err := config.NewTestComponent(
15-
*config.Project.Canonical, *config.Environment.Canonical, t.Name(), config.Org+":"+pipelineTestStackCanonical, pipelineTestStackUseCase, pipelineTestDefaultVars,
16+
*config.Project.Canonical, *config.Environment.Canonical, t.Name(), config.Org+":"+pipelineTestStackCanonical, pipelineTestStackUseCase, "", "", *config.CatalogRepoVersionStacks.CommitHash, pipelineTestDefaultVars,
1617
)
1718
if err != nil {
1819
t.Errorf("failed to setup base component for test %q: %v", t.Name(), err)
@@ -26,9 +27,8 @@ func TestComponentPipeline(t *testing.T) {
2627
return
2728
}
2829

29-
if !reflect.DeepEqual(*got.Component, *component) {
30-
t.Fatalf("component in pipeline doesn't match, got:\n%v\nexpect: %v", *got.Component, *component)
31-
}
30+
got.Component.Project.Owner = component.Project.Owner
31+
require.Equal(t, *got.Component, *component)
3232
})
3333

3434
t.Run("PausePipeline", func(t *testing.T) {
@@ -129,15 +129,15 @@ jobs:
129129

130130
err = m.AbortBuild(config.Org, *config.Project.Canonical, *config.Environment.Canonical, *component.Canonical, *updatedPipeline.Name, *pipelineJobs[0].Name, buildIDStr)
131131
if err != nil {
132-
t.Fatalf("failed to abort build '%s': %s", buildIDStr, err)
132+
t.Errorf("failed to abort build '%s': %s", buildIDStr, err)
133133
}
134134

135135
// // Add a bit of time, concourse seems to not like it
136136
// time.Sleep(3 * time.Second)
137137
//
138138
// _, err = m.RerunBuild(config.Org, *config.Project.Canonical, *config.Environment.Canonical, *component.Canonical, *updatedPipeline.Name, *pipelineJobs[0].Name, buildIDStr)
139139
// if err != nil {
140-
// t.Fatalf("failed to re-run build '%s': %s", buildIDStr, err)
140+
// t.Errorf("failed to re-run build '%s': %s", buildIDStr, err)
141141
// }
142142
})
143143
})

cmd/cycloid/middleware/infra_policies.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func (m *middleware) CreateInfraPolicy(org, policyFile, policyCanonical, descrip
4444
// Reads file content and converts it into string
4545
policyFileContent, err := os.ReadFile(policyFile)
4646
if err != nil {
47-
return nil, fmt.Errorf("unable to read rego file: %v", err)
47+
return nil, fmt.Errorf("unable to read rego file: %w", err)
4848
}
4949
// If canonical empty,use the default one
5050
if policyCanonical == "" {
@@ -64,7 +64,7 @@ func (m *middleware) CreateInfraPolicy(org, policyFile, policyCanonical, descrip
6464

6565
err = body.Validate(strfmt.Default)
6666
if err != nil {
67-
return nil, fmt.Errorf("InfraPolicy invalid: %v", err)
67+
return nil, fmt.Errorf("InfraPolicy invalid: %w", err)
6868
}
6969

7070
params.SetBody(body)
@@ -131,7 +131,7 @@ func (m *middleware) UpdateInfraPolicy(org, infraPolicy, policyFile, description
131131
// Reads file content and converts it into string
132132
policyFileContent, err := os.ReadFile(policyFile)
133133
if err != nil {
134-
return nil, fmt.Errorf("unable to read rego file: %v", err)
134+
return nil, fmt.Errorf("unable to read rego file: %w", err)
135135
}
136136
policyBody := string(policyFileContent)
137137

@@ -146,7 +146,7 @@ func (m *middleware) UpdateInfraPolicy(org, infraPolicy, policyFile, description
146146

147147
err = body.Validate(strfmt.Default)
148148
if err != nil {
149-
return nil, fmt.Errorf("InfraPolicy invalid: %v", err)
149+
return nil, fmt.Errorf("InfraPolicy invalid: %w", err)
150150
}
151151

152152
params.SetBody(body)

cmd/cycloid/middleware/init_first_org.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import (
1414
// current console.
1515
// If apiKeyCanonical != nil, will also create an api key admin and add it to a
1616
// credential.
17-
func (m *middleware) InitFirstOrg(org, username, fullName, email, password, licence string, apiKeyCanonical *string) (*FirstOrgData, error) {
18-
err := m.UserSignup(username, email, password, fullName)
17+
func (m *middleware) InitFirstOrg(org, userName, fullName, email, password, licence string, apiKeyCanonical *string) (*FirstOrgData, error) {
18+
err := m.UserSignup(userName, email, password, fullName)
1919
var signupErr *APIError
2020
if errors.As(err, &signupErr) {
2121
if signupErr.HTTPCode != "409" && err != nil {
@@ -50,7 +50,7 @@ func (m *middleware) InitFirstOrg(org, username, fullName, email, password, lice
5050

5151
output := &FirstOrgData{
5252
Org: org,
53-
Username: username,
53+
Username: userName,
5454
FullName: fullName,
5555
Email: email,
5656
Password: password,

cmd/cycloid/middleware/middleware.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ type Middleware interface {
3535
GetStack(org, ref string) (*models.ServiceCatalog, error)
3636
UpdateStack(org, ref, teamCanonical string, visibility *string) (*models.ServiceCatalog, error)
3737
ListStacks(org string) ([]*models.ServiceCatalog, error)
38-
ListStackUseCases(org, ref string) ([]*models.StackUseCase, error)
38+
ListStackUseCases(org, ref, versionTag, versionBranch, versionCommitHash string) ([]*models.StackUseCase, error)
39+
ListStackVersions(org, ref string) ([]*models.ServiceCatalogSourceVersion, error)
3940
ListBlueprints(org string) ([]*models.ServiceCatalog, error)
4041
CreateStackFromBlueprint(org, blueprintRef, name, stack, catalogRepository, useCase string) (*models.ServiceCatalog, error)
4142

@@ -133,16 +134,16 @@ type Middleware interface {
133134
DeleteEnv(org, project, env string) error
134135

135136
// Component
136-
CreateComponent(org, project, env, component, description string, componentName, serviceCatalogRef *string, cloudProviderCanonical string) (*models.Component, error)
137+
CreateComponent(org, project, env, component, description, componentName, serviceCatalogRef, versionTag, versionBranch, versionCommitHash, cloudProviderCanonical string) (*models.Component, error)
137138
UpdateComponent(org, project, env, component, description string, componentName *string) (*models.Component, error)
138-
CreateAndConfigureComponent(org, project, env, component, description string, componentName *string, serviceCatalogRef, useCase, cloudProviderCanonical string, vars models.FormVariables) (*models.Component, error)
139+
CreateAndConfigureComponent(org, project, env, component, description, componentName, serviceCatalogRef, versionTag, versionBranch, versionCommitHash, useCase, cloudProviderCanonical string, vars models.FormVariables) (*models.Component, error)
139140
ConfigureComponent(org, project, env, component, useCase string, vars models.FormVariables) error
140141
ListComponents(org, project, env string) ([]*models.Component, error)
141142
GetComponent(org, project, env, component string) (*models.Component, error)
142143
MigrateComponent(org, project, env, component, targetProject, targetEnv, newCanonical, newName string) (*models.Component, error)
143144
DeleteComponent(org, project, env, component string) error
144145
GetComponentConfig(org, project, env, component string) (models.FormVariables, error)
145-
GetComponentStackConfig(org, project, env, component, useCase string) (models.ServiceCatalogConfigs, error)
146+
GetComponentStackConfig(org, project, env, component, useCase, versionTag, versionBranch, versionCommitHash string) (models.ServiceCatalogConfigs, error)
146147

147148
DeleteRole(org, role string) error
148149
GetRole(org, role string) (*models.Role, error)
@@ -170,7 +171,7 @@ type Middleware interface {
170171
CostEstimation(org string, plan []byte) (*models.CostEstimationResult, error)
171172

172173
// Extra actions out of the api
173-
InitFirstOrg(org, username, fullName, email, password, licence string, apiKeyCanonical *string) (*FirstOrgData, error)
174+
InitFirstOrg(org, userName, fullName, email, password, licence string, apiKeyCanonical *string) (*FirstOrgData, error)
174175
}
175176

176177
type FirstOrgData struct {

cmd/cycloid/middleware/middleware_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func runMain(ctx context.Context, main *testing.M) (int, error) {
2020
config, err = testcfg.NewConfig("middleware")
2121
defer config.Cleanup()
2222
if err != nil {
23-
return 1, fmt.Errorf("Config setup failed for package middleware: %v", err)
23+
return 1, fmt.Errorf("config setup failed for package middleware: %w", err)
2424
}
2525

2626
os.Setenv("CY_API_URL", config.APIUrl)

0 commit comments

Comments
 (0)