-
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.
external integration list, show, detach
- Loading branch information
1 parent
63af706
commit 371f392
Showing
3 changed files
with
237 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,73 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/exoscale/cli/pkg/account" | ||
"github.com/exoscale/cli/pkg/globalstate" | ||
v3 "github.com/exoscale/egoscale/v3" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type dbaasExternalIntegrationDetachCmd struct { | ||
cliCommandSettings `cli-cmd:"-"` | ||
|
||
_ bool `cli-cmd:"detach"` | ||
|
||
SourceServiceName string `cli-arg:"#"` | ||
|
||
IntegrationID string `cli-flag:"integration-id" cli-usage:"External integration id"` | ||
} | ||
|
||
func (c *dbaasExternalIntegrationDetachCmd) cmdAliases() []string { | ||
return []string{"a"} | ||
} | ||
|
||
func (c *dbaasExternalIntegrationDetachCmd) cmdLong() string { | ||
return "Disable sending data from an existing DBaaS service to an external endpoint" | ||
} | ||
|
||
func (c *dbaasExternalIntegrationDetachCmd) cmdShort() string { | ||
return "Detach a DBaaS service from an external endpoint" | ||
} | ||
|
||
func (c *dbaasExternalIntegrationDetachCmd) cmdPreRun(cmd *cobra.Command, args []string) error { | ||
return cliCommandDefaultPreRun(c, cmd, args) | ||
} | ||
|
||
func(c *dbaasExternalIntegrationDetachCmd) cmdRun(cmd *cobra.Command, args []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) | ||
} | ||
|
||
req := v3.DetachDBAASServiceFromEndpointRequest{ | ||
IntegrationID: integrationID, | ||
} | ||
|
||
op, err := client.DetachDBAASServiceFromEndpoint(ctx, c.SourceServiceName, req) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
decorateAsyncOperation(fmt.Sprintf("Detaching service %s from endpoint %s", c.SourceServiceName, integrationID), func() { | ||
_, err = client.Wait(ctx, op, v3.OperationStateSuccess) | ||
}) | ||
|
||
return err | ||
} | ||
|
||
func init() { | ||
cobra.CheckErr(registerCLICommand(dbaasExternalIntegrationCmd, &dbaasExternalIntegrationDetachCmd{ | ||
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,81 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"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 dbaasExternalIntegrationListItemOutput struct { | ||
Description string `json:"description"` | ||
DestEndpointName string `json:"dest-endpoint-name"` | ||
DestEndpointID string `json:"dest-endpoint-id"` | ||
IntegrationID string `json:"id"` | ||
Status string `json:"status"` | ||
SourceServiceName string `json:"source-service-name"` | ||
SourceServiceType string `json:"source-service-type"` | ||
Type string `json:"type"` | ||
} | ||
|
||
type dbaasExternalIntegrationListOutput []dbaasExternalIntegrationListItemOutput | ||
|
||
func (o *dbaasExternalIntegrationListOutput) ToJSON() { output.JSON(o) } | ||
func (o *dbaasExternalIntegrationListOutput) ToText() { output.Text(o) } | ||
func (o *dbaasExternalIntegrationListOutput) ToTable() { output.Table(o) } | ||
|
||
type dbaasExternalIntegrationListCmd struct { | ||
cliCommandSettings `cli-cmd:"-"` | ||
|
||
_ bool `cli-cmd:"list"` | ||
|
||
ServiceName string `cli-arg:"#"` | ||
} | ||
|
||
func (c *dbaasExternalIntegrationListCmd) cmdAliases() []string { return gListAlias } | ||
func (c *dbaasExternalIntegrationListCmd) cmdShort() string { return "List External Integrations"} | ||
func (c *dbaasExternalIntegrationListCmd) cmdLong() string { return "List External Integrations"} | ||
func (c *dbaasExternalIntegrationListCmd) cmdPreRun(cmd *cobra.Command, args []string) error { | ||
return cliCommandDefaultPreRun(c, cmd, args) | ||
} | ||
|
||
func (c *dbaasExternalIntegrationListCmd) cmdRun(_ *cobra.Command, _ []string) error { | ||
ctx := gContext | ||
|
||
client, err := switchClientZoneV3(ctx, globalstate.EgoscaleV3Client, v3.ZoneName(account.CurrentAccount.DefaultZone)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
res, err := client.ListDBAASExternalIntegrations(ctx,c.ServiceName) | ||
if err != nil { | ||
return fmt.Errorf("error listing integrations: %w", err) | ||
} | ||
|
||
out := make(dbaasExternalIntegrationListOutput, 0) | ||
|
||
for _, integration := range res.ExternalIntegrations { | ||
out = append(out, dbaasExternalIntegrationListItemOutput{ | ||
IntegrationID: string(integration.IntegrationID), | ||
Type: string(integration.Type), | ||
Description: integration.Description, | ||
DestEndpointName: integration.DestEndpointName, | ||
DestEndpointID: integration.DestEndpointID, | ||
Status: integration.Status, | ||
SourceServiceName: integration.SourceServiceName, | ||
SourceServiceType: string(integration.SourceServiceType), | ||
}) | ||
} | ||
|
||
return c.outputFunc(&out, nil) | ||
} | ||
|
||
func init() { | ||
cobra.CheckErr(registerCLICommand(dbaasExternalIntegrationCmd, &dbaasExternalIntegrationListCmd{ | ||
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,83 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"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 dbaasExternalIntegrationShowOutput struct { | ||
Description string `json:"description"` | ||
DestEndpointName string `json:"dest-endpoint-name"` | ||
DestEndpointID string `json:"dest-endpoint-id"` | ||
IntegrationID string `json:"id"` | ||
Status string `json:"status"` | ||
SourceServiceName string `json:"source-service-name"` | ||
SourceServiceType string `json:"source-service-type"` | ||
Type string `json:"type"` | ||
} | ||
|
||
func (o *dbaasExternalIntegrationShowOutput) ToJSON() { output.JSON(o) } | ||
func (o *dbaasExternalIntegrationShowOutput) ToText() { output.Text(o) } | ||
func (o *dbaasExternalIntegrationShowOutput) ToTable() { output.Table(o) } | ||
|
||
type dbaasExternalIntegrationShowCmd struct { | ||
cliCommandSettings `cli-cmd:"-"` | ||
|
||
_ bool `cli-cmd:"show"` | ||
|
||
IntegrationID string `cli-arg:"#"` | ||
} | ||
|
||
func (c *dbaasExternalIntegrationShowCmd) showExternalIntegration() (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.GetDBAASExternalIntegration(ctx, integrationID) | ||
if err != nil { | ||
return nil, fmt.Errorf("error showing integration: %w", err) | ||
} | ||
|
||
out := &dbaasExternalIntegrationShowOutput{ | ||
IntegrationID: string(res.IntegrationID), | ||
Type: string(res.Type), | ||
Description: res.Description, | ||
DestEndpointName: res.DestEndpointName, | ||
DestEndpointID: res.DestEndpointID, | ||
Status: res.Status, | ||
SourceServiceName: res.SourceServiceName, | ||
SourceServiceType: string(res.SourceServiceType), | ||
} | ||
return out, nil | ||
} | ||
|
||
func (c *dbaasExternalIntegrationShowCmd) cmdAliases() []string { return gShowAlias } | ||
func (c *dbaasExternalIntegrationShowCmd) cmdShort() string { return "Show External Integration"} | ||
func (c *dbaasExternalIntegrationShowCmd) cmdLong() string { return "Show External Integration"} | ||
func (c *dbaasExternalIntegrationShowCmd) cmdPreRun(cmd *cobra.Command, args []string) error { | ||
return cliCommandDefaultPreRun(c, cmd, args) | ||
} | ||
|
||
func (c *dbaasExternalIntegrationShowCmd) cmdRun(_ *cobra.Command, _ []string) error { | ||
return c.outputFunc(c.showExternalIntegration()) | ||
} | ||
|
||
func init() { | ||
cobra.CheckErr(registerCLICommand(dbaasExternalIntegrationCmd, &dbaasExternalIntegrationShowCmd{ | ||
cliCommandSettings: defaultCLICmdSettings(), | ||
})) | ||
} |