-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c48eb83
commit 4349141
Showing
3 changed files
with
117 additions
and
6 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
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.`) | ||
} | ||
|
||
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 { | ||
ID string `json:"id"` | ||
Name string `json:"name"` | ||
Type v3.EnumExternalEndpointTypes `json:"type"` | ||
// Settings any `json:"settings"` | ||
} | ||
|
||
func (o *externalEndpointShowOutput) ToJSON() { output.JSON(o) } | ||
|
||
func (o *externalEndpointShowOutput) ToText() { output.Text(o) } | ||
|
||
func (o *externalEndpointShowOutput) ToTable() { | ||
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)}) | ||
} | ||
|
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,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 | ||
} |