summaryrefslogtreecommitdiff
path: root/lib/chef/resource/hostname.rb
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2018-03-28 20:34:32 -0700
committerTim Smith <tsmith@chef.io>2018-03-28 20:34:32 -0700
commit55ac0da13539f5a80080809ee9059b676dabc5a8 (patch)
tree9c3002ab7d40a098081197bc08f3d1070a01dd3e /lib/chef/resource/hostname.rb
parentff4656d9ae70d2e8810ec0a45f322b394c31083d (diff)
downloadchef-55ac0da13539f5a80080809ee9059b676dabc5a8.tar.gz
Add basic hostname validation
alphanumeric, -, . or _ Starts with an alphanumeric We could get a lot more complex here and that might not be a bad idea, but this is probably a step in the right direction. Signed-off-by: Tim Smith <tsmith@chef.io>
Diffstat (limited to 'lib/chef/resource/hostname.rb')
-rw-r--r--lib/chef/resource/hostname.rb2
1 files changed, 2 insertions, 0 deletions
diff --git a/lib/chef/resource/hostname.rb b/lib/chef/resource/hostname.rb
index f785d1b620..1c91e412a8 100644
--- a/lib/chef/resource/hostname.rb
+++ b/lib/chef/resource/hostname.rb
@@ -11,6 +11,8 @@ class Chef
introduced "14.0"
property :hostname, String,
+ regex: /^([A-Za-z0-9])+([A-Za-z0-9-._])*$/, # http://rubular.com/r/c5xKppWX4i
+ validation_message: "Hostnames can contain alphanumeric characters, -, ., and _ ,but must start with an alphanumeric character.",
description: "The hostname if different than the resource's name",
name_property: true