gophercloudext

package
v0.0.0-...-19cec9c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 12, 2025 License: Apache-2.0 Imports: 9 Imported by: 4

Documentation

Overview

Package gophercloudext contains convenience functions for use with Gophercloud. Its func NewProviderClient is specifically intended as a lightweight replacement for gophercloud/utils with fewer dependencies, but there are also other generalized utility functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetProjectIDFromTokenScope

func GetProjectIDFromTokenScope(provider *gophercloud.ProviderClient) (string, error)

GetProjectIDFromTokenScope returns the project ID from the client's token scope.

This is useful in applications that usually operate on the cloud-admin level, when using an API endpoint that requires a project ID in its URL. Usually this is then overridden by a query parameter like "?all_projects=True".

func NewProviderClient

func NewProviderClient(ctx context.Context, optsPtr *ClientOpts) (*gophercloud.ProviderClient, gophercloud.EndpointOpts, error)

NewProviderClient authenticates with OpenStack using the credentials found in the usual OS_* environment variables.

Ref: https://docs.openstack.org/python-openstackclient/latest/cli/man/openstack.html

This function has the same purpose as AuthenticatedClient from package github.com/gophercloud/utils/openstack/clientconfig, except for some differences that make it specifically suited for long-running server applications and remove functionality only needed for interactive use:

  • It always sets AllowReauth on the ProviderClient.
  • It does not support authenticating with a pre-existing Keystone token.
  • It does not support reading clouds.yaml files.
  • It does not support the old Keystone v2 authentication (only v3).

Also, to simplify things, some legacy or fallback environment variables are not supported:

  • OS_TENANT_ID (give OS_PROJECT_ID instead)
  • OS_TENANT_NAME (give OS_PROJECT_NAME instead)
  • OS_DEFAULT_DOMAIN_ID (give OS_PROJECT_DOMAIN_ID and OS_USER_DOMAIN_ID instead)
  • OS_DEFAULT_DOMAIN_NAME (give OS_PROJECT_DOMAIN_NAME and OS_USER_DOMAIN_NAME instead)
  • OS_APPLICATION_CREDENTIAL_NAME (give OS_APPLICATION_CREDENTIAL_ID instead)

Types

type ClientOpts

type ClientOpts struct {
	// EnvPrefix allows a custom environment variable prefix to be used.
	// If not set, "OS_" is used.
	EnvPrefix string

	// HTTPClient is the ProviderClient's internal HTTP client.
	// If not set, a fresh http.Client using http.DefaultTransport will be used.
	//
	// This is a weird behavior, but we cannot do better because
	// gophercloud.ProviderClient insists on taking ownership of whatever is
	// given here, so we cannot just give http.DefaultClient here.
	HTTPClient *http.Client

	// CustomizeAuthOptions is a callback that can be used to modify the
	// constructed AuthOptions before they are passed to the ProviderClient.
	//
	// This is used in rare special cases, e.g. when an application needs to
	// spawn clients with different token scopes for specific operations.
	CustomizeAuthOptions func(*gophercloud.AuthOptions)
}

ClientOpts contains configuration for NewProviderClient().

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL