-
Notifications
You must be signed in to change notification settings - Fork 9
/
requests.go
52 lines (40 loc) · 1.2 KB
/
requests.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
42
43
44
45
46
47
48
49
50
51
52
package swauth
import "github.com/opentelekomcloud/gophertelekomcloud"
// AuthOptsBuilder describes struct types that can be accepted by the Auth call.
type AuthOptsBuilder interface {
ToAuthOptsMap() (map[string]string, error)
}
// AuthOpts specifies an authentication request.
type AuthOpts struct {
// User is an Swauth-based username in username:tenant format.
User string `h:"X-Auth-User" required:"true"`
// Key is a secret/password to authenticate the User with.
Key string `h:"X-Auth-Key" required:"true"`
}
// ToAuthOptsMap formats an AuthOpts structure into a request body.
func (opts AuthOpts) ToAuthOptsMap() (map[string]string, error) {
return golangsdk.BuildHeaders(opts)
}
// Auth performs an authentication request for a Swauth-based user.
func Auth(c *golangsdk.ProviderClient, opts AuthOptsBuilder) (r GetAuthResult) {
h := make(map[string]string)
if opts != nil {
headers, err := opts.ToAuthOptsMap()
if err != nil {
r.Err = err
return
}
for k, v := range headers {
h[k] = v
}
}
resp, err := c.Request("GET", getURL(c), &golangsdk.RequestOpts{
MoreHeaders: h,
OkCodes: []int{200},
})
if resp != nil {
r.Header = resp.Header
}
r.Err = err
return r
}