@@ -16,20 +16,30 @@ import (
16
16
// Type alias for the OpenStack keystone configuration.
17
17
type KeystoneConf = conf.SyncOpenStackKeystoneConfig
18
18
19
+ // KeystoneAPI for OpenStack.
19
20
type KeystoneAPI interface {
21
+ // Authenticate against the OpenStack keystone.
20
22
Authenticate (context.Context ) error
23
+ // Get the OpenStack provider client.
21
24
Client () * gophercloud.ProviderClient
25
+ // Find the endpoint for the given service type and availability.
26
+ FindEndpoint (availability , serviceType string ) (string , error )
22
27
}
23
28
29
+ // KeystoneAPI implementation.
24
30
type keystoneAPI struct {
25
- client * gophercloud.ProviderClient
31
+ // OpenStack provider client.
32
+ client * gophercloud.ProviderClient
33
+ // OpenStack keystone configuration.
26
34
keystoneConf KeystoneConf
27
35
}
28
36
37
+ // Create a new OpenStack keystone API.
29
38
func newKeystoneAPI (keystoneConf KeystoneConf ) KeystoneAPI {
30
39
return & keystoneAPI {keystoneConf : keystoneConf }
31
40
}
32
41
42
+ // Authenticate against OpenStack keystone.
33
43
func (api * keystoneAPI ) Authenticate (ctx context.Context ) error {
34
44
if api .client != nil {
35
45
// Already authenticated.
@@ -64,6 +74,15 @@ func (api *keystoneAPI) Authenticate(ctx context.Context) error {
64
74
return nil
65
75
}
66
76
77
+ // Find the endpoint for the given service type and availability.
78
+ func (api * keystoneAPI ) FindEndpoint (availability , serviceType string ) (string , error ) {
79
+ return api .client .EndpointLocator (gophercloud.EndpointOpts {
80
+ Type : serviceType ,
81
+ Availability : gophercloud .Availability (availability ),
82
+ })
83
+ }
84
+
85
+ // Get the OpenStack provider client.
67
86
func (api * keystoneAPI ) Client () * gophercloud.ProviderClient {
68
87
return api .client
69
88
}
0 commit comments