Conversation
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"),
)
```
4538eef to
22c5682
Compare
EmilienM
approved these changes
Feb 8, 2024
Contributor
|
I think it's correct, thanks Pierre for the force push. Unit tests seem happy. |
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.Parsefunction keeps the separation between the ProviderClient (holding the cloud coordinates and a Keystone token) and the ServiceClient (holding specific endpoint configuration).By default,
clouds.Parsefetches its configuration from the environment, just like the openstack client would do.Example use:
The
clouds.Parsefunction accepts several functional options that can modify its behaviour. For example, to use aclouds.yamlthat exists in a non-standard path: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.