TLS sdc-be-init: truststore & keystore handling
[sdc.git] / catalog-be / sdc-backend-init / chef-repo / cookbooks / sdc-catalog-be-setup / recipes / 3_import_Normatives.rb
1 require 'base64'
2 be_ip=node['Nodes'][:BE]
3
4 if node['disableHttp']
5   protocol = "https"
6   be_port = node['BE']['https_port']
7   param="-i #{be_ip} -p #{be_port} --https"
8   if node['BE-init']['tls_cert'] && node['BE-init']['tls_key']
9     tls_key = "--tls_key " + node['BE-init']['tls_key']
10     tls_cert = "--tls_cert " + node['BE-init']['tls_cert']
11     if node['BE-init']['tls_password']
12       tls_key_pw = "--tls_key_pw " + node['BE-init']['tls_password']
13     end
14   end
15   if node['BE-init']['ca_cert']
16     ca_cert =  "--ca_cert " + node['BE-init']['ca_cert']
17   end
18 else
19   protocol = "http"
20   be_port = node['BE']['http_port']
21   param="-i #{be_ip} -p #{be_port}"
22 end
23
24 if node['basic_auth']
25   basic_auth_enabled = node['basic_auth']['enabled']
26   basic_auth_user = node['basic_auth']['user_name']
27   basic_auth_pass = node['basic_auth']['user_pass']
28   if basic_auth_enabled
29     basic_auth_config = "--header " + Base64.strict_encode64(basic_auth_user + ":" + basic_auth_pass)
30   else
31     # set default user configuration file
32     basic_auth_config = ""
33   end
34 end
35 cookbook_file "/var/tmp/normatives.tar.gz" do
36   source "normatives.tar.gz"
37 end
38
39 execute "create-jetty-modules" do
40   command "set -ex && tar -xvf normatives.tar.gz && cd /var/tmp/normatives/import/tosca && sdcinit #{param} #{basic_auth_config} #{tls_cert} #{tls_key} #{tls_key_pw} #{ca_cert} > #{ENV['ONAP_LOG']}/init.log"
41   cwd "/var/tmp/"
42   action :run
43 end