Skip to content

Commit 23c4e25

Browse files
authored
Provider Integration V2 - Separate create command into Create, Update, and Validate instead of all in one go (#3207)
1 parent f87c143 commit 23c4e25

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1779
-3
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ require (
4646
github.com/confluentinc/ccloud-sdk-go-v2/networking-ip v0.2.0
4747
github.com/confluentinc/ccloud-sdk-go-v2/networking-privatelink v0.3.0
4848
github.com/confluentinc/ccloud-sdk-go-v2/org v0.9.0
49-
github.com/confluentinc/ccloud-sdk-go-v2/provider-integration v0.1.0
49+
github.com/confluentinc/ccloud-sdk-go-v2/provider-integration v0.2.0
5050
github.com/confluentinc/ccloud-sdk-go-v2/service-quota v0.2.0
5151
github.com/confluentinc/ccloud-sdk-go-v2/srcm v0.7.3
5252
github.com/confluentinc/ccloud-sdk-go-v2/sso v0.0.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,8 @@ github.com/confluentinc/ccloud-sdk-go-v2/networking-privatelink v0.3.0 h1:mC0E1n
250250
github.com/confluentinc/ccloud-sdk-go-v2/networking-privatelink v0.3.0/go.mod h1:GIHF2cYOUKx+6ycYokr4i8E4cuNBC22xqvO/IhqZ31U=
251251
github.com/confluentinc/ccloud-sdk-go-v2/org v0.9.0 h1:FtaqHX0kBTK7fCQK+9SJcOso+XpWCWzY2roT3gBQGfw=
252252
github.com/confluentinc/ccloud-sdk-go-v2/org v0.9.0/go.mod h1:X0uaTYPp+mr19W1R/Z1LuB1ePZJZrH7kxnQckDx6zoc=
253-
github.com/confluentinc/ccloud-sdk-go-v2/provider-integration v0.1.0 h1:a6GlDTUoeX5zRlIPVToH3Aa779QA2Ajj/LYyJC5UQN8=
254-
github.com/confluentinc/ccloud-sdk-go-v2/provider-integration v0.1.0/go.mod h1:aNAIuiIUbfvqtQrl4yp1f7dMdUInXs+PDrHLvKCr0PE=
253+
github.com/confluentinc/ccloud-sdk-go-v2/provider-integration v0.2.0 h1:UN2a+aqYhk95ro+wVLkeB/8W7n+UV2KsE3jNFbbDCSw=
254+
github.com/confluentinc/ccloud-sdk-go-v2/provider-integration v0.2.0/go.mod h1:TzompS9F0G6awN5xMC+nguNG8ULElN5UqX2XOBOIPuM=
255255
github.com/confluentinc/ccloud-sdk-go-v2/service-quota v0.2.0 h1:xVSmwdycExze1E2Jta99CaFuMOlL6k6KExOOSY1hSFg=
256256
github.com/confluentinc/ccloud-sdk-go-v2/service-quota v0.2.0/go.mod h1:zZWZoGWJuO0Qm4lO6H2KlXMx4OoB/yhD8y6J1ZB/97Q=
257257
github.com/confluentinc/ccloud-sdk-go-v2/srcm v0.7.3 h1:ozdDSJHruQIgtxS5hwz8Rp8pUSX0i4h9besp2H9NYzU=

internal/provider-integration/command.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package providerintegration
33
import (
44
"github.com/spf13/cobra"
55

6+
v2 "github.com/confluentinc/cli/v4/internal/provider-integration/v2"
67
pcmd "github.com/confluentinc/cli/v4/pkg/cmd"
78
)
89

@@ -35,6 +36,7 @@ func New(prerunner pcmd.PreRunner) *cobra.Command {
3536
cmd.AddCommand(c.newDeleteCommand())
3637
cmd.AddCommand(c.newDescribeCommand())
3738
cmd.AddCommand(c.newListCommand())
39+
cmd.AddCommand(v2.New(prerunner))
3840

3941
return cmd
4042
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright 2024 Confluent Inc. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package v2
16+
17+
import (
18+
"github.com/spf13/cobra"
19+
20+
pcmd "github.com/confluentinc/cli/v4/pkg/cmd"
21+
)
22+
23+
type command struct {
24+
*pcmd.AuthenticatedCLICommand
25+
}
26+
27+
func New(prerunner pcmd.PreRunner) *cobra.Command {
28+
cmd := &cobra.Command{
29+
Use: "v2",
30+
Short: "Manage provider integrations (v2).",
31+
Long: "Manage provider integrations that allow users to configure access to cloud provider resources through Confluent resources.\n\nCurrently supports: Azure and GCP.",
32+
Annotations: map[string]string{pcmd.RunRequirement: pcmd.RequireCloudLogin},
33+
}
34+
35+
c := &command{
36+
AuthenticatedCLICommand: pcmd.NewAuthenticatedCLICommand(cmd, prerunner),
37+
}
38+
39+
cmd.AddCommand(c.newCreateCommand())
40+
cmd.AddCommand(c.newDeleteCommand())
41+
cmd.AddCommand(c.newDescribeCommand())
42+
cmd.AddCommand(c.newListCommand())
43+
cmd.AddCommand(c.newUpdateCommand())
44+
cmd.AddCommand(c.newValidateCommand())
45+
46+
return cmd
47+
}
48+
49+
const (
50+
// Provider constants
51+
providerAzure = "azure"
52+
providerGcp = "gcp"
53+
)
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// Copyright 2024 Confluent Inc. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package v2
16+
17+
import (
18+
"fmt"
19+
"strings"
20+
21+
"github.com/spf13/cobra"
22+
23+
piv2 "github.com/confluentinc/ccloud-sdk-go-v2/provider-integration/v2"
24+
25+
pcmd "github.com/confluentinc/cli/v4/pkg/cmd"
26+
"github.com/confluentinc/cli/v4/pkg/examples"
27+
)
28+
29+
func (c *command) newCreateCommand() *cobra.Command {
30+
cmd := &cobra.Command{
31+
Use: "create <display-name>",
32+
Short: "Create a provider integration.",
33+
Long: "Create a provider integration that allows users to manage access to cloud provider resources through Confluent resources. The integration is created in DRAFT state.",
34+
Args: cobra.ExactArgs(1),
35+
RunE: c.create,
36+
Example: examples.BuildExampleString(
37+
examples.Example{
38+
Text: `Create Azure provider integration "azure-integration" in the current environment.`,
39+
Code: "confluent provider-integration v2 create azure-integration --cloud azure",
40+
},
41+
examples.Example{
42+
Text: `Create GCP provider integration "gcp-integration" in environment "env-123456".`,
43+
Code: "confluent provider-integration v2 create gcp-integration --cloud gcp --environment env-123456",
44+
},
45+
),
46+
}
47+
48+
cmd.Flags().String("cloud", "", fmt.Sprintf("Cloud provider (%s or %s).", providerAzure, providerGcp))
49+
pcmd.AddEnvironmentFlag(cmd, c.AuthenticatedCLICommand)
50+
pcmd.AddContextFlag(cmd, c.CLICommand)
51+
pcmd.AddOutputFlag(cmd)
52+
53+
cobra.CheckErr(cmd.MarkFlagRequired("cloud"))
54+
55+
return cmd
56+
}
57+
58+
func (c *command) create(cmd *cobra.Command, args []string) error {
59+
displayName := args[0]
60+
61+
cloud, err := cmd.Flags().GetString("cloud")
62+
if err != nil {
63+
return err
64+
}
65+
66+
cloud = strings.ToLower(cloud)
67+
if cloud != providerAzure && cloud != providerGcp {
68+
return fmt.Errorf("cloud provider must be either %s or %s", providerAzure, providerGcp)
69+
}
70+
71+
environmentId, err := c.Context.EnvironmentId()
72+
if err != nil {
73+
return err
74+
}
75+
76+
// Create the integration in DRAFT state
77+
request := piv2.PimV2Integration{
78+
DisplayName: &displayName,
79+
Provider: &cloud,
80+
Environment: &piv2.ObjectReference{Id: environmentId},
81+
}
82+
83+
providerIntegration, err := c.V2Client.CreatePimV2Integration(cmd.Context(), request)
84+
if err != nil {
85+
return err
86+
}
87+
88+
return printProviderIntegrationTable(cmd, providerIntegration)
89+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// Copyright 2024 Confluent Inc. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package v2
16+
17+
import (
18+
"github.com/spf13/cobra"
19+
20+
pcmd "github.com/confluentinc/cli/v4/pkg/cmd"
21+
"github.com/confluentinc/cli/v4/pkg/deletion"
22+
"github.com/confluentinc/cli/v4/pkg/examples"
23+
"github.com/confluentinc/cli/v4/pkg/resource"
24+
)
25+
26+
func (c *command) newDeleteCommand() *cobra.Command {
27+
cmd := &cobra.Command{
28+
Use: "delete <id-1> [id-2] ... [id-n]",
29+
Short: "Delete one or more provider integrations.",
30+
Long: "Delete one or more provider integrations. This operation cannot be undone.",
31+
Args: cobra.MinimumNArgs(1),
32+
RunE: c.delete,
33+
Example: examples.BuildExampleString(
34+
examples.Example{
35+
Text: "Delete provider integration \"pi-123456\" in the current environment.",
36+
Code: "confluent provider-integration v2 delete pi-123456",
37+
},
38+
examples.Example{
39+
Text: "Delete provider integrations \"pi-123456\" and \"pi-789012\" in environment \"env-345678\".",
40+
Code: "confluent provider-integration v2 delete pi-123456 pi-789012 --environment env-345678",
41+
},
42+
),
43+
}
44+
45+
cmd.Flags().Bool("force", false, "Skip the deletion confirmation prompt.")
46+
pcmd.AddEnvironmentFlag(cmd, c.AuthenticatedCLICommand)
47+
pcmd.AddContextFlag(cmd, c.CLICommand)
48+
49+
return cmd
50+
}
51+
52+
func (c *command) delete(cmd *cobra.Command, args []string) error {
53+
environmentId, err := c.Context.EnvironmentId()
54+
if err != nil {
55+
return err
56+
}
57+
58+
existenceFunc := func(id string) bool {
59+
integration, err := c.V2Client.GetPimV2Integration(cmd.Context(), id, environmentId)
60+
if err != nil {
61+
return false
62+
}
63+
// Check if the integration has any usages
64+
if len(integration.GetUsages()) > 0 {
65+
cmd.Printf("Warning: provider integration %q is currently in use by %d resource(s). Remove all usages before deleting.\n", id, len(integration.GetUsages()))
66+
return false
67+
}
68+
return true
69+
}
70+
71+
if err := deletion.ValidateAndConfirm(cmd, args, existenceFunc, resource.ProviderIntegration); err != nil {
72+
return err
73+
}
74+
75+
deleteFunc := func(id string) error {
76+
return c.V2Client.DeletePimV2Integration(cmd.Context(), id, environmentId)
77+
}
78+
79+
_, err = deletion.Delete(cmd, args, deleteFunc, resource.ProviderIntegration)
80+
return err
81+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright 2024 Confluent Inc. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package v2
16+
17+
import (
18+
"github.com/spf13/cobra"
19+
20+
pcmd "github.com/confluentinc/cli/v4/pkg/cmd"
21+
"github.com/confluentinc/cli/v4/pkg/examples"
22+
)
23+
24+
func (c *command) newDescribeCommand() *cobra.Command {
25+
cmd := &cobra.Command{
26+
Use: "describe <id>",
27+
Short: "Describe a provider integration.",
28+
Long: "Describe a provider integration including its configuration and status.",
29+
Args: cobra.ExactArgs(1),
30+
RunE: c.describe,
31+
Example: examples.BuildExampleString(
32+
examples.Example{
33+
Text: `Describe provider integration "pi-123456" in the current environment.`,
34+
Code: "confluent provider-integration v2 describe pi-123456",
35+
},
36+
examples.Example{
37+
Text: `Describe provider integration "pi-123456" in environment "env-789012".`,
38+
Code: "confluent provider-integration v2 describe pi-123456 --environment env-789012",
39+
},
40+
),
41+
}
42+
43+
pcmd.AddEnvironmentFlag(cmd, c.AuthenticatedCLICommand)
44+
pcmd.AddContextFlag(cmd, c.CLICommand)
45+
pcmd.AddOutputFlag(cmd)
46+
47+
return cmd
48+
}
49+
50+
func (c *command) describe(cmd *cobra.Command, args []string) error {
51+
integrationId := args[0]
52+
53+
environmentId, err := c.Context.EnvironmentId()
54+
if err != nil {
55+
return err
56+
}
57+
58+
integration, err := c.V2Client.GetPimV2Integration(cmd.Context(), integrationId, environmentId)
59+
if err != nil {
60+
return err
61+
}
62+
63+
return printProviderIntegrationTable(cmd, integration)
64+
}

0 commit comments

Comments
 (0)