OLD | NEW |
1 // goose/identity - Go package to interact with OpenStack Identity (Keystone) AP
I. | 1 // goose/identity - Go package to interact with OpenStack Identity (Keystone) AP
I. |
2 | 2 |
3 package identity | 3 package identity |
4 | 4 |
5 import ( | 5 import ( |
6 "fmt" | 6 "fmt" |
7 "os" | 7 "os" |
8 "reflect" | 8 "reflect" |
| 9 |
| 10 goosehttp "launchpad.net/goose/http" |
9 ) | 11 ) |
10 | 12 |
11 // AuthMode defines the authentication method to use (see Auth* | 13 // AuthMode defines the authentication method to use (see Auth* |
12 // constants below). | 14 // constants below). |
13 type AuthMode int | 15 type AuthMode int |
14 | 16 |
15 const ( | 17 const ( |
16 AuthLegacy = AuthMode(iota) // Legacy authentication | 18 AuthLegacy = AuthMode(iota) // Legacy authentication |
17 AuthUserPass // Username + password authentication | 19 AuthUserPass // Username + password authentication |
18 AuthKeyPair // Access/secret key pair authentication | 20 AuthKeyPair // Access/secret key pair authentication |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 v := reflect.ValueOf(cred).Elem() | 92 v := reflect.ValueOf(cred).Elem() |
91 t := v.Type() | 93 t := v.Type() |
92 for i := 0; i < v.NumField(); i++ { | 94 for i := 0; i < v.NumField(); i++ { |
93 f := v.Field(i) | 95 f := v.Field(i) |
94 if f.String() == "" { | 96 if f.String() == "" { |
95 err = fmt.Errorf("required environment variable not set
for credentials attribute: %s", t.Field(i).Name) | 97 err = fmt.Errorf("required environment variable not set
for credentials attribute: %s", t.Field(i).Name) |
96 } | 98 } |
97 } | 99 } |
98 return | 100 return |
99 } | 101 } |
| 102 |
| 103 // NewAuthenticator creates an authenticator matching the supplied AuthMode. |
| 104 // The httpclient is allowed to be nil, the Authenticator will just use the |
| 105 // default http.Client |
| 106 func NewAuthenticator(authMode AuthMode, httpClient *goosehttp.Client) Authentic
ator { |
| 107 if httpClient == nil { |
| 108 httpClient = goosehttp.New() |
| 109 } |
| 110 switch authMode { |
| 111 default: |
| 112 panic(fmt.Errorf("Invalid identity authorisation mode: %d", auth
Mode)) |
| 113 case AuthLegacy: |
| 114 return &Legacy{client: httpClient} |
| 115 case AuthUserPass: |
| 116 return &UserPass{client: httpClient} |
| 117 case AuthKeyPair: |
| 118 return &KeyPair{client: httpClient} |
| 119 } |
| 120 } |
OLD | NEW |