Skip to content

Commit

Permalink
update settings
Browse files Browse the repository at this point in the history
  • Loading branch information
simisoft-exo committed Oct 7, 2024
1 parent 2fc8693 commit f4a891f
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 0 deletions.
48 changes: 48 additions & 0 deletions cmd/dbaas_external_integration_settings_update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package cmd
import (
"fmt"
"os"
"github.com/spf13/cobra"
)

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

_ bool `cli-cmd:"update"`

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

HelpDatadog bool `cli-usage:"show usage for flags specific to the datadog external integration type"`

DatadogDbmEnabled bool `cli-flag:"datadog-dbm-enabled" cli-usage:"Enable/Disable pg stats with Datadog" cli-hidden:""`
DatadogPgbouncerEnabled bool `cli-flag:"datadog-pgbouncer-enabled" cli-usage:"Enable/Disable pgbouncer stats with Datadog" cli-hidden:""`
}

func (c *dbaasExternalIntegrationSettingsUpdateCmd) cmdAliases() []string { return nil }
func (c *dbaasExternalIntegrationSettingsUpdateCmd) cmdShort() string { return "Update external integration settings"}
func (c *dbaasExternalIntegrationSettingsUpdateCmd) cmdLong() string { return "Update external integration settings"}
func (c *dbaasExternalIntegrationSettingsUpdateCmd) cmdPreRun(cmd *cobra.Command, args []string) error {
switch {
case cmd.Flags().Changed("help-datadog"):
cmdShowHelpFlags(cmd.Flags(), "datadog-")
os.Exit(0)
}

return cliCommandDefaultPreRun(c, cmd, args)
}

func (c *dbaasExternalIntegrationSettingsUpdateCmd) cmdRun(cmd *cobra.Command, args []string) error {
switch c.Type {
case "datadog":
return c.updateDatadog(cmd, args)
default:
return fmt.Errorf("unsupported updating external integration settings for type %q", c.Type)
}
}

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

import (
"fmt"

"github.com/spf13/cobra"

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

type dbaasExternalIntegrationSettingsUpdateDatadogCmd struct {

Check failure on line 13 in cmd/dbaas_external_integration_settings_update_datadog.go

View workflow job for this annotation

GitHub Actions / build

type dbaasExternalIntegrationSettingsUpdateDatadogCmd is unused (U1000)
DatadogDbmEnabled bool `json:"datadog-dbm-enabled"`
DatadogPgbouncerEnabled bool `json:"datadog-pgbouncer-enabled"`
}

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

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

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

payload := v3.UpdateDBAASExternalIntegrationSettingsDatadogRequest{
Settings: &v3.DBAASIntegrationSettingsDatadog{},
}

if c.DatadogDbmEnabled {
payload.Settings.DatadogDbmEnabled = v3.Bool(c.DatadogDbmEnabled)
}

if c.DatadogPgbouncerEnabled {
payload.Settings.DatadogPgbouncerEnabled = v3.Bool(c.DatadogPgbouncerEnabled)
}

op, err := client.UpdateDBAASExternalIntegrationSettingsDatadog(ctx, integrationID, payload)

if err != nil {
return fmt.Errorf("error updating settings for integration: %w", err)
}

decorateAsyncOperation(fmt.Sprintf("Updating DBaaS Datadog external integration settings %q", c.IntegrationID), func() {
op, err = client.Wait(ctx, op, v3.OperationStateSuccess)
})

if err != nil {
return err
}


if !globalstate.Quiet {
return (&dbaasExternalIntegrationSettingsShowCmd{
cliCommandSettings: defaultCLICmdSettings(),
IntegrationID: string(integrationID),
Type: "datadog",
}).cmdRun(nil, nil)
}


return nil
}

0 comments on commit f4a891f

Please sign in to comment.