(ctx context.Context, appName, envVariableName string, urlSchemes []string)
| 29 | } |
| 30 | |
| 31 | func 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 | |
| 52 | func extractCredentials(ctx context.Context, u *url.URL) (string, string, error) { |
| 53 | if u.User == nil { |
no test coverage detected