-
Notifications
You must be signed in to change notification settings - Fork 50
/
properties.go
59 lines (51 loc) · 2.38 KB
/
properties.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
package properties
import (
osbv1alpha1 "github.com/cloudfoundry-incubator/service-fabrik-broker/interoperator/api/osb/v1alpha1"
"github.com/cloudfoundry-incubator/service-fabrik-broker/interoperator/pkg/errors"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/yaml"
)
var log = logf.Log.WithName("properties")
// GenericStatus defines template provided by the service for binding response
type GenericStatus struct {
State string `yaml:"state" json:"state"`
Error string `yaml:"error,omitempty" json:"error,omitempty"`
Response string `yaml:"response,omitempty" json:"response,omitempty"`
}
// InstanceStatus defines template provided by the service for provision response
type InstanceStatus struct {
State string `yaml:"state" json:"state"`
Error string `yaml:"error,omitempty" json:"error,omitempty"`
Response string `yaml:"response,omitempty" json:"response,omitempty"`
DashboardURL string `yaml:"dashboardUrl,omitempty" json:"dashboardUrl,omitempty"`
InstanceUsable string `yaml:"instanceUsable,omitempty" json:"instanceUsable,omitempty"`
UpdateRepeatable string `yaml:"updateRepeatable,omitempty" json:"updateRepeatable,omitempty"`
}
// Status is all the data to be read by interoperator from
// services. status template is unmarshalled to this struct
type Status struct {
Provision InstanceStatus `yaml:"provision" json:"provision"`
Bind GenericStatus `yaml:"bind" json:"bind"`
Unbind GenericStatus `yaml:"unbind" json:"unbind"`
Deprovision InstanceStatus `yaml:"deprovision" json:"deprovision"`
}
// ParseSources decodes sources yaml into a map
func ParseSources(sourcesString string) (map[string]osbv1alpha1.Source, error) {
sources := make(map[string]osbv1alpha1.Source)
err := yaml.Unmarshal([]byte(sourcesString), &sources)
if err != nil {
log.Error(err, "ParseSources: unable to unmarshal from yaml")
return nil, errors.NewUnmarshalError("unable to unmarshal from yaml: "+sourcesString, err)
}
return sources, nil
}
// ParseStatus decodes status template into a Status struct
func ParseStatus(propertiesString string) (*Status, error) {
status := &Status{}
err := yaml.Unmarshal([]byte(propertiesString), status)
if err != nil {
log.Error(err, "ParseStatus: unable to unmarshal from yaml")
return nil, errors.NewUnmarshalError("unable to unmarshal from yaml: "+propertiesString, err)
}
return status, nil
}