Skip to content

Commit

Permalink
the broken show
Browse files Browse the repository at this point in the history
  • Loading branch information
simisoft-exo committed Sep 11, 2024
1 parent c48eb83 commit 4349141
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 6 deletions.
6 changes: 0 additions & 6 deletions cmd/dbaas_external_endpoint_create_datadog.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,3 @@ func (c *dbaasExternalEndpointCreateCmd) createDatadog(_ *cobra.Command, _ []str

return nil
}

func init() {
cobra.CheckErr(registerCLICommand(dbaasExternalEndpointCmd, &dbaasExternalEndpointCreateCmd{
cliCommandSettings: defaultCLICmdSettings(),
}))
}
72 changes: 72 additions & 0 deletions cmd/dbaas_external_endpoint_show.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package cmd

import (
"fmt"
"os"

"github.com/exoscale/cli/pkg/output"
"github.com/exoscale/cli/table"
v3 "github.com/exoscale/egoscale/v3"
"github.com/spf13/cobra"
)

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

_ bool `cli-cmd:"show"`

Type string `cli-arg:"#"`
EndpointID string `cli-arg:"#"`
}

func (c *dbaasExternalEndpointShowCmd) cmdAliases() []string { return gShowAlias }

func (c *dbaasExternalEndpointShowCmd) cmdShort() string {
return "Show a Database External endpoint details"
}

func (c *dbaasExternalEndpointShowCmd) cmdLong() string {
return fmt.Sprintf(`This command shows a Database Service external endpoint details.`)

Check failure on line 29 in cmd/dbaas_external_endpoint_show.go

View workflow job for this annotation

GitHub Actions / build

unnecessary use of fmt.Sprintf (S1039)
}

func (c *dbaasExternalEndpointShowCmd) cmdPreRun(cmd *cobra.Command, args []string) error {
return cliCommandDefaultPreRun(c, cmd, args)
}

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

switch c.Type {
case "datadog":
return c.outputFunc(c.showDatadog())
default:
return fmt.Errorf("unsupported external endpoint type %q", c.Type)
}
}

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

type externalEndpointShowOutput struct {

Check failure on line 52 in cmd/dbaas_external_endpoint_show.go

View workflow job for this annotation

GitHub Actions / build

type externalEndpointShowOutput is unused (U1000)
ID string `json:"id"`
Name string `json:"name"`
Type v3.EnumExternalEndpointTypes `json:"type"`
// Settings any `json:"settings"`
}

func (o *externalEndpointShowOutput) ToJSON() { output.JSON(o) }

Check failure on line 59 in cmd/dbaas_external_endpoint_show.go

View workflow job for this annotation

GitHub Actions / build

func (*externalEndpointShowOutput).ToJSON is unused (U1000)

func (o *externalEndpointShowOutput) ToText() { output.Text(o) }

Check failure on line 61 in cmd/dbaas_external_endpoint_show.go

View workflow job for this annotation

GitHub Actions / build

func (*externalEndpointShowOutput).ToText is unused (U1000)

func (o *externalEndpointShowOutput) ToTable() {

Check failure on line 63 in cmd/dbaas_external_endpoint_show.go

View workflow job for this annotation

GitHub Actions / build

func (*externalEndpointShowOutput).ToTable is unused (U1000)
t := table.NewTable(os.Stdout)
t.SetHeader([]string{"DBaaS External Endpoint"})
defer t.Render()

t.Append([]string{"Name", o.Name})
t.Append([]string{"ID", string(o.ID)})
t.Append([]string{"Type", string(o.Type)})
}

45 changes: 45 additions & 0 deletions cmd/dbaas_external_endpoint_show_datadog.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package cmd

import (
"fmt"

"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 datadogOutput struct {
output.Outputter
ID string `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
// Settings v3.DBAASEndpointDatadog `json:"settings"`
}

func (c *dbaasExternalEndpointShowCmd) showDatadog() (output.Outputter, error) {
ctx := gContext

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

endpointUUID, err := v3.ParseUUID(c.EndpointID)
if err != nil {
return nil, fmt.Errorf("invalid endpoint ID: %w", err)
}
endpointResponse, err := client.GetDBAASExternalEndpointDatadog(ctx, endpointUUID)
if err != nil {
return nil, fmt.Errorf("error getting Datadog external endpoint: %w", err)
}

output := &datadogOutput{
ID: endpointResponse.ID.String(),
Name: endpointResponse.Name,
Type: string(endpointResponse.Type),
// Settings: *endpointResponse.Settings,
}

return output, nil
}

0 comments on commit 4349141

Please sign in to comment.