Make using `ssl_verify_mode` more robust (#7769)

And prettify the template output by removing additions empty lines.
This commit is contained in:
Sander van Harmelen 2016-07-22 16:01:48 +02:00 committed by GitHub
parent 9de8a263c0
commit 4004790247
3 changed files with 28 additions and 26 deletions

View File

@ -220,6 +220,7 @@ func TestResourceProvider_linuxCreateConfigFiles(t *testing.T) {
"run_list": []interface{}{"cookbook::recipe"}, "run_list": []interface{}{"cookbook::recipe"},
"secret_key_path": "test-fixtures/encrypted_data_bag_secret", "secret_key_path": "test-fixtures/encrypted_data_bag_secret",
"server_url": "https://chef.local", "server_url": "https://chef.local",
"ssl_verify_mode": "verify_none",
"validation_client_name": "validator", "validation_client_name": "validator",
"validation_key_path": "test-fixtures/validator.pem", "validation_key_path": "test-fixtures/validator.pem",
}), }),
@ -340,20 +341,15 @@ chef_server_url "https://chef.local"
validation_client_name "validator" validation_client_name "validator"
node_name "nodename1" node_name "nodename1"
http_proxy "http://proxy.local" http_proxy "http://proxy.local"
ENV['http_proxy'] = "http://proxy.local" ENV['http_proxy'] = "http://proxy.local"
ENV['HTTP_PROXY'] = "http://proxy.local" ENV['HTTP_PROXY'] = "http://proxy.local"
https_proxy "https://proxy.local" https_proxy "https://proxy.local"
ENV['https_proxy'] = "https://proxy.local" ENV['https_proxy'] = "https://proxy.local"
ENV['HTTPS_PROXY'] = "https://proxy.local" ENV['HTTPS_PROXY'] = "https://proxy.local"
no_proxy "http://local.local,https://local.local" no_proxy "http://local.local,https://local.local"
ENV['no_proxy'] = "http://local.local,https://local.local"` ENV['no_proxy'] = "http://local.local,https://local.local"
ssl_verify_mode :verify_none`

View File

@ -43,35 +43,40 @@ log_location STDOUT
chef_server_url "{{ .ServerURL }}" chef_server_url "{{ .ServerURL }}"
validation_client_name "{{ .ValidationClientName }}" validation_client_name "{{ .ValidationClientName }}"
node_name "{{ .NodeName }}" node_name "{{ .NodeName }}"
{{ if .UsePolicyfile }} {{ if .UsePolicyfile }}
use_policyfile true use_policyfile true
policy_group "{{ .PolicyGroup }}" policy_group "{{ .PolicyGroup }}"
policy_name "{{ .PolicyName }}" policy_name "{{ .PolicyName }}"
{{ end }} {{ end -}}
{{ if .HTTPProxy }} {{ if .HTTPProxy }}
http_proxy "{{ .HTTPProxy }}" http_proxy "{{ .HTTPProxy }}"
ENV['http_proxy'] = "{{ .HTTPProxy }}" ENV['http_proxy'] = "{{ .HTTPProxy }}"
ENV['HTTP_PROXY'] = "{{ .HTTPProxy }}" ENV['HTTP_PROXY'] = "{{ .HTTPProxy }}"
{{ end }} {{ end -}}
{{ if .HTTPSProxy }} {{ if .HTTPSProxy }}
https_proxy "{{ .HTTPSProxy }}" https_proxy "{{ .HTTPSProxy }}"
ENV['https_proxy'] = "{{ .HTTPSProxy }}" ENV['https_proxy'] = "{{ .HTTPSProxy }}"
ENV['HTTPS_PROXY'] = "{{ .HTTPSProxy }}" ENV['HTTPS_PROXY'] = "{{ .HTTPSProxy }}"
{{ end }} {{ end -}}
{{ if .NOProxy }} {{ if .NOProxy }}
no_proxy "{{ join .NOProxy "," }}" no_proxy "{{ join .NOProxy "," }}"
ENV['no_proxy'] = "{{ join .NOProxy "," }}" ENV['no_proxy'] = "{{ join .NOProxy "," }}"
{{ end -}}
{{ if .SSLVerifyMode }}
ssl_verify_mode {{ .SSLVerifyMode }}
{{- end -}}
{{ if .DisableReporting }}
enable_reporting false
{{ end -}}
{{ if .ClientOptions }}
{{ join .ClientOptions "\n" }}
{{ end }} {{ end }}
{{ if .SSLVerifyMode }}ssl_verify_mode {{ .SSLVerifyMode }}{{ end }}
{{ if .DisableReporting }}enable_reporting false{{ end }}
{{ if .ClientOptions }}{{ join .ClientOptions "\n" }}{{ end }}
` `
// Provisioner represents a specificly configured chef provisioner // Provisioner represents a specificly configured chef provisioner
@ -452,6 +457,11 @@ func (p *Provisioner) deployConfigFiles(
} }
} }
// Make sure the SSLVerifyMode value is written as a symbol
if p.SSLVerifyMode != "" && !strings.HasPrefix(p.SSLVerifyMode, ":") {
p.SSLVerifyMode = fmt.Sprintf(":%s", p.SSLVerifyMode)
}
// Make strings.Join available for use within the template // Make strings.Join available for use within the template
funcMap := template.FuncMap{ funcMap := template.FuncMap{
"join": strings.Join, "join": strings.Join,

View File

@ -137,6 +137,7 @@ func TestResourceProvider_windowsCreateConfigFiles(t *testing.T) {
"run_list": []interface{}{"cookbook::recipe"}, "run_list": []interface{}{"cookbook::recipe"},
"secret_key_path": "test-fixtures/encrypted_data_bag_secret", "secret_key_path": "test-fixtures/encrypted_data_bag_secret",
"server_url": "https://chef.local", "server_url": "https://chef.local",
"ssl_verify_mode": "verify_none",
"validation_client_name": "validator", "validation_client_name": "validator",
"validation_key_path": "test-fixtures/validator.pem", "validation_key_path": "test-fixtures/validator.pem",
}), }),
@ -366,20 +367,15 @@ chef_server_url "https://chef.local"
validation_client_name "validator" validation_client_name "validator"
node_name "nodename1" node_name "nodename1"
http_proxy "http://proxy.local" http_proxy "http://proxy.local"
ENV['http_proxy'] = "http://proxy.local" ENV['http_proxy'] = "http://proxy.local"
ENV['HTTP_PROXY'] = "http://proxy.local" ENV['HTTP_PROXY'] = "http://proxy.local"
https_proxy "https://proxy.local" https_proxy "https://proxy.local"
ENV['https_proxy'] = "https://proxy.local" ENV['https_proxy'] = "https://proxy.local"
ENV['HTTPS_PROXY'] = "https://proxy.local" ENV['HTTPS_PROXY'] = "https://proxy.local"
no_proxy "http://local.local,https://local.local" no_proxy "http://local.local,https://local.local"
ENV['no_proxy'] = "http://local.local,https://local.local"` ENV['no_proxy'] = "http://local.local,https://local.local"
ssl_verify_mode :verify_none`