forked from cloudfoundry/cli
/
service_instance_user_provided.go
98 lines (83 loc) · 2.9 KB
/
service_instance_user_provided.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 ccv2
import (
"bytes"
"encoding/json"
"code.cloudfoundry.org/cli/api/cloudcontroller"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccerror"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv2/internal"
)
// GetUserProvidedServiceInstances returns back a list of *user provided* Service Instances based
// off the provided queries.
func (client *Client) GetUserProvidedServiceInstances(filters ...Filter) ([]ServiceInstance, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetUserProvidedServiceInstancesRequest,
Query: ConvertFilterParameters(filters),
})
if err != nil {
return nil, nil, err
}
var fullInstancesList []ServiceInstance
warnings, err := client.paginate(request, ServiceInstance{}, func(item interface{}) error {
if instance, ok := item.(ServiceInstance); ok {
fullInstancesList = append(fullInstancesList, instance)
} else {
return ccerror.UnknownObjectInListError{
Expected: ServiceInstance{},
Unexpected: item,
}
}
return nil
})
return fullInstancesList, warnings, err
}
// UserProvidedServiceInstance represents the data to update a user-provided
// service instance. All fields are optional.
type UserProvidedServiceInstance struct {
// Tags on the user-provided service instance
Tags *[]string `json:"tags,omitempty"`
// SyslogDrainURL for the user-provided service instance
SyslogDrainURL *string `json:"syslog_drain_url,omitempty"`
// RouteServiceURL for the user-provided service instance
RouteServiceURL *string `json:"route_service_url,omitempty"`
// Credentials for the user-provided service instance
Credentials interface{} `json:"credentials,omitempty"`
}
func (u UserProvidedServiceInstance) WithCredentials(creds map[string]interface{}) UserProvidedServiceInstance {
if creds == nil {
creds = make(map[string]interface{})
}
u.Credentials = creds
return u
}
func (u UserProvidedServiceInstance) WithRouteServiceURL(url string) UserProvidedServiceInstance {
u.RouteServiceURL = &url
return u
}
func (u UserProvidedServiceInstance) WithSyslogDrainURL(url string) UserProvidedServiceInstance {
u.SyslogDrainURL = &url
return u
}
func (u UserProvidedServiceInstance) WithTags(tags []string) UserProvidedServiceInstance {
if tags == nil {
tags = []string{}
}
u.Tags = &tags
return u
}
func (client *Client) UpdateUserProvidedServiceInstance(serviceGUID string, instance UserProvidedServiceInstance) (Warnings, error) {
bodyBytes, err := json.Marshal(instance)
if err != nil {
return nil, err
}
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.PutUserProvidedServiceInstance,
URIParams: Params{"user_provided_service_instance_guid": serviceGUID},
Body: bytes.NewReader(bodyBytes),
})
if err != nil {
return nil, err
}
response := cloudcontroller.Response{}
err = client.connection.Make(request, &response)
return response.Warnings, err
}