Skip to content

Commit

Permalink
setting supdates works with nils
Browse files Browse the repository at this point in the history
  • Loading branch information
simisoft-exo committed Oct 7, 2024
1 parent f4a891f commit 9d89396
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
16 changes: 11 additions & 5 deletions cmd/dbaas_external_integration_settings_update.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package cmd

import (
"fmt"
"os"

"github.com/spf13/cobra"
)

Expand All @@ -13,15 +15,19 @@ type dbaasExternalIntegrationSettingsUpdateCmd struct {
Type string `cli-arg:"#"`
IntegrationID string `cli-arg:"#"`

HelpDatadog bool `cli-usage:"show usage for flags specific to the datadog external integration type"`
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:""`
DatadogDbmEnabled bool `cli-flag:"datadog-dbm-enabled" cli-usage:"Enable/Disable pg stats with Datadog"`
DatadogPgbouncerEnabled bool `cli-flag:"datadog-pgbouncer-enabled" cli-usage:"Enable/Disable pgbouncer stats with Datadog"`
}

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) 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"):
Expand Down
20 changes: 6 additions & 14 deletions cmd/dbaas_external_integration_settings_update_datadog.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ import (
v3 "github.com/exoscale/egoscale/v3"
)

type dbaasExternalIntegrationSettingsUpdateDatadogCmd struct {
DatadogDbmEnabled bool `json:"datadog-dbm-enabled"`
DatadogPgbouncerEnabled bool `json:"datadog-pgbouncer-enabled"`
}

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

client, err := switchClientZoneV3(ctx, globalstate.EgoscaleV3Client, v3.ZoneName(account.CurrentAccount.DefaultZone))
Expand All @@ -32,37 +27,34 @@ func (c *dbaasExternalIntegrationSettingsUpdateCmd) updateDatadog(_ *cobra.Comma
Settings: &v3.DBAASIntegrationSettingsDatadog{},
}

if c.DatadogDbmEnabled {
if cmd.Flags().Changed("datadog-dbm-enabled") {
payload.Settings.DatadogDbmEnabled = v3.Bool(c.DatadogDbmEnabled)
}

if c.DatadogPgbouncerEnabled {
if cmd.Flags().Changed("datadog-pgbouncer-enabled") {
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() {
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",
IntegrationID: string(integrationID),
Type: "datadog",
}).cmdRun(nil, nil)
}


return nil
}

0 comments on commit 9d89396

Please sign in to comment.