Skip to content
Open
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
10 changes: 7 additions & 3 deletions internal/connect/command_artifact_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
}

cmd.Flags().String("artifact-file", "", "Connect artifact JAR file or ZIP file.")
pcmd.AddCloudAwsAzureFlag(cmd)
pcmd.AddCloudFlag(cmd)
pcmd.AddEnvironmentFlag(cmd, c.AuthenticatedCLICommand)
cmd.Flags().String("description", "", "Specify the Connect artifact description.")
pcmd.AddContextFlag(cmd, c.CLICommand)
Expand All @@ -47,7 +47,7 @@
return cmd
}

func (c *artifactCommand) createArtifact(cmd *cobra.Command, args []string) error {

Check failure on line 50 in internal/connect/command_artifact_create.go

View check run for this annotation

SonarQube-Confluent / SonarQube Code Analysis

Refactor this method to reduce its Cognitive Complexity from 18 to the 15 allowed.

[S3776] Cognitive Complexity of functions should not be too high See more on https://sonarqube.confluent.io/project/issues?id=cli&pullRequest=3255&issues=35da8b24-b2bd-49c7-bca7-a4c147da1b04&open=35da8b24-b2bd-49c7-bca7-a4c147da1b04
displayName := args[0]
artifactFile, err := cmd.Flags().GetString("artifact-file")
if err != nil {
Expand Down Expand Up @@ -80,9 +80,9 @@
Environment: camv1.PtrString(environment),
}

supportedClouds := []string{"aws", "azure"}
supportedClouds := []string{"aws", "azure", "gcp"}
if !slices.Contains(supportedClouds, strings.ToLower(cloud)) {
return fmt.Errorf("only clouds supported are `AWS` and `AZURE`")
return fmt.Errorf("only clouds supported are `AWS`, `AZURE` and `GCP`")
}

resp, err := c.V2Client.GetArtifactPresignedUrl(request)
Expand All @@ -94,6 +94,10 @@
if err := utils.UploadFileToAzureBlob(resp.GetUploadUrl(), artifactFile, strings.ToLower(resp.GetContentFormat())); err != nil {
return err
}
} else if strings.ToLower(cloud) == "gcp" {
if err := utils.UploadFileToGoogleCloudStorage(resp.GetUploadUrl(), artifactFile, strings.ToLower(resp.GetContentFormat())); err != nil {
return err
}
} else {
if err := utils.UploadFile(resp.GetUploadUrl(), artifactFile, resp.GetUploadFormData()); err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion internal/connect/command_artifact_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (c *artifactCommand) newDeleteCommand() *cobra.Command {
),
}

pcmd.AddCloudAwsAzureFlag(cmd)
pcmd.AddCloudFlag(cmd)
pcmd.AddEnvironmentFlag(cmd, c.AuthenticatedCLICommand)
pcmd.AddContextFlag(cmd, c.CLICommand)
pcmd.AddForceFlag(cmd)
Expand Down
2 changes: 1 addition & 1 deletion internal/connect/command_artifact_describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (c *artifactCommand) newDescribeCommand() *cobra.Command {
),
}

pcmd.AddCloudAwsAzureFlag(cmd)
pcmd.AddCloudFlag(cmd)
pcmd.AddEnvironmentFlag(cmd, c.AuthenticatedCLICommand)
pcmd.AddContextFlag(cmd, c.CLICommand)
pcmd.AddOutputFlag(cmd)
Expand Down
2 changes: 1 addition & 1 deletion internal/connect/command_artifact_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (c *artifactCommand) newListCommand() *cobra.Command {
),
}

pcmd.AddCloudAwsAzureFlag(cmd)
pcmd.AddCloudFlag(cmd)
pcmd.AddEnvironmentFlag(cmd, c.AuthenticatedCLICommand)
pcmd.AddContextFlag(cmd, c.CLICommand)
pcmd.AddOutputFlag(cmd)
Expand Down
15 changes: 14 additions & 1 deletion test/connect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (s *CLITestSuite) TestConnectArtifact() {
tests := []CLITest{
{args: `connect artifact create my-connect-artifact-jar --artifact-file "test/fixtures/input/connect/artifact-example.jar" --cloud aws --environment env-123456 --description new-jar-artifact`, fixture: "connect/artifact/create-jar.golden"},
{args: `connect artifact create my-connect-artifact-zip --artifact-file "test/fixtures/input/connect/artifact-example.zip" --cloud aws --environment env-123456 --description new-zip-artifact`, fixture: "connect/artifact/create-zip.golden"},
{args: `connect artifact create my-connect-artifact --artifact-file "test/fixtures/input/connect/artifact-example.zip" --cloud gcp --environment env-123456 --description new-invalid-artifact`, fixture: "connect/artifact/create-invalid-cloud-type.golden", exitCode: 1},
{args: `connect artifact create my-connect-artifact --artifact-file "test/fixtures/input/connect/artifact-example.zip" --cloud invalid --environment env-123456 --description new-invalid-artifact`, fixture: "connect/artifact/create-invalid-cloud-type.golden", exitCode: 1},
{args: `connect artifact create my-connect-artifact --artifact-file "test/fixtures/input/connect/artifact-example.jpg" --cloud aws --environment env-123456 --description new-invalid-artifact`, fixture: "connect/artifact/create-invalid-file-type.golden", exitCode: 1},
{args: "connect artifact list --cloud aws --environment env-123456", fixture: "connect/artifact/list.golden"},
{args: "connect artifact list --cloud aws --environment env-123456 -o json", fixture: "connect/artifact/list-json.golden"},
Expand All @@ -76,6 +76,19 @@ func (s *CLITestSuite) TestConnectArtifact() {
{args: "connect artifact describe cfa-azure-jar123 --cloud azure --environment env-123456 -o yaml", fixture: "connect/artifact/describe-azure-yaml.golden"},
{args: "connect artifact delete cfa-azure-zip123 --cloud azure --environment env-123456 --force", fixture: "connect/artifact/delete-azure-force.golden"},
{args: "connect artifact delete cfa-azure-zip123 --cloud azure --environment env-123456", input: "y\n", fixture: "connect/artifact/delete-azure-prompt.golden"},

// GCP tests
{args: `connect artifact create my-connect-artifact-gcp-jar --artifact-file "test/fixtures/input/connect/artifact-example.jar" --cloud gcp --environment env-123456 --description new-jar-artifact`, fixture: "connect/artifact/create-gcp-jar.golden"},
{args: `connect artifact create my-connect-artifact-gcp-zip --artifact-file "test/fixtures/input/connect/artifact-example.zip" --cloud gcp --environment env-123456 --description new-zip-artifact`, fixture: "connect/artifact/create-gcp-zip.golden"},
{args: "connect artifact list --cloud gcp --environment env-123456", fixture: "connect/artifact/list-gcp.golden"},
{args: "connect artifact list --cloud gcp --environment env-123456 -o json", fixture: "connect/artifact/list-gcp-json.golden"},
{args: "connect artifact list --cloud gcp --environment env-123456 -o yaml", fixture: "connect/artifact/list-gcp-yaml.golden"},
{args: "connect artifact describe cfa-gcp-zip123 --cloud gcp --environment env-123456", fixture: "connect/artifact/describe-gcp-zip.golden"},
{args: "connect artifact describe cfa-gcp-jar123 --cloud gcp --environment env-123456", fixture: "connect/artifact/describe-gcp-jar.golden"},
{args: "connect artifact describe cfa-gcp-jar123 --cloud gcp --environment env-123456 -o json", fixture: "connect/artifact/describe-gcp-json.golden"},
{args: "connect artifact describe cfa-gcp-jar123 --cloud gcp --environment env-123456 -o yaml", fixture: "connect/artifact/describe-gcp-yaml.golden"},
{args: "connect artifact delete cfa-gcp-zip123 --cloud gcp --environment env-123456 --force", fixture: "connect/artifact/delete-gcp-force.golden"},
{args: "connect artifact delete cfa-gcp-zip123 --cloud gcp --environment env-123456", input: "y\n", fixture: "connect/artifact/delete-gcp-prompt.golden"},
}

for _, test := range tests {
Expand Down
9 changes: 9 additions & 0 deletions test/fixtures/output/connect/artifact/create-gcp-jar.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
+----------------+-----------------------------+
| ID | cfa-gcp-jar123 |
| Name | my-connect-artifact-gcp-jar |
| Description | new-jar-artifact |
| Cloud | GCP |
| Environment | env-123456 |
| Content Format | JAR |
| Status | PROCESSING |
+----------------+-----------------------------+
9 changes: 9 additions & 0 deletions test/fixtures/output/connect/artifact/create-gcp-zip.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
+----------------+-----------------------------+
| ID | cfa-gcp-zip123 |
| Name | my-connect-artifact-gcp-zip |
| Description | new-zip-artifact |
| Cloud | GCP |
| Environment | env-123456 |
| Content Format | ZIP |
| Status | PROCESSING |
+----------------+-----------------------------+
2 changes: 1 addition & 1 deletion test/fixtures/output/connect/artifact/create-help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Create Connect artifact "my-connect-artifact".

Flags:
--artifact-file string REQUIRED: Connect artifact JAR file or ZIP file.
--cloud string REQUIRED: Specify the cloud provider as "aws" or "azure".
--cloud string REQUIRED: Specify the cloud provider as "aws", "azure", or "gcp".
--environment string Environment ID.
--description string Specify the Connect artifact description.
--context string CLI context name.
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Error: only clouds supported are `AWS` and `AZURE`
Error: only clouds supported are `AWS`, `AZURE` and `GCP`
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Deleted Connect Artifact "cfa-gcp-zip123".
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Are you sure you want to delete Connect Artifact "cfa-gcp-zip123"? (y/n): Deleted Connect Artifact "cfa-gcp-zip123".
2 changes: 1 addition & 1 deletion test/fixtures/output/connect/artifact/delete-help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Delete Connect artifact.
$ confluent connect artifact delete cfa-abc123 --cloud aws --environment env-abc123

Flags:
--cloud string REQUIRED: Specify the cloud provider as "aws" or "azure".
--cloud string REQUIRED: Specify the cloud provider as "aws", "azure", or "gcp".
--environment string Environment ID.
--context string CLI context name.
--force Skip the deletion confirmation prompt.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
+----------------+-----------------------------+
| ID | cfa-gcp-jar123 |
| Name | my-connect-artifact-gcp-jar |
| Description | new-jar-artifact |
| Cloud | GCP |
| Environment | env-123456 |
| Content Format | JAR |
| Status | READY |
+----------------+-----------------------------+
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"id": "cfa-gcp-jar123",
"name": "my-connect-artifact-gcp-jar",
"description": "new-jar-artifact",
"cloud": "GCP",
"environment": "env-123456",
"content_format": "JAR",
"status": "READY"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
id: cfa-gcp-jar123
name: my-connect-artifact-gcp-jar
description: new-jar-artifact
cloud: GCP
environment: env-123456
content_format: JAR
status: READY
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
+----------------+-----------------------------+
| ID | cfa-gcp-zip123 |
| Name | my-connect-artifact-gcp-zip |
| Description | new-zip-artifact |
| Cloud | GCP |
| Environment | env-123456 |
| Content Format | ZIP |
| Status | PROCESSING |
+----------------+-----------------------------+
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Describe a Connect artifact.
$ confluent connect artifact describe cfa-abc123 --cloud aws --environment env-abc123

Flags:
--cloud string REQUIRED: Specify the cloud provider as "aws" or "azure".
--cloud string REQUIRED: Specify the cloud provider as "aws", "azure", or "gcp".
--environment string Environment ID.
--context string CLI context name.
-o, --output string Specify the output format as "human", "json", or "yaml". (default "human")
Expand Down
20 changes: 20 additions & 0 deletions test/fixtures/output/connect/artifact/list-gcp-json.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[
{
"id": "cfa-gcp-jar123",
"name": "my-connect-artifact-gcp-jar",
"description": "new-jar-artifact",
"cloud": "GCP",
"environment": "env-123456",
"content_format": "JAR",
"status": "READY"
},
{
"id": "cfa-gcp-zip123",
"name": "my-connect-artifact-gcp-zip",
"description": "new-zip-artifact",
"cloud": "GCP",
"environment": "env-123456",
"content_format": "ZIP",
"status": "PROCESSING"
}
]
14 changes: 14 additions & 0 deletions test/fixtures/output/connect/artifact/list-gcp-yaml.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
- id: cfa-gcp-jar123
name: my-connect-artifact-gcp-jar
description: new-jar-artifact
cloud: GCP
environment: env-123456
content_format: JAR
status: READY
- id: cfa-gcp-zip123
name: my-connect-artifact-gcp-zip
description: new-zip-artifact
cloud: GCP
environment: env-123456
content_format: ZIP
status: PROCESSING
4 changes: 4 additions & 0 deletions test/fixtures/output/connect/artifact/list-gcp.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ID | Name | Description | Cloud | Environment | Content Format | Status
-----------------+-----------------------------+------------------+-------+-------------+----------------+-------------
cfa-gcp-jar123 | my-connect-artifact-gcp-jar | new-jar-artifact | GCP | env-123456 | JAR | READY
cfa-gcp-zip123 | my-connect-artifact-gcp-zip | new-zip-artifact | GCP | env-123456 | ZIP | PROCESSING
2 changes: 1 addition & 1 deletion test/fixtures/output/connect/artifact/list-help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ List Connect artifacts.
$ confluent connect artifact list --cloud aws --environment env-abc123

Flags:
--cloud string REQUIRED: Specify the cloud provider as "aws" or "azure".
--cloud string REQUIRED: Specify the cloud provider as "aws", "azure", or "gcp".
--environment string Environment ID.
--context string CLI context name.
-o, --output string Specify the output format as "human", "json", or "yaml". (default "human")
Expand Down
12 changes: 9 additions & 3 deletions test/test-server/connect_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
var artifactStore = make(map[string]camv1.CamV1ConnectArtifact)

// Handler for: "/api/cam/v1/connect-artifacts"
func handleConnectArtifacts(t *testing.T) http.HandlerFunc {

Check failure on line 172 in test/test-server/connect_handler.go

View check run for this annotation

SonarQube-Confluent / SonarQube Code Analysis

Refactor this method to reduce its Cognitive Complexity from 39 to the 15 allowed.

[S3776] Cognitive Complexity of functions should not be too high See more on https://sonarqube.confluent.io/project/issues?id=cli&pullRequest=3255&issues=b515fe6b-8947-4305-993c-1df766043df3&open=b515fe6b-8947-4305-993c-1df766043df3
return func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodPost:
Expand All @@ -180,17 +180,23 @@

switch artifact.Spec.GetDisplayName() {
case "my-connect-artifact-jar":
artifact.SetId("cfa-jar123")

Check failure on line 183 in test/test-server/connect_handler.go

View check run for this annotation

SonarQube-Confluent / SonarQube Code Analysis

Define a constant instead of duplicating this literal "cfa-jar123" 3 times.

[S1192] String literals should not be duplicated See more on https://sonarqube.confluent.io/project/issues?id=cli&pullRequest=3255&issues=8279a2d9-56d9-40c9-84c0-7d143e58fd8a&open=8279a2d9-56d9-40c9-84c0-7d143e58fd8a
artifact.Spec.SetContentFormat("JAR")
case "my-connect-artifact-zip":
artifact.SetId("cfa-zip123")
artifact.Spec.SetContentFormat("ZIP")
case "my-connect-artifact-azure-jar":
artifact.SetId("cfa-azure-jar123")

Check failure on line 189 in test/test-server/connect_handler.go

View check run for this annotation

SonarQube-Confluent / SonarQube Code Analysis

Define a constant instead of duplicating this literal "cfa-azure-jar123" 3 times.

[S1192] String literals should not be duplicated See more on https://sonarqube.confluent.io/project/issues?id=cli&pullRequest=3255&issues=77fab9e5-52ac-4589-91e8-b42f8a2d023c&open=77fab9e5-52ac-4589-91e8-b42f8a2d023c
artifact.Spec.SetContentFormat("JAR")
case "my-connect-artifact-azure-zip":
artifact.SetId("cfa-azure-zip123")
artifact.Spec.SetContentFormat("ZIP")
case "my-connect-artifact-gcp-jar":
artifact.SetId("cfa-gcp-jar123")

Check failure on line 195 in test/test-server/connect_handler.go

View check run for this annotation

SonarQube-Confluent / SonarQube Code Analysis

Define a constant instead of duplicating this literal "cfa-gcp-jar123" 3 times.

[S1192] String literals should not be duplicated See more on https://sonarqube.confluent.io/project/issues?id=cli&pullRequest=3255&issues=131c6a3a-9f6b-46a7-9c2d-88f07fbbeab0&open=131c6a3a-9f6b-46a7-9c2d-88f07fbbeab0
artifact.Spec.SetContentFormat("JAR")
case "my-connect-artifact-gcp-zip":
artifact.SetId("cfa-gcp-zip123")
artifact.Spec.SetContentFormat("ZIP")
}

artifact.Status = &camv1.CamV1ConnectArtifactStatus{
Expand Down Expand Up @@ -227,7 +233,7 @@
if cloud != "" && strings.ToUpper(artifact.Spec.GetCloud()) != cloud {
continue
}
if artifact.GetId() == "cfa-jar123" || artifact.GetId() == "cfa-azure-jar123" {
if artifact.GetId() == "cfa-jar123" || artifact.GetId() == "cfa-azure-jar123" || artifact.GetId() == "cfa-gcp-jar123" {
artifact.Status = &camv1.CamV1ConnectArtifactStatus{
Phase: "READY",
}
Expand All @@ -242,7 +248,7 @@
}

// Handler for: "/api/cam/v1/connect-artifacts/{id}"
func handleConnectArtifactId(t *testing.T) http.HandlerFunc {

Check failure on line 251 in test/test-server/connect_handler.go

View check run for this annotation

SonarQube-Confluent / SonarQube Code Analysis

Refactor this method to reduce its Cognitive Complexity from 16 to the 15 allowed.

[S3776] Cognitive Complexity of functions should not be too high See more on https://sonarqube.confluent.io/project/issues?id=cli&pullRequest=3255&issues=cb38b72f-40cc-4f45-9dd6-d96fbfdf1227&open=cb38b72f-40cc-4f45-9dd6-d96fbfdf1227
return func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodGet:
Expand All @@ -256,7 +262,7 @@
return
}

if id == "cfa-jar123" || id == "cfa-azure-jar123" {
if id == "cfa-jar123" || id == "cfa-azure-jar123" || id == "cfa-gcp-jar123" {
artifact.Status = &camv1.CamV1ConnectArtifactStatus{
Phase: "READY",
}
Expand All @@ -273,7 +279,7 @@
return
}

if id == "cfa-zip123" || id == "cfa-azure-zip123" {
if id == "cfa-zip123" || id == "cfa-azure-zip123" || id == "cfa-gcp-zip123" {
w.WriteHeader(http.StatusNoContent)
}
}
Expand Down