1 package clientconfig
2 3 import "encoding/json"
4 5 // PublicClouds represents a collection of PublicCloud entries in clouds-public.yaml file.
6 // The format of the clouds-public.yml is documented at
7 // https://docs.openstack.org/python-openstackclient/latest/configuration/
8 type PublicClouds struct {
9 Clouds map[string]Cloud `yaml:"public-clouds" json:"public-clouds"`
10 }
11 12 // Clouds represents a collection of Cloud entries in a clouds.yaml file.
13 // The format of clouds.yaml is documented at
14 // https://docs.openstack.org/os-client-config/latest/user/configuration.html.
15 type Clouds struct {
16 Clouds map[string]Cloud `yaml:"clouds" json:"clouds"`
17 }
18 19 // Cloud represents an entry in a clouds.yaml/public-clouds.yaml/secure.yaml file.
20 type Cloud struct {
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"`
27 28 // EndpointType and Interface both specify whether to use the public, internal,
29 // or admin interface of a service. They should be considered synonymous, but
30 // EndpointType will take precedence when both are specified.
31 EndpointType string `yaml:"endpoint_type,omitempty" json:"endpoint_type,omitempty"`
32 Interface string `yaml:"interface,omitempty" json:"interface,omitempty"`
33 34 // API Version overrides.
35 IdentityAPIVersion string `yaml:"identity_api_version,omitempty" json:"identity_api_version,omitempty"`
36 VolumeAPIVersion string `yaml:"volume_api_version,omitempty" json:"volume_api_version,omitempty"`
37 38 // Verify whether or not SSL API requests should be verified.
39 Verify *bool `yaml:"verify,omitempty" json:"verify,omitempty"`
40 41 // CACertFile a path to a CA Cert bundle that can be used as part of
42 // verifying SSL API requests.
43 CACertFile string `yaml:"cacert,omitempty" json:"cacert,omitempty"`
44 45 // ClientCertFile a path to a client certificate to use as part of the SSL
46 // transaction.
47 ClientCertFile string `yaml:"cert,omitempty" json:"cert,omitempty"`
48 49 // ClientKeyFile a path to a client key to use as part of the SSL
50 // transaction.
51 ClientKeyFile string `yaml:"key,omitempty" json:"key,omitempty"`
52 }
53 54 // AuthInfo represents the auth section of a cloud entry or
55 // auth options entered explicitly in ClientOpts.
56 type AuthInfo struct {
57 // AuthURL is the keystone/identity endpoint URL.
58 AuthURL string `yaml:"auth_url,omitempty" json:"auth_url,omitempty"`
59 60 // Token is a pre-generated authentication token.
61 Token string `yaml:"token,omitempty" json:"token,omitempty"`
62 63 // Username is the username of the user.
64 Username string `yaml:"username,omitempty" json:"username,omitempty"`
65 66 // UserID is the unique ID of a user.
67 UserID string `yaml:"user_id,omitempty" json:"user_id,omitempty"`
68 69 // Password is the password of the user.
70 Password string `yaml:"password,omitempty" json:"password,omitempty"`
71 72 // Application Credential ID to login with.
73 ApplicationCredentialID string `yaml:"application_credential_id,omitempty" json:"application_credential_id,omitempty"`
74 75 // Application Credential name to login with.
76 ApplicationCredentialName string `yaml:"application_credential_name,omitempty" json:"application_credential_name,omitempty"`
77 78 // Application Credential secret to login with.
79 ApplicationCredentialSecret string `yaml:"application_credential_secret,omitempty" json:"application_credential_secret,omitempty"`
80 81 // SystemScope is a system information to scope to.
82 SystemScope string `yaml:"system_scope,omitempty" json:"system_scope,omitempty"`
83 84 // ProjectName is the common/human-readable name of a project.
85 // Users can be scoped to a project.
86 // ProjectName on its own is not enough to ensure a unique scope. It must
87 // also be combined with either a ProjectDomainName or ProjectDomainID.
88 // ProjectName cannot be combined with ProjectID in a scope.
89 ProjectName string `yaml:"project_name,omitempty" json:"project_name,omitempty"`
90 91 // ProjectID is the unique ID of a project.
92 // It can be used to scope a user to a specific project.
93 ProjectID string `yaml:"project_id,omitempty" json:"project_id,omitempty"`
94 95 // UserDomainName is the name of the domain where a user resides.
96 // It is used to identify the source domain of a user.
97 UserDomainName string `yaml:"user_domain_name,omitempty" json:"user_domain_name,omitempty"`
98 99 // UserDomainID is the unique ID of the domain where a user resides.
100 // It is used to identify the source domain of a user.
101 UserDomainID string `yaml:"user_domain_id,omitempty" json:"user_domain_id,omitempty"`
102 103 // ProjectDomainName is the name of the domain where a project resides.
104 // It is used to identify the source domain of a project.
105 // ProjectDomainName can be used in addition to a ProjectName when scoping
106 // a user to a specific project.
107 ProjectDomainName string `yaml:"project_domain_name,omitempty" json:"project_domain_name,omitempty"`
108 109 // ProjectDomainID is the name of the domain where a project resides.
110 // It is used to identify the source domain of a project.
111 // ProjectDomainID can be used in addition to a ProjectName when scoping
112 // a user to a specific project.
113 ProjectDomainID string `yaml:"project_domain_id,omitempty" json:"project_domain_id,omitempty"`
114 115 // DomainName is the name of a domain which can be used to identify the
116 // source domain of either a user or a project.
117 // If UserDomainName and ProjectDomainName are not specified, then DomainName
118 // is used as a default choice.
119 // It can also be used be used to specify a domain-only scope.
120 DomainName string `yaml:"domain_name,omitempty" json:"domain_name,omitempty"`
121 122 // DomainID is the unique ID of a domain which can be used to identify the
123 // source domain of eitehr a user or a project.
124 // If UserDomainID and ProjectDomainID are not specified, then DomainID is
125 // used as a default choice.
126 // It can also be used be used to specify a domain-only scope.
127 DomainID string `yaml:"domain_id,omitempty" json:"domain_id,omitempty"`
128 129 // DefaultDomain is the domain ID to fall back on if no other domain has
130 // been specified and a domain is required for scope.
131 DefaultDomain string `yaml:"default_domain,omitempty" json:"default_domain,omitempty"`
132 133 // AllowReauth should be set to true if you grant permission for Gophercloud to
134 // cache your credentials in memory, and to allow Gophercloud to attempt to
135 // re-authenticate automatically if/when your token expires. If you set it to
136 // false, it will not cache these settings, but re-authentication will not be
137 // possible. This setting defaults to false.
138 AllowReauth bool `yaml:"allow_reauth,omitempty" json:"allow_reauth,omitempty"`
139 }
140 141 // Region represents a region included as part of cloud in clouds.yaml
142 // According to Python-based openstacksdk, this can be either a struct (as defined)
143 // or a plain string. Custom unmarshallers handle both cases.
144 type Region struct {
145 Name string `yaml:"name,omitempty" json:"name,omitempty"`
146 Values Cloud `yaml:"values,omitempty" json:"values,omitempty"`
147 }
148 149 // UnmarshalJSON handles either a plain string acting as the Name property or
150 // a struct, mimicking the Python-based openstacksdk.
151 func (r *Region) UnmarshalJSON(data []byte) error {
152 var name string
153 if err := json.Unmarshal(data, &name); err == nil {
154 r.Name = name
155 return nil
156 }
157 158 type region Region
159 var tmp region
160 if err := json.Unmarshal(data, &tmp); err != nil {
161 return err
162 }
163 r.Name = tmp.Name
164 r.Values = tmp.Values
165 166 return nil
167 }
168 169 // UnmarshalYAML handles either a plain string acting as the Name property or
170 // a struct, mimicking the Python-based openstacksdk.
171 func (r *Region) UnmarshalYAML(unmarshal func(interface{}) error) error {
172 var name string
173 if err := unmarshal(&name); err == nil {
174 r.Name = name
175 return nil
176 }
177 178 type region Region
179 var tmp region
180 if err := unmarshal(&tmp); err != nil {
181 return err
182 }
183 r.Name = tmp.Name
184 r.Values = tmp.Values
185 186 return nil
187 }
188