-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
… `network gateway` commands (#2666) Co-authored-by: Sherwin Young <[email protected]> Co-authored-by: Brian Strauch <[email protected]>
- Loading branch information
1 parent
869c7c1
commit 76551ca
Showing
83 changed files
with
2,531 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package network | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
pcmd "github.com/confluentinc/cli/v3/pkg/cmd" | ||
) | ||
|
||
type accessPointCommand struct { | ||
*pcmd.AuthenticatedCLICommand | ||
} | ||
|
||
type accessPointOut struct { | ||
Id string `human:"ID" serialized:"id"` | ||
Name string `human:"Name,omitempty" serialized:"name,omitempty"` | ||
AwsVpcEndpointService string `human:"AWS VPC Endpoint Service,omitempty" serialized:"aws_vpc_endpoint_service,omitempty"` | ||
AwsVpcEndpoint string `human:"AWS VPC Endpoint,omitempty" serialized:"aws_vpc_endpoint,omitempty"` | ||
AwsVpcEndpointDnsName string `human:"AWS VPC Endpoint DNS Name,omitempty" serialized:"aws_vpc_endpoint_dns_name,omitempty"` | ||
HighAvailability bool `human:"High Availability,omitempty" serialized:"high_availability,omitempty"` | ||
Environment string `human:"Environment" serialized:"environment"` | ||
Gateway string `human:"Gateway" serialized:"gateway"` | ||
Phase string `human:"Phase" serialized:"phase"` | ||
} | ||
|
||
func newAccessPointCommand(prerunner pcmd.PreRunner) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "access-point", | ||
Short: "Manage access points.", | ||
Annotations: map[string]string{pcmd.RunRequirement: pcmd.RequireNonAPIKeyCloudLogin}, | ||
} | ||
|
||
c := &accessPointCommand{pcmd.NewAuthenticatedCLICommand(cmd, prerunner)} | ||
|
||
cmd.AddCommand(c.newPrivateLinkCommand()) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package network | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func (c *accessPointCommand) newPrivateLinkCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "private-link", | ||
Short: "Manage access point private links.", | ||
} | ||
|
||
cmd.AddCommand(c.newEgressEndpointCommand()) | ||
|
||
return cmd | ||
} |
92 changes: 92 additions & 0 deletions
92
internal/network/command_access_point_private_link_egress_endpoint.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package network | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
networkingaccesspointv1 "github.com/confluentinc/ccloud-sdk-go-v2/networking-access-point/v1" | ||
|
||
"github.com/confluentinc/cli/v3/pkg/errors" | ||
"github.com/confluentinc/cli/v3/pkg/output" | ||
) | ||
|
||
func (c *accessPointCommand) newEgressEndpointCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "egress-endpoint", | ||
Short: "Manage private link egress endpoints.", | ||
} | ||
|
||
cmd.AddCommand(c.newCreateCommand()) | ||
cmd.AddCommand(c.newDeleteCommand()) | ||
cmd.AddCommand(c.newDescribeCommand()) | ||
cmd.AddCommand(c.newListCommand()) | ||
cmd.AddCommand(c.newUpdateCommand()) | ||
|
||
return cmd | ||
} | ||
|
||
func (c *accessPointCommand) validArgs(cmd *cobra.Command, args []string) []string { | ||
if len(args) > 0 { | ||
return nil | ||
} | ||
|
||
return c.validArgsMultiple(cmd, args) | ||
} | ||
|
||
func (c *accessPointCommand) validArgsMultiple(cmd *cobra.Command, args []string) []string { | ||
if err := c.PersistentPreRunE(cmd, args); err != nil { | ||
return nil | ||
} | ||
|
||
return c.autocompleteEgressEndpoints() | ||
} | ||
|
||
func (c *accessPointCommand) autocompleteEgressEndpoints() []string { | ||
environmentId, err := c.Context.EnvironmentId() | ||
if err != nil { | ||
return nil | ||
} | ||
|
||
egressEndpoints, err := c.V2Client.ListAccessPoints(environmentId, nil) | ||
if err != nil { | ||
return nil | ||
} | ||
|
||
suggestions := make([]string, len(egressEndpoints)) | ||
for i, egressEndpoint := range egressEndpoints { | ||
suggestions[i] = fmt.Sprintf("%s\t%s", egressEndpoint.GetId(), egressEndpoint.Spec.GetDisplayName()) | ||
} | ||
return suggestions | ||
} | ||
|
||
func printPrivateLinkEgressEndpointTable(cmd *cobra.Command, egressEndpoint networkingaccesspointv1.NetworkingV1AccessPoint) error { | ||
if egressEndpoint.Spec == nil { | ||
return fmt.Errorf(errors.CorruptedNetworkResponseErrorMsg, "spec") | ||
} | ||
if egressEndpoint.Status == nil { | ||
return fmt.Errorf(errors.CorruptedNetworkResponseErrorMsg, "status") | ||
} | ||
|
||
out := &accessPointOut{ | ||
Id: egressEndpoint.GetId(), | ||
Name: egressEndpoint.Spec.GetDisplayName(), | ||
Gateway: egressEndpoint.Spec.Gateway.GetId(), | ||
Environment: egressEndpoint.Spec.Environment.GetId(), | ||
Phase: egressEndpoint.Status.GetPhase(), | ||
} | ||
|
||
if egressEndpoint.Spec.Config != nil && egressEndpoint.Spec.Config.NetworkingV1AwsEgressPrivateLinkEndpoint != nil { | ||
out.AwsVpcEndpointService = egressEndpoint.Spec.Config.NetworkingV1AwsEgressPrivateLinkEndpoint.GetVpcEndpointServiceName() | ||
out.HighAvailability = egressEndpoint.Spec.Config.NetworkingV1AwsEgressPrivateLinkEndpoint.GetEnableHighAvailability() | ||
} | ||
|
||
if egressEndpoint.Status.Config != nil && egressEndpoint.Status.Config.NetworkingV1AwsEgressPrivateLinkEndpointStatus != nil { | ||
out.AwsVpcEndpoint = egressEndpoint.Status.Config.NetworkingV1AwsEgressPrivateLinkEndpointStatus.GetVpcEndpointId() | ||
out.AwsVpcEndpointDnsName = egressEndpoint.Status.Config.NetworkingV1AwsEgressPrivateLinkEndpointStatus.GetVpcEndpointDnsName() | ||
} | ||
|
||
table := output.NewTable(cmd) | ||
table.Add(out) | ||
return table.Print() | ||
} |
103 changes: 103 additions & 0 deletions
103
internal/network/command_access_point_private_link_egress_endpoint_create.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package network | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
networkingaccesspointv1 "github.com/confluentinc/ccloud-sdk-go-v2/networking-access-point/v1" | ||
|
||
pcmd "github.com/confluentinc/cli/v3/pkg/cmd" | ||
"github.com/confluentinc/cli/v3/pkg/examples" | ||
) | ||
|
||
func (c *accessPointCommand) newCreateCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "create [name]", | ||
Short: "Create an egress endpoint.", | ||
Args: cobra.MaximumNArgs(1), | ||
RunE: c.create, | ||
Example: examples.BuildExampleString( | ||
examples.Example{ | ||
Text: "Create an AWS private link egress endpoint with high availability.", | ||
Code: "confluent network access-point private-link egress-endpoint create --cloud aws --gateway gw-123456 --service com.amazonaws.vpce.us-west-2.vpce-svc-00000000000000000 --high-availability", | ||
}, | ||
), | ||
} | ||
|
||
cmd.Flags().String("cloud", "", "Specify the cloud provider as aws.") | ||
cmd.Flags().String("service", "", "Name of an AWS VPC endpoint service.") | ||
addGatewayFlag(cmd, c.AuthenticatedCLICommand) | ||
cmd.Flags().Bool("high-availability", false, "Enable high availability for AWS egress endpoint.") | ||
pcmd.AddContextFlag(cmd, c.CLICommand) | ||
pcmd.AddEnvironmentFlag(cmd, c.AuthenticatedCLICommand) | ||
pcmd.AddOutputFlag(cmd) | ||
|
||
cobra.CheckErr(cmd.MarkFlagRequired("cloud")) | ||
cobra.CheckErr(cmd.MarkFlagRequired("gateway")) | ||
cobra.CheckErr(cmd.MarkFlagRequired("service")) | ||
|
||
return cmd | ||
} | ||
|
||
func (c *accessPointCommand) create(cmd *cobra.Command, args []string) error { | ||
name := "" | ||
if len(args) == 1 { | ||
name = args[0] | ||
} | ||
|
||
cloud, err := cmd.Flags().GetString("cloud") | ||
if err != nil { | ||
return err | ||
} | ||
cloud = strings.ToUpper(cloud) | ||
|
||
gateway, err := cmd.Flags().GetString("gateway") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
service, err := cmd.Flags().GetString("service") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
environmentId, err := c.Context.EnvironmentId() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
highAvailability, err := cmd.Flags().GetBool("high-availability") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
createEgressEndpoint := networkingaccesspointv1.NetworkingV1AccessPoint{ | ||
Spec: &networkingaccesspointv1.NetworkingV1AccessPointSpec{ | ||
Environment: &networkingaccesspointv1.ObjectReference{Id: environmentId}, | ||
Gateway: &networkingaccesspointv1.ObjectReference{Id: gateway}, | ||
}, | ||
} | ||
|
||
if name != "" { | ||
createEgressEndpoint.Spec.SetDisplayName(name) | ||
} | ||
|
||
switch cloud { | ||
case CloudAws: | ||
createEgressEndpoint.Spec.Config = &networkingaccesspointv1.NetworkingV1AccessPointSpecConfigOneOf{ | ||
NetworkingV1AwsEgressPrivateLinkEndpoint: &networkingaccesspointv1.NetworkingV1AwsEgressPrivateLinkEndpoint{ | ||
Kind: "AwsEgressPrivateLinkEndpoint", | ||
VpcEndpointServiceName: service, | ||
EnableHighAvailability: networkingaccesspointv1.PtrBool(highAvailability), | ||
}, | ||
} | ||
} | ||
|
||
egressEndpoint, err := c.V2Client.CreateAccessPoint(createEgressEndpoint) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return printPrivateLinkEgressEndpointTable(cmd, egressEndpoint) | ||
} |
63 changes: 63 additions & 0 deletions
63
internal/network/command_access_point_private_link_egress_endpoint_delete.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package network | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
pcmd "github.com/confluentinc/cli/v3/pkg/cmd" | ||
"github.com/confluentinc/cli/v3/pkg/deletion" | ||
"github.com/confluentinc/cli/v3/pkg/errors" | ||
"github.com/confluentinc/cli/v3/pkg/output" | ||
"github.com/confluentinc/cli/v3/pkg/resource" | ||
"github.com/confluentinc/cli/v3/pkg/utils" | ||
) | ||
|
||
func (c *accessPointCommand) newDeleteCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "delete <id-1> [id-2] ... [id-n]", | ||
Short: "Delete one or more egress endpoints.", | ||
Args: cobra.MinimumNArgs(1), | ||
ValidArgsFunction: pcmd.NewValidArgsFunction(c.validArgsMultiple), | ||
RunE: c.delete, | ||
} | ||
|
||
pcmd.AddForceFlag(cmd) | ||
pcmd.AddContextFlag(cmd, c.CLICommand) | ||
pcmd.AddEnvironmentFlag(cmd, c.AuthenticatedCLICommand) | ||
|
||
return cmd | ||
} | ||
|
||
func (c *accessPointCommand) delete(cmd *cobra.Command, args []string) error { | ||
environmentId, err := c.Context.EnvironmentId() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
existenceFunc := func(id string) bool { | ||
_, err := c.V2Client.GetAccessPoint(environmentId, id) | ||
return err == nil | ||
} | ||
|
||
if err := deletion.ValidateAndConfirmDeletionYesNo(cmd, args, existenceFunc, resource.AccessPoint); err != nil { | ||
return err | ||
} | ||
|
||
deleteFunc := func(id string) error { | ||
if err := c.V2Client.DeleteAccessPoint(environmentId, id); err != nil { | ||
return fmt.Errorf(errors.DeleteResourceErrorMsg, resource.AccessPoint, id, err) | ||
} | ||
return nil | ||
} | ||
|
||
deletedIds, err := deletion.DeleteWithoutMessage(args, deleteFunc) | ||
deleteMsg := "Requested to delete %s %s.\n" | ||
if len(deletedIds) == 1 { | ||
output.Printf(c.Config.EnableColor, deleteMsg, resource.AccessPoint, fmt.Sprintf(`"%s"`, deletedIds[0])) | ||
} else if len(deletedIds) > 1 { | ||
output.Printf(c.Config.EnableColor, deleteMsg, resource.Plural(resource.AccessPoint), utils.ArrayToCommaDelimitedString(deletedIds, "and")) | ||
} | ||
|
||
return err | ||
} |
Oops, something went wrong.