Skip to content

Commit 9d3f812

Browse files
yuri-perncw
authored andcommitted
Support UserId for auth v3
Authentication in IBM Bluemix requires UserId instead of UserName
1 parent af59a5a commit 9d3f812

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

auth_v3.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,15 @@ func (auth *v3Auth) Request(c *Connection) (*http.Request, error) {
117117

118118
v3 := v3AuthRequest{}
119119

120-
if c.UserName == "" {
120+
if c.UserName == "" && c.UserId == "" {
121121
v3.Auth.Identity.Methods = []string{v3AuthMethodToken}
122122
v3.Auth.Identity.Token = &v3AuthToken{Id: c.ApiKey}
123123
} else {
124124
v3.Auth.Identity.Methods = []string{v3AuthMethodPassword}
125125
v3.Auth.Identity.Password = &v3AuthPassword{
126126
User: v3User{
127127
Name: c.UserName,
128+
Id: c.UserId,
128129
Password: c.ApiKey,
129130
},
130131
}

swift.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ type Connection struct {
9999
Domain string // User's domain name
100100
DomainId string // User's domain Id
101101
UserName string // UserName for api
102+
UserId string // User Id
102103
ApiKey string // Key for api access
103104
AuthUrl string // Auth URL
104105
Retries int // Retries on error (default is 3)
@@ -191,6 +192,7 @@ func setFromEnv(param interface{}, name string) (err error) {
191192
// For v3 authentication
192193
// OS_AUTH_URL - Auth URL
193194
// OS_USERNAME - UserName for api
195+
// OS_USER_ID - User Id
194196
// OS_PASSWORD - Key for api access
195197
// OS_USER_DOMAIN_NAME - User's domain name
196198
// OS_USER_DOMAIN_ID - User's domain Id
@@ -223,6 +225,7 @@ func (c *Connection) ApplyEnvironment() (err error) {
223225
{&c.Domain, "OS_USER_DOMAIN_NAME"},
224226
{&c.DomainId, "OS_USER_DOMAIN_ID"},
225227
{&c.UserName, "OS_USERNAME"},
228+
{&c.UserId, "OS_USER_ID"},
226229
{&c.ApiKey, "OS_PASSWORD"},
227230
{&c.AuthUrl, "OS_AUTH_URL"},
228231
{&c.Retries, "GOSWIFT_RETRIES"},

swift_internal_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,7 @@ func TestApplyEnvironmentAll(t *testing.T) {
576576
{1, &c.Domain, "OS_USER_DOMAIN_NAME", "os_user_domain_name", "os_user_domain_name", ""},
577577
{1, &c.DomainId, "OS_USER_DOMAIN_ID", "os_user_domain_id", "os_user_domain_id", ""},
578578
{1, &c.UserName, "OS_USERNAME", "os_username", "os_username", ""},
579+
{1, &c.UserId, "OS_USER_ID", "os_user_id", "os_user_id", ""},
579580
{1, &c.ApiKey, "OS_PASSWORD", "os_password", "os_password", ""},
580581
{1, &c.AuthUrl, "OS_AUTH_URL", "os_auth_url", "os_auth_url", ""},
581582
{1, &c.Retries, "GOSWIFT_RETRIES", "4", 4, ""},

0 commit comments

Comments
 (0)