github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/config/clouds/types.go (about)

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