aws-sdk-resources 2.0.10.pre → 2.0.11.pre
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/aws-sdk-resources/builder_sources.rb +1 -7
- data/lib/aws-sdk-resources/documenter/base_operation_documenter.rb +1 -1
- data/lib/aws-sdk-resources/operations.rb +1 -3
- data/lib/aws-sdk-resources/validator.rb +159 -68
- data/lib/aws-sdk-resources/validator/context.rb +24 -28
- data/lib/aws-sdk-resources/validator/dsl.rb +89 -0
- data/lib/aws-sdk-resources/validator/operation_validator.rb +4 -4
- data/lib/aws-sdk-resources/validator/path_resolver.rb +34 -0
- data/lib/aws-sdk-resources/validator/rule.rb +2 -24
- metadata +6 -6
- data/lib/aws-sdk-resources/validator/identifier_validator.rb +0 -107
- data/lib/aws-sdk-resources/validator/shape_validator.rb +0 -47
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c40fdd4d2650569c8c2c171fc78ff3b028bcca01
|
4
|
+
data.tar.gz: eaa5e8d378d80948885606de523ab83fa48cd1fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b28aff2fd2739d2412ff3b259a63cf283477485fdcaa45b67d10e5b11d19fa732a636f5efbfdb9b6d9f64590c2e5df42bfc31f358e9936638df63f915fdda5f
|
7
|
+
data.tar.gz: baf2c5ba95436817c23af6caa2bbc5576591ea8e03dbd245479f72612a50514546fd1ff171e52e33990750521728948124df11ce5d5c87c5c64a89a0545caeb5
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'jmespath'
|
2
|
-
|
3
1
|
module Aws
|
4
2
|
module Resources
|
5
3
|
module BuilderSources
|
@@ -118,11 +116,7 @@ module Aws
|
|
118
116
|
|
119
117
|
# @option [required, Seahorse::Client::Response] :response
|
120
118
|
def extract(options)
|
121
|
-
|
122
|
-
response(options).data
|
123
|
-
else
|
124
|
-
JMESPath.search(source, response(options).data)
|
125
|
-
end
|
119
|
+
JMESPath.search(source, response(options).data)
|
126
120
|
end
|
127
121
|
|
128
122
|
private
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'jmespath'
|
2
|
-
|
3
1
|
module Aws
|
4
2
|
module Resources
|
5
3
|
module Operations
|
@@ -66,7 +64,7 @@ module Aws
|
|
66
64
|
private
|
67
65
|
|
68
66
|
def extract(resp)
|
69
|
-
|
67
|
+
JMESPath.search(@path, resp.data)
|
70
68
|
end
|
71
69
|
|
72
70
|
end
|
@@ -1,96 +1,187 @@
|
|
1
|
-
require 'multi_json'
|
2
1
|
require 'json-schema'
|
3
2
|
require 'aws-sdk-resources/validator/context'
|
3
|
+
require 'aws-sdk-resources/validator/dsl'
|
4
|
+
require 'aws-sdk-resources/validator/path_resolver'
|
4
5
|
require 'aws-sdk-resources/validator/rule'
|
5
|
-
require 'aws-sdk-resources/validator/shape_validator'
|
6
|
-
require 'aws-sdk-resources/validator/identifier_validator'
|
7
6
|
require 'aws-sdk-resources/validator/operation_validator'
|
8
7
|
|
9
8
|
module Aws
|
10
9
|
module Resources
|
11
10
|
module Validator
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
# @return [Array<String>]
|
30
|
-
def validate(definition, api)
|
31
|
-
errors = apply_schema(definition)
|
32
|
-
errors = lint('#', definition, definition, api) if errors.empty?
|
33
|
-
errors
|
34
|
-
end
|
35
|
-
|
36
|
-
private
|
37
|
-
|
38
|
-
# Validates the resource definition document against the JSON
|
39
|
-
# schema for resources.
|
40
|
-
# @param [Hash] definition
|
41
|
-
# @return [Array<String>] Returns an array of schema validation errors.
|
42
|
-
# Returns an empty array if there are no errors.
|
43
|
-
def apply_schema(definition)
|
44
|
-
schema = MultiJson.load(File.read(SCHEMA_PATH))
|
45
|
-
JSON::Validator.fully_validate(schema, definition)
|
46
|
-
end
|
47
|
-
|
48
|
-
# Recursively lints the resource definition hash against the given
|
49
|
-
# api.
|
50
|
-
# @param [Hash] definition
|
51
|
-
# @param [Hash] api
|
52
|
-
# @return [Array<String>] Returns an array of schema validation errors.
|
53
|
-
# Returns an empty array if there are no errors.
|
54
|
-
def lint(prefix, node, definition, api, errors = [])
|
55
|
-
lint_node(prefix, node, definition, api, errors)
|
56
|
-
case node
|
57
|
-
when Hash
|
58
|
-
node.each do |key, value|
|
59
|
-
lint("#{prefix}/#{key}", value, definition, api, errors)
|
60
|
-
end
|
61
|
-
when Array
|
62
|
-
node.each.with_index do |value, index|
|
63
|
-
lint("#{prefix}/#{index}", value, definition, api, errors)
|
64
|
-
end
|
12
|
+
extend Validator::DSL
|
13
|
+
|
14
|
+
# identifiers_may_not_be_prefixed_by_their_resource_name
|
15
|
+
match('#/resources/(\w+)/identifiers/\d+/name') do |c, matches|
|
16
|
+
resource_name = matches[1]
|
17
|
+
if c.value.match(/^#{resource_name}/)
|
18
|
+
c.error("#{c.path} must not be prefixed with '#{resource_name}'")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# identifiers_must_have_unique_names
|
23
|
+
match('#/resources/\w+/identifiers') do |c|
|
24
|
+
identifiers = c.value.map { |v| v['name'] }
|
25
|
+
identifiers.each.with_index do |identifier, n|
|
26
|
+
unless identifiers.count(identifier) == 1
|
27
|
+
c.error("#{c.path}/#{n}/name must be uniq within #{c.path}/*/name")
|
65
28
|
end
|
66
|
-
errors
|
67
29
|
end
|
30
|
+
end
|
68
31
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
32
|
+
# identifiers_with_memberName_require_the_resource_to_have_a_shape
|
33
|
+
match('#/resources/(\w+)/identifiers/(\d+)/memberName') do |c, matches|
|
34
|
+
resource_name = matches[1]
|
35
|
+
shape_path = "#/resources/#{resource_name}/shape"
|
36
|
+
unless c.definition['resources'][resource_name]['shape']
|
37
|
+
c.error("#{c.path} requires #{shape_path} to be set")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# identifiers_with_memberName_require_the_resource_shape_to_have_that_member
|
42
|
+
match('#/resources/(\w+)/identifiers/(\d+)/memberName') do |c, matches|
|
43
|
+
resource_name = matches[1]
|
44
|
+
shape_path = "#/resources/#{resource_name}/shape"
|
45
|
+
shape_name = c.definition['resources'][resource_name]['shape']
|
46
|
+
if
|
47
|
+
shape_name &&
|
48
|
+
c.api['shapes'][shape_name] &&
|
49
|
+
c.api['shapes'][shape_name]['type'] == 'structure' &&
|
50
|
+
!c.api['shapes'][shape_name]['members'].key?(c.value)
|
51
|
+
then
|
52
|
+
c.error("#{c.path} is not defined at api#/shapes/#{shape_name}/members/#{c.value}")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# shape_must_be_defined_in_the_api
|
57
|
+
match('#/resources/\w+/shape') do |c|
|
58
|
+
unless c.api['shapes'][c.value]
|
59
|
+
c.error("#{c.path} not found at api#/shapes/#{c.value}")
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# shape_must_be_a_structure
|
64
|
+
# load_requires_shape_to_be_a_structure
|
65
|
+
match('#/resources/\w+/shape') do |c|
|
66
|
+
shape = c.api['shapes'][c.value]
|
67
|
+
if shape && shape['type'] != 'structure'
|
68
|
+
c.error("#{c.path} must resolve to a structure")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# load_requires_shape_to_be_set
|
73
|
+
match('#/resources/(\w+)/load') do |c, matches|
|
74
|
+
resource = matches[1]
|
75
|
+
unless c.definition['resources'][resource]['shape']
|
76
|
+
c.error("#{c.path} requires #/resources/#{resource}/shape to be set")
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
# load_operation_must_exist
|
82
|
+
# TODO : add assertions for service/actions, service/hasMany, actions, etc
|
83
|
+
match(*%w(
|
84
|
+
#/service/actions/\w+/request/operation
|
85
|
+
#/service/hasMany/\w+/request/operation
|
86
|
+
#/resources/\w+/load/request/operation
|
87
|
+
#/resources/\w+/actions/\w+/request/operation
|
88
|
+
#/resources/\w+/batchActions/\w+/request/operation
|
89
|
+
#/resources/\w+/hasMany/\w+/request/operation
|
90
|
+
)) do |c|
|
91
|
+
unless c.api['operations'][c.value]
|
92
|
+
c.error("#{c.path} is set but is not defined at api#/operations/#{c.value}")
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# load_operation_must_accept_input_if_params_given
|
97
|
+
match(*%w(
|
98
|
+
#/service/actions/\w+/request
|
99
|
+
#/service/hasMany/\w+/request
|
100
|
+
#/resources/\w+/load/request
|
101
|
+
#/resources/\w+/actions/\w+/request
|
102
|
+
#/resources/\w+/batchActions/\w+/request
|
103
|
+
#/resources/\w+/hasMany/\w+/request
|
104
|
+
)) do |c|
|
105
|
+
# ...
|
106
|
+
end
|
107
|
+
|
108
|
+
# load_path_must_resolve_to_shape
|
109
|
+
match('#/resources/(\w+)/load/path') do |c, matches|
|
110
|
+
operation_name =
|
111
|
+
c.definition['resources'][matches[1]]['load']['request']['operation']
|
112
|
+
if operation = c.api['operations'][operation_name]
|
113
|
+
if from = operation['output']
|
114
|
+
if shape_name = c.definition['resources'][matches[1]]['shape']
|
115
|
+
resolved = PathResolver.new(c.api).resolve(c.value, from)
|
116
|
+
unless resolved == shape_name
|
117
|
+
c.error("#{c.path} must resolve to a '#{shape_name}' shape")
|
118
|
+
end
|
119
|
+
else
|
120
|
+
# resource defines load but does not define shape
|
73
121
|
end
|
122
|
+
else
|
123
|
+
# resource load operation does not have output shape reference
|
74
124
|
end
|
125
|
+
else
|
126
|
+
# resource load operation not in API model
|
75
127
|
end
|
128
|
+
end
|
129
|
+
|
130
|
+
match(*%w(
|
131
|
+
#/service/actions/\w+/request
|
132
|
+
#/resources/\w+/load/request
|
133
|
+
#/resources/\w+/actions/\w+/request
|
134
|
+
#/resources/\w+/batchActions/\w+/request
|
135
|
+
#/resources/\w+/hasMany/\w+/request
|
136
|
+
)) do |c|
|
137
|
+
end
|
76
138
|
|
139
|
+
match(*%w(
|
140
|
+
#/service/hasMany/\w+/resource/type
|
141
|
+
#/resources/\w+/actions/\w+/resource/type
|
142
|
+
#/resources/\w+/batchActions/\w+/resource/type
|
143
|
+
#/resources/\w+/hasMany/\w+/resource/type
|
144
|
+
)) do |c|
|
77
145
|
end
|
78
146
|
|
79
|
-
match(
|
80
|
-
|
147
|
+
match(*%w(
|
148
|
+
#/service/hasMany/\w+/resource/identifiers
|
149
|
+
#/resources/\w+/actions/\w+/resource/identifiers
|
150
|
+
#/resources/\w+/batchActions/\w+/resource/identifiers
|
151
|
+
#/resources/\w+/hasMany/\w+/resource/identifiers
|
152
|
+
)) do |c|
|
153
|
+
# must provide ALL of the identifiers for the target resource
|
154
|
+
# each identifier must resolve from its
|
81
155
|
end
|
82
156
|
|
83
|
-
match(
|
84
|
-
|
85
|
-
|
157
|
+
match(*%w(
|
158
|
+
#/service/hasMany/\w+/resource/path
|
159
|
+
#/resources/\w+/actions/\w+/resource/path
|
160
|
+
#/resources/\w+/batchActions/\w+/resource/path
|
161
|
+
#/resources/\w+/hasMany/\w+/resource/path
|
162
|
+
)) do |c|
|
163
|
+
type = c.parent['type']
|
164
|
+
from = c.parent.parent['request']['operation']
|
165
|
+
from = c.api['operations'][from]['output']
|
166
|
+
expected = c.definition['resources'][type]['shape']
|
167
|
+
resolved = PathResolver.new(c.api).resolve(c.value, from)
|
168
|
+
unless expected == resolved
|
169
|
+
c.error("#{c.path} must resolve to a \"#{expected}\" shape")
|
86
170
|
end
|
87
171
|
end
|
88
172
|
|
173
|
+
# load_params_can_be_nested
|
174
|
+
# load_params_must_match_their_static_types
|
175
|
+
# load_params_must_not_be_dataMembers
|
176
|
+
# load_params_must_resolve
|
177
|
+
# load_path_accepts_dollar_signs
|
178
|
+
# load_path_accepts_nested_paths
|
179
|
+
|
89
180
|
match('#/resources/(\w+)/load') do |context|
|
90
181
|
v = OperationValidator.new(context)
|
91
182
|
v.validate_request do
|
92
183
|
v.validate_param_source_type_not_used('dataMember')
|
93
|
-
v.validate_path(origin: :response, target: :self)
|
184
|
+
#v.validate_path(origin: :response, target: :self)
|
94
185
|
end
|
95
186
|
v.validate_path_set
|
96
187
|
v.validate_resource_not_set
|
@@ -123,7 +214,7 @@ module Aws
|
|
123
214
|
end
|
124
215
|
end
|
125
216
|
|
126
|
-
match('#/resources/(\w+)/
|
217
|
+
match('#/resources/(\w+)/belongsTo/\w+') do |context, matches|
|
127
218
|
v = OperationValidator.new(context)
|
128
219
|
v.validate_request_not_set
|
129
220
|
v.validate_resource do
|
@@ -134,7 +225,7 @@ module Aws
|
|
134
225
|
# to the target resource data
|
135
226
|
v.validate_path(origin: :self, target: :resource)
|
136
227
|
|
137
|
-
if
|
228
|
+
if matches[2] == 'hasSome'
|
138
229
|
# at least one identifier source must be plural
|
139
230
|
# path must be plural if given
|
140
231
|
else
|
@@ -3,22 +3,29 @@ module Aws
|
|
3
3
|
module Validator
|
4
4
|
class Context
|
5
5
|
|
6
|
-
# @option options [required, String] :path
|
7
|
-
# @option options [required, Object] :value
|
8
|
-
# @option options [required, Hash] :definition
|
9
|
-
# @option options [required, Hash] :api
|
10
|
-
# @option options [required, MatchData] :matches
|
11
6
|
def initialize(options = {})
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
19
|
-
@errors = []
|
7
|
+
@parent = options[:parent]
|
8
|
+
@path = options[:path]
|
9
|
+
@value = options[:value]
|
10
|
+
@definition = options[:definition]
|
11
|
+
@api = options[:api]
|
12
|
+
@errors = options[:errors] || []
|
20
13
|
end
|
21
14
|
|
15
|
+
def child(at)
|
16
|
+
Context.new(
|
17
|
+
parent: self,
|
18
|
+
path: "#{path}/#{at}",
|
19
|
+
value: value[at],
|
20
|
+
definition: definition,
|
21
|
+
api: api,
|
22
|
+
errors: errors
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
# @return [Context,nil]
|
27
|
+
attr_reader :parent
|
28
|
+
|
22
29
|
# @return [String]
|
23
30
|
attr_reader :path
|
24
31
|
|
@@ -31,29 +38,18 @@ module Aws
|
|
31
38
|
# @return [Hash]
|
32
39
|
attr_reader :api
|
33
40
|
|
34
|
-
# @return [MatchData]
|
35
|
-
attr_reader :matches
|
36
|
-
|
37
41
|
# @return [Array<String>]
|
38
42
|
attr_reader :errors
|
39
43
|
|
44
|
+
def [] key
|
45
|
+
@value[key]
|
46
|
+
end
|
47
|
+
|
40
48
|
def error(msg)
|
41
49
|
@errors << msg
|
42
50
|
false
|
43
51
|
end
|
44
52
|
|
45
|
-
def resource
|
46
|
-
definition['resources'][matches[1]]
|
47
|
-
end
|
48
|
-
|
49
|
-
def resource_name
|
50
|
-
matches[1]
|
51
|
-
end
|
52
|
-
|
53
|
-
def shape(name)
|
54
|
-
api['shapes'][name]
|
55
|
-
end
|
56
|
-
|
57
53
|
end
|
58
54
|
end
|
59
55
|
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
module Aws
|
2
|
+
module Resources
|
3
|
+
module Validator
|
4
|
+
module DSL
|
5
|
+
|
6
|
+
def self.extended(base)
|
7
|
+
|
8
|
+
# @api private
|
9
|
+
base.const_set(:RULES, [])
|
10
|
+
|
11
|
+
# @api private
|
12
|
+
base.const_set(:SCHEMA_PATH, File.expand_path(File.join([
|
13
|
+
File.dirname(__FILE__), '..', '..', '..', 'resources.schema.json'
|
14
|
+
])))
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
def match(*patterns, &block)
|
19
|
+
patterns.each do |pattern|
|
20
|
+
RULES << Rule.new(pattern, &block)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# @param [Hash] definition
|
25
|
+
# @param [Hash] api
|
26
|
+
# @return [Array<String>]
|
27
|
+
def validate(definition, api)
|
28
|
+
errors = validate_against_schema(definition)
|
29
|
+
if errors.empty?
|
30
|
+
lint(new_context(definition, api))
|
31
|
+
else
|
32
|
+
errors
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def new_context(definition, api)
|
39
|
+
Validator::Context.new(
|
40
|
+
path: '#',
|
41
|
+
value: definition,
|
42
|
+
definition: definition,
|
43
|
+
api: api,
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
# Validates the resource definition document against the JSON
|
48
|
+
# schema for resources.
|
49
|
+
# @param [Hash] definition
|
50
|
+
# @return [Array<String>] Returns an array of schema validation errors.
|
51
|
+
# Returns an empty array if there are no errors.
|
52
|
+
def validate_against_schema(definition)
|
53
|
+
schema = MultiJson.load(File.read(SCHEMA_PATH))
|
54
|
+
JSON::Validator.fully_validate(schema, definition)
|
55
|
+
end
|
56
|
+
|
57
|
+
# Recursively lints the resource definition hash against the given
|
58
|
+
# api.
|
59
|
+
# @param [Hash] definition
|
60
|
+
# @param [Hash] api
|
61
|
+
# @return [Array<String>] Returns an array of schema validation errors.
|
62
|
+
# Returns an empty array if there are no errors.
|
63
|
+
def lint(context)
|
64
|
+
lint_node(context)
|
65
|
+
case context.value
|
66
|
+
when Hash
|
67
|
+
context.value.keys.each do |key, value|
|
68
|
+
lint(context.child(key))
|
69
|
+
end
|
70
|
+
when Array
|
71
|
+
(0...context.value.size).each do |index|
|
72
|
+
lint(context.child(index))
|
73
|
+
end
|
74
|
+
end
|
75
|
+
context.errors
|
76
|
+
end
|
77
|
+
|
78
|
+
def lint_node(context)
|
79
|
+
RULES.each do |rule|
|
80
|
+
if matches = rule.matches(context.path)
|
81
|
+
rule.apply(context, matches)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -319,11 +319,11 @@ module Aws
|
|
319
319
|
end
|
320
320
|
|
321
321
|
def validate_operation_exists
|
322
|
-
if api_operation
|
322
|
+
#if api_operation
|
323
323
|
true
|
324
|
-
else
|
325
|
-
|
326
|
-
end
|
324
|
+
#else
|
325
|
+
# error("'#{path}/request/operation' is set but is not defined at 'api#/operations/#{operation_name}'.")
|
326
|
+
#end
|
327
327
|
end
|
328
328
|
|
329
329
|
def resource_name
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Aws
|
2
|
+
module Resources
|
3
|
+
module Validator
|
4
|
+
# @api private
|
5
|
+
class PathResolver
|
6
|
+
|
7
|
+
def initialize(api)
|
8
|
+
@api = api
|
9
|
+
end
|
10
|
+
|
11
|
+
# @param [String<JMESPathExpression>] expression
|
12
|
+
# @param [Hash<Shape Reference>] from The shape reference, typically
|
13
|
+
# an operation, to resolve the path starting from.
|
14
|
+
# @return [String, nil] Returns the class name resolved, or `nil`
|
15
|
+
# if the path does not resolve in the model.
|
16
|
+
def resolve(expression, from)
|
17
|
+
ref = expression.scan(/\w+|\[.*?\]/).inject(from) do |ref, part|
|
18
|
+
shape = @api['shapes'][ref['shape']]
|
19
|
+
if part[0] == '['
|
20
|
+
return nil unless shape['type'] == 'list'
|
21
|
+
shape['member']
|
22
|
+
else
|
23
|
+
return nil unless shape['type'] == 'structure'
|
24
|
+
return nil unless shape['members'][part]
|
25
|
+
shape['members'][part]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
ref && ref['shape']
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -4,39 +4,17 @@ module Aws
|
|
4
4
|
# @api private
|
5
5
|
class Rule
|
6
6
|
|
7
|
-
# @param [String] pattern
|
8
7
|
def initialize(pattern, &block)
|
9
8
|
@pattern = Regexp.new('^' + pattern + '$')
|
10
9
|
@block = block
|
11
10
|
end
|
12
11
|
|
13
|
-
# @param [String] path
|
14
|
-
# @return [Boolean]
|
15
|
-
def applies?(path)
|
16
|
-
!!path.match(@pattern)
|
17
|
-
end
|
18
|
-
|
19
|
-
# @param [String] path
|
20
|
-
# @return [MatchData]
|
21
12
|
def matches(path)
|
22
13
|
path.match(@pattern)
|
23
14
|
end
|
24
15
|
|
25
|
-
|
26
|
-
|
27
|
-
# @param [Hash] definition
|
28
|
-
# @param [Hash] api
|
29
|
-
# @return [Array<String>]
|
30
|
-
def validate(path, value, definition, api)
|
31
|
-
context = Validator::Context.new(
|
32
|
-
path: path,
|
33
|
-
value: value,
|
34
|
-
definition: definition,
|
35
|
-
api: api,
|
36
|
-
matches: matches(path),
|
37
|
-
)
|
38
|
-
@block.call(context)
|
39
|
-
context.errors
|
16
|
+
def apply(context, matches)
|
17
|
+
@block.call(context, matches)
|
40
18
|
end
|
41
19
|
|
42
20
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aws-sdk-resources
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.11.pre
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Amazon Web Services
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-core
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.0.
|
19
|
+
version: 2.0.11
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 2.0.
|
26
|
+
version: 2.0.11
|
27
27
|
description: Provides resource-oriented abstractions for AWS.
|
28
28
|
email:
|
29
29
|
executables: []
|
@@ -64,10 +64,10 @@ files:
|
|
64
64
|
- lib/aws-sdk-resources/services/sqs.rb
|
65
65
|
- lib/aws-sdk-resources/source.rb
|
66
66
|
- lib/aws-sdk-resources/validator/context.rb
|
67
|
-
- lib/aws-sdk-resources/validator/
|
67
|
+
- lib/aws-sdk-resources/validator/dsl.rb
|
68
68
|
- lib/aws-sdk-resources/validator/operation_validator.rb
|
69
|
+
- lib/aws-sdk-resources/validator/path_resolver.rb
|
69
70
|
- lib/aws-sdk-resources/validator/rule.rb
|
70
|
-
- lib/aws-sdk-resources/validator/shape_validator.rb
|
71
71
|
- lib/aws-sdk-resources/validator.rb
|
72
72
|
- lib/aws-sdk-resources.rb
|
73
73
|
homepage: http://github.com/aws/aws-sdk-core-ruby
|
@@ -1,107 +0,0 @@
|
|
1
|
-
module Aws
|
2
|
-
module Resources
|
3
|
-
module Validator
|
4
|
-
class IdentifierValidator
|
5
|
-
|
6
|
-
# @param [Validator::Context] context
|
7
|
-
# @param [Hash] identifier
|
8
|
-
# @param [Integer] index
|
9
|
-
def initialize(context, identifier, index)
|
10
|
-
@context = context
|
11
|
-
@identifier = identifier
|
12
|
-
@index = index
|
13
|
-
end
|
14
|
-
|
15
|
-
attr_reader :identifier
|
16
|
-
|
17
|
-
attr_reader :index
|
18
|
-
|
19
|
-
def validate
|
20
|
-
validate_name_is_uniq
|
21
|
-
validate_name_is_not_prefixed
|
22
|
-
if member_name
|
23
|
-
validate_resource_has_shape && validate_resource_shape_contains_member
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
def validate_name_is_uniq
|
30
|
-
if all_identifier_names.count(name) > 1
|
31
|
-
error("#{path("#{index}/name")} must be uniq within #{path('*/name')}.")
|
32
|
-
else
|
33
|
-
true
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def validate_name_is_not_prefixed
|
38
|
-
if name.match(/^#{resource_name}/)
|
39
|
-
error("#{path("#{index}/name")} must not be prefixed with '#{resource_name}'.")
|
40
|
-
else
|
41
|
-
true
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def validate_resource_has_shape
|
46
|
-
if resource_shape_name
|
47
|
-
true
|
48
|
-
else
|
49
|
-
error("#{path("#{index}/memberName")} requires '#/resources/#{resource_name}/shape' to be set.")
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def validate_resource_shape_contains_member
|
54
|
-
if
|
55
|
-
resource_shape['type'] == 'structure' &&
|
56
|
-
resource_shape['members'].key?(member_name)
|
57
|
-
then
|
58
|
-
true
|
59
|
-
else
|
60
|
-
error("#{path("#{index}/memberName")} is not defined at 'api#/shapes/#{resource_shape_name}/members/#{member_name}'.")
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def error(msg)
|
65
|
-
@context.error(msg)
|
66
|
-
end
|
67
|
-
|
68
|
-
def path(suffix = nil)
|
69
|
-
if suffix
|
70
|
-
"'#{@context.path}/#{suffix}'"
|
71
|
-
else
|
72
|
-
"'#{@context.path}'"
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def name
|
77
|
-
@identifier['name']
|
78
|
-
end
|
79
|
-
|
80
|
-
def member_name
|
81
|
-
@identifier['memberName']
|
82
|
-
end
|
83
|
-
|
84
|
-
def resource_name
|
85
|
-
@context.matches[1]
|
86
|
-
end
|
87
|
-
|
88
|
-
def all_identifier_names
|
89
|
-
@context.value.map { |i| i['name'] }
|
90
|
-
end
|
91
|
-
|
92
|
-
def resource
|
93
|
-
@context.definition['resources'][resource_name]
|
94
|
-
end
|
95
|
-
|
96
|
-
def resource_shape_name
|
97
|
-
resource['shape']
|
98
|
-
end
|
99
|
-
|
100
|
-
def resource_shape
|
101
|
-
@context.api['shapes'][resource_shape_name]
|
102
|
-
end
|
103
|
-
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
module Aws
|
2
|
-
module Resources
|
3
|
-
module Validator
|
4
|
-
class ShapeValidator
|
5
|
-
|
6
|
-
# @param [Validator::Context] context
|
7
|
-
# @param [String] shape_name
|
8
|
-
def initialize(context, shape_name)
|
9
|
-
@context = context
|
10
|
-
@shape_name = shape_name
|
11
|
-
@path = context.path
|
12
|
-
end
|
13
|
-
|
14
|
-
attr_reader :shape_name
|
15
|
-
|
16
|
-
attr_reader :path
|
17
|
-
|
18
|
-
def validate
|
19
|
-
validate_shape_is_defined && validate_shape_is_a_structure
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
def validate_shape_is_defined
|
25
|
-
if shape
|
26
|
-
true
|
27
|
-
else
|
28
|
-
@context.error("'#{path}' not found at api#/shapes/#{shape_name}.")
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def validate_shape_is_a_structure
|
33
|
-
if shape['type'] == 'structure'
|
34
|
-
true
|
35
|
-
else
|
36
|
-
@context.error("'#{path}' must resolve to a structure shape.")
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def shape
|
41
|
-
@context.api['shapes'][shape_name]
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|