Skip to content
This repository has been archived by the owner on Jun 5, 2020. It is now read-only.

Commit

Permalink
Merge pull request #120 from garethr/type-checking-properties
Browse files Browse the repository at this point in the history
(CLOUD-259) Add validation of types for properties
  • Loading branch information
cmurphy committed Mar 23, 2015
2 parents 0e2ff12 + d0b3d5f commit 9532687
Show file tree
Hide file tree
Showing 33 changed files with 405 additions and 10 deletions.
14 changes: 13 additions & 1 deletion lib/puppet/type/cloudwatch_alarm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,31 @@
desc 'The name of the alarm.'
validate do |value|
fail 'alarms must have a name' if value == ''
fail 'Name should be a String' unless value.is_a?(String)
end
end

newproperty(:metric) do
desc 'The name of the metric to track.'
validate do |value|
fail 'metric must not be blank' if value == ''
fail 'metric should be a String' unless value.is_a?(String)
end
end

newproperty(:namespace) do
desc 'The namespace of the metric to track.'
validate do |value|
fail 'namespace must not be blank' if value == ''
fail 'namespace should be a String' unless value.is_a?(String)
end
end

newproperty(:statistic) do
desc 'The statistic to track for the metric.'
validate do |value|
fail 'statistic must not be blank' if value == ''
fail 'statistic should be a String' unless value.is_a?(String)
end
end

Expand Down Expand Up @@ -64,7 +68,8 @@
newproperty(:comparison_operator) do
desc 'The operator to use to test the metric.'
validate do |value|
fail 'comparison operator must not be blank' if value == ''
fail 'comparison_operator must not be blank' if value == ''
fail 'comparison_operator should be a String' unless value.is_a?(String)
end
end

Expand All @@ -73,6 +78,7 @@
validate do |value|
fail 'region should not contain spaces' if value =~ /\s/
fail 'region should not be blank' if value == ''
fail 'region should be a String' unless value.is_a?(String)
end
end

Expand All @@ -81,10 +87,16 @@
def insync?(is)
is.to_set == should.to_set
end
validate do |value|
fail 'dimensions should be a Hash' unless value.is_a?(Hash)
end
end

newproperty(:alarm_actions, :array_matching => :all) do
desc 'The actions to trigger when the alarm triggers.'
validate do |value|
fail 'alarm_actions should be a String' unless value.is_a?(String)
end
end

autorequire(:ec2_scalingpolicy) do
Expand Down
10 changes: 8 additions & 2 deletions lib/puppet/type/ec2_autoscalinggroup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
desc 'The name of the auto scaling group.'
validate do |value|
fail 'Auto scaling groups must have a name' if value == ''
fail 'name should be a String' unless value.is_a?(String)
end
end

Expand Down Expand Up @@ -35,13 +36,15 @@
validate do |value|
fail 'region should not contain spaces' if value =~ /\s/
fail 'region should not be blank' if value == ''
fail 'region should be a String' unless value.is_a?(String)
end
end

newproperty(:launch_configuration) do
desc 'The launch configuration to use for the group.'
validate do |value|
fail 'launch configuration cannot be blank' if value == ''
fail 'launch_configuration cannot be blank' if value == ''
fail 'launch_configuration should be a String' unless value.is_a?(String)
end
end

Expand All @@ -55,7 +58,7 @@
newproperty(:availability_zones, :array_matching => :all) do
desc 'The availability zones in which to launch the instances.'
validate do |value|
fail 'must provide a list of availability zones' if value.empty?
fail 'availability_zones should be a String' unless value.is_a?(String)
end
def insync?(is)
is.to_set == should.to_set
Expand All @@ -64,6 +67,9 @@ def insync?(is)

newproperty(:subnets, :array_matching => :all) do
desc 'The subnets to associate the autoscaling group.'
validate do |value|
fail 'subnets should be a String' unless value.is_a?(String)
end
def insync?(is)
is.to_set == should.to_set
end
Expand Down
2 changes: 2 additions & 0 deletions lib/puppet/type/ec2_elastic_ip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
newproperty(:region) do
desc 'The name of the region in which the Elastic IP is found.'
validate do |value|
fail 'region should be a String' unless value.is_a?(String)
fail 'You must provide a region for Elastic IPs.' if value.nil? || value.empty?
end
end

newproperty(:instance) do
desc 'The name of the instance associated with the Elastic IP.'
validate do |value|
fail 'instance should be a String' unless value.is_a?(String)
fail 'You must provide an instance for the Elastic IP association' if value.nil? || value.empty?
end
end
Expand Down
14 changes: 14 additions & 0 deletions lib/puppet/type/ec2_instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def insync?(is)
desc 'The name of the instance.'
validate do |value|
fail 'Instances must have a name' if value == ''
fail 'name should be a String' unless value.is_a?(String)
end
end

Expand All @@ -40,6 +41,9 @@ def insync?(is)
def insync?(is)
is.to_set == should.to_set
end
validate do |value|
fail 'security_groups should be a String' unless value.is_a?(String)
end
end

newproperty(:tags, :parent => PuppetX::Property::AwsTag) do
Expand All @@ -52,6 +56,9 @@ def insync?(is)

newproperty(:key_name) do
desc 'The name of the key pair associated with this instance.'
validate do |value|
fail 'key_name should be a String' unless value.is_a?(String)
end
end

newproperty(:monitoring) do
Expand All @@ -67,6 +74,7 @@ def insync?(is)
desc 'The region in which to launch the instance.'
validate do |value|
fail 'region should not contain spaces' if value =~ /\s/
fail 'region should be a String' unless value.is_a?(String)
end
end

Expand All @@ -75,6 +83,7 @@ def insync?(is)
validate do |value|
fail 'image_id should not contain spaces' if value =~ /\s/
fail 'image_id should not be blank' if value == ''
fail 'image_id should be a String' unless value.is_a?(String)
end
end

Expand All @@ -83,6 +92,7 @@ def insync?(is)
validate do |value|
fail 'availability_zone should not contain spaces' if value =~ /\s/
fail 'availability_zone should not be blank' if value == ''
fail 'availability_zone should be a String' unless value.is_a?(String)
end
end

Expand All @@ -91,6 +101,7 @@ def insync?(is)
validate do |value|
fail 'instance type should not contains spaces' if value =~ /\s/
fail 'instance_type should not be blank' if value == ''
fail 'instance_type should be a String' unless value.is_a?(String)
end
end

Expand Down Expand Up @@ -145,6 +156,9 @@ def insync?(is)

newproperty(:subnet) do
desc 'The VPC subnet to attach the instance to.'
validate do |value|
fail 'subnet should be a String' unless value.is_a?(String)
end
end

newproperty(:ebs_optimized) do
Expand Down
13 changes: 12 additions & 1 deletion lib/puppet/type/ec2_launchconfiguration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
desc 'The name of the launch configuration.'
validate do |value|
fail 'launch configurations must have a name' if value == ''
fail 'name should be a String' unless value.is_a?(String)
end
end

newproperty(:security_groups, :array_matching => :all) do
desc 'The security groups to associate with the instances.'
validate do |value|
fail 'you must specifiy security groups for the launch configuration' if value.empty?
fail 'security_groups should be a String' unless value.is_a?(String)
fail 'you must specify security groups for the launch configuration' if value.empty?
end
def insync?(is)
is.to_set == should.to_set
Expand All @@ -26,13 +28,17 @@ def insync?(is)

newproperty(:key_name) do
desc 'The name of the key pair associated with this instance.'
validate do |value|
fail 'key_name should be a String' unless value.is_a?(String)
end
end

newproperty(:region) do
desc 'The region in which to launch the instances.'
validate do |value|
fail 'region should not contain spaces' if value =~ /\s/
fail 'region should not be blank' if value == ''
fail 'region should be a String' unless value.is_a?(String)
end
end

Expand All @@ -41,6 +47,7 @@ def insync?(is)
validate do |value|
fail 'instance_type should not contains spaces' if value =~ /\s/
fail 'instance_type should not be blank' if value == ''
fail 'instance_type should be a String' unless value.is_a?(String)
end
end

Expand All @@ -49,11 +56,15 @@ def insync?(is)
validate do |value|
fail 'image_id should not contain spaces' if value =~ /\s/
fail 'image_id should not be blank' if value == ''
fail 'image_id should be a String' unless value.is_a?(String)
end
end

newparam(:vpc) do
desc 'A hint to specify the VPC, useful when detecting ambiguously named security groups like default.'
validate do |value|
fail 'vpc should be a String' unless value.is_a?(String)
end
end

autorequire(:ec2_securitygroup) do
Expand Down
10 changes: 7 additions & 3 deletions lib/puppet/type/ec2_scalingpolicy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
desc 'The name of the scaling policy.'
validate do |value|
fail 'Scaling policies must have a name' if value == ''
fail 'name should be a String' unless value.is_a?(String)
end
end

Expand All @@ -25,21 +26,24 @@
validate do |value|
fail 'region should not contain spaces' if value =~ /\s/
fail 'region should not be blank' if value == ''
fail 'region should be a String' unless value.is_a?(String)
end
end

newproperty(:adjustment_type) do
desc 'The type of policy.'
validate do |value|
fail 'adjustment type should not contain spaces' if value =~ /\s/
fail 'adjustment type should not be blank' if value == ''
fail 'adjustment_type should not contain spaces' if value =~ /\s/
fail 'adjustment_type should not be blank' if value == ''
fail 'adjustment_type should be a String' unless value.is_a?(String)
end
end

newproperty(:auto_scaling_group) do
desc 'The auto scaling group to attach the policy to.'
validate do |value|
fail 'auto scaling group cannot be blank' if value == ''
fail 'auto_scaling_group cannot be blank' if value == ''
fail 'auto_scaling_group should be a String' unless value.is_a?(String)
end
end

Expand Down
16 changes: 13 additions & 3 deletions lib/puppet/type/ec2_securitygroup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
newparam(:name, namevar: true) do
desc 'the name of the security group'
validate do |value|
fail 'Security groups must have a name' if value == ''
fail 'security groups must have a name' if value == ''
fail 'name should be a String' unless value.is_a?(String)
end
end

newproperty(:region) do
desc 'the region in which to launch the security group'
validate do |value|
fail 'region should not contains spaces' if value =~ /\s/
fail 'region should not contain spaces' if value =~ /\s/
fail 'region should be a String' unless value.is_a?(String)
end
end

Expand All @@ -29,6 +31,10 @@ def insync?(is)
to_delete = parser.rules_to_delete(is)
to_create.empty? && to_delete.empty?
end

validate do |value|
fail 'ingress should be a Hash' unless value.is_a?(Hash)
end
end

newproperty(:tags, :parent => PuppetX::Property::AwsTag) do
Expand All @@ -38,12 +44,16 @@ def insync?(is)
newproperty(:description) do
desc 'a short description of the group'
validate do |value|
fail 'description cannot be blank' if value == ''
fail 'description cannot be blank' if value == ''
fail 'description should be a String' unless value.is_a?(String)
end
end

newproperty(:vpc) do
desc 'A VPC to which the group should be associated'
validate do |value|
fail 'vpc should be a String' unless value.is_a?(String)
end
end

def should_autorequire?(rule)
Expand Down
5 changes: 5 additions & 0 deletions lib/puppet/type/ec2_vpc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
desc 'The name of the VPC.'
validate do |value|
fail 'a VPC must have a name' if value == ''
fail 'name should be a String' unless value.is_a?(String)
end
end

newproperty(:region) do
desc 'The region in which to launch the VPC.'
validate do |value|
fail 'region should not contain spaces' if value =~ /\s/
fail 'region should be a String' unless value.is_a?(String)
end
end

Expand All @@ -25,6 +27,9 @@

newproperty(:dhcp_options) do
desc 'The DHCP option set to use for this VPC.'
validate do |value|
fail 'dhcp_options should be a String' unless value.is_a?(String)
end
end

newproperty(:instance_tenancy) do
Expand Down
2 changes: 2 additions & 0 deletions lib/puppet/type/ec2_vpc_customer_gateway.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
desc 'The name of the customer gateway.'
validate do |value|
fail 'customer gateways must have a name' if value == ''
fail 'name should be a String' unless value.is_a?(String)
end
end

Expand All @@ -34,6 +35,7 @@
desc 'The region in which to launch the customer gateway.'
validate do |value|
fail 'region should not contain spaces' if value =~ /\s/
fail 'region should be a String' unless value.is_a?(String)
end
end

Expand Down
Loading

0 comments on commit 9532687

Please sign in to comment.