Skip to content

[v1] Authenticate with a clouds.yaml#2899

Merged
EmilienM merged 1 commit intov1from
bp-v1-d7e07ae
Feb 8, 2024
Merged

[v1] Authenticate with a clouds.yaml#2899
EmilienM merged 1 commit intov1from
bp-v1-d7e07ae

Conversation

@gophercloud-backport-bot
Copy link
Copy Markdown

Backport: #2892

This commit imports the clouds.yaml parsing code from the utils module, and exposes it in a way that fits the natural Gophercloud authentication flow.

Unlike the code from utils, this new clouds.Parse function keeps the separation between the ProviderClient (holding the cloud coordinates and a Keystone token) and the ServiceClient (holding specific endpoint configuration).

By default, clouds.Parse fetches its configuration from the environment, just like the openstack client would do.

Example use:

func main() {
	ctx := context.Background()
	ao, eo, tlsConfig, err := clouds.Parse()
	if err != nil {
		panic(err)
	}

	providerClient, err := config.NewProviderClient(ctx, ao, config.WithTLSConfig(tlsConfig))
	if err != nil {
		panic(err)
	}

	networkClient, err := openstack.NewNetworkV2(providerClient, eo)
	if err != nil {
		panic(err)
	}
}

The clouds.Parse function accepts several functional options that can modify its behaviour. For example, to use a clouds.yaml that exists in a non-standard path:

ao, eo, tlsConfig, err := clouds.Parse(clouds.WithLocations("/my/path/clouds2.yaml"))

It is also possible to pass a reader directly. Note that any number of options can be passed, with each of them taking precedence of the previous if there is conflict.

const exampleClouds = `clouds:
  openstack:
    auth:
      auth_url: https://example.com:13000`

ao, eo, tlsConfig, err := clouds.Parse(
	clouds.WithCloudsYAML(strings.NewReader(exampleClouds)),
	clouds.WithIdentityEndpoint("https://example.com:13001"),
	clouds.WithCloudName("osp1"),
	clouds.WithUsername("alice"),
)

@github-actions github-actions bot added the semver:minor Backwards-compatible change label Feb 8, 2024
@coveralls
Copy link
Copy Markdown

coveralls commented Feb 8, 2024

Coverage Status

coverage: 77.271% (-0.7%) from 77.921%
when pulling 22c5682 on bp-v1-d7e07ae
into 9c47cb0 on v1.

This commit imports the clouds.yaml parsing code from the utils module, and exposes it in a way that fits the natural Gophercloud authentication flow.

Unlike the code from utils, this new `clouds.Parse` function keeps the separation between the ProviderClient (holding the cloud coordinates and a Keystone token) and the ServiceClient (holding specific endpoint configuration).

By default, `clouds.Parse` fetches its configuration from the environment, just like the openstack client would do.

Example use:

```Go
func main() {
	ctx := context.Background()
	ao, eo, tlsConfig, err := clouds.Parse()
	if err != nil {
		panic(err)
	}

	providerClient, err := config.NewProviderClient(ctx, ao, config.WithTLSConfig(tlsConfig))
	if err != nil {
		panic(err)
	}

	networkClient, err := openstack.NewNetworkV2(providerClient, eo)
	if err != nil {
		panic(err)
	}
}
```

The `clouds.Parse` function accepts several functional options that can modify its behaviour. For example, to use a `clouds.yaml` that exists in a non-standard path:

```Go
ao, eo, tlsConfig, err := clouds.Parse(clouds.WithLocations("/my/path/clouds2.yaml"))
```

It is also possible to pass a reader directly. Note that any number of options can be passed, with each of them taking precedence of the previous if there is conflict.

```Go
const exampleClouds = `clouds:
  openstack:
    auth:
      auth_url: https://example.com:13000`

ao, eo, tlsConfig, err := clouds.Parse(
	clouds.WithCloudsYAML(strings.NewReader(exampleClouds)),
	clouds.WithIdentityEndpoint("https://example.com:13001"),
	clouds.WithCloudName("osp1"),
	clouds.WithUsername("alice"),
)
```
@github-actions github-actions bot added semver:minor Backwards-compatible change and removed semver:minor Backwards-compatible change labels Feb 8, 2024
@EmilienM
Copy link
Copy Markdown
Contributor

EmilienM commented Feb 8, 2024

I think it's correct, thanks Pierre for the force push. Unit tests seem happy.

@EmilienM EmilienM merged commit e3f126e into v1 Feb 8, 2024
@EmilienM EmilienM deleted the bp-v1-d7e07ae branch February 8, 2024 13:57
@mandre mandre mentioned this pull request Mar 6, 2024
@pierreprinetti pierreprinetti added the v1 This PR targets v1 label Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

semver:minor Backwards-compatible change v1 This PR targets v1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants