MCPcopy Create free account
hub / github.com/Scalingo/cli / currentDatabaseNameAndUUID

Function currentDatabaseNameAndUUID

detect/app.go:161–199  ·  view source on GitHub ↗

currentDatabaseNameAndUUID returns the database name and its UUID if database name has been found in one of the following: database flag, environment variable "SCALINGO_DATABASE". It returns an empty string and errDatabaseNotFound error if the database name is not provided or resource ID not found.

(ctx context.Context, c *cli.Command)

Source from the content-addressed store, hash-verified

159// It returns an empty string and errDatabaseNotFound error if the database name
160// is not provided or resource ID not found.
161func currentDatabaseNameAndUUID(ctx context.Context, c *cli.Command) (string, string, error) {
162 dbName := ExtractDatabaseNameFromCommandLineOrEnv(c)
163 if dbName == "" {
164 return "", "", errDatabaseNotFound
165 }
166 debug.Println("[detect] Database name is", dbName)
167
168 client, err := config.ScalingoClient(ctx)
169 if err != nil {
170 return "", "", errors.Wrap(ctx, err, "get Scalingo client")
171 }
172
173 // In case of a database, addons list should return only one element.
174 addons, err := client.AddonsList(ctx, dbName)
175 if err != nil {
176 return "", "", errors.Wrap(ctx, err, "list addons")
177 }
178
179 if len(addons) == 0 {
180 io.Warning("No database found with the given name.")
181 return "", "", errDatabaseNotFound
182 }
183
184 if len(addons) > 1 {
185 io.Error("Multiple databases found with the given name, it may be an application. Please use the database name instead.")
186 return "", "", errDatabaseNotFound
187 }
188
189 databaseUUID := addons[0].ID
190
191 if databaseUUID == "" {
192 io.Error("Unable to find the database ID with the given name.")
193 return "", "", errDatabaseNotFound
194 }
195
196 debug.Println("[detect] Database UUID is", databaseUUID)
197
198 return dbName, databaseUUID, nil
199}
200
201// GetAppNameFromGitRemote searches into the current directory and its parent for a remote
202// named remoteName or scalingo-<remoteName>.

Callers 2

GetCurrentDatabaseFunction · 0.85

Calls 4

ScalingoClientFunction · 0.92
WarningFunction · 0.92
ErrorFunction · 0.92

Tested by

no test coverage detected