#!/bin/sh

set -e

test -f ca.pem || ( cfssl gencert -initca ca_csr.json | cfssljson -bare ca )

for crt in "$@"; do
    jq ".CN |= \"${crt}.dev.svc.cluster.local\"" < template.json > service_${crt}.json
    test -f ${crt}.pem || ( cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca_config.json -profile=test service_${crt}.json | cfssljson -bare ${crt} )
    rm -f service_${crt}.json
done
