-
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
2fc8693
commit f4a891f
Showing
2 changed files
with
116 additions
and
0 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
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(), | ||
})) | ||
} |
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,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 { | ||
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 | ||
} |