{"modulePath":"github.com/gophercloud/utils","version":"v0.0.0-20231010081019-80377eca5d56","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package clientconfig\n\nPackage clientconfig provides convienent functions for creating OpenStack clients. It is based on the Python os-client-config library.\n\nSee [https://docs.openstack.org/os-client-config/latest](https://docs.openstack.org/os-client-config/latest) for details.\n\nExample to Create a Provider Client From clouds.yaml\n\n\topts := \u0026clientconfig.ClientOpts{\n\t\tCloud: \"hawaii\",\n\t}\n\n\tpClient, err := clientconfig.AuthenticatedClient(opts)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\nExample to Manually Create a Provider Client\n\n\topts := \u0026clientconfig.ClientOpts{\n\t\tAuthInfo: \u0026clientconfig.AuthInfo{\n\t\t\tAuthURL:     \"https://hi.example.com:5000/v3\",\n\t\t\tUsername:    \"jdoe\",\n\t\t\tPassword:    \"password\",\n\t\t\tProjectName: \"Some Project\",\n\t\t\tDomainName:  \"default\",\n\t\t},\n\t}\n\n\tpClient, err := clientconfig.AuthenticatedClient(opts)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\nExample to Create a Service Client from clouds.yaml\n\n\topts := \u0026clientconfig.ClientOpts{\n\t\tCloud: \"hawaii\",\n\t}\n\n\tcomputeClient, err := clientconfig.NewServiceClient(\"compute\", opts)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n## Functions\n\n```go\nfunc AuthOptions(opts *ClientOpts) (*gophercloud.AuthOptions, error)\n```\nAuthOptions creates a gophercloud.AuthOptions structure with the settings found in a specific cloud entry of a clouds.yaml file or based on authentication settings given in ClientOpts.\n\nThis attempts to be a single point of entry for all OpenStack authentication.\n\nSee [http://docs.openstack.org/developer/os-client-config](http://docs.openstack.org/developer/os-client-config) and [https://github.com/openstack/os-client-config/blob/master/os\\_client\\_config/config.py](https://github.com/openstack/os-client-config/blob/master/os_client_config/config.py).\n\n```go\nfunc AuthenticatedClient(opts *ClientOpts) (*gophercloud.ProviderClient, error)\n```\nAuthenticatedClient is a convenience function to get a new provider client based on a clouds.yaml entry.\n\n```go\nfunc FindAndReadCloudsYAML() (string, []byte, error)\n```\nFindAndReadCloudsYAML attempts to locate a clouds.yaml file in the following locations:\n\n1\\. OS\\_CLIENT\\_CONFIG\\_FILE 2. Current directory. 3. unix-specific user\\_config\\_dir (~/.config/openstack/clouds.yaml) 4. unix-specific site\\_config\\_dir (/etc/openstack/clouds.yaml)\n\nIf found, the contents of the file is returned.\n\n```go\nfunc FindAndReadPublicCloudsYAML() (string, []byte, error)\n```\n\n```go\nfunc FindAndReadSecureCloudsYAML() (string, []byte, error)\n```\n\n```go\nfunc FindAndReadYAML(yamlFile string) (string, []byte, error)\n```\n\n```go\nfunc GetEndpointType(endpointType string) gophercloud.Availability\n```\nGetEndpointType is a helper method to determine the endpoint type requested by the user.\n\n```go\nfunc LoadCloudsYAML() (map[string]Cloud, error)\n```\nLoadCloudsYAML will load a clouds.yaml file and return the full config. This is called by the YAMLOpts method. Calling this function directly is supported for now but has only been retained for backwards compatibility from before YAMLOpts was defined. This may be removed in the future.\n\n```go\nfunc LoadPublicCloudsYAML() (map[string]Cloud, error)\n```\nLoadPublicCloudsYAML will load a public-clouds.yaml file and return the full config. This is called by the YAMLOpts method. Calling this function directly is supported for now but has only been retained for backwards compatibility from before YAMLOpts was defined. This may be removed in the future.\n\n```go\nfunc LoadSecureCloudsYAML() (map[string]Cloud, error)\n```\nLoadSecureCloudsYAML will load a secure.yaml file and return the full config. This is called by the YAMLOpts method. Calling this function directly is supported for now but has only been retained for backwards compatibility from before YAMLOpts was defined. This may be removed in the future.\n\n```go\nfunc NewServiceClient(service string, opts *ClientOpts) (*gophercloud.ServiceClient, error)\n```\nNewServiceClient is a convenience function to get a new service client.\n\n## Types\n\n```go\ntype AuthInfo struct {\n\t// AuthURL is the keystone/identity endpoint URL.\n\tAuthURL string `yaml:\"auth_url,omitempty\" json:\"auth_url,omitempty\"`\n\n\t// Token is a pre-generated authentication token.\n\tToken string `yaml:\"token,omitempty\" json:\"token,omitempty\"`\n\n\t// Username is the username of the user.\n\tUsername string `yaml:\"username,omitempty\" json:\"username,omitempty\"`\n\n\t// UserID is the unique ID of a user.\n\tUserID string `yaml:\"user_id,omitempty\" json:\"user_id,omitempty\"`\n\n\t// Password is the password of the user.\n\tPassword string `yaml:\"password,omitempty\" json:\"password,omitempty\"`\n\n\t// Application Credential ID to login with.\n\tApplicationCredentialID string `yaml:\"application_credential_id,omitempty\" json:\"application_credential_id,omitempty\"`\n\n\t// Application Credential name to login with.\n\tApplicationCredentialName string `yaml:\"application_credential_name,omitempty\" json:\"application_credential_name,omitempty\"`\n\n\t// Application Credential secret to login with.\n\tApplicationCredentialSecret string `yaml:\"application_credential_secret,omitempty\" json:\"application_credential_secret,omitempty\"`\n\n\t// SystemScope is a system information to scope to.\n\tSystemScope string `yaml:\"system_scope,omitempty\" json:\"system_scope,omitempty\"`\n\n\t// ProjectName is the common/human-readable name of a project.\n\t// Users can be scoped to a project.\n\t// ProjectName on its own is not enough to ensure a unique scope. It must\n\t// also be combined with either a ProjectDomainName or ProjectDomainID.\n\t// ProjectName cannot be combined with ProjectID in a scope.\n\tProjectName string `yaml:\"project_name,omitempty\" json:\"project_name,omitempty\"`\n\n\t// ProjectID is the unique ID of a project.\n\t// It can be used to scope a user to a specific project.\n\tProjectID string `yaml:\"project_id,omitempty\" json:\"project_id,omitempty\"`\n\n\t// UserDomainName is the name of the domain where a user resides.\n\t// It is used to identify the source domain of a user.\n\tUserDomainName string `yaml:\"user_domain_name,omitempty\" json:\"user_domain_name,omitempty\"`\n\n\t// UserDomainID is the unique ID of the domain where a user resides.\n\t// It is used to identify the source domain of a user.\n\tUserDomainID string `yaml:\"user_domain_id,omitempty\" json:\"user_domain_id,omitempty\"`\n\n\t// ProjectDomainName is the name of the domain where a project resides.\n\t// It is used to identify the source domain of a project.\n\t// ProjectDomainName can be used in addition to a ProjectName when scoping\n\t// a user to a specific project.\n\tProjectDomainName string `yaml:\"project_domain_name,omitempty\" json:\"project_domain_name,omitempty\"`\n\n\t// ProjectDomainID is the name of the domain where a project resides.\n\t// It is used to identify the source domain of a project.\n\t// ProjectDomainID can be used in addition to a ProjectName when scoping\n\t// a user to a specific project.\n\tProjectDomainID string `yaml:\"project_domain_id,omitempty\" json:\"project_domain_id,omitempty\"`\n\n\t// DomainName is the name of a domain which can be used to identify the\n\t// source domain of either a user or a project.\n\t// If UserDomainName and ProjectDomainName are not specified, then DomainName\n\t// is used as a default choice.\n\t// It can also be used be used to specify a domain-only scope.\n\tDomainName string `yaml:\"domain_name,omitempty\" json:\"domain_name,omitempty\"`\n\n\t// DomainID is the unique ID of a domain which can be used to identify the\n\t// source domain of eitehr a user or a project.\n\t// If UserDomainID and ProjectDomainID are not specified, then DomainID is\n\t// used as a default choice.\n\t// It can also be used be used to specify a domain-only scope.\n\tDomainID string `yaml:\"domain_id,omitempty\" json:\"domain_id,omitempty\"`\n\n\t// DefaultDomain is the domain ID to fall back on if no other domain has\n\t// been specified and a domain is required for scope.\n\tDefaultDomain string `yaml:\"default_domain,omitempty\" json:\"default_domain,omitempty\"`\n\n\t// AllowReauth should be set to true if you grant permission for Gophercloud to\n\t// cache your credentials in memory, and to allow Gophercloud to attempt to\n\t// re-authenticate automatically if/when your token expires.  If you set it to\n\t// false, it will not cache these settings, but re-authentication will not be\n\t// possible.  This setting defaults to false.\n\tAllowReauth bool `yaml:\"allow_reauth,omitempty\" json:\"allow_reauth,omitempty\"`\n}\n```\nAuthInfo represents the auth section of a cloud entry or auth options entered explicitly in ClientOpts.\n\n```go\ntype AuthType string\n```\nAuthType respresents a valid method of authentication.\n\n```go\nconst (\n\t// AuthPassword defines an unknown version of the password\n\tAuthPassword AuthType = \"password\"\n\t// AuthToken defined an unknown version of the token\n\tAuthToken AuthType = \"token\"\n\n\t// AuthV2Password defines version 2 of the password\n\tAuthV2Password AuthType = \"v2password\"\n\t// AuthV2Token defines version 2 of the token\n\tAuthV2Token AuthType = \"v2token\"\n\n\t// AuthV3Password defines version 3 of the password\n\tAuthV3Password AuthType = \"v3password\"\n\t// AuthV3Token defines version 3 of the token\n\tAuthV3Token AuthType = \"v3token\"\n\n\t// AuthV3ApplicationCredential defines version 3 of the application credential\n\tAuthV3ApplicationCredential AuthType = \"v3applicationcredential\"\n)\n```\n\n```go\ntype ClientOpts struct {\n\t// Cloud is the cloud entry in clouds.yaml to use.\n\tCloud string\n\n\t// EnvPrefix allows a custom environment variable prefix to be used.\n\tEnvPrefix string\n\n\t// AuthType specifies the type of authentication to use.\n\t// By default, this is \"password\".\n\tAuthType AuthType\n\n\t// AuthInfo defines the authentication information needed to\n\t// authenticate to a cloud when clouds.yaml isn't used.\n\tAuthInfo *AuthInfo\n\n\t// RegionName is the region to create a Service Client in.\n\t// This will override a region in clouds.yaml or can be used\n\t// when authenticating directly with AuthInfo.\n\tRegionName string\n\n\t// EndpointType specifies whether to use the public, internal, or\n\t// admin endpoint of a service.\n\tEndpointType string\n\n\t// HTTPClient provides the ability customize the ProviderClient's\n\t// internal HTTP client.\n\tHTTPClient *http.Client\n\n\t// YAMLOpts provides the ability to pass a customized set\n\t// of options and methods for loading the YAML file.\n\t// It takes a YAMLOptsBuilder interface that is defined\n\t// in this file. This is optional and the default behavior\n\t// is to call the local LoadCloudsYAML functions defined\n\t// in this file.\n\tYAMLOpts YAMLOptsBuilder\n}\n```\nClientOpts represents options to customize the way a client is configured.\n\n```go\ntype Cloud struct {\n\tCloud      string    `yaml:\"cloud,omitempty\" json:\"cloud,omitempty\"`\n\tProfile    string    `yaml:\"profile,omitempty\" json:\"profile,omitempty\"`\n\tAuthInfo   *AuthInfo `yaml:\"auth,omitempty\" json:\"auth,omitempty\"`\n\tAuthType   AuthType  `yaml:\"auth_type,omitempty\" json:\"auth_type,omitempty\"`\n\tRegionName string    `yaml:\"region_name,omitempty\" json:\"region_name,omitempty\"`\n\tRegions    []Region  `yaml:\"regions,omitempty\" json:\"regions,omitempty\"`\n\n\t// EndpointType and Interface both specify whether to use the public, internal,\n\t// or admin interface of a service. They should be considered synonymous, but\n\t// EndpointType will take precedence when both are specified.\n\tEndpointType string `yaml:\"endpoint_type,omitempty\" json:\"endpoint_type,omitempty\"`\n\tInterface    string `yaml:\"interface,omitempty\" json:\"interface,omitempty\"`\n\n\t// API Version overrides.\n\tIdentityAPIVersion string `yaml:\"identity_api_version,omitempty\" json:\"identity_api_version,omitempty\"`\n\tVolumeAPIVersion   string `yaml:\"volume_api_version,omitempty\" json:\"volume_api_version,omitempty\"`\n\n\t// Verify whether or not SSL API requests should be verified.\n\tVerify *bool `yaml:\"verify,omitempty\" json:\"verify,omitempty\"`\n\n\t// CACertFile a path to a CA Cert bundle that can be used as part of\n\t// verifying SSL API requests.\n\tCACertFile string `yaml:\"cacert,omitempty\" json:\"cacert,omitempty\"`\n\n\t// ClientCertFile a path to a client certificate to use as part of the SSL\n\t// transaction.\n\tClientCertFile string `yaml:\"cert,omitempty\" json:\"cert,omitempty\"`\n\n\t// ClientKeyFile a path to a client key to use as part of the SSL\n\t// transaction.\n\tClientKeyFile string `yaml:\"key,omitempty\" json:\"key,omitempty\"`\n}\n```\nCloud represents an entry in a clouds.yaml/public-clouds.yaml/secure.yaml file.\n\n```go\nfunc GetCloudFromYAML(opts *ClientOpts) (*Cloud, error)\n```\nGetCloudFromYAML will return a cloud entry from a clouds.yaml file.\n\n```go\ntype Clouds struct {\n\tClouds map[string]Cloud `yaml:\"clouds\" json:\"clouds\"`\n}\n```\nClouds represents a collection of Cloud entries in a clouds.yaml file. The format of clouds.yaml is documented at [https://docs.openstack.org/os-client-config/latest/user/configuration.html](https://docs.openstack.org/os-client-config/latest/user/configuration.html).\n\n```go\ntype PublicClouds struct {\n\tClouds map[string]Cloud `yaml:\"public-clouds\" json:\"public-clouds\"`\n}\n```\nPublicClouds represents a collection of PublicCloud entries in clouds-public.yaml file. The format of the clouds-public.yml is documented at [https://docs.openstack.org/python-openstackclient/latest/configuration/](https://docs.openstack.org/python-openstackclient/latest/configuration/)\n\n```go\ntype Region struct {\n\tName   string `yaml:\"name,omitempty\" json:\"name,omitempty\"`\n\tValues Cloud  `yaml:\"values,omitempty\" json:\"values,omitempty\"`\n}\n```\nRegion represents a region included as part of cloud in clouds.yaml According to Python-based openstacksdk, this can be either a struct (as defined) or a plain string. Custom unmarshallers handle both cases.\n\n```go\nfunc (r *Region) UnmarshalJSON(data []byte) error\n```\nUnmarshalJSON handles either a plain string acting as the Name property or a struct, mimicking the Python-based openstacksdk.\n\n```go\nfunc (r *Region) UnmarshalYAML(unmarshal func(interface{}) error) error\n```\nUnmarshalYAML handles either a plain string acting as the Name property or a struct, mimicking the Python-based openstacksdk.\n\n```go\ntype YAMLOpts struct {\n}\n```\nYAMLOpts represents options and methods to load a clouds.yaml file.\n\n```go\nfunc (opts YAMLOpts) LoadCloudsYAML() (map[string]Cloud, error)\n```\nLoadCloudsYAML defines how to load a clouds.yaml file. By default, this calls the local LoadCloudsYAML function.\n\n```go\nfunc (opts YAMLOpts) LoadPublicCloudsYAML() (map[string]Cloud, error)\n```\nLoadPublicCloudsYAML defines how to load a public-secure.yaml file. By default, this calls the local LoadPublicCloudsYAML function.\n\n```go\nfunc (opts YAMLOpts) LoadSecureCloudsYAML() (map[string]Cloud, error)\n```\nLoadSecureCloudsYAML defines how to load a secure.yaml file. By default, this calls the local LoadSecureCloudsYAML function.\n\n```go\ntype YAMLOptsBuilder interface {\n\tLoadCloudsYAML() (map[string]Cloud, error)\n\tLoadSecureCloudsYAML() (map[string]Cloud, error)\n\tLoadPublicCloudsYAML() (map[string]Cloud, error)\n}\n```\nYAMLOptsBuilder defines an interface for customization when loading a clouds.yaml file.\n\n","path":"github.com/gophercloud/utils/openstack/clientconfig","name":"clientconfig","synopsis":"Package clientconfig provides convienent functions for creating OpenStack clients.","isRedistributable":true}
