Skip to content

Commit cbf8029

Browse files
author
Ryan Bak
committed
Minor performance improvements for logon
Sets no catalog flag Gets token from existing token
1 parent 6fd1377 commit cbf8029

File tree

2 files changed

+52
-22
lines changed

2 files changed

+52
-22
lines changed

pkg/api/keystone/keystone_requests.go

Lines changed: 51 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,40 @@ type auth_struct struct {
2121
Scope string `json:"scope"`
2222
}
2323

24-
type scoped_auth_request_struct struct {
25-
Auth scoped_auth_struct `json:"auth"`
24+
type scoped_auth_token_request_struct struct {
25+
Auth scoped_auth_token_struct `json:"auth"`
2626
}
2727

28-
type scoped_auth_struct struct {
29-
Identity auth_identity_struct `json:"identity"`
30-
Scope auth_scope_struct `json:"scope"`
28+
type scoped_auth_password_request_struct struct {
29+
Auth scoped_auth_password_struct `json:"auth"`
30+
}
31+
32+
type scoped_auth_token_struct struct {
33+
Nocatalog bool `json:"nocatalog"`
34+
Identity auth_scoped_identity_struct `json:"identity"`
35+
Scope auth_scope_struct `json:"scope"`
36+
}
37+
38+
type scoped_auth_password_struct struct {
39+
Nocatalog bool `json:"nocatalog"`
40+
Identity auth_identity_struct `json:"identity"`
41+
Scope auth_scope_struct `json:"scope"`
42+
}
43+
44+
type auth_scoped_identity_struct struct {
45+
Methods []string `json:"methods"`
46+
Token auth_token_method_struct `json:"token"`
3147
}
3248

3349
type auth_identity_struct struct {
3450
Methods []string `json:"methods"`
3551
Password auth_password_method_struct `json:"password"`
3652
}
3753

54+
type auth_token_method_struct struct {
55+
Id string `json:"id"`
56+
}
57+
3858
type auth_password_method_struct struct {
3959
User auth_user_struct `json:"user"`
4060
}
@@ -92,28 +112,39 @@ type project_struct struct {
92112

93113
// Authentication Section Section
94114
type Auth_data struct {
95-
Server string
96-
Domain string
97-
Username string
98-
Password string
99-
Project string
115+
Server string
116+
Domain string
117+
Username string
118+
Password string
119+
Project string
120+
UnscopedToken string
100121
//response
101122
Token string
102123
Expiration string
103124
Roles []auth_roles_struct
104125
}
105126

106127
func AuthenticateScoped(data *Auth_data) error {
107-
var auth_post scoped_auth_request_struct
108-
auth_post.Auth.Identity.Methods = []string{"password"}
109-
auth_post.Auth.Identity.Password.User.Name = data.Username
110-
auth_post.Auth.Identity.Password.User.Password = data.Password
111-
auth_post.Auth.Identity.Password.User.Domain.Name = data.Domain
112-
auth_post.Auth.Scope.Project.Domain.Name = data.Domain
113-
auth_post.Auth.Scope.Project.Name = data.Project
114-
b, _ := json.Marshal(auth_post)
115-
116-
return authenticate(data, b)
128+
if data.UnscopedToken != "" {
129+
var auth_post scoped_auth_token_request_struct
130+
auth_post.Auth.Identity.Methods = []string{"token"}
131+
auth_post.Auth.Identity.Token.Id = data.UnscopedToken
132+
auth_post.Auth.Scope.Project.Domain.Name = data.Domain
133+
auth_post.Auth.Scope.Project.Name = data.Project
134+
b, _ := json.Marshal(auth_post)
135+
return authenticate(data, b)
136+
} else {
137+
var auth_post scoped_auth_password_request_struct
138+
auth_post.Auth.Nocatalog = true
139+
auth_post.Auth.Identity.Methods = []string{"password"}
140+
auth_post.Auth.Identity.Password.User.Name = data.Username
141+
auth_post.Auth.Identity.Password.User.Password = data.Password
142+
auth_post.Auth.Identity.Password.User.Domain.Name = data.Domain
143+
auth_post.Auth.Scope.Project.Domain.Name = data.Domain
144+
auth_post.Auth.Scope.Project.Name = data.Project
145+
b, _ := json.Marshal(auth_post)
146+
return authenticate(data, b)
147+
}
117148
}
118149

119150
func AuthenticateUnscoped(data *Auth_data) error {

pkg/login/keystone.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,9 @@ func (a *keystoneAuther) getProjectList(username, password string) error {
287287
for _, project := range projects {
288288
var auth keystone.Auth_data
289289
auth.Server = a.server
290-
auth.Username = username
291-
auth.Password = password
292290
auth.Domain = a.domainname
293291
auth.Project = project
292+
auth.UnscopedToken = a.token
294293
if err := keystone.AuthenticateScoped(&auth); err != nil {
295294
return err
296295
}

0 commit comments

Comments
 (0)