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

Function GetAddonUUIDFromType

utils/addon_uuid.go:11–54  ·  view source on GitHub ↗
(ctx context.Context, app, addonTypeOrUUID string)

Source from the content-addressed store, hash-verified

9)
10
11func GetAddonUUIDFromType(ctx context.Context, app, addonTypeOrUUID string) (string, error) {
12 // If addon does not contain a UUID, we consider it contains an addon type (e.g. MongoDB)
13 if strings.HasPrefix(addonTypeOrUUID, "ad-") {
14 return addonTypeOrUUID, nil
15 }
16 addonType := addonTypeOrUUID
17
18 addonsClient, err := config.ScalingoClient(ctx)
19 if err != nil {
20 return "", errors.Wrapf(ctx, err, "unable to get Scalingo client")
21 }
22
23 aliases := map[string]string{
24 "psql": "postgresql",
25 "pgsql": "postgresql",
26 "postgres": "postgresql",
27
28 "mgo": "mongodb",
29 "mongo": "mongodb",
30
31 "influx": "influxdb",
32
33 "es": "elasticsearch",
34
35 "redis": "redis® oss",
36 }
37 addonTypeFromAlias, isAlias := aliases[addonType]
38 if isAlias {
39 addonType = addonTypeFromAlias
40 }
41
42 addons, err := addonsClient.AddonsList(ctx, app)
43 if err != nil {
44 return "", errors.Wrapf(ctx, err, "list the addons to get the type UUID")
45 }
46
47 for _, addon := range addons {
48 if strings.EqualFold(addonType, addon.AddonProvider.Name) {
49 return addon.ID, nil
50 }
51 }
52
53 return "", errors.Newf(ctx, "no '%s' addon exists", addonType)
54}

Callers 3

addons.goFile · 0.92
addonUUIDFromFlagsFunction · 0.92
UpdateConfigFunction · 0.92

Calls 1

ScalingoClientFunction · 0.92

Tested by

no test coverage detected