-
Notifications
You must be signed in to change notification settings - Fork 160
/
deployment_configs.go
60 lines (48 loc) · 1.41 KB
/
deployment_configs.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
package director
import (
"encoding/json"
"fmt"
"net/http"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
)
type DeploymentConfigProperties struct {
Id int
Type string
Name string
}
type DeploymentConfig struct {
Config DeploymentConfigProperties
}
type DeploymentConfigs struct {
Configs []DeploymentConfig
}
func (d DeploymentConfigs) GetConfig(idx int) DeploymentConfigProperties {
return d.Configs[idx].Config
}
func (d DeploymentConfigs) GetConfigs() []DeploymentConfigProperties {
configProperties := make([]DeploymentConfigProperties, len(d.Configs))
for i, cp := range d.Configs {
configProperties[i] = cp.Config
}
return configProperties
}
func (d DirectorImpl) ListDeploymentConfigs(name string) (DeploymentConfigs, error) {
return d.client.listDeploymentConfigs(name)
}
func (c Client) listDeploymentConfigs(name string) (DeploymentConfigs, error) {
var deps DeploymentConfigs
path := fmt.Sprintf("/deployment_configs?deployment[]=%s", name)
respBody, response, err := c.clientRequest.RawGet(path, nil, nil)
if err != nil {
if response != nil && response.StatusCode == http.StatusNotFound {
// endpoint couldn't be found => return empty array for compatibility with old directors
return deps, nil
}
return deps, err
}
err = json.Unmarshal(respBody, &deps.Configs)
if err != nil {
return deps, bosherr.WrapError(err, "Unmarshaling Director response")
}
return deps, nil
}