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
1=== modified file 'environs/openstack/config.go'
2--- environs/openstack/config.go 2013-04-10 02:56:46 +0000
3+++ environs/openstack/config.go 2013-05-09 00:36:24 +0000
4@@ -15,6 +15,8 @@
5 "tenant-name": schema.String(),
6 "auth-url": schema.String(),
7 "auth-mode": schema.String(),
8+ "access-key": schema.String(),
9+ "secret-key": schema.String(),
10 "region": schema.String(),
11 "control-bucket": schema.String(),
12 "public-bucket": schema.String(),
13@@ -29,6 +31,8 @@
14 "tenant-name": "",
15 "auth-url": "",
16 "auth-mode": string(AuthUserPass),
17+ "access-key": "",
18+ "secret-key": "",
19 "region": "",
20 "control-bucket": "",
21 "public-bucket": "juju-dist",
22@@ -68,6 +72,14 @@
23 return c.attrs["auth-mode"].(string)
24 }
25
26+func (c *environConfig) accessKey() string {
27+ return c.attrs["access-key"].(string)
28+}
29+
30+func (c *environConfig) secretKey() string {
31+ return c.attrs["secret-key"].(string)
32+}
33+
34 func (c *environConfig) controlBucket() string {
35 return c.attrs["control-bucket"].(string)
36 }
37@@ -103,6 +115,7 @@
38 type AuthMode string
39
40 const (
41+ AuthKeyPair AuthMode = "keypair"
42 AuthLegacy AuthMode = "legacy"
43 AuthUserPass AuthMode = "userpass"
44 )
45@@ -118,8 +131,9 @@
46 }
47 ecfg := &environConfig{cfg, v.(map[string]interface{})}
48
49- authMode := ecfg.authMode()
50- switch AuthMode(authMode) {
51+ authMode := AuthMode(ecfg.authMode())
52+ switch authMode {
53+ case AuthKeyPair:
54 case AuthLegacy:
55 case AuthUserPass:
56 default:
57@@ -134,17 +148,32 @@
58 }
59 cred := identity.CredentialsFromEnv()
60 format := "required environment variable not set for credentials attribute: %s"
61- if ecfg.username() == "" {
62- if cred.User == "" {
63- return nil, fmt.Errorf(format, "User")
64- }
65- ecfg.attrs["username"] = cred.User
66- }
67- if ecfg.password() == "" {
68- if cred.Secrets == "" {
69- return nil, fmt.Errorf(format, "Secrets")
70- }
71- ecfg.attrs["password"] = cred.Secrets
72+ if authMode == AuthUserPass || authMode == AuthLegacy {
73+ if ecfg.username() == "" {
74+ if cred.User == "" {
75+ return nil, fmt.Errorf(format, "User")
76+ }
77+ ecfg.attrs["username"] = cred.User
78+ }
79+ if ecfg.password() == "" {
80+ if cred.Secrets == "" {
81+ return nil, fmt.Errorf(format, "Secrets")
82+ }
83+ ecfg.attrs["password"] = cred.Secrets
84+ }
85+ } else if authMode == AuthKeyPair {
86+ if ecfg.accessKey() == "" {
87+ if cred.User == "" {
88+ return nil, fmt.Errorf(format, "User")
89+ }
90+ ecfg.attrs["access-key"] = cred.User
91+ }
92+ if ecfg.secretKey() == "" {
93+ if cred.Secrets == "" {
94+ return nil, fmt.Errorf(format, "Secrets")
95+ }
96+ ecfg.attrs["secret-key"] = cred.Secrets
97+ }
98 }
99 if ecfg.authURL() == "" {
100 if cred.URL == "" {
101
102=== modified file 'environs/openstack/config_test.go'
103--- environs/openstack/config_test.go 2013-04-09 18:26:11 +0000
104+++ environs/openstack/config_test.go 2013-05-09 00:36:24 +0000
105@@ -49,6 +49,8 @@
106 tenantName string
107 authMode string
108 authURL string
109+ accessKey string
110+ secretKey string
111 firewallMode config.FirewallMode
112 err string
113 }
114@@ -125,6 +127,12 @@
115 if t.authMode != "" {
116 c.Assert(ecfg.authMode(), Equals, t.authMode)
117 }
118+ if t.accessKey != "" {
119+ c.Assert(ecfg.accessKey(), Equals, t.accessKey)
120+ }
121+ if t.secretKey != "" {
122+ c.Assert(ecfg.secretKey(), Equals, t.secretKey)
123+ }
124 if t.username != "" {
125 c.Assert(ecfg.username(), Equals, t.username)
126 c.Assert(ecfg.password(), Equals, t.password)
127@@ -265,6 +273,36 @@
128 },
129 err: ".*invalid authorization mode.*",
130 }, {
131+ summary: "keypair authorization mode",
132+ config: attrs{
133+ "auth-mode": "keypair",
134+ "access-key": "MyAccessKey",
135+ "secret-key": "MySecretKey",
136+ },
137+ authMode: "keypair",
138+ accessKey: "MyAccessKey",
139+ secretKey: "MySecretKey",
140+ }, {
141+ summary: "keypair authorization mode without access key",
142+ config: attrs{
143+ "auth-mode": "keypair",
144+ "secret-key": "MySecretKey",
145+ },
146+ envVars: map[string]string{
147+ "OS_USERNAME": "",
148+ },
149+ err: "required environment variable not set for credentials attribute: User",
150+ }, {
151+ summary: "keypair authorization mode without secret key",
152+ config: attrs{
153+ "auth-mode": "keypair",
154+ "access-key": "MyAccessKey",
155+ },
156+ envVars: map[string]string{
157+ "OS_PASSWORD": "",
158+ },
159+ err: "required environment variable not set for credentials attribute: Secrets",
160+ }, {
161 summary: "invalid auth-url format",
162 config: attrs{
163 "auth-url": "invalid",
164
165=== modified file 'environs/openstack/local_test.go'
166--- environs/openstack/local_test.go 2013-04-29 01:39:21 +0000
167+++ environs/openstack/local_test.go 2013-05-09 00:36:24 +0000
168@@ -130,7 +130,7 @@
169 s.Server.Config.Handler = s.Mux
170 cred.URL = s.Server.URL
171 c.Logf("Started service at: %v", s.Server.URL)
172- s.Service = openstackservice.New(cred)
173+ s.Service = openstackservice.New(cred, identity.AuthUserPass)
174 s.Service.SetupHTTP(s.Mux)
175 openstack.ShortTimeouts(true)
176 }
177
178=== modified file 'environs/openstack/provider.go'
179--- environs/openstack/provider.go 2013-04-23 04:03:33 +0000
180+++ environs/openstack/provider.go 2013-05-09 00:36:24 +0000
181@@ -540,6 +540,10 @@
182 authMode = identity.AuthLegacy
183 case AuthUserPass:
184 authMode = identity.AuthUserPass
185+ case AuthKeyPair:
186+ authMode = identity.AuthKeyPair
187+ cred.User = ecfg.accessKey()
188+ cred.Secrets = ecfg.secretKey()
189 }
190 return client.NewClient(cred, authMode, nil)
191 }

Subscribers

People subscribed via source and target branches