forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
info.go
127 lines (98 loc) · 2.06 KB
/
info.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package director
import (
bosherr "github.com/cloudfoundry/bosh-utils/errors"
)
/*
{
"version": "1.3167.0 (00000000)",
"uuid": "a57b8733-163e-443a-a3d7-9ac58a886d7b",
"name": "my-bosh",
"cpi": "vsphere_cpi",
"user": null,
"features": {
"snapshots": {
"status": false
},
"compiled_package_cache": {
"extras": { "provider": null },
"status": false
},
"dns": {
"extras": { "domain_name": "bosh" },
"status": false
}
},
"user_authentication": {
"options": { "url": "https://10.244.3.2:8443" },
"type": "uaa"
}
}
*/
type Info struct {
Name string
UUID string
Version string
User string
Auth UserAuthentication
Features map[string]bool
CPI string
}
type UserAuthentication struct {
Type string
Options map[string]interface{}
}
type InfoResp struct {
Name string // e.g. "Bosh Lite Director"
UUID string // e.g. "71d36859-4f21-446f-8a02-f18d7f1263c6"
Version string // e.g. "1.2922.0 (00000000)"
User string
Auth UserAuthenticationResp `json:"user_authentication"`
Features map[string]InfoFeatureResp
CPI string
}
type InfoFeatureResp struct {
Status bool
// ignore extras
}
type UserAuthenticationResp struct {
Type string
Options map[string]interface{}
}
func (d DirectorImpl) IsAuthenticated() (bool, error) {
r, err := d.client.Info()
if err != nil {
return false, err
}
authed := len(r.User) > 0
return authed, nil
}
func (d DirectorImpl) Info() (Info, error) {
r, err := d.client.Info()
if err != nil {
return Info{}, err
}
info := Info{
Name: r.Name,
UUID: r.UUID,
Version: r.Version,
User: r.User,
Auth: UserAuthentication{
Type: r.Auth.Type,
Options: r.Auth.Options,
},
Features: map[string]bool{},
CPI: r.CPI,
}
for k, featResp := range r.Features {
info.Features[k] = featResp.Status
}
return info, nil
}
func (c Client) Info() (InfoResp, error) {
var info InfoResp
err := c.clientRequest.Get("/info", &info)
if err != nil {
return info, bosherr.WrapErrorf(err, "Fetching info")
}
return info, nil
}