Skip to content

Commit 96ae126

Browse files
guyb1claude
andauthored
fix: add --cloud-url flag to migrate command (#70)
The export service needs to know the cloud API URL to send data to. Without this flag, it defaults to https://api.onecli.sh (production). For non-production environments, the migration script passes --cloud-url automatically. Companion to onecli-cloud#497. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 57d856d commit 96ae126

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

cmd/onecli/migrate.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,36 @@ import (
1111
// MigrateCmd is `onecli migrate`.
1212
type MigrateCmd struct {
1313
CloudKey string `required:"" name:"cloud-key" help:"OneCLI Cloud API key."`
14+
CloudUrl string `optional:"" name:"cloud-url" help:"OneCLI Cloud API URL (default: production)."`
1415
DryRun bool `optional:"" name:"dry-run" help:"Validate the request without executing it."`
1516
}
1617

1718
func (c *MigrateCmd) Run(out *output.Writer) error {
1819
if err := validate.APIKey(c.CloudKey); err != nil {
1920
return fmt.Errorf("invalid cloud API key: %w", err)
2021
}
22+
if c.CloudUrl != "" {
23+
if err := validate.URL(c.CloudUrl); err != nil {
24+
return fmt.Errorf("invalid cloud URL: %w", err)
25+
}
26+
}
2127

2228
if c.DryRun {
29+
target := "https://api.onecli.sh"
30+
if c.CloudUrl != "" {
31+
target = c.CloudUrl
32+
}
2333
return out.WriteDryRun("Would migrate data to OneCLI Cloud", map[string]string{
2434
"source": config.APIHost(),
25-
"target": "https://api.onecli.sh",
35+
"target": target,
2636
})
2737
}
2838

2939
client, err := newClient()
3040
if err != nil {
3141
return err
3242
}
33-
result, err := client.MigrateToCloud(newContext(), c.CloudKey)
43+
result, err := client.MigrateToCloud(newContext(), c.CloudKey, c.CloudUrl)
3444
if err != nil {
3545
return err
3646
}

internal/api/migrate.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,13 @@ type MigrateSkipped struct {
2929

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

0 commit comments

Comments
 (0)