diff --git a/cmd/autocomplete/databases_ng_list.go b/cmd/autocomplete/databases_ng_list.go index 13c4682c7..183ab9db9 100644 --- a/cmd/autocomplete/databases_ng_list.go +++ b/cmd/autocomplete/databases_ng_list.go @@ -17,7 +17,7 @@ func DatabasesNgListAutoComplete(ctx context.Context) error { databases, err := client.Preview().DatabasesList(ctx) if err == nil { for _, db := range databases { - fmt.Println(db.App.ID) + fmt.Println(db.ID) } } diff --git a/dbng/create.go b/dbng/create.go index 61458b1e8..ae3501bd7 100644 --- a/dbng/create.go +++ b/dbng/create.go @@ -35,9 +35,9 @@ func Create(ctx context.Context, params scalingo.DatabaseCreateParams, wait bool return errors.Wrap(ctx, err, "create database") } io.Statusf("Your %s database %s ('%s') is being provisioned…\n\n", - db.Addon.AddonProvider.Name, - db.App.ID, - db.App.Name, + db.Technology, + db.ID, + db.Name, ) if wait { @@ -46,7 +46,7 @@ func Create(ctx context.Context, params scalingo.DatabaseCreateParams, wait bool spinner.Start() defer spinner.Stop() - err = waitForRunningDatabase(ctx, c, db.App.ID) + err = waitForRunningDatabase(ctx, c, db.ID) if err != nil { return errors.Wrap(ctx, err, "wait for running database") } diff --git a/dbng/destroy.go b/dbng/destroy.go index 2a98e2084..37d76b6ed 100644 --- a/dbng/destroy.go +++ b/dbng/destroy.go @@ -20,7 +20,7 @@ func Destroy(ctx context.Context, appID string) error { return errors.Wrap(ctx, err, "delete database") } - io.Warningf("You're going to delete database %s ('%s'),\n", db.App.ID, db.App.Name) + io.Warningf("You're going to delete database %s ('%s'),\n", db.ID, db.Name) io.Warning() io.Warning("This operation is irreversible, all data including backups of your database will be deleted.") @@ -32,7 +32,7 @@ func Destroy(ctx context.Context, appID string) error { } fmt.Println() - if validationID != db.App.ID && validationID != db.App.Name { + if validationID != db.ID && validationID != db.Name { return errors.Newf(ctx, "'%s' is not the ID or the name of the database, aborting…\n", validationID) } @@ -41,7 +41,7 @@ func Destroy(ctx context.Context, appID string) error { return errors.Wrap(ctx, err, "delete database") } - io.Statusf("The database %s has been deleted.", db.App.ID) + io.Statusf("The database %s has been deleted.", db.ID) return nil } diff --git a/dbng/info.go b/dbng/info.go index 7683b5fee..c4646f22a 100644 --- a/dbng/info.go +++ b/dbng/info.go @@ -35,10 +35,10 @@ func Info(ctx context.Context, appID string) error { } data := [][]string{ - {"ID", db.App.ID}, - {"Name", db.App.Name}, - {"Type", db.Addon.AddonProvider.Name}, - {"Plan", db.Addon.Plan.Name}, + {"ID", db.ID}, + {"Name", db.Name}, + {"Type", db.Technology}, + {"Plan", db.Plan}, {"Status", string(db.Database.Status)}, {"Version", db.Database.ReadableVersion}, {"Force TLS ", forceSSL}, diff --git a/dbng/list.go b/dbng/list.go index a663018f9..ad749f406 100644 --- a/dbng/list.go +++ b/dbng/list.go @@ -37,12 +37,12 @@ func List(ctx context.Context) error { role := utils.AppRole(currentUser, &db.App) _ = t.Append([]string{ - db.App.ID, - db.App.Name, - db.Addon.AddonProvider.Name, - db.Addon.Plan.Name, + db.ID, + db.Name, + db.Technology, + db.Plan, string(role), - string(db.Addon.Status), + string(db.Database.Status), db.App.Project.Name, }) } diff --git a/go.mod b/go.mod index e9986287c..0b4ca4100 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.24.0 require ( github.com/AlecAivazis/survey/v2 v2.3.7 - github.com/Scalingo/go-scalingo/v8 v8.8.0 + github.com/Scalingo/go-scalingo/v8 v8.9.0 github.com/Scalingo/go-utils/errors/v2 v2.5.1 github.com/Scalingo/go-utils/logger v1.11.0 github.com/Scalingo/gopassword v1.1.0 diff --git a/go.sum b/go.sum index b0c818cae..40672dd0f 100644 --- a/go.sum +++ b/go.sum @@ -9,8 +9,8 @@ github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2 h1:+vx7roKuyA63n github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2/go.mod h1:HBCaDeC1lPdgDeDbhX8XFpy1jqjK0IBG8W5K+xYqA0w= github.com/ProtonMail/go-crypto v1.3.0 h1:ILq8+Sf5If5DCpHQp4PbZdS1J7HDFRXz/+xKBiRGFrw= github.com/ProtonMail/go-crypto v1.3.0/go.mod h1:9whxjD8Rbs29b4XWbB8irEcE8KHMqaR2e7GWU1R+/PE= -github.com/Scalingo/go-scalingo/v8 v8.8.0 h1:OY14XbEEdZabwImRgXGL0txjesdhW8fX5/GrlAsxlBg= -github.com/Scalingo/go-scalingo/v8 v8.8.0/go.mod h1:C87ufsz8H4/tUutK6cAmUaLpM4HwV8QOGAyfZyRgFAA= +github.com/Scalingo/go-scalingo/v8 v8.9.0 h1:r1yJxPenMjrvsG2C7K+aycDxjT06gbDNkZ8i6PIw9mM= +github.com/Scalingo/go-scalingo/v8 v8.9.0/go.mod h1:C87ufsz8H4/tUutK6cAmUaLpM4HwV8QOGAyfZyRgFAA= github.com/Scalingo/go-utils/errors/v2 v2.5.1 h1:1tfJW6/ZxTgrRmFTlKQCOtArQquOW0/XdZQzx8wMHoM= github.com/Scalingo/go-utils/errors/v2 v2.5.1/go.mod h1:SbR1JuMtfAl+gpM7ahUW/c3Jm5MMzMAwJBk1pEHkVd8= github.com/Scalingo/go-utils/logger v1.11.0 h1:QUsGgZIv6LWUCyKKy06DuW67FLmzSmWPmnhD/3YlxeM= diff --git a/utils/consent.go b/utils/consent.go index 7dba8485b..89d46f0ce 100644 --- a/utils/consent.go +++ b/utils/consent.go @@ -84,7 +84,7 @@ func CheckForConsent(ctx context.Context, resourceName string, consentTypes ...C } for _, db := range dbs { - if db.App.Name == resourceName || db.App.ID == resourceName { + if db.Name == resourceName || db.ID == resourceName { // The operator is a collaborator, no consent needed return } diff --git a/vendor/github.com/Scalingo/go-scalingo/v8/CHANGELOG.md b/vendor/github.com/Scalingo/go-scalingo/v8/CHANGELOG.md index 889836e7e..6e88a30b2 100644 --- a/vendor/github.com/Scalingo/go-scalingo/v8/CHANGELOG.md +++ b/vendor/github.com/Scalingo/go-scalingo/v8/CHANGELOG.md @@ -1,6 +1,15 @@ # Changelog -## To Be Released +## 8.9.0 + +* feat(databases): update databases preview service to use database object from API +* feat(addons): add support of `to_be_discontinued` attribute +* feat(databases): add firewall rules management for databases next generation +* feat(addons): add support of `trial_available` attribute + +## 8.8.0 + +* feat(projects): get project private network information ## 8.8.0 diff --git a/vendor/github.com/Scalingo/go-scalingo/v8/README.md b/vendor/github.com/Scalingo/go-scalingo/v8/README.md index 0d8ecfea1..c813e86b8 100644 --- a/vendor/github.com/Scalingo/go-scalingo/v8/README.md +++ b/vendor/github.com/Scalingo/go-scalingo/v8/README.md @@ -1,4 +1,4 @@ -# Go client for Scalingo API v8.8.0 +# Go client for Scalingo API v8.9.0 This repository is the Go client for the [Scalingo APIs](https://developers.scalingo.com/). @@ -80,7 +80,7 @@ Bump new version number in: Commit, tag and create a new release: ```sh -version="8.8.0" +version="8.9.0" git switch --create release/${version} git add CHANGELOG.md README.md version.go diff --git a/vendor/github.com/Scalingo/go-scalingo/v8/addons_providers.go b/vendor/github.com/Scalingo/go-scalingo/v8/addons_providers.go index c3d0dc43e..37ee6ae33 100644 --- a/vendor/github.com/Scalingo/go-scalingo/v8/addons_providers.go +++ b/vendor/github.com/Scalingo/go-scalingo/v8/addons_providers.go @@ -26,6 +26,8 @@ type Plan struct { DisabledAlternativePlanID bool `json:"disabled_alternative_plan_id"` SKU string `json:"sku"` HDSAvailable bool `json:"hds_available"` + ToBeDiscontinued bool `json:"to_be_discontinued"` + TrialAvailable bool `json:"trial_available"` } type PlansParams struct { diff --git a/vendor/github.com/Scalingo/go-scalingo/v8/databases_preview.go b/vendor/github.com/Scalingo/go-scalingo/v8/databases_preview.go index a32801fb4..cee5d3463 100644 --- a/vendor/github.com/Scalingo/go-scalingo/v8/databases_preview.go +++ b/vendor/github.com/Scalingo/go-scalingo/v8/databases_preview.go @@ -4,6 +4,7 @@ import ( "context" stderrors "errors" + "github.com/Scalingo/go-scalingo/v8/debug" "github.com/Scalingo/go-utils/errors/v2" ) @@ -26,9 +27,17 @@ var _ DatabasesPreviewService = (*PreviewClient)(nil) // DatabaseNG stands for Database Next Generation. type DatabaseNG struct { - App App `json:"app"` - Addon Addon `json:"addon"` - Database *Database `json:"database,omitempty"` + ID string `json:"id"` + Name string `json:"name"` + ProjectID string `json:"project_id"` + Technology string `json:"technology"` + Plan string `json:"plan"` + Database Database `json:"database"` + App App `json:"app"` +} + +type databaseListItem struct { + Database DatabaseNG `json:"database"` } type PreviewClient struct { @@ -59,33 +68,36 @@ func (c *PreviewClient) DatabaseCreate(ctx context.Context, params DatabaseCreat } func (c *PreviewClient) DatabasesList(ctx context.Context) ([]DatabaseNG, error) { - var res []DatabaseNG + var listRes []databaseListItem - err := c.parent.ScalingoAPI().ResourceList(ctx, databasesResource, nil, &res) + err := c.parent.ScalingoAPI().ResourceList(ctx, databasesResource, nil, &listRes) if err != nil { - return res, errors.Wrap(ctx, err, "list databases") + return nil, errors.Wrap(ctx, err, "list databases") } - return res, nil + + databasesNG := make([]DatabaseNG, len(listRes)) + + for i, apiResponse := range listRes { + dbNG, err := c.populateAPIResponse(ctx, apiResponse) + if err != nil { + return nil, errors.Wrap(ctx, err, "populate database NG") + } + + databasesNG[i] = dbNG + } + + return databasesNG, nil } // DatabaseShow currently uses appID as the database identifier. func (c *PreviewClient) DatabaseShow(ctx context.Context, appID string) (DatabaseNG, error) { var res DatabaseNG - databaseNG, err := c.searchDatabase(ctx, appID) + res, err := c.searchDatabase(ctx, appID) if err != nil { return res, errors.Wrap(ctx, err, "search database") } - database, err := c.parent.DatabaseShow(ctx, databaseNG.App.ID, databaseNG.Addon.ID) - if err != nil { - return res, errors.Wrap(ctx, err, "show database") - } - - res.App = databaseNG.App - res.Addon = databaseNG.Addon - res.Database = &database - return res, nil } @@ -96,9 +108,7 @@ func (c *PreviewClient) DatabaseDestroy(ctx context.Context, appID string) error return errors.Wrap(ctx, err, "search database") } - appName := database.App.Name - - err = c.parent.AppsDestroy(ctx, appName, appName) + err = c.parent.AppsDestroy(ctx, database.Name, database.Name) if err != nil { return errors.Wrap(ctx, err, "destroy database app") } @@ -115,9 +125,42 @@ func (c *PreviewClient) searchDatabase(ctx context.Context, appID string) (Datab } for _, databaseNG := range databases { - if databaseNG.App.ID == appID { + if databaseNG.ID == appID { return databaseNG, nil } } return res, ErrDatabaseNotFound } + +// populateAPIResponse populates a DatabaseNG without using the App and Addon from the databases endpoints. +func (c *PreviewClient) populateAPIResponse(ctx context.Context, apiResponse databaseListItem) (DatabaseNG, error) { + databaseNG := DatabaseNG{ + ID: apiResponse.Database.ID, + Name: apiResponse.Database.Name, + ProjectID: apiResponse.Database.ProjectID, + Technology: apiResponse.Database.Technology, + Plan: apiResponse.Database.Plan, + } + + addons, err := c.parent.AddonsList(ctx, apiResponse.Database.ID) + if err != nil { + return databaseNG, errors.Wrap(ctx, err, "list addons") + } + + if len(addons) == 0 { + return databaseNG, errors.New(ctx, "no addons found for database") + } + + app, err := c.parent.AppsShow(ctx, apiResponse.Database.Name) + if err != nil { + return databaseNG, errors.Wrap(ctx, err, "show app") + } + databaseNG.App = *app + + databaseNG.Database, err = c.parent.DatabaseShow(ctx, apiResponse.Database.ID, addons[0].ID) + if err != nil { + debug.Printf("Addon has been removed from app: %+v\n", databaseNG.Name) + } + + return databaseNG, nil +} diff --git a/vendor/github.com/Scalingo/go-scalingo/v8/version.go b/vendor/github.com/Scalingo/go-scalingo/v8/version.go index 9318e77a6..fca90b735 100644 --- a/vendor/github.com/Scalingo/go-scalingo/v8/version.go +++ b/vendor/github.com/Scalingo/go-scalingo/v8/version.go @@ -1,3 +1,3 @@ package scalingo -var Version = "8.8.0" +var Version = "8.9.0" diff --git a/vendor/modules.txt b/vendor/modules.txt index 05088ca0c..832b14f3b 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -37,7 +37,7 @@ github.com/ProtonMail/go-crypto/openpgp/packet github.com/ProtonMail/go-crypto/openpgp/s2k github.com/ProtonMail/go-crypto/openpgp/x25519 github.com/ProtonMail/go-crypto/openpgp/x448 -# github.com/Scalingo/go-scalingo/v8 v8.8.0 +# github.com/Scalingo/go-scalingo/v8 v8.9.0 ## explicit; go 1.24.0 github.com/Scalingo/go-scalingo/v8 github.com/Scalingo/go-scalingo/v8/billing