-
Notifications
You must be signed in to change notification settings - Fork 21
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
9992629
commit d51eacd
Showing
3 changed files
with
89 additions
and
1 deletion.
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
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,14 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var dbaasExternalIntegrationCmd = &cobra.Command{ | ||
Use: "external-integration", | ||
Short: "Manage DBaaS external integrations", | ||
} | ||
|
||
func init() { | ||
dbaasCmd.AddCommand(dbaasExternalIntegrationCmd) | ||
} |
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,74 @@ | ||
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 dbaasExternalIntegrationAttachCmd struct { | ||
cliCommandSettings `cli-cmd:"-"` | ||
|
||
_ bool `cli-cmd:"attach"` | ||
|
||
Type string `cli-arg:"#"` | ||
SourceServiceName string `cli-flag:"source-service-name" cli-usage:"DBaaS source service name" cli-hidden:""` | ||
DestinationEndpointID string `cli-flag:"destination-endpoint-id" cli-usage:"Destination external endpoint id" cli-hidden:""` | ||
} | ||
|
||
func (c *dbaasExternalIntegrationAttachCmd) cmdAliases() []string { | ||
return []string{"a"} | ||
} | ||
|
||
func (c *dbaasExternalIntegrationAttachCmd) cmdLong() string { | ||
return "Enable sending data from an existing DBaaS service to an external endpoint" | ||
} | ||
|
||
func (c *dbaasExternalIntegrationAttachCmd) cmdShort() string { | ||
return "Attach a DBaaS service to an external endpoint" | ||
} | ||
|
||
func (c *dbaasExternalIntegrationAttachCmd) cmdPreRun(cmd *cobra.Command, args []string) error { | ||
return cliCommandDefaultPreRun(c, cmd, args) | ||
} | ||
|
||
func(c *dbaasExternalIntegrationAttachCmd) 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 | ||
} | ||
|
||
endpointID, err := v3.ParseUUID(c.DestinationEndpointID) | ||
if err != nil { | ||
return fmt.Errorf("invalid endpoint ID: %w", err) | ||
} | ||
|
||
req := v3.AttachDBAASServiceToEndpointRequest{ | ||
DestEndpointID: endpointID, | ||
Type: v3.EnumExternalEndpointTypes(c.Type), | ||
} | ||
|
||
op, err := client.AttachDBAASServiceToEndpoint(ctx, c.SourceServiceName, req) | ||
|
||
if err != nil { | ||
return nil | ||
} | ||
|
||
decorateAsyncOperation(fmt.Sprintf("Attaching service %s to endpoint %s", c.SourceServiceName, endpointID), func() { | ||
_, err = client.Wait(ctx, op, v3.OperationStateSuccess) | ||
}) | ||
|
||
return err | ||
} | ||
|
||
func init() { | ||
cobra.CheckErr(registerCLICommand(dbaasExternalIntegrationCmd, &dbaasExternalIntegrationAttachCmd{ | ||
cliCommandSettings: defaultCLICmdSettings(), | ||
})) | ||
} |