Types
Manage type checking parameter values with rules and ranges. Use the Type feature for guardrails, policy enforcement and eliminating misconfigurations.



Last updated
Was this helpful?
Was this helpful?
#!/bin/bash
API_KEY="YOUR-API-KEY"
usage() { echo "Usage: $0 [-n <enum name>] [-r <rules>]" 1>&2; exit 1; }
while getopts ":n:d:r:" o; do
case "${o}" in
n)
enum_name=${OPTARG}
;;
d)
enum_desc=${OPTARG}
;;
r)
constraints=${OPTARG}
;;
*)
usage
;;
esac
done
shift $((OPTIND-1))
if [ -z "${enum_name}" ] || [ -z "${constraints}" ] || [ "${API_KEY}" == "fill-me-in" ]
then
usage
fi
data_str='{"name":"'${enum_name}'","description":"'${enum_desc}'","parent":"https://api.cloudtruth.io/api/v1/types/1b606a2f-197d-4173-a588-70c12c8b794d/"}'
response=$(curl -X POST 'https://api.cloudtruth.io/api/v1/types/' -H 'content-type: application/json' -H 'authorization: Api-Key '"${API_KEY}" --data-raw "${data_str}")
echo "${response}"
type_id=`echo "${response}" | jq -r '.id'`
echo "Type ID: ${type_id}"
curl -X POST 'https://api.cloudtruth.io/api/v1/types/'"${type_id}"'/rules/' \
-H 'authorization: Api-Key '"${API_KEY}" \
-H 'content-type: application/json' \
--data-raw '{"type":"one_of","constraints":'"${constraints}"',"typeId":"'"${type_id}"'"}'./create_enum.sh -n "Fetch Interval" -d "Interval to trigger a fetch." -r '["daily", "weekly", "monthly"]'