Skip to content

Commit 4070805

Browse files
author
Joshua Seidel
committed
ran gofmt removed required, added IF
1 parent 61f47d4 commit 4070805

4 files changed

Lines changed: 66 additions & 67 deletions

File tree

builtin/provisioners/chef/linux_provisioner_test.go

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func TestResourceProvider_linuxInstallChefClient(t *testing.T) {
2020
"server_url": "https://chef.local",
2121
"validation_client_name": "validator",
2222
"validation_key_path": "validator.pem",
23-
"secret_key_path": "encrypted_data_bag_secret",
23+
"secret_key_path": "encrypted_data_bag_secret",
2424
}),
2525

2626
Commands: map[string]bool{
@@ -38,7 +38,7 @@ func TestResourceProvider_linuxInstallChefClient(t *testing.T) {
3838
"server_url": "https://chef.local",
3939
"validation_client_name": "validator",
4040
"validation_key_path": "validator.pem",
41-
"secret_key_path": "encrypted_data_bag_secret",
41+
"secret_key_path": "encrypted_data_bag_secret",
4242
}),
4343

4444
Commands: map[string]bool{
@@ -57,7 +57,7 @@ func TestResourceProvider_linuxInstallChefClient(t *testing.T) {
5757
"server_url": "https://chef.local",
5858
"validation_client_name": "validator",
5959
"validation_key_path": "validator.pem",
60-
"secret_key_path": "encrypted_data_bag_secret",
60+
"secret_key_path": "encrypted_data_bag_secret",
6161
}),
6262

6363
Commands: map[string]bool{
@@ -76,7 +76,7 @@ func TestResourceProvider_linuxInstallChefClient(t *testing.T) {
7676
"server_url": "https://chef.local",
7777
"validation_client_name": "validator",
7878
"validation_key_path": "validator.pem",
79-
"secret_key_path": "encrypted_data_bag_secret",
79+
"secret_key_path": "encrypted_data_bag_secret",
8080
}),
8181

8282
Commands: map[string]bool{
@@ -96,7 +96,7 @@ func TestResourceProvider_linuxInstallChefClient(t *testing.T) {
9696
"server_url": "https://chef.local",
9797
"validation_client_name": "validator",
9898
"validation_key_path": "validator.pem",
99-
"secret_key_path": "encrypted_data_bag_secret",
99+
"secret_key_path": "encrypted_data_bag_secret",
100100
}),
101101

102102
Commands: map[string]bool{
@@ -117,7 +117,7 @@ func TestResourceProvider_linuxInstallChefClient(t *testing.T) {
117117
"server_url": "https://chef.local",
118118
"validation_client_name": "validator",
119119
"validation_key_path": "validator.pem",
120-
"secret_key_path": "encrypted_data_bag_secret",
120+
"secret_key_path": "encrypted_data_bag_secret",
121121
"version": "11.18.6",
122122
}),
123123

@@ -164,7 +164,7 @@ func TestResourceProvider_linuxCreateConfigFiles(t *testing.T) {
164164
"server_url": "https://chef.local",
165165
"validation_client_name": "validator",
166166
"validation_key_path": "test-fixtures/validator.pem",
167-
"secret_key_path": "test-fixtures/encrypted_data_bag_secret",
167+
"secret_key_path": "test-fixtures/encrypted_data_bag_secret",
168168
}),
169169

170170
Commands: map[string]bool{
@@ -176,11 +176,11 @@ func TestResourceProvider_linuxCreateConfigFiles(t *testing.T) {
176176
},
177177

178178
Uploads: map[string]string{
179-
linuxConfDir + "/validation.pem": "VALIDATOR-PEM-FILE",
180-
linuxConfDir + "/encrypted_data_bag_secret":"SECRET-KEY-FILE",
181-
linuxConfDir + "/ohai/hints/ohaihint.json": "OHAI-HINT-FILE",
182-
linuxConfDir + "/client.rb": defaultLinuxClientConf,
183-
linuxConfDir + "/first-boot.json": `{"run_list":["cookbook::recipe"]}`,
179+
linuxConfDir + "/validation.pem": "VALIDATOR-PEM-FILE",
180+
linuxConfDir + "/encrypted_data_bag_secret": "SECRET-KEY-FILE",
181+
linuxConfDir + "/ohai/hints/ohaihint.json": "OHAI-HINT-FILE",
182+
linuxConfDir + "/client.rb": defaultLinuxClientConf,
183+
linuxConfDir + "/first-boot.json": `{"run_list":["cookbook::recipe"]}`,
184184
},
185185
},
186186

@@ -192,18 +192,18 @@ func TestResourceProvider_linuxCreateConfigFiles(t *testing.T) {
192192
"server_url": "https://chef.local",
193193
"validation_client_name": "validator",
194194
"validation_key_path": "test-fixtures/validator.pem",
195-
"secret_key_path": "test-fixtures/encrypted_data_bag_secret",
195+
"secret_key_path": "test-fixtures/encrypted_data_bag_secret",
196196
}),
197197

198198
Commands: map[string]bool{
199199
"mkdir -p " + linuxConfDir: true,
200200
},
201201

202202
Uploads: map[string]string{
203-
linuxConfDir + "/validation.pem": "VALIDATOR-PEM-FILE",
204-
linuxConfDir + "/encrypted_data_bag_secret":"SECRET-KEY-FILE",
205-
linuxConfDir + "/client.rb": defaultLinuxClientConf,
206-
linuxConfDir + "/first-boot.json": `{"run_list":["cookbook::recipe"]}`,
203+
linuxConfDir + "/validation.pem": "VALIDATOR-PEM-FILE",
204+
linuxConfDir + "/encrypted_data_bag_secret": "SECRET-KEY-FILE",
205+
linuxConfDir + "/client.rb": defaultLinuxClientConf,
206+
linuxConfDir + "/first-boot.json": `{"run_list":["cookbook::recipe"]}`,
207207
},
208208
},
209209

@@ -218,18 +218,18 @@ func TestResourceProvider_linuxCreateConfigFiles(t *testing.T) {
218218
"server_url": "https://chef.local",
219219
"validation_client_name": "validator",
220220
"validation_key_path": "test-fixtures/validator.pem",
221-
"secret_key_path": "test-fixtures/encrypted_data_bag_secret",
221+
"secret_key_path": "test-fixtures/encrypted_data_bag_secret",
222222
}),
223223

224224
Commands: map[string]bool{
225225
"mkdir -p " + linuxConfDir: true,
226226
},
227227

228228
Uploads: map[string]string{
229-
linuxConfDir + "/validation.pem": "VALIDATOR-PEM-FILE",
230-
linuxConfDir + "/encrypted_data_bag_secret":"SECRET-KEY-FILE",
231-
linuxConfDir + "/client.rb": proxyLinuxClientConf,
232-
linuxConfDir + "/first-boot.json": `{"run_list":["cookbook::recipe"]}`,
229+
linuxConfDir + "/validation.pem": "VALIDATOR-PEM-FILE",
230+
linuxConfDir + "/encrypted_data_bag_secret": "SECRET-KEY-FILE",
231+
linuxConfDir + "/client.rb": proxyLinuxClientConf,
232+
linuxConfDir + "/first-boot.json": `{"run_list":["cookbook::recipe"]}`,
233233
},
234234
},
235235

@@ -262,17 +262,17 @@ func TestResourceProvider_linuxCreateConfigFiles(t *testing.T) {
262262
"server_url": "https://chef.local",
263263
"validation_client_name": "validator",
264264
"validation_key_path": "test-fixtures/validator.pem",
265-
"secret_key_path": "test-fixtures/encrypted_data_bag_secret",
265+
"secret_key_path": "test-fixtures/encrypted_data_bag_secret",
266266
}),
267267

268268
Commands: map[string]bool{
269269
"mkdir -p " + linuxConfDir: true,
270270
},
271271

272272
Uploads: map[string]string{
273-
linuxConfDir + "/validation.pem": "VALIDATOR-PEM-FILE",
273+
linuxConfDir + "/validation.pem": "VALIDATOR-PEM-FILE",
274274
linuxConfDir + "/encrypted_data_bag_secret": "SECRET-KEY-FILE",
275-
linuxConfDir + "/client.rb": defaultLinuxClientConf,
275+
linuxConfDir + "/client.rb": defaultLinuxClientConf,
276276
linuxConfDir + "/first-boot.json": `{"key1":{"subkey1":{"subkey2a":["val1","val2","val3"],` +
277277
`"subkey2b":{"subkey3":"value3"}}},"key2":"value2","run_list":["cookbook::recipe"]}`,
278278
},

builtin/provisioners/chef/resource_provisioner.go

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ type Provisioner struct {
6868
OSType string `mapstructure:"os_type"`
6969
PreventSudo bool `mapstructure:"prevent_sudo"`
7070
RunList []string `mapstructure:"run_list"`
71-
SecretKeyPath string `mapstructure:"secret_key_path"`
71+
SecretKeyPath string `mapstructure:"secret_key_path"`
7272
ServerURL string `mapstructure:"server_url"`
7373
SkipInstall bool `mapstructure:"skip_install"`
7474
SSLVerifyMode string `mapstructure:"ssl_verify_mode"`
@@ -175,9 +175,6 @@ func (r *ResourceProvisioner) Validate(c *terraform.ResourceConfig) (ws []string
175175
if p.ServerURL == "" {
176176
es = append(es, fmt.Errorf("Key not found: server_url"))
177177
}
178-
if p.SecretKeyPath == "" {
179-
es = append(es, fmt.Errorf("Key not found: secret_key_path"))
180-
}
181178
if p.ValidationClientName == "" {
182179
es = append(es, fmt.Errorf("Key not found: validation_client_name"))
183180
}
@@ -233,13 +230,13 @@ func (r *ResourceProvisioner) decodeConfig(c *terraform.ResourceConfig) (*Provis
233230
}
234231
p.ValidationKeyPath = vkeyPath
235232
}
236-
if p.SecretKeyPath != "" {
237-
skeyPath, err := homedir.Expand(p.SecretKeyPath)
238-
if err != nil {
239-
return nil, fmt.Errorf("Error expanding the secret key path: %v", err)
240-
}
241-
p.SecretKeyPath = skeyPath
242-
}
233+
if p.SecretKeyPath != "" {
234+
skeyPath, err := homedir.Expand(p.SecretKeyPath)
235+
if err != nil {
236+
return nil, fmt.Errorf("Error expanding the secret key path: %v", err)
237+
}
238+
p.SecretKeyPath = skeyPath
239+
}
243240
if attrs, ok := c.Config["attributes"]; ok {
244241
p.Attributes, err = rawToJSON(attrs)
245242
if err != nil {
@@ -357,16 +354,18 @@ func (p *Provisioner) deployConfigFiles(
357354
return fmt.Errorf("Uploading %s failed: %v", validationKey, err)
358355
}
359356

360-
// Open the secret key file
361-
s, err := os.Open(p.SecretKeyPath)
362-
if err != nil {
363-
return err
364-
}
365-
defer s.Close()
357+
if p.SecretKeyPath != "" {
358+
// Open the secret key file
359+
s, err := os.Open(p.SecretKeyPath)
360+
if err != nil {
361+
return err
362+
}
363+
defer s.Close()
366364

367-
// Copy the secret key to the new instance
368-
if err := comm.Upload(path.Join(confDir, secretKey), s); err != nil {
369-
return fmt.Errorf("Uploading %s failed: %v", secretKey, err)
365+
// Copy the secret key to the new instance
366+
if err := comm.Upload(path.Join(confDir, secretKey), s); err != nil {
367+
return fmt.Errorf("Uploading %s failed: %v", secretKey, err)
368+
}
370369
}
371370

372371
// Make strings.Join available for use within the template

builtin/provisioners/chef/resource_provisioner_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func TestResourceProvider_Validate_good(t *testing.T) {
2121
"server_url": "https://chef.local",
2222
"validation_client_name": "validator",
2323
"validation_key_path": "validator.pem",
24-
"secret_key_path": "encrypted_data_bag_secret",
24+
"secret_key_path": "encrypted_data_bag_secret",
2525
})
2626
r := new(ResourceProvisioner)
2727
warn, errs := r.Validate(c)
@@ -69,7 +69,7 @@ func TestResourceProvider_runChefClient(t *testing.T) {
6969
"server_url": "https://chef.local",
7070
"validation_client_name": "validator",
7171
"validation_key_path": "test-fixtures/validator.pem",
72-
"secret_key_path": "test-fixtures/encrypted_data_bag_secret",
72+
"secret_key_path": "test-fixtures/encrypted_data_bag_secret",
7373
}),
7474

7575
ConfDir: linuxConfDir,
@@ -87,7 +87,7 @@ func TestResourceProvider_runChefClient(t *testing.T) {
8787
"server_url": "https://chef.local",
8888
"validation_client_name": "validator",
8989
"validation_key_path": "test-fixtures/validator.pem",
90-
"secret_key_path": "test-fixtures/encrypted_data_bag_secret",
90+
"secret_key_path": "test-fixtures/encrypted_data_bag_secret",
9191
}),
9292

9393
ConfDir: linuxConfDir,
@@ -106,7 +106,7 @@ func TestResourceProvider_runChefClient(t *testing.T) {
106106
"server_url": "https://chef.local",
107107
"validation_client_name": "validator",
108108
"validation_key_path": "test-fixtures/validator.pem",
109-
"secret_key_path": "test-fixtures/encrypted_data_bag_secret",
109+
"secret_key_path": "test-fixtures/encrypted_data_bag_secret",
110110
}),
111111

112112
ConfDir: windowsConfDir,

builtin/provisioners/chef/windows_provisioner_test.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func TestResourceProvider_windowsInstallChefClient(t *testing.T) {
2222
"server_url": "https://chef.local",
2323
"validation_client_name": "validator",
2424
"validation_key_path": "validator.pem",
25-
"secret_key_path": "encrypted_data_bag_secret",
25+
"secret_key_path": "encrypted_data_bag_secret",
2626
}),
2727

2828
Commands: map[string]bool{
@@ -43,7 +43,7 @@ func TestResourceProvider_windowsInstallChefClient(t *testing.T) {
4343
"server_url": "https://chef.local",
4444
"validation_client_name": "validator",
4545
"validation_key_path": "validator.pem",
46-
"secret_key_path": "encrypted_data_bag_secret",
46+
"secret_key_path": "encrypted_data_bag_secret",
4747
}),
4848

4949
Commands: map[string]bool{
@@ -62,7 +62,7 @@ func TestResourceProvider_windowsInstallChefClient(t *testing.T) {
6262
"server_url": "https://chef.local",
6363
"validation_client_name": "validator",
6464
"validation_key_path": "validator.pem",
65-
"secret_key_path": "encrypted_data_bag_secret",
65+
"secret_key_path": "encrypted_data_bag_secret",
6666
"version": "11.18.6",
6767
}),
6868

@@ -112,7 +112,7 @@ func TestResourceProvider_windowsCreateConfigFiles(t *testing.T) {
112112
"server_url": "https://chef.local",
113113
"validation_client_name": "validator",
114114
"validation_key_path": "test-fixtures/validator.pem",
115-
"secret_key_path": "test-fixtures/encrypted_data_bag_secret",
115+
"secret_key_path": "test-fixtures/encrypted_data_bag_secret",
116116
}),
117117

118118
Commands: map[string]bool{
@@ -123,11 +123,11 @@ func TestResourceProvider_windowsCreateConfigFiles(t *testing.T) {
123123
},
124124

125125
Uploads: map[string]string{
126-
windowsConfDir + "/validation.pem": "VALIDATOR-PEM-FILE",
127-
windowsConfDir + "/encrypted_data_bag_secret":"SECRET-KEY-FILE",
128-
windowsConfDir + "/ohai/hints/ohaihint.json": "OHAI-HINT-FILE",
129-
windowsConfDir + "/client.rb": defaultWindowsClientConf,
130-
windowsConfDir + "/first-boot.json": `{"run_list":["cookbook::recipe"]}`,
126+
windowsConfDir + "/validation.pem": "VALIDATOR-PEM-FILE",
127+
windowsConfDir + "/encrypted_data_bag_secret": "SECRET-KEY-FILE",
128+
windowsConfDir + "/ohai/hints/ohaihint.json": "OHAI-HINT-FILE",
129+
windowsConfDir + "/client.rb": defaultWindowsClientConf,
130+
windowsConfDir + "/first-boot.json": `{"run_list":["cookbook::recipe"]}`,
131131
},
132132
},
133133

@@ -141,18 +141,18 @@ func TestResourceProvider_windowsCreateConfigFiles(t *testing.T) {
141141
"server_url": "https://chef.local",
142142
"validation_client_name": "validator",
143143
"validation_key_path": "test-fixtures/validator.pem",
144-
"secret_key_path": "test-fixtures/encrypted_data_bag_secret",
144+
"secret_key_path": "test-fixtures/encrypted_data_bag_secret",
145145
}),
146146

147147
Commands: map[string]bool{
148148
fmt.Sprintf("if not exist %q mkdir %q", windowsConfDir, windowsConfDir): true,
149149
},
150150

151151
Uploads: map[string]string{
152-
windowsConfDir + "/validation.pem": "VALIDATOR-PEM-FILE",
153-
windowsConfDir + "/encrypted_data_bag_secret":"SECRET-KEY-FILE",
154-
windowsConfDir + "/client.rb": proxyWindowsClientConf,
155-
windowsConfDir + "/first-boot.json": `{"run_list":["cookbook::recipe"]}`,
152+
windowsConfDir + "/validation.pem": "VALIDATOR-PEM-FILE",
153+
windowsConfDir + "/encrypted_data_bag_secret": "SECRET-KEY-FILE",
154+
windowsConfDir + "/client.rb": proxyWindowsClientConf,
155+
windowsConfDir + "/first-boot.json": `{"run_list":["cookbook::recipe"]}`,
156156
},
157157
},
158158

@@ -184,17 +184,17 @@ func TestResourceProvider_windowsCreateConfigFiles(t *testing.T) {
184184
"server_url": "https://chef.local",
185185
"validation_client_name": "validator",
186186
"validation_key_path": "test-fixtures/validator.pem",
187-
"secret_key_path": "test-fixtures/encrypted_data_bag_secret",
187+
"secret_key_path": "test-fixtures/encrypted_data_bag_secret",
188188
}),
189189

190190
Commands: map[string]bool{
191191
fmt.Sprintf("if not exist %q mkdir %q", windowsConfDir, windowsConfDir): true,
192192
},
193193

194194
Uploads: map[string]string{
195-
windowsConfDir + "/validation.pem": "VALIDATOR-PEM-FILE",
196-
windowsConfDir + "/encrypted_data_bag_secret":"SECRET-KEY-FILE",
197-
windowsConfDir + "/client.rb": defaultWindowsClientConf,
195+
windowsConfDir + "/validation.pem": "VALIDATOR-PEM-FILE",
196+
windowsConfDir + "/encrypted_data_bag_secret": "SECRET-KEY-FILE",
197+
windowsConfDir + "/client.rb": defaultWindowsClientConf,
198198
windowsConfDir + "/first-boot.json": `{"key1":{"subkey1":{"subkey2a":["val1","val2","val3"],` +
199199
`"subkey2b":{"subkey3":"value3"}}},"key2":"value2","run_list":["cookbook::recipe"]}`,
200200
},

0 commit comments

Comments
 (0)