-
Notifications
You must be signed in to change notification settings - Fork 3
/
catalog.go
202 lines (172 loc) · 8.16 KB
/
catalog.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
package rdsbroker
import (
"fmt"
"strings"
)
/* As much as it would be nice to use brokerapi.Service here rather than redefining
* the whole structure ourselves, the version in brokerapi is specifically
* replicating the structure sent to cloud foundry. And we want to add a few more
* options for defining the RDS properties. And brokerapi doesn't let us dump it in
* metadata.
*
* TODO: Find a better way
*/
type Catalog struct {
Services []Service `yaml:"services,omitempty"`
}
type Service struct {
ID string `json:"id" yaml:"id"`
Name string `json:"name" yaml:"name"`
Description string `json:"description" yaml:"description"`
Bindable bool `json:"bindable,omitempty" yaml:"bindable,omitempty"`
Tags []string `json:"tags,omitempty" yaml:"tags,omitempty"`
Metadata *ServiceMetadata `json:"metadata,omitempty" yaml:"metadata,omitempty"`
Requires []string `json:"requires,omitempty" yaml:"requires,omitempty"`
PlanUpdateable bool `json:"plan_updateable" yaml:"plan_updateable"`
Plans []ServicePlan `json:"plans,omitempty" yaml:"plans,omitempty"`
DashboardClient *DashboardClient `json:"dashboard_client,omitempty" yaml:"dashboard_client,omitempty"`
}
type ServiceMetadata struct {
DisplayName string `json:"displayName,omitempty" yaml:"displayName,omitempty"`
ImageURL string `json:"imageUrl,omitempty" yaml:"imageUrl,omitempty"`
LongDescription string `json:"longDescription,omitempty" yaml:"longDescription,omitempty"`
ProviderDisplayName string `json:"providerDisplayName,omitempty" yaml:"providerDisplayName,omitempty"`
DocumentationURL string `json:"documentationUrl,omitempty" yaml:"documentationUrl,omitempty"`
SupportURL string `json:"supportUrl,omitempty" yaml:"supportUrl,omitempty"`
}
type ServicePlan struct {
ID string `json:"id" yaml:"id"`
Name string `json:"name" yaml:"name"`
Description string `json:"description" yaml:"description"`
Metadata *ServicePlanMetadata `json:"metadata,omitempty" yaml:"metadata,omitempty"`
Free *bool `json:"free" yaml:"free"`
RDSProperties RDSProperties `json:"rds_properties,omitempty" yaml:"rds_properties,omitempty"`
}
type ServicePlanMetadata struct {
Bullets []string `json:"bullets,omitempty" yaml:"bullets,omitempty"`
Costs []Cost `json:"costs,omitempty" yaml:"costs,omitempty"`
DisplayName string `json:"displayName,omitempty" yaml:"displayName,omitempty"`
}
type DashboardClient struct {
ID string `json:"id,omitempty" yaml:"id,omitempty"`
Secret string `json:"secret,omitempty" yaml:"secret,omitempty"`
RedirectURI string `json:"redirect_uri,omitempty" yaml:"redirect_uri,omitempty"`
}
type Cost struct {
Amount map[string]interface{} `json:"amount,omitempty" yaml:"amount,omitempty"`
Unit string `json:"unit,omitempty" yaml:"unit,omitempty"`
}
type RDSProperties struct {
DBInstanceClass string `json:"db_instance_class,omitempty" yaml:"db_instance_class,omitempty"`
Engine string `json:"engine" yaml:"engine"`
EngineVersion string `json:"engine_version,omitempty" yaml:"engine_version,omitempty"`
AllocatedStorage int64 `json:"allocated_storage,omitempty" yaml:"allocated_storage,omitempty"`
AutoMinorVersionUpgrade bool `json:"auto_minor_version_upgrade,omitempty" yaml:"auto_minor_version_upgrade,omitempty"`
AvailabilityZone string `json:"availability_zone,omitempty" yaml:"availability_zone,omitempty"`
BackupRetentionPeriod int64 `json:"backup_retention_period,omitempty" yaml:"backup_retention_period,omitempty"`
CharacterSetName string `json:"character_set_name,omitempty" yaml:"character_set_name,omitempty"`
DBParameterGroupName string `json:"db_parameter_group_name,omitempty" yaml:"db_parameter_group_name,omitempty"`
DBClusterParameterGroupName string `json:"db_cluster_parameter_group_name,omitempty" yaml:"db_cluster_parameter_group_name,omitempty"`
DBSecurityGroups []string `json:"db_security_groups,omitempty" yaml:"db_security_groups,omitempty"`
DBSubnetGroupName string `json:"db_subnet_group_name,omitempty" yaml:"db_subnet_group_name,omitempty"`
LicenseModel string `json:"license_model,omitempty" yaml:"license_model,omitempty"`
MultiAZ bool `json:"multi_az,omitempty" yaml:"multi_az,omitempty"`
OptionGroupName string `json:"option_group_name,omitempty" yaml:"option_group_name,omitempty"`
Port int64 `json:"port,omitempty" yaml:"port,omitempty"`
PreferredBackupWindow string `json:"preferred_backup_window,omitempty" yaml:"preferred_backup_window,omitempty"`
PreferredMaintenanceWindow string `json:"preferred_maintenance_window,omitempty" yaml:"preferred_maintenance_window,omitempty"`
PubliclyAccessible bool `json:"publicly_accessible,omitempty" yaml:"publicly_accessible,omitempty"`
StorageEncrypted bool `json:"storage_encrypted,omitempty" yaml:"storage_encrypted,omitempty"`
KmsKeyID string `json:"kms_key_id,omitempty" yaml:"kms_key_id,omitempty"`
StorageType string `json:"storage_type,omitempty" yaml:"storage_type,omitempty"`
Iops int64 `json:"iops,omitempty" yaml:"iops,omitempty"`
VpcSecurityGroupIds []string `json:"vpc_security_group_ids,omitempty" yaml:"vpc_security_group_ids,omitempty"`
CopyTagsToSnapshot bool `json:"copy_tags_to_snapshot,omitempty" yaml:"copy_tags_to_snapshot,omitempty"`
SkipFinalSnapshot bool `json:"skip_final_snapshot,omitempty" yaml:"skip_final_snapshot,omitempty"`
Shared bool `json:"shared" yaml:"shared"`
}
func (c Catalog) Validate() error {
for _, service := range c.Services {
if err := service.Validate(); err != nil {
return fmt.Errorf("Validating Services configuration: %s", err)
}
}
return nil
}
func (c Catalog) FindService(serviceID string) (service Service, found bool) {
for _, service := range c.Services {
if service.ID == serviceID {
return service, true
}
}
return service, false
}
func (c Catalog) FindServicePlan(serviceID, planID string) (plan ServicePlan, found bool) {
service, found := c.FindService(serviceID)
if !found {
return plan, false
}
for _, plan := range service.Plans {
if plan.ID == planID {
return plan, true
}
}
return plan, false
}
func (s Service) Validate() error {
if s.ID == "" {
return fmt.Errorf("Must provide a non-empty ID (%+v)", s)
}
if s.Name == "" {
return fmt.Errorf("Must provide a non-empty Name (%+v)", s)
}
if s.Description == "" {
return fmt.Errorf("Must provide a non-empty Description (%+v)", s)
}
for _, servicePlan := range s.Plans {
if err := servicePlan.Validate(); err != nil {
return fmt.Errorf("Validating Plans configuration: %s", err)
}
}
return nil
}
func (sp ServicePlan) Validate() error {
if sp.ID == "" {
return fmt.Errorf("Must provide a non-empty ID (%+v)", sp)
}
if sp.Name == "" {
return fmt.Errorf("Must provide a non-empty Name (%+v)", sp)
}
if sp.Description == "" {
return fmt.Errorf("Must provide a non-empty Description (%+v)", sp)
}
if err := sp.RDSProperties.Validate(); err != nil {
return fmt.Errorf("Validating RDS Properties configuration: %s", err)
}
return nil
}
func (rp RDSProperties) Validate() error {
if !rp.Shared && rp.DBInstanceClass == "" {
return fmt.Errorf("Must provide a non-empty DBInstanceClass (%+v)", rp)
}
if rp.Engine == "" {
return fmt.Errorf("Must provide a non-empty Engine (%+v)", rp)
}
switch strings.ToLower(rp.Engine) {
case "aurora":
case "mariadb":
case "mysql":
case "postgres":
default:
return fmt.Errorf("This broker does not support RDS engine '%s' (%+v)", rp.Engine, rp)
}
if rp.Shared {
switch strings.ToLower(rp.Engine) {
case "mysql":
case "postgres":
default:
return fmt.Errorf("This broker does not support RDS engine '%s' with a shared instance (%+v)", rp.Engine, rp)
}
}
return nil
}