Skip to content

Commit

Permalink
listing endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
simisoft-exo committed Sep 12, 2024
1 parent 572e378 commit 96f403c
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions cmd/dbaas_external_endpoint_list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package cmd

import (
"fmt"

"github.com/spf13/cobra"

"github.com/exoscale/cli/pkg/account"
"github.com/exoscale/cli/pkg/globalstate"
"github.com/exoscale/cli/pkg/output"
v3 "github.com/exoscale/egoscale/v3"
)

type dbaasExternalEndpointListItemOutput struct {
Name string `json:"name"`
ID string `json:"id"`
Type string `json:"type"`
}

type dbaasExternalEndpointListOutput []dbaasExternalEndpointListItemOutput

func (o *dbaasExternalEndpointListOutput) ToJSON() { output.JSON(o) }
func (o *dbaasExternalEndpointListOutput) ToText() { output.Text(o) }
func (o *dbaasExternalEndpointListOutput) ToTable() { output.Table(o) }

type dbaasExternalEndpointListCmd struct {
cliCommandSettings `cli-cmd:"-"`

_ bool `cli-cmd:"list"`
}

func (c *dbaasExternalEndpointListCmd) cmdAliases() []string { return gListAlias }
func (c *dbaasExternalEndpointListCmd) cmdShort() string { return "List External Endpoints"}
func (c *dbaasExternalEndpointListCmd) cmdLong() string { return "List External Endpoints"}
func (c *dbaasExternalEndpointListCmd) cmdPreRun(cmd *cobra.Command, args []string) error {
return cliCommandDefaultPreRun(c, cmd, args)
}

func (c *dbaasExternalEndpointListCmd) cmdRun(_ *cobra.Command, _ []string) error {
ctx := gContext

client, err := switchClientZoneV3(ctx, globalstate.EgoscaleV3Client, v3.ZoneName(account.CurrentAccount.DefaultZone))
if err != nil {
return err
}

res, err := client.ListDBAASExternalEndpoints(ctx)
if err != nil {
return fmt.Errorf("error listing endpoints: %w", err)
}

out := make(dbaasExternalEndpointListOutput, 0)

for _, endpoint := range res.DBAASEndpoints {
out = append(out, dbaasExternalEndpointListItemOutput{
Name: *&endpoint.Name,

Check failure on line 56 in cmd/dbaas_external_endpoint_list.go

View workflow job for this annotation

GitHub Actions / build

*&x will be simplified to x. It will not copy x. (SA4001)
ID: string(*&endpoint.ID),

Check failure on line 57 in cmd/dbaas_external_endpoint_list.go

View workflow job for this annotation

GitHub Actions / build

*&x will be simplified to x. It will not copy x. (SA4001)
Type: string(*&endpoint.Type),

Check failure on line 58 in cmd/dbaas_external_endpoint_list.go

View workflow job for this annotation

GitHub Actions / build

*&x will be simplified to x. It will not copy x. (SA4001)
})
}

return c.outputFunc(&out, nil)
}

func init() {
cobra.CheckErr(registerCLICommand(dbaasExternalEndpointCmd, &dbaasExternalEndpointListCmd{
cliCommandSettings: defaultCLICmdSettings(),
}))
}

0 comments on commit 96f403c

Please sign in to comment.