Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 28 additions & 25 deletions internal/cmd/pipeline/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,43 @@ import (
)

type Pipeline struct {
Id string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
KsqlCluster string `json:"ksql_cluster"`
SecretNames []string `json:"secret_names"`
State string `json:"state"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Id string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
KsqlCluster string `json:"ksql_cluster"`
SecretNames []string `json:"secret_names"`
ActivationPrivilege bool `json:"activation_privilege"`
State string `json:"state"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}

var (
pipelineListFields = []string{"Id", "Name", "Description", "KsqlCluster", "State"}
pipelineListHumanLabels = []string{"ID", "Name", "Description", "KSQL Cluster", "State"}
pipelineListStructuredLabels = []string{"id", "name", "description", "ksql_cluster", "state"}
pipelineDescribeFields = []string{"Id", "Name", "Description", "KsqlCluster", "SecretNames", "State", "CreatedAt", "UpdatedAt"}
pipelineDescribeFields = []string{"Id", "Name", "Description", "KsqlCluster", "SecretNames", "ActivationPrivilege", "State", "CreatedAt", "UpdatedAt"}
pipelineDescribeHumanLabels = map[string]string{
"Id": "ID",
"Name": "Name",
"Description": "Description",
"KsqlCluster": "KSQL Cluster",
"SecretNames": "Secret Names",
"State": "State",
"CreatedAt": "Created At",
"UpdatedAt": "Updated At",
"Id": "ID",
"Name": "Name",
"Description": "Description",
"KsqlCluster": "KSQL Cluster",
"SecretNames": "Secret Names",
"ActivationPrivilege": "Activation Privilege",
"State": "State",
"CreatedAt": "Created At",
"UpdatedAt": "Updated At",
}
pipelineDescribeStructuredLabels = map[string]string{
"Id": "id",
"Name": "name",
"Description": "description",
"KsqlCluster": "ksql_cluster",
"SecretNames": "secret_names",
"State": "state",
"CreatedAt": "created_at",
"UpdatedAt": "updated_at",
"Id": "id",
"Name": "name",
"Description": "description",
"KsqlCluster": "ksql_cluster",
"SecretNames": "secret_names",
"ActivationPrivilege": "activation_privilege",
"State": "state",
"CreatedAt": "created_at",
"UpdatedAt": "updated_at",
}
secretMappingWithoutEmptyValue = `^([a-zA-Z_][a-zA-Z0-9_]*)=(.+)$`
secretMappingWithEmptyValue = `^([a-zA-Z_][a-zA-Z0-9_]*)=(.*)$`
Expand Down
17 changes: 9 additions & 8 deletions internal/cmd/pipeline/command_activate.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,15 @@ func (c *command) activate(cmd *cobra.Command, args []string) error {

// *pipeline.state will be activating
element := &Pipeline{
Id: *pipeline.Id,
Name: *pipeline.Spec.DisplayName,
Description: *pipeline.Spec.Description,
KsqlCluster: pipeline.Spec.KsqlCluster.Id,
SecretNames: getOrderedSecretNames(pipeline.Spec.Secrets),
State: *pipeline.Status.State,
CreatedAt: *pipeline.Metadata.CreatedAt,
UpdatedAt: *pipeline.Metadata.UpdatedAt,
Id: *pipeline.Id,
Name: *pipeline.Spec.DisplayName,
Description: *pipeline.Spec.Description,
KsqlCluster: pipeline.Spec.KsqlCluster.Id,
SecretNames: getOrderedSecretNames(pipeline.Spec.Secrets),
ActivationPrivilege: *pipeline.Spec.ActivationPrivilege,
State: *pipeline.Status.State,
CreatedAt: *pipeline.Metadata.CreatedAt,
UpdatedAt: *pipeline.Metadata.UpdatedAt,
}

return output.DescribeObject(cmd, element, pipelineDescribeFields, pipelineDescribeHumanLabels, pipelineDescribeStructuredLabels)
Expand Down
17 changes: 9 additions & 8 deletions internal/cmd/pipeline/command_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,15 @@ func (c *command) create(cmd *cobra.Command, args []string) error {
}

element := &Pipeline{
Id: *pipeline.Id,
Name: *pipeline.Spec.DisplayName,
Description: *pipeline.Spec.Description,
KsqlCluster: pipeline.Spec.KsqlCluster.Id,
SecretNames: getOrderedSecretNames(pipeline.Spec.Secrets),
State: *pipeline.Status.State,
CreatedAt: *pipeline.Metadata.CreatedAt,
UpdatedAt: *pipeline.Metadata.UpdatedAt,
Id: *pipeline.Id,
Name: *pipeline.Spec.DisplayName,
Description: *pipeline.Spec.Description,
KsqlCluster: pipeline.Spec.KsqlCluster.Id,
SecretNames: getOrderedSecretNames(pipeline.Spec.Secrets),
ActivationPrivilege: *pipeline.Spec.ActivationPrivilege,
State: *pipeline.Status.State,
CreatedAt: *pipeline.Metadata.CreatedAt,
UpdatedAt: *pipeline.Metadata.UpdatedAt,
}

return output.DescribeObject(cmd, element, pipelineDescribeFields, pipelineDescribeHumanLabels, pipelineDescribeStructuredLabels)
Expand Down
17 changes: 9 additions & 8 deletions internal/cmd/pipeline/command_deactivate.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,15 @@ func (c *command) deactivate(cmd *cobra.Command, args []string) error {

// *pipeline.state will be deactivating
element := &Pipeline{
Id: *pipeline.Id,
Name: *pipeline.Spec.DisplayName,
Description: *pipeline.Spec.Description,
KsqlCluster: pipeline.Spec.KsqlCluster.Id,
SecretNames: getOrderedSecretNames(pipeline.Spec.Secrets),
State: *pipeline.Status.State,
CreatedAt: *pipeline.Metadata.CreatedAt,
UpdatedAt: *pipeline.Metadata.UpdatedAt,
Id: *pipeline.Id,
Name: *pipeline.Spec.DisplayName,
Description: *pipeline.Spec.Description,
KsqlCluster: pipeline.Spec.KsqlCluster.Id,
SecretNames: getOrderedSecretNames(pipeline.Spec.Secrets),
ActivationPrivilege: *pipeline.Spec.ActivationPrivilege,
State: *pipeline.Status.State,
CreatedAt: *pipeline.Metadata.CreatedAt,
UpdatedAt: *pipeline.Metadata.UpdatedAt,
}

return output.DescribeObject(cmd, element, pipelineDescribeFields, pipelineDescribeHumanLabels, pipelineDescribeStructuredLabels)
Expand Down
17 changes: 9 additions & 8 deletions internal/cmd/pipeline/command_describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@ func (c *command) describe(cmd *cobra.Command, args []string) error {
}

element := &Pipeline{
Id: *pipeline.Id,
Name: *pipeline.Spec.DisplayName,
Description: *pipeline.Spec.Description,
KsqlCluster: pipeline.Spec.KsqlCluster.Id,
SecretNames: getOrderedSecretNames(pipeline.Spec.Secrets),
State: *pipeline.Status.State,
CreatedAt: *pipeline.Metadata.CreatedAt,
UpdatedAt: *pipeline.Metadata.UpdatedAt,
Id: *pipeline.Id,
Name: *pipeline.Spec.DisplayName,
Description: *pipeline.Spec.Description,
KsqlCluster: pipeline.Spec.KsqlCluster.Id,
SecretNames: getOrderedSecretNames(pipeline.Spec.Secrets),
ActivationPrivilege: *pipeline.Spec.ActivationPrivilege,
State: *pipeline.Status.State,
CreatedAt: *pipeline.Metadata.CreatedAt,
UpdatedAt: *pipeline.Metadata.UpdatedAt,
}

return output.DescribeObject(cmd, element, pipelineDescribeFields, pipelineDescribeHumanLabels, pipelineDescribeStructuredLabels)
Expand Down
36 changes: 25 additions & 11 deletions internal/cmd/pipeline/command_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ func (c *command) newUpdateCommand(prerunner pcmd.PreRunner, enableSourceCode bo
Text: `Request to update Stream Designer pipeline "pipe-12345", with new name and new description.`,
Code: `confluent pipeline update pipe-12345 --name test-pipeline --description "Description of the pipeline"`,
},
examples.Example{
Text: `Grant privilege to activate Stream Designer pipeline "pipe-12345".`,
Code: `confluent pipeline update pipe-12345 --activation-privilege true`,
},
examples.Example{
Text: `Revoke privilege to activate Stream Designer pipeline "pipe-12345".`,
Code: `confluent pipeline update pipe-12345 --activation-privilege false`,
},
),
}

Expand All @@ -34,7 +42,7 @@ func (c *command) newUpdateCommand(prerunner pcmd.PreRunner, enableSourceCode bo
"where <secret-name> consists of 1-128 lowercase, uppercase, numeric or underscore characters but may not begin with a digit.\n"+
"If <secret-value> is empty, the named secret will be removed from Stream Designer.")
}

cmd.Flags().Bool("activation-privilege", true, "Grant or revoke the privilege to active this pipeline.")
pcmd.AddOutputFlag(cmd)
pcmd.AddClusterFlag(cmd, c.AuthenticatedCLICommand)
pcmd.AddEnvironmentFlag(cmd, c.AuthenticatedCLICommand)
Expand All @@ -53,8 +61,8 @@ func (c *command) update(cmd *cobra.Command, args []string) error {
return err
}

if name == "" && description == "" && sqlFile == "" && len(secrets) == 0 {
return fmt.Errorf("one of the update options must be provided: --name, --description, --sql-file, --secret")
if name == "" && description == "" && sqlFile == "" && len(secrets) == 0 && !cmd.Flags().Changed("activation-privilege") {
return fmt.Errorf("one of the update options must be provided: --name, --description, --sql-file, --secret, --activation-privilege")
}

updatePipeline := streamdesignerv1.SdV1PipelineUpdate{Spec: &streamdesignerv1.SdV1PipelineSpecUpdate{}}
Expand All @@ -80,21 +88,27 @@ func (c *command) update(cmd *cobra.Command, args []string) error {
}
updatePipeline.Spec.SetSecrets(secretMappings)

if cmd.Flags().Changed("activation-privilege") {
activationPrivilege, _ := cmd.Flags().GetBool("activation-privilege")
updatePipeline.Spec.SetActivationPrivilege(activationPrivilege)
}

// call api
pipeline, err := c.V2Client.UpdateSdPipeline(c.EnvironmentId(), cluster.ID, args[0], updatePipeline)
if err != nil {
return err
}

element := &Pipeline{
Id: *pipeline.Id,
Name: *pipeline.Spec.DisplayName,
Description: *pipeline.Spec.Description,
KsqlCluster: pipeline.Spec.KsqlCluster.Id,
SecretNames: getOrderedSecretNames(pipeline.Spec.Secrets),
State: *pipeline.Status.State,
CreatedAt: *pipeline.Metadata.CreatedAt,
UpdatedAt: *pipeline.Metadata.UpdatedAt,
Id: *pipeline.Id,
Name: *pipeline.Spec.DisplayName,
Description: *pipeline.Spec.Description,
KsqlCluster: pipeline.Spec.KsqlCluster.Id,
SecretNames: getOrderedSecretNames(pipeline.Spec.Secrets),
ActivationPrivilege: *pipeline.Spec.ActivationPrivilege,
State: *pipeline.Status.State,
CreatedAt: *pipeline.Metadata.CreatedAt,
UpdatedAt: *pipeline.Metadata.UpdatedAt,
}

return output.DescribeObject(cmd, element, pipelineDescribeFields, pipelineDescribeHumanLabels, pipelineDescribeStructuredLabels)
Expand Down
21 changes: 11 additions & 10 deletions test/fixtures/output/pipeline/activate.golden
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
+--------------+-------------------------------+
| ID | pipe-12345 |
| Name | testPipeline |
| Description | description |
| KSQL Cluster | lksqlc-12345 |
| Secret Names | [name1 name2 name3] |
| State | activating |
| Created At | 2022-10-04 06:00:00 +0000 UTC |
| Updated At | 2022-10-06 06:00:00 +0000 UTC |
+--------------+-------------------------------+
+----------------------+-------------------------------+
| ID | pipe-12345 |
| Name | testPipeline |
| Description | description |
| KSQL Cluster | lksqlc-12345 |
| Secret Names | [name1 name2 name3] |
| Activation Privilege | false |
| State | activating |
| Created At | 2022-10-04 06:00:00 +0000 UTC |
| Updated At | 2022-10-06 06:00:00 +0000 UTC |
+----------------------+-------------------------------+
23 changes: 12 additions & 11 deletions test/fixtures/output/pipeline/create-with-secret-names.golden
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
+--------------+-----------------------------------------------------------------------------------------------------------------------------------+
| ID | pipe-12345 |
| Name | testPipeline |
| Description | description |
| KSQL Cluster | lksqlc-12345 |
| Secret Names | [a_really_really_really_really_really_really_really_really_really_really_really_really_long_secret_name_but_not_exceeding_128_yet |
| | name1 name2 name3] |
| State | draft |
| Created At | 2022-10-04 06:00:00 +0000 UTC |
| Updated At | 2022-10-06 06:00:00 +0000 UTC |
+--------------+-----------------------------------------------------------------------------------------------------------------------------------+
+----------------------+-----------------------------------------------------------------------------------------------------------------------------------+
| ID | pipe-12345 |
| Name | testPipeline |
| Description | description |
| KSQL Cluster | lksqlc-12345 |
| Secret Names | [a_really_really_really_really_really_really_really_really_really_really_really_really_long_secret_name_but_not_exceeding_128_yet |
| | name1 name2 name3] |
| Activation Privilege | false |
| State | draft |
| Created At | 2022-10-04 06:00:00 +0000 UTC |
| Updated At | 2022-10-06 06:00:00 +0000 UTC |
+----------------------+-----------------------------------------------------------------------------------------------------------------------------------+
21 changes: 11 additions & 10 deletions test/fixtures/output/pipeline/create.golden
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
+--------------+-------------------------------+
| ID | pipe-12345 |
| Name | testPipeline |
| Description | description |
| KSQL Cluster | lksqlc-12345 |
| Secret Names | [] |
| State | draft |
| Created At | 2022-10-04 06:00:00 +0000 UTC |
| Updated At | 2022-10-06 06:00:00 +0000 UTC |
+--------------+-------------------------------+
+----------------------+-------------------------------+
| ID | pipe-12345 |
| Name | testPipeline |
| Description | description |
| KSQL Cluster | lksqlc-12345 |
| Secret Names | [] |
| Activation Privilege | false |
| State | draft |
| Created At | 2022-10-04 06:00:00 +0000 UTC |
| Updated At | 2022-10-06 06:00:00 +0000 UTC |
+----------------------+-------------------------------+
21 changes: 11 additions & 10 deletions test/fixtures/output/pipeline/deactivate.golden
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
+--------------+-------------------------------+
| ID | pipe-12345 |
| Name | testPipeline |
| Description | description |
| KSQL Cluster | lksqlc-12345 |
| Secret Names | [name1 name2 name3] |
| State | deactivating |
| Created At | 2022-10-04 06:00:00 +0000 UTC |
| Updated At | 2022-10-06 06:00:00 +0000 UTC |
+--------------+-------------------------------+
+----------------------+-------------------------------+
| ID | pipe-12345 |
| Name | testPipeline |
| Description | description |
| KSQL Cluster | lksqlc-12345 |
| Secret Names | [name1 name2 name3] |
| Activation Privilege | false |
| State | deactivating |
| Created At | 2022-10-04 06:00:00 +0000 UTC |
| Updated At | 2022-10-06 06:00:00 +0000 UTC |
+----------------------+-------------------------------+
21 changes: 11 additions & 10 deletions test/fixtures/output/pipeline/describe-pass.golden
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
+--------------+-------------------------------+
| ID | pipe-12345 |
| Name | testPipeline |
| Description | description |
| KSQL Cluster | lksqlc-12345 |
| Secret Names | [name1 name2] |
| State | draft |
| Created At | 2022-10-04 06:00:00 +0000 UTC |
| Updated At | 2022-10-06 06:00:00 +0000 UTC |
+--------------+-------------------------------+
+----------------------+-------------------------------+
| ID | pipe-12345 |
| Name | testPipeline |
| Description | description |
| KSQL Cluster | lksqlc-12345 |
| Secret Names | [name1 name2] |
| Activation Privilege | false |
| State | draft |
| Created At | 2022-10-04 06:00:00 +0000 UTC |
| Updated At | 2022-10-06 06:00:00 +0000 UTC |
+----------------------+-------------------------------+
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
+----------------------+-------------------------------+
| ID | pipe-12345 |
| Name | testPipeline |
| Description | description |
| KSQL Cluster | lksqlc-12345 |
| Secret Names | [name1 name2 name3] |
| Activation Privilege | true |
| State | draft |
| Created At | 2022-10-04 06:00:00 +0000 UTC |
| Updated At | 2022-10-06 06:00:00 +0000 UTC |
+----------------------+-------------------------------+
Loading