Replace newlines from chef-server-admin-key.txt with \n
Also use HEREDOCs to simplify calls to CreateServer and CreateOrg
@@ -126,26 +126,30 @@ configure_retention() {
configure_automate_infra_views() {
if chef-automate dev grpcurl automate-gateway list | grep "chef.automate.api.infra_proxy.InfraProxy" &> /dev/null; then
- chef_server_admin_key=$(cat "/hab/chef-server-admin-key.txt")
+ chef_server_admin_key="$(</hab/chef-server-admin-key.txt tr '\n' ':' | sed 's/:/\\n/g')"
server_id="auto-deployed-chef-server"
org_id="auto-deployed-chef-org"
if ! chef-automate dev grpcurl automate-gateway -- chef.automate.api.infra_proxy.InfraProxy.GetServer -d "{\"id\": \"$server_id\"}" 2> /dev/null | grep "$server_id" &> /dev/null; then
- chef-automate dev grpcurl automate-gateway -- chef.automate.api.infra_proxy.InfraProxy.CreateServer -d "{
- \"id\": \"$server_id\",
- \"name\": \"$server_id\",
- \"fqdn\": \"localhost\",
- \"ip_address\": \"127.0.0.1\"
- }"
+ chef-automate dev grpcurl automate-gateway -- chef.automate.api.infra_proxy.InfraProxy.CreateServer -d @ <<EOM
+ {
+ "id": "$server_id",
+ "name": "$server_id",
+ "fqdn": "localhost",
+ "ip_address": "127.0.0.1"
+ }
+EOM
fi
if ! chef-automate dev grpcurl automate-gateway -- chef.automate.api.infra_proxy.InfraProxy.GetOrg -d "{\"id\": \"$org_id\", \"server_id\": \"$server_id\"}" 2> /dev/null | grep "$org_id" &> /dev/null; then
- chef-automate dev grpcurl automate-gateway -- chef.automate.api.infra_proxy.InfraProxy.CreateOrg -d "{
- \"id\": \"$org_id\",
- \"name\": \"${chef_server_org}\",
- \"admin_user\": \"${chef_server_admin_name}\",
- \"admin_key\": \"$chef_server_admin_key\",
- \"server_id\": \"$server_id\"
- }"
+ chef-automate dev grpcurl automate-gateway -- chef.automate.api.infra_proxy.InfraProxy.CreateOrg -d @ <<EOM
+ {
+ "id": "$org_id",
+ "name": "${chef_server_org}",
+ "admin_user": "${chef_server_admin_name}",
+ "admin_key": "$chef_server_admin_key",
+ "server_id": "$server_id"
+ }
+EOM
fi
fi
}
