Types

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

Managing Types requires Contributor or Admin permissions.

Select Types under the Admin menu to open the screen below. (First-time customers will see an empty screen.)

  1. List of base types and what they do.

Boolean: Can be used directly for parameters or as a parent for custom types. Automatically includes permutations such as Yes, No, True, False.

Enum: Must be used as a parent for custom types. Create lists that scope the selection to only approved values.

Integer: This can be used directly for parameters or as a parent for custom types.

String: This can be used directly for parameters or as a parent for custom types. The string type is the base type for regular expressions (Regex).

  1. An example of a type rule that uses a regex to validate an AWS Region is correctly formatted.

  1. An example of an enum list to validate a parameter value is correct.

Use the UI for short enum lists or the API to bulk-add longer list items.

Copy the code below and replace the API_KEY value with an API key for your organization with Contributor or Admin permissions.

#!/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}"'"}'

Sample command line for the script (assumes the script file is named "create_enum.sh"):

-n Type name (should be short)

-d Description

-r List items. Use quote comma-separated structure

./create_enum.sh -n "Fetch Interval" -d "Interval to trigger a fetch." -r '["daily", "weekly", "monthly"]'

Last updated

Copyright© 2023 CloudTruth