forked from go-goose/goose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
keypair.go
41 lines (34 loc) · 999 Bytes
/
keypair.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package identity
import (
goosehttp "gopkg.in/niedbalski/goose.v3/http"
)
// KeyPair allows OpenStack cloud authentication using an access and
// secret key.
//
// It implements Authenticator interface by providing the Auth method.
type KeyPair struct {
client *goosehttp.Client
}
type keypairCredentials struct {
AccessKey string `json:"accessKey"`
SecretKey string `json:"secretKey"`
}
type authKeypairRequest struct {
KeypairCredentials keypairCredentials `json:"apiAccessKeyCredentials"`
TenantName string `json:"tenantName"`
}
type authKeypairWrapper struct {
Auth authKeypairRequest `json:"auth"`
}
func (u *KeyPair) Auth(creds *Credentials) (*AuthDetails, error) {
if u.client == nil {
u.client = goosehttp.New()
}
auth := authKeypairWrapper{Auth: authKeypairRequest{
KeypairCredentials: keypairCredentials{
AccessKey: creds.User,
SecretKey: creds.Secrets,
},
TenantName: creds.TenantName}}
return keystoneAuth(u.client, auth, creds.URL)
}