configuration_service 4.1.1 → 4.2.0
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a08e439b4b3ae82204b37d1220da1ad995d05724
|
4
|
+
data.tar.gz: d6cf937e29cf6f2d521eeecaf1b20a3096ebeafd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f330c463b9dd838d0f9702e29853df543070cb7b2f737274d2388d11371dc6de9f9d5233681b07118c8e5621f71b88676a2773b0f1ceb8c7c32838b24c9ebc9e
|
7
|
+
data.tar.gz: a73776f84e1b156bafbd6129b27eb8c10f29c8ec3bdeb39939a0ab71c2b1334f19fcf5493b748d4fd50066a7a8fe4a2ba936ba0d38ed0de2abc8a65f3ceb589e
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'configuration_service/configuration'
|
2
2
|
require 'configuration_service/decorator_registry'
|
3
|
+
require 'configuration_service/errors'
|
3
4
|
require 'delegate'
|
4
5
|
|
5
6
|
module ConfigurationService
|
@@ -71,6 +72,12 @@ module ConfigurationService
|
|
71
72
|
#
|
72
73
|
class ReferenceResolver < SimpleDelegator
|
73
74
|
|
75
|
+
##
|
76
|
+
#
|
77
|
+
# Configuration with a referenced identifier was not found
|
78
|
+
#
|
79
|
+
class MissingReferenceError < ConfigurationService::ConfigurationNotFoundError; end
|
80
|
+
|
74
81
|
##
|
75
82
|
# The regular expression used to match configuration identifier references
|
76
83
|
#
|
@@ -115,7 +122,7 @@ module ConfigurationService
|
|
115
122
|
#
|
116
123
|
def authorize_consumption(identifier, credentials)
|
117
124
|
configuration = @provider.request_configuration(identifier, credentials)
|
118
|
-
identifiers =
|
125
|
+
identifiers = find_configuration_identifiers(configuration.data)
|
119
126
|
identifiers.unshift(identifier)
|
120
127
|
@provider.authorize_consumption(identifiers, credentials)
|
121
128
|
end
|
@@ -126,24 +133,56 @@ module ConfigurationService
|
|
126
133
|
# @param [Hash] configuration_data
|
127
134
|
# the data dictionary whose String values to search for configuration identifier references
|
128
135
|
# @return [Array] list of referenced configuration identifiers found
|
129
|
-
|
130
|
-
def
|
131
|
-
configuration_data.
|
132
|
-
|
133
|
-
}.map { |value|
|
134
|
-
match = value.match(PATTERN)
|
135
|
-
match[1] if not match.nil?
|
136
|
-
}.compact
|
137
|
-
end
|
136
|
+
#
|
137
|
+
def find_configuration_identifiers(configuration_data)
|
138
|
+
enumerate_references(configuration_data).map { |_, _, reference| reference }
|
139
|
+
end
|
138
140
|
|
141
|
+
##
|
142
|
+
# Provide resolved configuration data
|
143
|
+
#
|
144
|
+
# @param [Hash] configuration_data
|
145
|
+
# the data dictionary whose configuration identifier references to resolve
|
146
|
+
#
|
147
|
+
# @return [Hash] a deep copy of +configuration_data+ in which references have been replaced
|
148
|
+
# with the configuration data they reference.
|
149
|
+
#
|
139
150
|
def resolve_configuration_data(configuration_data, credentials)
|
140
|
-
configuration_data.
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
151
|
+
deep_copy(configuration_data).tap do |resolved_data|
|
152
|
+
enumerate_references(resolved_data).each do |c, k, reference|
|
153
|
+
if resolved = @provider.request_configuration(reference, credentials)
|
154
|
+
c[k] = resolved.data
|
155
|
+
else
|
156
|
+
raise MissingReferenceError.new("unresolved reference %{#{reference}}")
|
157
|
+
end
|
145
158
|
end
|
146
|
-
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
##
|
163
|
+
# Enumerate all references in a configuration data dictionary
|
164
|
+
#
|
165
|
+
# @param [Hash] configuration_data
|
166
|
+
# the data dictionary to walk
|
167
|
+
#
|
168
|
+
# @return [Enumerator] an enumerator over all (possibly nested) references.
|
169
|
+
# The enumerator yields an array of the (sub)dictionary in which the reference
|
170
|
+
# was found, the key that mapped to the reference, and the reference.
|
171
|
+
#
|
172
|
+
def enumerate_references(configuration_data)
|
173
|
+
Enumerator.new do |enum|
|
174
|
+
configuration_data.each do |key, value|
|
175
|
+
if value.is_a?(Hash)
|
176
|
+
enumerate_references(value).each { |m| enum << m }
|
177
|
+
elsif value.to_s =~ PATTERN
|
178
|
+
enum << [configuration_data, key, $1]
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
def deep_copy(h)
|
185
|
+
Marshal.load(Marshal.dump(h))
|
147
186
|
end
|
148
187
|
|
149
188
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: configuration_service
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sheldon Hearn
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -160,3 +160,4 @@ signing_key:
|
|
160
160
|
specification_version: 4
|
161
161
|
summary: Configuration service
|
162
162
|
test_files: []
|
163
|
+
has_rdoc:
|