Merge lp:~justin-fathomdb/goose/keystone_improvements into lp:goose

Proposed by justinsb
Status: Needs review
Proposed branch: lp:~justin-fathomdb/goose/keystone_improvements
Merge into: lp:goose
Diff against target: 175 lines (+80/-8)
5 files modified
identity/identity.go (+12/-1)
identity/keypair.go (+10/-3)
identity/keystone.go (+1/-1)
identity/tenants.go (+47/-0)
identity/userpass.go (+10/-3)
To merge this branch: bzr merge lp:~justin-fathomdb/goose/keystone_improvements
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+234130@code.launchpad.net

Description of the change

Support TenantId & TenantName auth, also support token validation

Let me know if I should split this into two patches!

To post a comment you must log in.
Revision history for this message
justinsb (justin-fathomdb) wrote :

Ping?

Unmerged revisions

119. By justinsb

Support TenantId & TenantName, and support validation of tokens

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'identity/identity.go'
2--- identity/identity.go 2013-09-04 10:35:49 +0000
3+++ identity/identity.go 2014-09-10 14:48:20 +0000
4@@ -39,17 +39,28 @@
5 type AuthDetails struct {
6 Token string
7 TenantId string
8+ TenantName string
9 UserId string
10 RegionServiceURLs map[string]ServiceURLs // Service type to endpoint URLs for each region
11 }
12
13 // Credentials defines necessary parameters for authentication.
14+// For tenant scoping, specify either TenantId or TenantName, not both
15 type Credentials struct {
16 URL string // The URL to authenticate against
17 User string // The username to authenticate as
18 Secrets string // The secrets to pass
19 Region string // Region to send requests to
20- TenantName string // The tenant information for this connection
21+ TenantName string // The tenant name for this connection
22+ TenantId string // The tenant id for this connection
23+}
24+
25+// TenantInfo holds more information about a tenant
26+type TenantInfo struct {
27+ Id string
28+ Name string
29+ Description string
30+ Enabled bool
31 }
32
33 // Authenticator is implemented by each authentication method.
34
35=== modified file 'identity/keypair.go'
36--- identity/keypair.go 2013-05-21 01:07:40 +0000
37+++ identity/keypair.go 2014-09-10 14:48:20 +0000
38@@ -19,7 +19,8 @@
39
40 type authKeypairRequest struct {
41 KeypairCredentials keypairCredentials `json:"apiAccessKeyCredentials"`
42- TenantName string `json:"tenantName"`
43+ TenantName *string `json:"tenantName"`
44+ TenantId *string `json:"tenantId"`
45 }
46
47 type authKeypairWrapper struct {
48@@ -30,12 +31,18 @@
49 if u.client == nil {
50 u.client = goosehttp.New()
51 }
52- auth := authKeypairWrapper{Auth: authKeypairRequest{
53+ authData := authKeypairRequest{
54 KeypairCredentials: keypairCredentials{
55 AccessKey: creds.User,
56 SecretKey: creds.Secrets,
57 },
58- TenantName: creds.TenantName}}
59+ }
60+ if creds.TenantId != "" {
61+ authData.TenantId = &creds.TenantId
62+ } else {
63+ authData.TenantName = &creds.TenantName
64+ }
65+ auth := authKeypairWrapper{Auth: authData}
66
67 return keystoneAuth(u.client, auth, creds.URL)
68 }
69
70=== modified file 'identity/keystone.go'
71--- identity/keystone.go 2013-06-24 23:54:26 +0000
72+++ identity/keystone.go 2014-09-10 14:48:20 +0000
73@@ -57,7 +57,6 @@
74 // Uses `client` to submit HTTP requests to `URL`
75 // and posts `auth_data` as JSON.
76 func keystoneAuth(client *goosehttp.Client, auth_data interface{}, URL string) (*AuthDetails, error) {
77-
78 var accessWrapper accessWrapper
79 requestData := goosehttp.RequestData{ReqValue: auth_data, RespValue: &accessWrapper}
80 err := client.JsonRequest("POST", URL, "", &requestData, nil)
81@@ -73,6 +72,7 @@
82 }
83 details.Token = respToken.Id
84 details.TenantId = respToken.Tenant.Id
85+ details.TenantName = respToken.Tenant.Name
86 details.UserId = access.User.Id
87 details.RegionServiceURLs = make(map[string]ServiceURLs, len(access.ServiceCatalog))
88 for _, service := range access.ServiceCatalog {
89
90=== added file 'identity/tenants.go'
91--- identity/tenants.go 1970-01-01 00:00:00 +0000
92+++ identity/tenants.go 2014-09-10 14:48:20 +0000
93@@ -0,0 +1,47 @@
94+package identity
95+
96+import (
97+ goosehttp "launchpad.net/goose/http"
98+)
99+
100+type tenantResponse struct {
101+ Id string `json:"id"`
102+ Name string `json:"name"`
103+ // Description is a pointer since it may be null and this breaks Go < 1.1
104+ Description *string `json:"description"`
105+ Enabled bool `json:"enabled"`
106+}
107+
108+type validateResponse struct {
109+ Tenants []tenantResponse `json:"tenants"`
110+}
111+
112+// ListTenantsForToken gets the tenants associated with a particular token
113+// The httpclient is allowed to be nil, it will just use the
114+// default http.Client
115+func ListTenantsForToken(URL string, token string, client *goosehttp.Client) ([]TenantInfo, error) {
116+ if client == nil {
117+ client = goosehttp.New()
118+ }
119+ var validateResponse validateResponse
120+ requestData := goosehttp.RequestData{RespValue: &validateResponse}
121+ err := client.JsonRequest("GET", URL, token, &requestData, nil)
122+ if err != nil {
123+ return nil, err
124+ }
125+
126+ tenants := []TenantInfo{}
127+
128+ for _, tenant := range validateResponse.Tenants {
129+ tenantInfo := TenantInfo{}
130+ tenantInfo.Id = tenant.Id
131+ tenantInfo.Name = tenant.Name
132+ if tenant.Description != nil {
133+ tenantInfo.Description = *tenant.Description
134+ }
135+ tenantInfo.Enabled = tenant.Enabled
136+
137+ tenants = append(tenants, tenantInfo)
138+ }
139+ return tenants, nil
140+}
141
142=== modified file 'identity/userpass.go'
143--- identity/userpass.go 2013-09-04 09:06:21 +0000
144+++ identity/userpass.go 2014-09-10 14:48:20 +0000
145@@ -11,7 +11,8 @@
146
147 type authRequest struct {
148 PasswordCredentials passwordCredentials `json:"passwordCredentials"`
149- TenantName string `json:"tenantName"`
150+ TenantName *string `json:"tenantName"`
151+ TenantId *string `json:"tenantId"`
152 }
153
154 type authWrapper struct {
155@@ -26,12 +27,18 @@
156 if u.client == nil {
157 u.client = goosehttp.New()
158 }
159- auth := authWrapper{Auth: authRequest{
160+ authData := authRequest{
161 PasswordCredentials: passwordCredentials{
162 Username: creds.User,
163 Password: creds.Secrets,
164 },
165- TenantName: creds.TenantName}}
166+ }
167+ if creds.TenantId != "" {
168+ authData.TenantId = &creds.TenantId
169+ } else {
170+ authData.TenantName = &creds.TenantName
171+ }
172+ auth := authWrapper{Auth: authData}
173
174 return keystoneAuth(u.client, auth, creds.URL)
175 }

Subscribers

People subscribed via source and target branches