Skip to content

Commit

Permalink
show datadog settings
Browse files Browse the repository at this point in the history
  • Loading branch information
simisoft-exo committed Oct 7, 2024
1 parent 371f392 commit 2fc8693
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cmd/dbaas_external_integration_settings.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package cmd

import (
"github.com/spf13/cobra"
)

var dbaasExternalIntegrationSettingsCmd = &cobra.Command{
Use: "settings",
Short: "External integration settings management",
}

func init() {
dbaasExternalIntegrationCmd.AddCommand(dbaasExternalIntegrationSettingsCmd)
}
36 changes: 36 additions & 0 deletions cmd/dbaas_external_integration_settings_show.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package cmd
import (
"fmt"
"github.com/spf13/cobra"
)

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

_ bool `cli-cmd:"show"`

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

func (c *dbaasExternalIntegrationSettingsShowCmd) cmdAliases() []string { return gShowAlias }
func (c *dbaasExternalIntegrationSettingsShowCmd) cmdShort() string { return "Show External Integration Settings"}
func (c *dbaasExternalIntegrationSettingsShowCmd) cmdLong() string { return "Show External Integration Settings"}
func (c *dbaasExternalIntegrationSettingsShowCmd) cmdPreRun(cmd *cobra.Command, args []string) error {
return cliCommandDefaultPreRun(c, cmd, args)
}

func (c *dbaasExternalIntegrationSettingsShowCmd) cmdRun(_ *cobra.Command, _ []string) error {
switch c.Type {
case "datadog":
return c.outputFunc(c.showDatadog())
default:
return fmt.Errorf("unsupported external integration settings for type %q", c.Type)
}
}

func init() {
cobra.CheckErr(registerCLICommand(dbaasExternalIntegrationSettingsCmd, &dbaasExternalIntegrationSettingsShowCmd{
cliCommandSettings: defaultCLICmdSettings(),
}))
}
44 changes: 44 additions & 0 deletions cmd/dbaas_external_integration_settings_show_datadog.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
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 dbaasExternalIntegrationSettingsShowDatadogOutput struct {
DatadogDbmEnabled bool `json:"datadog-dbm-enabled"`
DatadogPgbouncerEnabled bool `json:"datadog-pgbouncer-enabled"`
}

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

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

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

integrationID, err := v3.ParseUUID(c.IntegrationID)
if err != nil {
return nil, fmt.Errorf("invalid integration ID: %w", err)
}

res, err := client.GetDBAASExternalIntegrationSettingsDatadog(ctx, integrationID)
if err != nil {
return nil, fmt.Errorf("error getting settings for integration: %w", err)
}

out := &dbaasExternalIntegrationSettingsShowDatadogOutput{
DatadogDbmEnabled: *res.Settings.DatadogDbmEnabled,
DatadogPgbouncerEnabled: *res.Settings.DatadogPgbouncerEnabled,
}
return out, nil
}

0 comments on commit 2fc8693

Please sign in to comment.