export SSO_IP=`kubectl get svc -A | grep "sso " | awk '{print $4}'`
export ASMUI_PASS=`kubectl get secret pfxm-asmui-creds -o json -n powerflex | jq '.data | map_values(@base64d)' | jq -r '.["keycloak-password"]'`
export PM_TOKEN=`curl -k --location --request POST "https://${SSO_IP}:8080/rest/auth/login" --header 'Accept: application/json' --header 'Content-Type: application/json' --data "{\"username\": \"asmuiuser\",\"password\": \"$ASMUI_PASS\"}" | jq -r .access_token`
export IN_IP=`kubectl get svc -A | grep -m1 rke2-ingress-nginx-controller | sort | awk '{print $5}'`

# parameter is a PEM encoded cetificate filename. Make sure the file is one line - no CR/LF characters, they are replaced with \n
# this can be achieved by passing regular PEM content through this pipe: tr -d '"' | base64 -d | tr -s '\n' '\\' | sed 's/\\/\\n/g'
# example of such file is output of the script get_ca_cert.sh, compare to get_ca_cert_pem.sh

CA=`cat $1`
curl -kL -X POST https://$IN_IP/Api/V1/CIAM/2/x509-certificates --header "Authorization: Bearer ${PM_TOKEN}" --data-raw "
{
  \"type\": \"CA\",
  \"service\": \"ALL\",
  \"certificate_format\": \"PEM\",
  \"certificate\": \"$CA\"
}"

