forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_json_v3.go
71 lines (63 loc) · 2.17 KB
/
config_json_v3.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
package configuration
import (
"encoding/json"
"github.com/cloudfoundry/cli/cf/models"
)
type configJsonV3 struct {
ConfigVersion int
Target string
ApiVersion string
AuthorizationEndpoint string
LoggregatorEndpoint string
UaaEndpoint string
AccessToken string
RefreshToken string
OrganizationFields models.OrganizationFields
SpaceFields models.SpaceFields
SSLDisabled bool
AsyncTimeout uint
Trace string
ColorEnabled string // need to be able to express true, false and undefined
}
func JsonMarshalV3(config *Data) (output []byte, err error) {
return json.MarshalIndent(configJsonV3{
ConfigVersion: 3,
Target: config.Target,
ApiVersion: config.ApiVersion,
AuthorizationEndpoint: config.AuthorizationEndpoint,
LoggregatorEndpoint: config.LoggregatorEndPoint,
UaaEndpoint: config.UaaEndpoint,
AccessToken: config.AccessToken,
RefreshToken: config.RefreshToken,
OrganizationFields: config.OrganizationFields,
SpaceFields: config.SpaceFields,
SSLDisabled: config.SSLDisabled,
Trace: config.Trace,
AsyncTimeout: config.AsyncTimeout,
ColorEnabled: config.ColorEnabled,
}, "", " ")
}
func JsonUnmarshalV3(input []byte, config *Data) (err error) {
configJson := new(configJsonV3)
err = json.Unmarshal(input, configJson)
if err != nil {
return
}
if configJson.ConfigVersion != 3 {
return
}
config.Target = configJson.Target
config.ApiVersion = configJson.ApiVersion
config.AccessToken = configJson.AccessToken
config.RefreshToken = configJson.RefreshToken
config.SpaceFields = configJson.SpaceFields
config.OrganizationFields = configJson.OrganizationFields
config.LoggregatorEndPoint = configJson.LoggregatorEndpoint
config.AuthorizationEndpoint = configJson.AuthorizationEndpoint
config.UaaEndpoint = configJson.UaaEndpoint
config.SSLDisabled = configJson.SSLDisabled
config.AsyncTimeout = configJson.AsyncTimeout
config.Trace = configJson.Trace
config.ColorEnabled = configJson.ColorEnabled
return
}