1
1
package clientconfig
2
2
3
+ import "encoding/json"
4
+
3
5
// PublicClouds represents a collection of PublicCloud entries in clouds-public.yaml file.
4
6
// The format of the clouds-public.yml is documented at
5
7
// https://docs.openstack.org/python-openstackclient/latest/configuration/
@@ -16,12 +18,12 @@ type Clouds struct {
16
18
17
19
// Cloud represents an entry in a clouds.yaml/public-clouds.yaml/secure.yaml file.
18
20
type Cloud struct {
19
- Cloud string `yaml:"cloud,omitempty" json:"cloud,omitempty"`
20
- Profile string `yaml:"profile,omitempty" json:"profile,omitempty"`
21
- AuthInfo * AuthInfo `yaml:"auth,omitempty" json:"auth,omitempty"`
22
- AuthType AuthType `yaml:"auth_type,omitempty" json:"auth_type,omitempty"`
23
- RegionName string `yaml:"region_name,omitempty" json:"region_name,omitempty"`
24
- Regions []interface {} `yaml:"regions,omitempty" json:"regions,omitempty"`
21
+ Cloud string `yaml:"cloud,omitempty" json:"cloud,omitempty"`
22
+ Profile string `yaml:"profile,omitempty" json:"profile,omitempty"`
23
+ AuthInfo * AuthInfo `yaml:"auth,omitempty" json:"auth,omitempty"`
24
+ AuthType AuthType `yaml:"auth_type,omitempty" json:"auth_type,omitempty"`
25
+ RegionName string `yaml:"region_name,omitempty" json:"region_name,omitempty"`
26
+ Regions []Region `yaml:"regions,omitempty" json:"regions,omitempty"`
25
27
26
28
// EndpointType and Interface both specify whether to use the public, internal,
27
29
// or admin interface of a service. They should be considered synonymous, but
@@ -125,3 +127,51 @@ type AuthInfo struct {
125
127
// been specified and a domain is required for scope.
126
128
DefaultDomain string `yaml:"default_domain,omitempty" json:"default_domain,omitempty"`
127
129
}
130
+
131
+ // Region represents a region included as part of cloud in clouds.yaml
132
+ // According to Python-based openstacksdk, this can be either a struct (as defined)
133
+ // or a plain string. Custom unmarshallers handle both cases.
134
+ type Region struct {
135
+ Name string `yaml:"name,omitempty" json:"name,omitempty"`
136
+ Values Cloud `yaml:"values,omitempty" json:"values,omitempty"`
137
+ }
138
+
139
+ // UnmarshalJSON handles either a plain string acting as the Name property or
140
+ // a struct, mimicking the Python-based openstacksdk.
141
+ func (r * Region ) UnmarshalJSON (data []byte ) error {
142
+ var name string
143
+ if err := json .Unmarshal (data , & name ); err == nil {
144
+ r .Name = name
145
+ return nil
146
+ }
147
+
148
+ type region Region
149
+ var tmp region
150
+ if err := json .Unmarshal (data , & tmp ); err != nil {
151
+ return err
152
+ }
153
+ r .Name = tmp .Name
154
+ r .Values = tmp .Values
155
+
156
+ return nil
157
+ }
158
+
159
+ // UnmarshalYAML handles either a plain string acting as the Name property or
160
+ // a struct, mimicking the Python-based openstacksdk.
161
+ func (r * Region ) UnmarshalYAML (unmarshal func (interface {}) error ) error {
162
+ var name string
163
+ if err := unmarshal (& name ); err == nil {
164
+ r .Name = name
165
+ return nil
166
+ }
167
+
168
+ type region Region
169
+ var tmp region
170
+ if err := unmarshal (& tmp ); err != nil {
171
+ return err
172
+ }
173
+ r .Name = tmp .Name
174
+ r .Values = tmp .Values
175
+
176
+ return nil
177
+ }
0 commit comments