Merge lp:~danilo/juju-core/bug-1135335 into lp:~juju/juju-core/trunk

Proposed by Данило Шеган
Status: Merged
Merged at revision: 1210
Proposed branch: lp:~danilo/juju-core/bug-1135335
Merge into: lp:~juju/juju-core/trunk
Diff against target: 191 lines (+85/-14)
4 files modified
environs/openstack/config.go (+42/-13)
environs/openstack/config_test.go (+38/-0)
environs/openstack/local_test.go (+1/-1)
environs/openstack/provider.go (+4/-0)
To merge this branch: bzr merge lp:~danilo/juju-core/bug-1135335
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+161377@code.launchpad.net

Description of the change

Support keypair auth for HP cloud

Add support for 'access-key' and 'secret-key' environment options (or appropriate environment variables) when auth-mode is set to 'keypair' (now supported). Make use of lp:goose r90 (or newer) to do the actual authentication.

https://codereview.appspot.com/8858049/

To post a comment you must log in.
Revision history for this message
Данило Шеган (danilo) wrote :

Reviewers: mp+161377_code.launchpad.net,

Message:
Please take a look.

Description:
Support keypair auth for HP cloud

Add support for 'access-key' and 'secret-key' environment options (or
appropriate environment variables) when auth-mode is set to 'keypair'
(now supported). Make use of goose (see lp:~danilo/goose/bug-1135335)
to do the actual authentication.

This has been tested with the actual HP cloud we've got access to.

https://code.launchpad.net/~danilo/juju-core/bug-1135335/+merge/161377

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/8858049/

Affected files:
   A [revision details]
   M environs/openstack/config.go
   M environs/openstack/config_test.go
   M environs/openstack/local_test.go
   M environs/openstack/provider.go

Revision history for this message
Dimiter Naydenov (dimitern) wrote :
Revision history for this message
Данило Шеган (danilo) wrote :

*** Submitted:

Support keypair auth for HP cloud

Add support for 'access-key' and 'secret-key' environment options (or
appropriate environment variables) when auth-mode is set to 'keypair'
(now supported). Make use of lp:goose r90 (or newer) to do the actual
authentication.

R=dimitern, TheMue
CC=
https://codereview.appspot.com/8858049

https://codereview.appspot.com/8858049/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'environs/openstack/config.go'
--- environs/openstack/config.go 2013-04-10 02:56:46 +0000
+++ environs/openstack/config.go 2013-05-09 00:36:24 +0000
@@ -15,6 +15,8 @@
15 "tenant-name": schema.String(),15 "tenant-name": schema.String(),
16 "auth-url": schema.String(),16 "auth-url": schema.String(),
17 "auth-mode": schema.String(),17 "auth-mode": schema.String(),
18 "access-key": schema.String(),
19 "secret-key": schema.String(),
18 "region": schema.String(),20 "region": schema.String(),
19 "control-bucket": schema.String(),21 "control-bucket": schema.String(),
20 "public-bucket": schema.String(),22 "public-bucket": schema.String(),
@@ -29,6 +31,8 @@
29 "tenant-name": "",31 "tenant-name": "",
30 "auth-url": "",32 "auth-url": "",
31 "auth-mode": string(AuthUserPass),33 "auth-mode": string(AuthUserPass),
34 "access-key": "",
35 "secret-key": "",
32 "region": "",36 "region": "",
33 "control-bucket": "",37 "control-bucket": "",
34 "public-bucket": "juju-dist",38 "public-bucket": "juju-dist",
@@ -68,6 +72,14 @@
68 return c.attrs["auth-mode"].(string)72 return c.attrs["auth-mode"].(string)
69}73}
7074
75func (c *environConfig) accessKey() string {
76 return c.attrs["access-key"].(string)
77}
78
79func (c *environConfig) secretKey() string {
80 return c.attrs["secret-key"].(string)
81}
82
71func (c *environConfig) controlBucket() string {83func (c *environConfig) controlBucket() string {
72 return c.attrs["control-bucket"].(string)84 return c.attrs["control-bucket"].(string)
73}85}
@@ -103,6 +115,7 @@
103type AuthMode string115type AuthMode string
104116
105const (117const (
118 AuthKeyPair AuthMode = "keypair"
106 AuthLegacy AuthMode = "legacy"119 AuthLegacy AuthMode = "legacy"
107 AuthUserPass AuthMode = "userpass"120 AuthUserPass AuthMode = "userpass"
108)121)
@@ -118,8 +131,9 @@
118 }131 }
119 ecfg := &environConfig{cfg, v.(map[string]interface{})}132 ecfg := &environConfig{cfg, v.(map[string]interface{})}
120133
121 authMode := ecfg.authMode()134 authMode := AuthMode(ecfg.authMode())
122 switch AuthMode(authMode) {135 switch authMode {
136 case AuthKeyPair:
123 case AuthLegacy:137 case AuthLegacy:
124 case AuthUserPass:138 case AuthUserPass:
125 default:139 default:
@@ -134,17 +148,32 @@
134 }148 }
135 cred := identity.CredentialsFromEnv()149 cred := identity.CredentialsFromEnv()
136 format := "required environment variable not set for credentials attribute: %s"150 format := "required environment variable not set for credentials attribute: %s"
137 if ecfg.username() == "" {151 if authMode == AuthUserPass || authMode == AuthLegacy {
138 if cred.User == "" {152 if ecfg.username() == "" {
139 return nil, fmt.Errorf(format, "User")153 if cred.User == "" {
140 }154 return nil, fmt.Errorf(format, "User")
141 ecfg.attrs["username"] = cred.User155 }
142 }156 ecfg.attrs["username"] = cred.User
143 if ecfg.password() == "" {157 }
144 if cred.Secrets == "" {158 if ecfg.password() == "" {
145 return nil, fmt.Errorf(format, "Secrets")159 if cred.Secrets == "" {
146 }160 return nil, fmt.Errorf(format, "Secrets")
147 ecfg.attrs["password"] = cred.Secrets161 }
162 ecfg.attrs["password"] = cred.Secrets
163 }
164 } else if authMode == AuthKeyPair {
165 if ecfg.accessKey() == "" {
166 if cred.User == "" {
167 return nil, fmt.Errorf(format, "User")
168 }
169 ecfg.attrs["access-key"] = cred.User
170 }
171 if ecfg.secretKey() == "" {
172 if cred.Secrets == "" {
173 return nil, fmt.Errorf(format, "Secrets")
174 }
175 ecfg.attrs["secret-key"] = cred.Secrets
176 }
148 }177 }
149 if ecfg.authURL() == "" {178 if ecfg.authURL() == "" {
150 if cred.URL == "" {179 if cred.URL == "" {
151180
=== modified file 'environs/openstack/config_test.go'
--- environs/openstack/config_test.go 2013-04-09 18:26:11 +0000
+++ environs/openstack/config_test.go 2013-05-09 00:36:24 +0000
@@ -49,6 +49,8 @@
49 tenantName string49 tenantName string
50 authMode string50 authMode string
51 authURL string51 authURL string
52 accessKey string
53 secretKey string
52 firewallMode config.FirewallMode54 firewallMode config.FirewallMode
53 err string55 err string
54}56}
@@ -125,6 +127,12 @@
125 if t.authMode != "" {127 if t.authMode != "" {
126 c.Assert(ecfg.authMode(), Equals, t.authMode)128 c.Assert(ecfg.authMode(), Equals, t.authMode)
127 }129 }
130 if t.accessKey != "" {
131 c.Assert(ecfg.accessKey(), Equals, t.accessKey)
132 }
133 if t.secretKey != "" {
134 c.Assert(ecfg.secretKey(), Equals, t.secretKey)
135 }
128 if t.username != "" {136 if t.username != "" {
129 c.Assert(ecfg.username(), Equals, t.username)137 c.Assert(ecfg.username(), Equals, t.username)
130 c.Assert(ecfg.password(), Equals, t.password)138 c.Assert(ecfg.password(), Equals, t.password)
@@ -265,6 +273,36 @@
265 },273 },
266 err: ".*invalid authorization mode.*",274 err: ".*invalid authorization mode.*",
267 }, {275 }, {
276 summary: "keypair authorization mode",
277 config: attrs{
278 "auth-mode": "keypair",
279 "access-key": "MyAccessKey",
280 "secret-key": "MySecretKey",
281 },
282 authMode: "keypair",
283 accessKey: "MyAccessKey",
284 secretKey: "MySecretKey",
285 }, {
286 summary: "keypair authorization mode without access key",
287 config: attrs{
288 "auth-mode": "keypair",
289 "secret-key": "MySecretKey",
290 },
291 envVars: map[string]string{
292 "OS_USERNAME": "",
293 },
294 err: "required environment variable not set for credentials attribute: User",
295 }, {
296 summary: "keypair authorization mode without secret key",
297 config: attrs{
298 "auth-mode": "keypair",
299 "access-key": "MyAccessKey",
300 },
301 envVars: map[string]string{
302 "OS_PASSWORD": "",
303 },
304 err: "required environment variable not set for credentials attribute: Secrets",
305 }, {
268 summary: "invalid auth-url format",306 summary: "invalid auth-url format",
269 config: attrs{307 config: attrs{
270 "auth-url": "invalid",308 "auth-url": "invalid",
271309
=== modified file 'environs/openstack/local_test.go'
--- environs/openstack/local_test.go 2013-04-29 01:39:21 +0000
+++ environs/openstack/local_test.go 2013-05-09 00:36:24 +0000
@@ -130,7 +130,7 @@
130 s.Server.Config.Handler = s.Mux130 s.Server.Config.Handler = s.Mux
131 cred.URL = s.Server.URL131 cred.URL = s.Server.URL
132 c.Logf("Started service at: %v", s.Server.URL)132 c.Logf("Started service at: %v", s.Server.URL)
133 s.Service = openstackservice.New(cred)133 s.Service = openstackservice.New(cred, identity.AuthUserPass)
134 s.Service.SetupHTTP(s.Mux)134 s.Service.SetupHTTP(s.Mux)
135 openstack.ShortTimeouts(true)135 openstack.ShortTimeouts(true)
136}136}
137137
=== modified file 'environs/openstack/provider.go'
--- environs/openstack/provider.go 2013-04-23 04:03:33 +0000
+++ environs/openstack/provider.go 2013-05-09 00:36:24 +0000
@@ -540,6 +540,10 @@
540 authMode = identity.AuthLegacy540 authMode = identity.AuthLegacy
541 case AuthUserPass:541 case AuthUserPass:
542 authMode = identity.AuthUserPass542 authMode = identity.AuthUserPass
543 case AuthKeyPair:
544 authMode = identity.AuthKeyPair
545 cred.User = ecfg.accessKey()
546 cred.Secrets = ecfg.secretKey()
543 }547 }
544 return client.NewClient(cred, authMode, nil)548 return client.NewClient(cred, authMode, nil)
545}549}

Subscribers

People subscribed via source and target branches