SUNETOPS-1935 - enforce new naming standard

This commit is contained in:
Rasmus Thorslund 2024-10-04 12:18:08 +02:00
parent 21a5a4dce4
commit e2152ab2c0
No known key found for this signature in database
GPG key ID: 502D33332E9E305D

14
addhost
View file

@ -5,19 +5,22 @@ cmd_do_bootstrap="no"
cmd_fqdn=""
function usage() {
echo "Usage: $0 [-h] [-b] [-n fqdn] [--] [<host>]"
echo "Usage: $0 [-h] [-b] [-o] [-p] [-n fqdn] [--] [<host>]"
echo " -h show help"
echo " -b bootstrap <host> (using ssh)"
echo " -n specify FQDN (if not the same as <host>)"
echo " -o override naming standard"
echo " -p specify ProxyJump host"
echo ""
echo " <host> can be an IP number, or something that resolves to one"
}
while getopts "bhnp:" this; do
while getopts "bhnop:" this; do
case "${this}" in
h) usage; exit 0;;
b) cmd_do_bootstrap="yes" ;;
n) cmd_fqdn="${OPTARG}" ; shift ;;
o) naming_override="yes" ;;
p) cmd_proxy="${OPTARG}" ; shift ;;
*) echo "Unknown option ${this}"; echo ""; usage; exit 1;;
esac
@ -37,6 +40,13 @@ if test -z "$cmd_hostname"; then
exit 1
fi
if [[ ! $naming_override ]]; then
if [[ ! "$cmd_hostname" =~ ^([a-z]+)-(sthb|dco|tug)-?(prod|dev|stage|staging|test)?-([1-9][0-9]*).sunet.se$ ]]; then
echo "$cmd_hostname is not following the naming standard: function-location-environment-number.sunet.se"
exit 1
fi
fi
if [[ -n $cmd_proxy ]]; then
proxyjump="-o ProxyJump=${cmd_proxy}"
fi