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

Function dbURLFromAPI

db/env.go:31–50  ·  view source on GitHub ↗
(ctx context.Context, appName, envVariableName string, urlSchemes []string)

Source from the content-addressed store, hash-verified

29}
30
31func dbURLFromAPI(ctx context.Context, appName, envVariableName string, urlSchemes []string) (string, error) {
32 scalingoClient, err := config.ScalingoClient(ctx)
33 if err != nil {
34 return "", errors.Wrapf(ctx, err, "fail to get Scalingo client to list the variables")
35 }
36
37 variables, err := scalingoClient.VariablesListWithoutAlias(ctx, appName)
38 if err != nil {
39 return "", errors.Wrapf(ctx, err, "list variables for app %s", appName)
40 }
41 for _, variable := range variables {
42 for _, scheme := range urlSchemes {
43 if strings.Contains(variable.Name, envVariableName) && strings.HasPrefix(variable.Value, scheme+"://") {
44 return variable.Value, nil
45 }
46 }
47 }
48
49 return "", errors.Newf(ctx, "no %v addon detected", strings.ToLower(envVariableName))
50}
51
52func extractCredentials(ctx context.Context, u *url.URL) (string, string, error) {
53 if u.User == nil {

Callers 1

dbURLFunction · 0.85

Calls 1

ScalingoClientFunction · 0.92

Tested by

no test coverage detected