Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions cmd/onecli/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,36 @@ import (
// MigrateCmd is `onecli migrate`.
type MigrateCmd struct {
CloudKey string `required:"" name:"cloud-key" help:"OneCLI Cloud API key."`
CloudUrl string `optional:"" name:"cloud-url" help:"OneCLI Cloud API URL (default: production)."`
DryRun bool `optional:"" name:"dry-run" help:"Validate the request without executing it."`
}

func (c *MigrateCmd) Run(out *output.Writer) error {
if err := validate.APIKey(c.CloudKey); err != nil {
return fmt.Errorf("invalid cloud API key: %w", err)
}
if c.CloudUrl != "" {
if err := validate.URL(c.CloudUrl); err != nil {
return fmt.Errorf("invalid cloud URL: %w", err)
}
}

if c.DryRun {
target := "https://api.onecli.sh"
if c.CloudUrl != "" {
target = c.CloudUrl
}
return out.WriteDryRun("Would migrate data to OneCLI Cloud", map[string]string{
"source": config.APIHost(),
"target": "https://api.onecli.sh",
"target": target,
})
}

client, err := newClient()
if err != nil {
return err
}
result, err := client.MigrateToCloud(newContext(), c.CloudKey)
result, err := client.MigrateToCloud(newContext(), c.CloudKey, c.CloudUrl)
if err != nil {
return err
}
Expand Down
5 changes: 4 additions & 1 deletion internal/api/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ type MigrateSkipped struct {

// MigrateToCloud triggers a data export from the current instance to OneCLI Cloud.
// The server decrypts secrets and sends them directly to cloud over HTTPS.
func (c *Client) MigrateToCloud(ctx context.Context, cloudKey string) (*MigrateResult, error) {
func (c *Client) MigrateToCloud(ctx context.Context, cloudKey string, cloudUrl string) (*MigrateResult, error) {
body := map[string]string{
"cloudApiKey": cloudKey,
}
if cloudUrl != "" {
body["cloudUrl"] = cloudUrl
}
var result MigrateResult
if err := c.do(ctx, http.MethodPost, "/v1/migrate/export", body, &result); err != nil {
return nil, fmt.Errorf("migrating to cloud: %w", err)
Expand Down
Loading