humidifier 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CloudFormationResourceSpecification.json +3 -3
- data/lib/humidifier/props/base.rb +0 -5
- data/lib/humidifier/props/boolean_prop.rb +5 -5
- data/lib/humidifier/props/double_prop.rb +7 -3
- data/lib/humidifier/props/integer_prop.rb +7 -3
- data/lib/humidifier/props/json_prop.rb +19 -1
- data/lib/humidifier/props/list_prop.rb +5 -0
- data/lib/humidifier/props/map_prop.rb +5 -0
- data/lib/humidifier/props/string_prop.rb +7 -3
- data/lib/humidifier/props/structure_prop.rb +20 -6
- data/lib/humidifier/props/timestamp_prop.rb +7 -3
- data/lib/humidifier/resource.rb +1 -1
- data/lib/humidifier/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee7bf139de1b6381e11257368d6cd1acbd8e8739
|
4
|
+
data.tar.gz: e4fdc11b944852860856039b9ba92c827719f0c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3eb8a3c2fff29252acae925ae9bf6b1254ec180d59b509c162da13eeca7f08b1e9cf03f0015e15eeb8d98647d9520b61d33d5c027512e076c78707876a4a5747
|
7
|
+
data.tar.gz: 58e0cb21ed854e887be41b33377b73ac567bc8a04ba6a32afa41879f3523e79f1e8819e4a9485493afbb22f2f1daae10e64e888e1aa484924418034aa95dba05
|
@@ -10096,7 +10096,7 @@
|
|
10096
10096
|
},
|
10097
10097
|
"EvaluationPeriods": {
|
10098
10098
|
"Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cw-alarm.html#cfn-cloudwatch-alarms-evaluationperiods",
|
10099
|
-
"PrimitiveType": "
|
10099
|
+
"PrimitiveType": "String",
|
10100
10100
|
"Required": true,
|
10101
10101
|
"UpdateType": "Mutable"
|
10102
10102
|
},
|
@@ -10130,7 +10130,7 @@
|
|
10130
10130
|
},
|
10131
10131
|
"Period": {
|
10132
10132
|
"Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cw-alarm.html#cfn-cloudwatch-alarms-period",
|
10133
|
-
"PrimitiveType": "
|
10133
|
+
"PrimitiveType": "String",
|
10134
10134
|
"Required": true,
|
10135
10135
|
"UpdateType": "Mutable"
|
10136
10136
|
},
|
@@ -10142,7 +10142,7 @@
|
|
10142
10142
|
},
|
10143
10143
|
"Threshold": {
|
10144
10144
|
"Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cw-alarm.html#cfn-cloudwatch-alarms-threshold",
|
10145
|
-
"PrimitiveType": "
|
10145
|
+
"PrimitiveType": "String",
|
10146
10146
|
"Required": true,
|
10147
10147
|
"UpdateType": "Mutable"
|
10148
10148
|
},
|
@@ -15,11 +15,6 @@ module Humidifier
|
|
15
15
|
after_initialize(substructs) if respond_to?(:after_initialize, true)
|
16
16
|
end
|
17
17
|
|
18
|
-
# true if the property type knows how to convert its values
|
19
|
-
def convertable?
|
20
|
-
respond_to?(:convert)
|
21
|
-
end
|
22
|
-
|
23
18
|
# the link to the AWS docs
|
24
19
|
def documentation
|
25
20
|
spec['Documentation']
|
@@ -2,19 +2,19 @@ module Humidifier
|
|
2
2
|
module Props
|
3
3
|
# A boolean property
|
4
4
|
class BooleanProp < Base
|
5
|
-
# converts through value == 'true'
|
5
|
+
# converts the value through `value == 'true'` unless it is valid
|
6
6
|
def convert(value)
|
7
|
-
if
|
7
|
+
if valid?(value) || !%w[true false].include?(value)
|
8
|
+
value
|
9
|
+
else
|
8
10
|
puts "WARNING: Property #{name} should be a boolean, not a string"
|
9
11
|
value == 'true'
|
10
|
-
else
|
11
|
-
value
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
# true if it is a boolean
|
16
16
|
def valid?(value)
|
17
|
-
value.is_a?(TrueClass) || value.is_a?(FalseClass)
|
17
|
+
whitelisted_value?(value) || value.is_a?(TrueClass) || value.is_a?(FalseClass)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -2,10 +2,14 @@ module Humidifier
|
|
2
2
|
module Props
|
3
3
|
# A double property
|
4
4
|
class DoubleProp < Base
|
5
|
-
# converts the value through #to_f unless it is
|
5
|
+
# converts the value through #to_f unless it is valid
|
6
6
|
def convert(value)
|
7
|
-
|
8
|
-
|
7
|
+
if valid?(value) || !value.respond_to?(:to_f)
|
8
|
+
value
|
9
|
+
else
|
10
|
+
puts "WARNING: Property #{name} should be a double"
|
11
|
+
value.to_f
|
12
|
+
end
|
9
13
|
end
|
10
14
|
|
11
15
|
# true if it is whitelisted, an Integer, or a Float
|
@@ -2,10 +2,14 @@ module Humidifier
|
|
2
2
|
module Props
|
3
3
|
# An integer property
|
4
4
|
class IntegerProp < Base
|
5
|
-
# converts the value through #to_i unless it is
|
5
|
+
# converts the value through #to_i unless it is valid
|
6
6
|
def convert(value)
|
7
|
-
|
8
|
-
|
7
|
+
if valid?(value) || !value.respond_to?(:to_i)
|
8
|
+
value
|
9
|
+
else
|
10
|
+
puts "WARNING: Property #{name} should be an integer"
|
11
|
+
value.to_i
|
12
|
+
end
|
9
13
|
end
|
10
14
|
|
11
15
|
# true if it is whitelisted or a Integer
|
@@ -2,9 +2,27 @@ module Humidifier
|
|
2
2
|
module Props
|
3
3
|
# A Json property
|
4
4
|
class JsonProp < Base
|
5
|
+
# converts the value through `Hash[value]` unless it is valid
|
6
|
+
def convert(value)
|
7
|
+
if valid?(value) || !convertable?(value)
|
8
|
+
value
|
9
|
+
else
|
10
|
+
puts "WARNING: Property #{name} should be a Hash"
|
11
|
+
Hash[value]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
5
15
|
# true if the value is whitelisted, a Hash, or an Array
|
6
16
|
def valid?(value)
|
7
|
-
whitelisted_value?(value) || value.is_a?(Hash)
|
17
|
+
whitelisted_value?(value) || value.is_a?(Hash)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def convertable?(value)
|
23
|
+
Hash[value]
|
24
|
+
rescue ArgumentError
|
25
|
+
false
|
8
26
|
end
|
9
27
|
end
|
10
28
|
end
|
@@ -4,6 +4,11 @@ module Humidifier
|
|
4
4
|
class ListProp < Base
|
5
5
|
attr_reader :subprop
|
6
6
|
|
7
|
+
# converts the value through mapping using the subprop unless it is valid
|
8
|
+
def convert(list)
|
9
|
+
valid?(list) ? list : list.map { |value| subprop.convert(value) }
|
10
|
+
end
|
11
|
+
|
7
12
|
# CFN stack syntax
|
8
13
|
def to_cf(list)
|
9
14
|
[key, list.map { |value| subprop.to_cf(value).last }]
|
@@ -4,6 +4,11 @@ module Humidifier
|
|
4
4
|
class MapProp < Base
|
5
5
|
attr_reader :subprop
|
6
6
|
|
7
|
+
# converts the value through mapping using the subprop unless it is valid
|
8
|
+
def convert(map)
|
9
|
+
valid?(map) ? map : Utils.enumerable_to_h(map) { |(key, value)| [key, subprop.convert(value)] }
|
10
|
+
end
|
11
|
+
|
7
12
|
# CFN stack syntax
|
8
13
|
def to_cf(map)
|
9
14
|
dumped =
|
@@ -2,10 +2,14 @@ module Humidifier
|
|
2
2
|
module Props
|
3
3
|
# A string property
|
4
4
|
class StringProp < Base
|
5
|
-
# converts the value through #to_s unless it is
|
5
|
+
# converts the value through #to_s unless it is valid
|
6
6
|
def convert(value)
|
7
|
-
|
8
|
-
|
7
|
+
if valid?(value)
|
8
|
+
value
|
9
|
+
else
|
10
|
+
puts "WARNING: Property #{name} should be a string"
|
11
|
+
value.to_s
|
12
|
+
end
|
9
13
|
end
|
10
14
|
|
11
15
|
# true if it is whitelisted or a String
|
@@ -4,10 +4,22 @@ module Humidifier
|
|
4
4
|
class StructureProp < Base
|
5
5
|
attr_reader :subprops
|
6
6
|
|
7
|
+
# converts the value through mapping using the subprop unless it is valid
|
8
|
+
def convert(struct)
|
9
|
+
if valid?(struct)
|
10
|
+
struct
|
11
|
+
else
|
12
|
+
Utils.enumerable_to_h(struct) do |(subkey, subvalue)|
|
13
|
+
subkey = Utils.underscore(subkey.to_s)
|
14
|
+
[subkey.to_sym, subprops[subkey].convert(subvalue)]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
7
19
|
# CFN stack syntax
|
8
|
-
def to_cf(
|
20
|
+
def to_cf(struct)
|
9
21
|
dumped =
|
10
|
-
Utils.enumerable_to_h(
|
22
|
+
Utils.enumerable_to_h(struct) do |(subkey, subvalue)|
|
11
23
|
subprops[subkey.to_s].to_cf(subvalue)
|
12
24
|
end
|
13
25
|
[key, dumped]
|
@@ -15,9 +27,7 @@ module Humidifier
|
|
15
27
|
|
16
28
|
# true if the value is whitelisted or Hash and all keys are valid for their corresponding props
|
17
29
|
def valid?(struct)
|
18
|
-
whitelisted_value?(struct) ||
|
19
|
-
(struct.is_a?(Hash) &&
|
20
|
-
struct.all? { |key, value| subprops.key?(key.to_s) && subprops[key.to_s].valid?(value) })
|
30
|
+
whitelisted_value?(struct) || (struct.is_a?(Hash) && valid_struct?(struct))
|
21
31
|
end
|
22
32
|
|
23
33
|
private
|
@@ -25,11 +35,15 @@ module Humidifier
|
|
25
35
|
def after_initialize(substructs)
|
26
36
|
type = spec['ItemType'] || spec['Type']
|
27
37
|
@subprops =
|
28
|
-
Utils.enumerable_to_h(substructs
|
38
|
+
Utils.enumerable_to_h(substructs.fetch(type, {}).fetch('Properties', {})) do |(key, config)|
|
29
39
|
subprop = config['ItemType'] == type ? self : Props.from(key, config, substructs)
|
30
40
|
[Utils.underscore(key), subprop]
|
31
41
|
end
|
32
42
|
end
|
43
|
+
|
44
|
+
def valid_struct?(struct)
|
45
|
+
struct.all? { |key, value| subprops.key?(key.to_s) && subprops[key.to_s].valid?(value) }
|
46
|
+
end
|
33
47
|
end
|
34
48
|
end
|
35
49
|
end
|
@@ -2,10 +2,14 @@ module Humidifier
|
|
2
2
|
module Props
|
3
3
|
# A timestamp (ISO 8601) property
|
4
4
|
class TimestampProp < Base
|
5
|
-
# converts the value through
|
5
|
+
# converts the value through DateTime.parse(value) unless it is valid
|
6
6
|
def convert(value)
|
7
|
-
|
8
|
-
|
7
|
+
if valid?(value) || !value.is_a?(String)
|
8
|
+
value
|
9
|
+
else
|
10
|
+
puts "WARNING: Property #{name} should be a Date or Time"
|
11
|
+
DateTime.parse(value)
|
12
|
+
end
|
9
13
|
end
|
10
14
|
|
11
15
|
# true if it is whitelisted, a Time, or a Date
|
data/lib/humidifier/resource.rb
CHANGED
@@ -106,7 +106,7 @@ module Humidifier
|
|
106
106
|
|
107
107
|
def validate_value(property, value, raw)
|
108
108
|
prop = self.class.props[property]
|
109
|
-
value = prop.convert(value) if raw
|
109
|
+
value = prop.convert(value) if raw
|
110
110
|
unless prop.valid?(value)
|
111
111
|
raise ArgumentError, "Invalid value for #{property}: #{value.inspect}"
|
112
112
|
end
|
data/lib/humidifier/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: humidifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Localytics
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|