-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice_offerings.go
86 lines (69 loc) · 2.08 KB
/
service_offerings.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
package resources
import (
"encoding/json"
"strconv"
"github.com/cloudfoundry/cli/cf/models"
)
type PaginatedServiceOfferingResources struct {
Resources []ServiceOfferingResource
}
type ServiceOfferingResource struct {
Resource
Entity ServiceOfferingEntity
}
type ServiceOfferingEntity struct {
Label string `json:"label"`
Version string `json:"version"`
Description string `json:"description"`
Provider string `json:"provider"`
BrokerGUID string `json:"service_broker_guid"`
Requires []string `json:"requires"`
ServicePlans []ServicePlanResource `json:"service_plans"`
Extra ServiceOfferingExtra
}
type ServiceOfferingExtra struct {
DocumentationURL string `json:"documentationURL"`
}
func (resource ServiceOfferingResource) ToFields() models.ServiceOfferingFields {
return models.ServiceOfferingFields{
Label: resource.Entity.Label,
Version: resource.Entity.Version,
Provider: resource.Entity.Provider,
Description: resource.Entity.Description,
BrokerGUID: resource.Entity.BrokerGUID,
GUID: resource.Metadata.GUID,
DocumentationURL: resource.Entity.Extra.DocumentationURL,
Requires: resource.Entity.Requires,
}
}
func (resource ServiceOfferingResource) ToModel() models.ServiceOffering {
offering := models.ServiceOffering{
ServiceOfferingFields: resource.ToFields(),
}
for _, p := range resource.Entity.ServicePlans {
offering.Plans = append(offering.Plans,
models.ServicePlanFields{
Name: p.Entity.Name,
GUID: p.Metadata.GUID,
},
)
}
return offering
}
type serviceOfferingExtra ServiceOfferingExtra
func (resource *ServiceOfferingExtra) UnmarshalJSON(rawData []byte) error {
if string(rawData) == "null" {
return nil
}
extra := serviceOfferingExtra{}
unquoted, err := strconv.Unquote(string(rawData))
if err != nil {
return err
}
err = json.Unmarshal([]byte(unquoted), &extra)
if err != nil {
return err
}
*resource = ServiceOfferingExtra(extra)
return nil
}