clowder-common-ruby 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,11 @@
1
+ require_relative 'config'
2
+
3
+ begin
4
+ config = ::ClowderCommonRuby::Config.load
5
+
6
+ puts config.inspect
7
+ puts "-------------------\nConfig #{ENV['ACG_CONFIG']} loaded successfully"
8
+ rescue => e
9
+ puts e.message
10
+ exit -1
11
+ end
@@ -0,0 +1,348 @@
1
+ # This file is automatically generated by bin/json_schema_ruby
2
+ require 'ostruct'
3
+
4
+ module ClowderCommonRuby
5
+ class AppConfig < OpenStruct
6
+ attr_accessor :logging
7
+ attr_accessor :kafka
8
+ attr_accessor :database
9
+ attr_accessor :objectStore
10
+ attr_accessor :inMemoryDb
11
+ attr_accessor :featureFlags
12
+ attr_accessor :endpoints
13
+ attr_accessor :privateEndpoints
14
+
15
+ def initialize(attributes)
16
+ super
17
+ raise 'The input argument (attributes) must be a hash' if (!attributes || !attributes.is_a?(Hash))
18
+
19
+ attributes = attributes.each_with_object({}) do |(k, v), h|
20
+ raise "The input [#{k}] is invalid" unless valid_keys.include?(k.to_sym)
21
+ h[k.to_sym] = v
22
+ end
23
+
24
+ @logging = LoggingConfig.new(attributes.fetch(:logging, {}))
25
+ @kafka = KafkaConfig.new(attributes.fetch(:kafka, {}))
26
+ @database = DatabaseConfig.new(attributes.fetch(:database, {}))
27
+ @objectStore = ObjectStoreConfig.new(attributes.fetch(:objectStore, {}))
28
+ @inMemoryDb = InMemoryDBConfig.new(attributes.fetch(:inMemoryDb, {}))
29
+ @featureFlags = FeatureFlagsConfig.new(attributes.fetch(:featureFlags, {}))
30
+ @endpoints = []
31
+ attributes.fetch(:endpoints, []).each do |attr|
32
+ @endpoints << DependencyEndpoint.new(attr)
33
+ end
34
+ @privateEndpoints = []
35
+ attributes.fetch(:privateEndpoints, []).each do |attr|
36
+ @privateEndpoints << PrivateDependencyEndpoint.new(attr)
37
+ end
38
+ end
39
+
40
+ def valid_keys
41
+ [].tap do |keys|
42
+ keys << :privatePort
43
+ keys << :publicPort
44
+ keys << :webPort
45
+ keys << :metricsPort
46
+ keys << :metricsPath
47
+ keys << :logging
48
+ keys << :kafka
49
+ keys << :database
50
+ keys << :objectStore
51
+ keys << :inMemoryDb
52
+ keys << :featureFlags
53
+ keys << :endpoints
54
+ keys << :privateEndpoints
55
+ end
56
+ end
57
+ end
58
+
59
+ class LoggingConfig < OpenStruct
60
+ attr_accessor :cloudwatch
61
+
62
+ def initialize(attributes)
63
+ super
64
+ raise 'The input argument (attributes) must be a hash' if (!attributes || !attributes.is_a?(Hash))
65
+
66
+ attributes = attributes.each_with_object({}) do |(k, v), h|
67
+ raise "The input [#{k}] is invalid" unless valid_keys.include?(k.to_sym)
68
+ h[k.to_sym] = v
69
+ end
70
+
71
+ @cloudwatch = CloudWatchConfig.new(attributes.fetch(:cloudwatch, {}))
72
+ end
73
+
74
+ def valid_keys
75
+ [].tap do |keys|
76
+ keys << :type
77
+ keys << :cloudwatch
78
+ end
79
+ end
80
+ end
81
+
82
+ class CloudWatchConfig < OpenStruct
83
+
84
+ def initialize(attributes)
85
+ super
86
+ raise 'The input argument (attributes) must be a hash' if (!attributes || !attributes.is_a?(Hash))
87
+
88
+ attributes = attributes.each_with_object({}) do |(k, v), h|
89
+ raise "The input [#{k}] is invalid" unless valid_keys.include?(k.to_sym)
90
+ h[k.to_sym] = v
91
+ end
92
+
93
+ end
94
+
95
+ def valid_keys
96
+ [].tap do |keys|
97
+ keys << :accessKeyId
98
+ keys << :secretAccessKey
99
+ keys << :region
100
+ keys << :logGroup
101
+ end
102
+ end
103
+ end
104
+
105
+ class KafkaConfig < OpenStruct
106
+ attr_accessor :brokers
107
+ attr_accessor :topics
108
+
109
+ def initialize(attributes)
110
+ super
111
+ raise 'The input argument (attributes) must be a hash' if (!attributes || !attributes.is_a?(Hash))
112
+
113
+ attributes = attributes.each_with_object({}) do |(k, v), h|
114
+ raise "The input [#{k}] is invalid" unless valid_keys.include?(k.to_sym)
115
+ h[k.to_sym] = v
116
+ end
117
+
118
+ @brokers = []
119
+ attributes.fetch(:brokers, []).each do |attr|
120
+ @brokers << BrokerConfig.new(attr)
121
+ end
122
+ @topics = []
123
+ attributes.fetch(:topics, []).each do |attr|
124
+ @topics << TopicConfig.new(attr)
125
+ end
126
+ end
127
+
128
+ def valid_keys
129
+ [].tap do |keys|
130
+ keys << :brokers
131
+ keys << :topics
132
+ end
133
+ end
134
+ end
135
+
136
+ class BrokerConfig < OpenStruct
137
+
138
+ def initialize(attributes)
139
+ super
140
+ raise 'The input argument (attributes) must be a hash' if (!attributes || !attributes.is_a?(Hash))
141
+
142
+ attributes = attributes.each_with_object({}) do |(k, v), h|
143
+ raise "The input [#{k}] is invalid" unless valid_keys.include?(k.to_sym)
144
+ h[k.to_sym] = v
145
+ end
146
+
147
+ end
148
+
149
+ def valid_keys
150
+ [].tap do |keys|
151
+ keys << :hostname
152
+ keys << :port
153
+ end
154
+ end
155
+ end
156
+
157
+ class TopicConfig < OpenStruct
158
+
159
+ def initialize(attributes)
160
+ super
161
+ raise 'The input argument (attributes) must be a hash' if (!attributes || !attributes.is_a?(Hash))
162
+
163
+ attributes = attributes.each_with_object({}) do |(k, v), h|
164
+ raise "The input [#{k}] is invalid" unless valid_keys.include?(k.to_sym)
165
+ h[k.to_sym] = v
166
+ end
167
+
168
+ end
169
+
170
+ def valid_keys
171
+ [].tap do |keys|
172
+ keys << :requestedName
173
+ keys << :name
174
+ keys << :consumerGroup
175
+ end
176
+ end
177
+ end
178
+
179
+ class DatabaseConfig < OpenStruct
180
+
181
+ def initialize(attributes)
182
+ super
183
+ raise 'The input argument (attributes) must be a hash' if (!attributes || !attributes.is_a?(Hash))
184
+
185
+ attributes = attributes.each_with_object({}) do |(k, v), h|
186
+ raise "The input [#{k}] is invalid" unless valid_keys.include?(k.to_sym)
187
+ h[k.to_sym] = v
188
+ end
189
+
190
+ end
191
+
192
+ def valid_keys
193
+ [].tap do |keys|
194
+ keys << :name
195
+ keys << :username
196
+ keys << :password
197
+ keys << :hostname
198
+ keys << :port
199
+ keys << :adminUsername
200
+ keys << :adminPassword
201
+ keys << :rdsCa
202
+ end
203
+ end
204
+ end
205
+
206
+ class ObjectStoreBucket < OpenStruct
207
+
208
+ def initialize(attributes)
209
+ super
210
+ raise 'The input argument (attributes) must be a hash' if (!attributes || !attributes.is_a?(Hash))
211
+
212
+ attributes = attributes.each_with_object({}) do |(k, v), h|
213
+ raise "The input [#{k}] is invalid" unless valid_keys.include?(k.to_sym)
214
+ h[k.to_sym] = v
215
+ end
216
+
217
+ end
218
+
219
+ def valid_keys
220
+ [].tap do |keys|
221
+ keys << :accessKey
222
+ keys << :secretKey
223
+ keys << :requestedName
224
+ keys << :name
225
+ end
226
+ end
227
+ end
228
+
229
+ class ObjectStoreConfig < OpenStruct
230
+ attr_accessor :buckets
231
+
232
+ def initialize(attributes)
233
+ super
234
+ raise 'The input argument (attributes) must be a hash' if (!attributes || !attributes.is_a?(Hash))
235
+
236
+ attributes = attributes.each_with_object({}) do |(k, v), h|
237
+ raise "The input [#{k}] is invalid" unless valid_keys.include?(k.to_sym)
238
+ h[k.to_sym] = v
239
+ end
240
+
241
+ @buckets = []
242
+ attributes.fetch(:buckets, []).each do |attr|
243
+ @buckets << ObjectStoreBucket.new(attr)
244
+ end
245
+ end
246
+
247
+ def valid_keys
248
+ [].tap do |keys|
249
+ keys << :buckets
250
+ keys << :accessKey
251
+ keys << :secretKey
252
+ keys << :hostname
253
+ keys << :port
254
+ keys << :tls
255
+ end
256
+ end
257
+ end
258
+
259
+ class FeatureFlagsConfig < OpenStruct
260
+
261
+ def initialize(attributes)
262
+ super
263
+ raise 'The input argument (attributes) must be a hash' if (!attributes || !attributes.is_a?(Hash))
264
+
265
+ attributes = attributes.each_with_object({}) do |(k, v), h|
266
+ raise "The input [#{k}] is invalid" unless valid_keys.include?(k.to_sym)
267
+ h[k.to_sym] = v
268
+ end
269
+
270
+ end
271
+
272
+ def valid_keys
273
+ [].tap do |keys|
274
+ keys << :hostname
275
+ keys << :port
276
+ end
277
+ end
278
+ end
279
+
280
+ class InMemoryDBConfig < OpenStruct
281
+
282
+ def initialize(attributes)
283
+ super
284
+ raise 'The input argument (attributes) must be a hash' if (!attributes || !attributes.is_a?(Hash))
285
+
286
+ attributes = attributes.each_with_object({}) do |(k, v), h|
287
+ raise "The input [#{k}] is invalid" unless valid_keys.include?(k.to_sym)
288
+ h[k.to_sym] = v
289
+ end
290
+
291
+ end
292
+
293
+ def valid_keys
294
+ [].tap do |keys|
295
+ keys << :hostname
296
+ keys << :port
297
+ keys << :username
298
+ keys << :password
299
+ end
300
+ end
301
+ end
302
+
303
+ class DependencyEndpoint < OpenStruct
304
+
305
+ def initialize(attributes)
306
+ super
307
+ raise 'The input argument (attributes) must be a hash' if (!attributes || !attributes.is_a?(Hash))
308
+
309
+ attributes = attributes.each_with_object({}) do |(k, v), h|
310
+ raise "The input [#{k}] is invalid" unless valid_keys.include?(k.to_sym)
311
+ h[k.to_sym] = v
312
+ end
313
+
314
+ end
315
+
316
+ def valid_keys
317
+ [].tap do |keys|
318
+ keys << :name
319
+ keys << :hostname
320
+ keys << :port
321
+ keys << :app
322
+ end
323
+ end
324
+ end
325
+
326
+ class PrivateDependencyEndpoint < OpenStruct
327
+
328
+ def initialize(attributes)
329
+ super
330
+ raise 'The input argument (attributes) must be a hash' if (!attributes || !attributes.is_a?(Hash))
331
+
332
+ attributes = attributes.each_with_object({}) do |(k, v), h|
333
+ raise "The input [#{k}] is invalid" unless valid_keys.include?(k.to_sym)
334
+ h[k.to_sym] = v
335
+ end
336
+
337
+ end
338
+
339
+ def valid_keys
340
+ [].tap do |keys|
341
+ keys << :name
342
+ keys << :hostname
343
+ keys << :port
344
+ keys << :app
345
+ end
346
+ end
347
+ end
348
+ end
@@ -0,0 +1,3 @@
1
+ module ClowderCommonRuby
2
+ VERSION = '0.2.1'.freeze
3
+ end
data/sync_config.sh ADDED
@@ -0,0 +1,4 @@
1
+ #!/bin/bash
2
+ cd bin/
3
+ wget https://raw.githubusercontent.com/RedHatInsights/clowder/master/controllers/cloud.redhat.com/config/schema.json -O schema.json
4
+ ./json_schema_ruby -o ../lib/clowder-common-ruby/types.rb schema.json
data/test.json ADDED
@@ -0,0 +1,86 @@
1
+ {
2
+ "webPort": 8000,
3
+ "metricsPort": 9000,
4
+ "metricsPath": "/metrics",
5
+ "logging": {
6
+ "type": "cloudwatch",
7
+ "cloudwatch": {
8
+ "accessKeyId": "ACCESS_KEY",
9
+ "secretAccessKey": "SECRET_ACCESS_KEY",
10
+ "region": "EU",
11
+ "logGroup": "base_app"
12
+ }
13
+ },
14
+ "kafka": {
15
+ "brokers": [
16
+ {
17
+ "hostname": "broker-host",
18
+ "port": 27015
19
+ }
20
+ ],
21
+ "topics": [
22
+ {
23
+ "requestedName": "originalName",
24
+ "name": "someTopic",
25
+ "consumerGroup": "someGroupName"
26
+ }
27
+ ]
28
+ },
29
+ "database": {
30
+ "name": "dBaseName",
31
+ "username": "username",
32
+ "password": "password",
33
+ "hostname": "hostname",
34
+ "port": 5432,
35
+ "adminUsername": "adminusername",
36
+ "adminPassword": "adminpassword",
37
+ "rdsCa": "ca"
38
+ },
39
+ "objectStore": {
40
+ "hostname": "endpoint",
41
+ "port" : 9292,
42
+ "accessKey": "Testing",
43
+ "secretKey": "Testing",
44
+ "tls": false,
45
+ "buckets": [
46
+ {
47
+ "accessKey": "accessKey1",
48
+ "secretKey": "secretKey1",
49
+ "requestedName": "reqname",
50
+ "name": "name"
51
+ }
52
+ ]
53
+ },
54
+ "featureFlags": {
55
+ "hostname": "ff-server.server.example.com",
56
+ "port": 4242
57
+ },
58
+ "endpoints": [
59
+ {
60
+ "name": "endpoint1",
61
+ "app": "app1",
62
+ "hostname": "endpoint1.svc",
63
+ "port": 8000
64
+ },
65
+ {
66
+ "name": "endpoint2",
67
+ "app": "app2",
68
+ "hostname": "endpoint2.svc",
69
+ "port": 8000
70
+ }
71
+ ],
72
+ "privateEndpoints": [
73
+ {
74
+ "name": "endpoint1",
75
+ "app": "app1",
76
+ "hostname": "endpoint1.svc",
77
+ "port": 10000
78
+ },
79
+ {
80
+ "name": "endpoint2",
81
+ "app": "app2",
82
+ "hostname": "endpoint2.svc",
83
+ "port": 10000
84
+ }
85
+ ]
86
+ }