forked from kyma-project/control-plane
-
Notifications
You must be signed in to change notification settings - Fork 0
/
broker.go
101 lines (85 loc) · 2.53 KB
/
broker.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
package broker
import (
"io/ioutil"
"strings"
"gopkg.in/yaml.v2"
"github.com/pkg/errors"
)
const (
KymaServiceID = "47c9dcbf-ff30-448e-ab36-d3bad66ba281"
KymaServiceName = "kymaruntime"
)
type KymaEnvironmentBroker struct {
*ServicesEndpoint
*ProvisionEndpoint
*DeprovisionEndpoint
*UpdateEndpoint
*GetInstanceEndpoint
*LastOperationEndpoint
*BindEndpoint
*UnbindEndpoint
*GetBindingEndpoint
*LastBindingOperationEndpoint
}
// Config represents configuration for broker
type Config struct {
EnablePlans EnablePlans `envconfig:"default=azure"`
OnlySingleTrialPerGA bool `envconfig:"default=true"`
}
type ServicesConfig map[string]Service
func NewServicesConfigFromFile(path string) (ServicesConfig, error) {
yamlFile, err := ioutil.ReadFile(path)
if err != nil {
return nil, errors.Wrap(err, "while reading YAML file with managed components list")
}
var servicesConfig struct {
Services ServicesConfig `yaml:"services"`
}
err = yaml.Unmarshal(yamlFile, &servicesConfig)
if err != nil {
return nil, errors.Wrap(err, "while unmarshaling YAML file with managed components list")
}
return servicesConfig.Services, nil
}
func (s ServicesConfig) DefaultPlansConfig() (PlansConfig, error) {
cfg, ok := s[KymaServiceName]
if !ok {
return nil, errors.Errorf("while getting data about %s plans", KymaServiceName)
}
return cfg.Plans, nil
}
type Service struct {
Description string `yaml:"description"`
Metadata ServiceMetadata `yaml:"metadata"`
Plans PlansConfig `yaml:"plans"`
}
type ServiceMetadata struct {
DisplayName string `yaml:"displayName"`
ImageUrl string `yaml:"imageUrl"`
LongDescription string `yaml:"longDescription"`
ProviderDisplayName string `yaml:"providerDisplayName"`
DocumentationUrl string `yaml:"documentationUrl"`
SupportUrl string `yaml:"supportUrl"`
}
type PlansConfig map[string]PlanData
type PlanData struct {
Description string `yaml:"description"`
Metadata PlanMetadata `yaml:"metadata"`
}
type PlanMetadata struct {
DisplayName string `yaml:"displayName"`
}
// EnablePlans defines the plans that should be available for provisioning
type EnablePlans []string
// Unmarshal provides custom parsing of enabled plans.
// Implements envconfig.Unmarshal interface.
func (m *EnablePlans) Unmarshal(in string) error {
plans := strings.Split(in, ",")
for _, name := range plans {
if _, exists := PlanIDsMapping[name]; !exists {
return errors.Errorf("unrecognized %v plan name ", name)
}
}
*m = plans
return nil
}