-
Notifications
You must be signed in to change notification settings - Fork 8
/
addons_providers.go
98 lines (83 loc) · 2.73 KB
/
addons_providers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package scalingo
import (
"context"
"gopkg.in/errgo.v1"
"github.com/Scalingo/go-scalingo/v7/http"
)
type AddonProvidersService interface {
AddonProvidersList(context.Context) ([]*AddonProvider, error)
AddonProviderPlansList(ctx context.Context, addon string) ([]*Plan, error)
}
var _ AddonProvidersService = (*Client)(nil)
type Plan struct {
ID string `json:"id"`
DisplayName string `json:"display_name"`
Name string `json:"name"`
Description string `json:"description"`
Position int `json:"position"`
OnDemand bool `json:"on_demand"`
Disabled bool `json:"disabled"`
DisabledAlternativePlanID bool `json:"disabled_alternative_plan_id"`
SKU string `json:"sku"`
HDSAvailable bool `json:"hds_available"`
}
type PlansParams struct {
Plans []*Plan `json:"plans"`
}
type Category struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Position int `json:"position"`
}
type AddonProvider struct {
ID string `json:"id"`
LogoURL string `json:"logo_url"`
Name string `json:"name"`
ShortDescription string `json:"short_description"`
Description string `json:"description"`
Category Category `json:"category"`
ProviderName string `json:"provider_name"`
ProviderURL string `json:"provider_url"`
HDSAvailable bool `json:"hds_available"`
Plans []Plan `json:"plans"`
}
type ListParams struct {
AddonProviders []*AddonProvider `json:"addon_providers"`
}
func (c *Client) AddonProvidersList(ctx context.Context) ([]*AddonProvider, error) {
req := &http.APIRequest{
NoAuth: true,
Endpoint: "/addon_providers",
}
var params ListParams
err := c.ScalingoAPI().DoRequest(ctx, req, ¶ms)
if err != nil {
return nil, errgo.Mask(err)
}
return params.AddonProviders, nil
}
var addonProviderTypo = map[string]string{
"scalingo-mongo": "scalingo-mongodb",
"scalingo-influx": "scalingo-influxdb",
"scalingo-postgres": "scalingo-postgresql",
"scalingo-postgre": "scalingo-postgresql",
"scalingo-pgsql": "scalingo-postgresql",
"scalingo-psql": "scalingo-postgresql",
}
func (c *Client) AddonProviderPlansList(ctx context.Context, addon string) ([]*Plan, error) {
correctAddon, ok := addonProviderTypo[addon]
if ok {
addon = correctAddon
}
var params PlansParams
req := &http.APIRequest{
NoAuth: true,
Endpoint: "/addon_providers/" + addon + "/plans",
}
err := c.ScalingoAPI().DoRequest(ctx, req, ¶ms)
if err != nil {
return nil, errgo.Notef(err, "fail to get plans")
}
return params.Plans, nil
}