diff --git a/apps.go b/apps.go index f3176f40..a67a73b4 100644 --- a/apps.go +++ b/apps.go @@ -95,6 +95,7 @@ type App struct { } `json:"owner"` GitUrl string `json:"git_url"` Url string `json:"url"` + BaseURL string `json:"base_url"` Status AppStatus `json:"status"` LastDeployedAt *time.Time `json:"last_deployed_at"` LastDeployedBy string `json:"last_deployed_by"` diff --git a/client.go b/client.go index ccd18dfb..bb7f4530 100644 --- a/client.go +++ b/client.go @@ -28,6 +28,7 @@ type API interface { NotifiersService OperationsService RegionsService + RegionMigrationsService RunsService SignUpService SourcesService diff --git a/region_migrations.go b/region_migrations.go new file mode 100644 index 00000000..69a3c283 --- /dev/null +++ b/region_migrations.go @@ -0,0 +1,87 @@ +package scalingo + +import ( + "time" + + errgo "gopkg.in/errgo.v1" +) + +const ( + RegionMigrationStatusScheduled RegionMigrationStatus = "scheduled" + RegionMigrationStatusPreflightError RegionMigrationStatus = "preflight-error" + RegionMigrationStatusRunning RegionMigrationStatus = "running" + RegionMigrationStatusError RegionMigrationStatus = "error" + RegionMigrationStatusDone RegionMigrationStatus = "done" + + StepStatusRunning StepStatus = "running" + StepStatusDone StepStatus = "done" + StepStatusError StepStatus = "error" +) + +type RegionMigrationsService interface { + CreateRegionMigration(appID string, params RegionMigrationParams) (RegionMigration, error) + ShowRegionMigration(appID, migrationID string) (RegionMigration, error) + ListRegionMigrations(appID string) ([]RegionMigration, error) +} + +type RegionMigrationParams struct { + Destination string `json:"destination"` +} + +type RegionMigration struct { + ID string `json:"id"` + AppName string `json:"app_name"` + AppID string `json:"app_id"` + NewAppID string `json:"new_app_id"` + Destination string `json:"destination"` + Status RegionMigrationStatus `json:"status"` + StartedAt time.Time `json:"started_at"` + FinishedAt time.Time `json:"finished_at"` + Steps Steps `json:"steps"` +} + +type StepStatus string +type RegionMigrationStatus string +type Steps []Step + +type Step struct { + ID string `json:"id"` + Name string `json:"name"` + Status StepStatus `json:"status"` + Logs string `json:"logs"` +} + +func (c *Client) CreateRegionMigration(appID string, params RegionMigrationParams) (RegionMigration, error) { + var migration RegionMigration + + err := c.ScalingoAPI().SubresourceAdd("apps", appID, "region_migrations", map[string]RegionMigrationParams{ + "migration": params, + }, &migration) + if err != nil { + return migration, errgo.Notef(err, "fail to create migration") + } + + return migration, nil +} + +func (c *Client) ShowRegionMigration(appID, migrationID string) (RegionMigration, error) { + var migration RegionMigration + + err := c.ScalingoAPI().SubresourceGet("apps", appID, "region_migrations", migrationID, nil, &migration) + if err != nil { + return migration, errgo.Notef(err, "fail to get migration") + } + + return migration, nil +} + +func (c *Client) ListRegionMigrations(appID string) ([]RegionMigration, error) { + var migrations []RegionMigration + + err := c.ScalingoAPI().SubresourceList("apps", appID, "region_migrations", nil, &migrations) + if err != nil { + return migrations, errgo.Notef(err, "fail to list migrations") + } + + return migrations, nil +}