clowder-common-ruby 0.2.0 → 0.2.4
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/LICENSE.txt +202 -0
- data/README.md +63 -0
- data/Rakefile +8 -0
- data/bin/json_schema_ruby +32 -0
- data/bin/output +134 -0
- data/bin/ruby_class_converter.rb +103 -0
- data/bin/schema.json +477 -0
- data/lib/clowder-common-ruby/config.rb +87 -0
- data/lib/clowder-common-ruby/test.rb +11 -0
- data/lib/clowder-common-ruby/types.rb +426 -0
- data/lib/clowder-common-ruby/version.rb +3 -0
- data/lib/clowder-common-ruby.rb +6 -0
- data/sync_config.sh +4 -0
- data/test.json +88 -0
- metadata +19 -5
data/bin/schema.json
ADDED
@@ -0,0 +1,477 @@
|
|
1
|
+
{
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
3
|
+
"$ref": "#/definitions/AppConfig",
|
4
|
+
"$id": "https://cloud.redhat.com/schemas/clowder-appconfig",
|
5
|
+
"title": "AppConfig",
|
6
|
+
"definitions": {
|
7
|
+
"AppConfig": {
|
8
|
+
"type": "object",
|
9
|
+
"description": "ClowdApp deployment configuration for Clowder enabled apps.",
|
10
|
+
"properties": {
|
11
|
+
"privatePort": {
|
12
|
+
"description": "Defines the private port that the app should be configured to listen on for API traffic.",
|
13
|
+
"type": "integer"
|
14
|
+
},
|
15
|
+
"publicPort": {
|
16
|
+
"description": "Defines the public port that the app should be configured to listen on for API traffic.",
|
17
|
+
"type": "integer"
|
18
|
+
},
|
19
|
+
"webPort": {
|
20
|
+
"description": "Deprecated: Use 'publicPort' instead.",
|
21
|
+
"type": "integer"
|
22
|
+
},
|
23
|
+
"metricsPort": {
|
24
|
+
"description": "Defines the metrics port that the app should be configured to listen on for metric traffic.",
|
25
|
+
"type": "integer"
|
26
|
+
},
|
27
|
+
"metricsPath": {
|
28
|
+
"description": "Defines the path to the metrics server that the app should be configured to listen on for metric traffic.",
|
29
|
+
"type": "string"
|
30
|
+
},
|
31
|
+
"logging": {
|
32
|
+
"$ref": "#/definitions/LoggingConfig"
|
33
|
+
},
|
34
|
+
"metadata": {
|
35
|
+
"$ref": "#/definitions/AppMetadata"
|
36
|
+
},
|
37
|
+
"kafka": {
|
38
|
+
"$ref": "#/definitions/KafkaConfig"
|
39
|
+
},
|
40
|
+
"database": {
|
41
|
+
"$ref": "#/definitions/DatabaseConfig"
|
42
|
+
},
|
43
|
+
"objectStore": {
|
44
|
+
"$ref": "#/definitions/ObjectStoreConfig"
|
45
|
+
},
|
46
|
+
"inMemoryDb": {
|
47
|
+
"$ref": "#/definitions/InMemoryDBConfig"
|
48
|
+
},
|
49
|
+
"featureFlags": {
|
50
|
+
"$ref": "#/definitions/FeatureFlagsConfig"
|
51
|
+
},
|
52
|
+
"endpoints": {
|
53
|
+
"id": "endpoints",
|
54
|
+
"type": "array",
|
55
|
+
"items": {
|
56
|
+
"$ref": "#/definitions/DependencyEndpoint"
|
57
|
+
}
|
58
|
+
},
|
59
|
+
"privateEndpoints": {
|
60
|
+
"id": "privateEndpoints",
|
61
|
+
"type": "array",
|
62
|
+
"items": {
|
63
|
+
"$ref": "#/definitions/PrivateDependencyEndpoint"
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
67
|
+
},
|
68
|
+
"required": [
|
69
|
+
"metricsPort",
|
70
|
+
"metricsPath",
|
71
|
+
"logging"
|
72
|
+
]
|
73
|
+
},
|
74
|
+
"LoggingConfig": {
|
75
|
+
"title": "LoggingConfig",
|
76
|
+
"type": "object",
|
77
|
+
"description": "Logging Configuration",
|
78
|
+
"properties": {
|
79
|
+
"type": {
|
80
|
+
"description": "Defines the type of logging configuration",
|
81
|
+
"type": "string"
|
82
|
+
},
|
83
|
+
"cloudwatch": {
|
84
|
+
"$ref": "#/definitions/CloudWatchConfig"
|
85
|
+
}
|
86
|
+
},
|
87
|
+
"required": [
|
88
|
+
"type"
|
89
|
+
]
|
90
|
+
},
|
91
|
+
"AppMetadata": {
|
92
|
+
"title": "AppMetadata",
|
93
|
+
"type": "object",
|
94
|
+
"description": "Arbitrary metadata pertaining to the application application",
|
95
|
+
"properties": {
|
96
|
+
"deployments": {
|
97
|
+
"description": "Metadata pertaining to an application's deployments",
|
98
|
+
"type": "array",
|
99
|
+
"items": {
|
100
|
+
"$ref": "#/definitions/DeploymentMetadata"
|
101
|
+
}
|
102
|
+
}
|
103
|
+
},
|
104
|
+
"required": []
|
105
|
+
},
|
106
|
+
"DeploymentMetadata": {
|
107
|
+
"title": "DeploymentMetadata",
|
108
|
+
"type": "object",
|
109
|
+
"description": "Deployment Metadata",
|
110
|
+
"properties": {
|
111
|
+
"name": {
|
112
|
+
"description": "Name of deployment",
|
113
|
+
"type": "string"
|
114
|
+
},
|
115
|
+
"image": {
|
116
|
+
"description": "Image used by deployment",
|
117
|
+
"type": "string"
|
118
|
+
}
|
119
|
+
},
|
120
|
+
"required": [
|
121
|
+
"name",
|
122
|
+
"image"
|
123
|
+
]
|
124
|
+
},
|
125
|
+
"CloudWatchConfig": {
|
126
|
+
"title": "CloudWatchConfig",
|
127
|
+
"type": "object",
|
128
|
+
"description": "Cloud Watch configuration",
|
129
|
+
"properties": {
|
130
|
+
"accessKeyId": {
|
131
|
+
"description": "Defines the access key that the app should use for configuring CloudWatch.",
|
132
|
+
"type": "string"
|
133
|
+
},
|
134
|
+
"secretAccessKey": {
|
135
|
+
"description": "Defines the secret key that the app should use for configuring CloudWatch.",
|
136
|
+
"type": "string"
|
137
|
+
},
|
138
|
+
"region": {
|
139
|
+
"description": "Defines the region that the app should use for configuring CloudWatch.",
|
140
|
+
"type": "string"
|
141
|
+
},
|
142
|
+
"logGroup": {
|
143
|
+
"description": "Defines the logGroup that the app should use for configuring CloudWatch.",
|
144
|
+
"type": "string"
|
145
|
+
}
|
146
|
+
},
|
147
|
+
"required": [
|
148
|
+
"accessKeyId",
|
149
|
+
"secretAccessKey",
|
150
|
+
"region",
|
151
|
+
"logGroup"
|
152
|
+
]
|
153
|
+
},
|
154
|
+
"KafkaConfig": {
|
155
|
+
"id": "kafkaConfig",
|
156
|
+
"type": "object",
|
157
|
+
"description": "Kafka Configuration",
|
158
|
+
"properties": {
|
159
|
+
"brokers": {
|
160
|
+
"description": "Defines the brokers the app should connect to for Kafka services.",
|
161
|
+
"type": "array",
|
162
|
+
"items": {
|
163
|
+
"$ref": "#/definitions/BrokerConfig"
|
164
|
+
}
|
165
|
+
},
|
166
|
+
"topics": {
|
167
|
+
"type": "array",
|
168
|
+
"description": "Defines a list of the topic configurations available to the application.",
|
169
|
+
"items": {
|
170
|
+
"$ref": "#/definitions/TopicConfig"
|
171
|
+
}
|
172
|
+
}
|
173
|
+
},
|
174
|
+
"required": [
|
175
|
+
"brokers",
|
176
|
+
"topics"
|
177
|
+
]
|
178
|
+
},
|
179
|
+
"KafkaSASLConfig":{
|
180
|
+
"id": "kafkaSASLConfig",
|
181
|
+
"type": "object",
|
182
|
+
"description": "SASL Configuration for Kafka",
|
183
|
+
"properties": {
|
184
|
+
"username": {
|
185
|
+
"type": "string"
|
186
|
+
},
|
187
|
+
"password": {
|
188
|
+
"type": "string"
|
189
|
+
}
|
190
|
+
},
|
191
|
+
"required": []
|
192
|
+
},
|
193
|
+
"BrokerConfig": {
|
194
|
+
"id": "brokerConfig",
|
195
|
+
"type": "object",
|
196
|
+
"description": "Broker Configuration",
|
197
|
+
"properties": {
|
198
|
+
"hostname": {
|
199
|
+
"type": "string"
|
200
|
+
},
|
201
|
+
"port": {
|
202
|
+
"type": "integer"
|
203
|
+
},
|
204
|
+
"cacert": {
|
205
|
+
"type": "string"
|
206
|
+
},
|
207
|
+
"authtype": {
|
208
|
+
"type": "string",
|
209
|
+
"enum": ["mtls", "sasl"]
|
210
|
+
},
|
211
|
+
"sasl": {
|
212
|
+
"$ref": "#/definitions/KafkaSASLConfig"
|
213
|
+
}
|
214
|
+
},
|
215
|
+
"required": [
|
216
|
+
"hostname"
|
217
|
+
]
|
218
|
+
},
|
219
|
+
"TopicConfig": {
|
220
|
+
"id": "topicConfig",
|
221
|
+
"type": "object",
|
222
|
+
"description": "Topic Configuration",
|
223
|
+
"properties": {
|
224
|
+
"requestedName": {
|
225
|
+
"description": "The name that the app requested in the ClowdApp definition.",
|
226
|
+
"type": "string"
|
227
|
+
},
|
228
|
+
"name": {
|
229
|
+
"description": "The name of the actual topic on the Kafka server.",
|
230
|
+
"type": "string"
|
231
|
+
}
|
232
|
+
},
|
233
|
+
"required": [
|
234
|
+
"name",
|
235
|
+
"requestedName"
|
236
|
+
]
|
237
|
+
},
|
238
|
+
"DatabaseConfig": {
|
239
|
+
"id": "database",
|
240
|
+
"title": "DatabaseConfig",
|
241
|
+
"type": "object",
|
242
|
+
"description": "Database Configuration",
|
243
|
+
"properties": {
|
244
|
+
"name": {
|
245
|
+
"description": "Defines the database name.",
|
246
|
+
"type": "string"
|
247
|
+
},
|
248
|
+
"username": {
|
249
|
+
"description": "Defines a username with standard access to the database.",
|
250
|
+
"type": "string"
|
251
|
+
},
|
252
|
+
"password": {
|
253
|
+
"description": "Defines the password for the standard user.",
|
254
|
+
"type": "string"
|
255
|
+
},
|
256
|
+
"hostname": {
|
257
|
+
"description": "Defines the hostname of the database configured for the ClowdApp.",
|
258
|
+
"type": "string"
|
259
|
+
},
|
260
|
+
"port": {
|
261
|
+
"description": "Defines the port of the database configured for the ClowdApp.",
|
262
|
+
"type": "integer"
|
263
|
+
},
|
264
|
+
"adminUsername": {
|
265
|
+
"description": "Defines the pgAdmin username.",
|
266
|
+
"type": "string"
|
267
|
+
},
|
268
|
+
"adminPassword": {
|
269
|
+
"description": "Defines the pgAdmin password.",
|
270
|
+
"type": "string"
|
271
|
+
},
|
272
|
+
"rdsCa": {
|
273
|
+
"description": "Defines the CA used to access the database.",
|
274
|
+
"type": "string"
|
275
|
+
},
|
276
|
+
"sslMode": {
|
277
|
+
"description": "Defines the postgres SSL mode that should be used.",
|
278
|
+
"type": "string"
|
279
|
+
}
|
280
|
+
},
|
281
|
+
"required": [
|
282
|
+
"name",
|
283
|
+
"username",
|
284
|
+
"password",
|
285
|
+
"hostname",
|
286
|
+
"port",
|
287
|
+
"adminUsername",
|
288
|
+
"adminPassword",
|
289
|
+
"sslMode"
|
290
|
+
]
|
291
|
+
},
|
292
|
+
"ObjectStoreBucket": {
|
293
|
+
"id": "objectStoreBucket",
|
294
|
+
"type": "object",
|
295
|
+
"description": "Object Storage Bucket",
|
296
|
+
"properties": {
|
297
|
+
"accessKey": {
|
298
|
+
"description": "Defines the access key for specificed bucket.",
|
299
|
+
"type": "string"
|
300
|
+
},
|
301
|
+
"secretKey": {
|
302
|
+
"description": "Defines the secret key for the specified bucket.",
|
303
|
+
"type": "string"
|
304
|
+
},
|
305
|
+
"region": {
|
306
|
+
"description": "Defines the region for the specified bucket.",
|
307
|
+
"type": "string"
|
308
|
+
},
|
309
|
+
"requestedName": {
|
310
|
+
"description": "The name that was requested for the bucket in the ClowdApp.",
|
311
|
+
"type": "string"
|
312
|
+
},
|
313
|
+
"name": {
|
314
|
+
"description": "The actual name of the bucket being accessed.",
|
315
|
+
"type": "string"
|
316
|
+
}
|
317
|
+
},
|
318
|
+
"required": [
|
319
|
+
"name",
|
320
|
+
"requestedName"
|
321
|
+
]
|
322
|
+
},
|
323
|
+
"ObjectStoreConfig": {
|
324
|
+
"id": "objectStoreConfig",
|
325
|
+
"type": "object",
|
326
|
+
"description": "Object Storage Configuration",
|
327
|
+
"properties": {
|
328
|
+
"buckets": {
|
329
|
+
"type": "array",
|
330
|
+
"items": {
|
331
|
+
"$ref": "#/definitions/ObjectStoreBucket"
|
332
|
+
}
|
333
|
+
},
|
334
|
+
"accessKey": {
|
335
|
+
"description": "Defines the access key for the Object Storage server configuration.",
|
336
|
+
"type": "string"
|
337
|
+
},
|
338
|
+
"secretKey": {
|
339
|
+
"description": "Defines the secret key for the Object Storage server configuration.",
|
340
|
+
"type": "string"
|
341
|
+
},
|
342
|
+
"hostname": {
|
343
|
+
"description": "Defines the hostname for the Object Storage server configuration.",
|
344
|
+
"type": "string"
|
345
|
+
},
|
346
|
+
"port": {
|
347
|
+
"description": "Defines the port for the Object Storage server configuration.",
|
348
|
+
"type": "integer"
|
349
|
+
},
|
350
|
+
"tls": {
|
351
|
+
"description": "Details if the Object Server uses TLS.",
|
352
|
+
"type": "boolean"
|
353
|
+
}
|
354
|
+
},
|
355
|
+
"required": [
|
356
|
+
"hostname",
|
357
|
+
"port",
|
358
|
+
"tls"
|
359
|
+
]
|
360
|
+
},
|
361
|
+
"FeatureFlagsConfig": {
|
362
|
+
"id": "featureFlagsConfig",
|
363
|
+
"type": "object",
|
364
|
+
"description": "Feature Flags Configuration",
|
365
|
+
"properties": {
|
366
|
+
"hostname": {
|
367
|
+
"description": "Defines the hostname for the FeatureFlags server",
|
368
|
+
"type": "string"
|
369
|
+
},
|
370
|
+
"port": {
|
371
|
+
"description": "Defines the port for the FeatureFlags server",
|
372
|
+
"type": "integer"
|
373
|
+
},
|
374
|
+
"clientAccessToken": {
|
375
|
+
"description": "Defines the client access token to use when connect to the FeatureFlags server",
|
376
|
+
"type": "string"
|
377
|
+
},
|
378
|
+
"scheme": {
|
379
|
+
"description": "Details the scheme to use for FeatureFlags http/https",
|
380
|
+
"type": "string",
|
381
|
+
"enum": ["http", "https"]
|
382
|
+
}
|
383
|
+
},
|
384
|
+
"required":[
|
385
|
+
"hostname",
|
386
|
+
"port",
|
387
|
+
"scheme"
|
388
|
+
]
|
389
|
+
},
|
390
|
+
"InMemoryDBConfig": {
|
391
|
+
"id": "inMemoryDbConfig",
|
392
|
+
"type": "object",
|
393
|
+
"description": "In Memory DB Configuration",
|
394
|
+
"properties": {
|
395
|
+
"hostname": {
|
396
|
+
"description": "Defines the hostname for the In Memory DB server configuration.",
|
397
|
+
"type": "string"
|
398
|
+
},
|
399
|
+
"port": {
|
400
|
+
"description": "Defines the port for the In Memory DB server configuration.",
|
401
|
+
"type": "integer"
|
402
|
+
},
|
403
|
+
"username": {
|
404
|
+
"description": "Defines the username for the In Memory DB server configuration.",
|
405
|
+
"type": "string"
|
406
|
+
},
|
407
|
+
"password": {
|
408
|
+
"description": "Defines the password for the In Memory DB server configuration.",
|
409
|
+
"type": "string"
|
410
|
+
}
|
411
|
+
},
|
412
|
+
"required": [
|
413
|
+
"hostname",
|
414
|
+
"port"
|
415
|
+
|
416
|
+
]
|
417
|
+
},
|
418
|
+
"DependencyEndpoint": {
|
419
|
+
"id": "dependency",
|
420
|
+
"type": "object",
|
421
|
+
"description": "Dependent service connection info",
|
422
|
+
"properties": {
|
423
|
+
"name": {
|
424
|
+
"description": "The PodSpec name of the dependent service inside the ClowdApp.",
|
425
|
+
"type": "string"
|
426
|
+
},
|
427
|
+
"hostname": {
|
428
|
+
"description": "The hostname of the dependent service.",
|
429
|
+
"type": "string"
|
430
|
+
},
|
431
|
+
"port": {
|
432
|
+
"description": "The port of the dependent service.",
|
433
|
+
"type": "integer"
|
434
|
+
},
|
435
|
+
"app": {
|
436
|
+
"description": "The app name of the ClowdApp hosting the service.",
|
437
|
+
"type": "string"
|
438
|
+
}
|
439
|
+
},
|
440
|
+
"required": [
|
441
|
+
"name",
|
442
|
+
"hostname",
|
443
|
+
"port",
|
444
|
+
"app"
|
445
|
+
]
|
446
|
+
},
|
447
|
+
"PrivateDependencyEndpoint": {
|
448
|
+
"id": "privateDependency",
|
449
|
+
"type": "object",
|
450
|
+
"description": "Dependent service connection info",
|
451
|
+
"properties": {
|
452
|
+
"name": {
|
453
|
+
"description": "The PodSpec name of the dependent service inside the ClowdApp.",
|
454
|
+
"type": "string"
|
455
|
+
},
|
456
|
+
"hostname": {
|
457
|
+
"description": "The hostname of the dependent service.",
|
458
|
+
"type": "string"
|
459
|
+
},
|
460
|
+
"port": {
|
461
|
+
"description": "The port of the dependent service.",
|
462
|
+
"type": "integer"
|
463
|
+
},
|
464
|
+
"app": {
|
465
|
+
"description": "The app name of the ClowdApp hosting the service.",
|
466
|
+
"type": "string"
|
467
|
+
}
|
468
|
+
},
|
469
|
+
"required": [
|
470
|
+
"name",
|
471
|
+
"hostname",
|
472
|
+
"port",
|
473
|
+
"app"
|
474
|
+
]
|
475
|
+
}
|
476
|
+
}
|
477
|
+
}
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
require 'json'
|
3
|
+
require_relative 'types'
|
4
|
+
|
5
|
+
module ClowderCommonRuby
|
6
|
+
class Config < AppConfig
|
7
|
+
# Check if clowder config's ENV var is defined
|
8
|
+
# If true, svc is deployed by Clowder
|
9
|
+
def self.clowder_enabled?
|
10
|
+
!ENV['ACG_CONFIG'].nil? && ENV['ACG_CONFIG'] != ""
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.load(acg_config = ENV['ACG_CONFIG'] || 'test.json')
|
14
|
+
unless File.exist?(acg_config)
|
15
|
+
raise "ERROR: #{acg_config} does not exist"
|
16
|
+
end
|
17
|
+
|
18
|
+
new(acg_config)
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize(acg_config)
|
22
|
+
super(JSON.parse(File.read(acg_config)))
|
23
|
+
kafka_servers
|
24
|
+
kafka_topics
|
25
|
+
object_buckets
|
26
|
+
dependency_endpoints
|
27
|
+
private_dependency_endpoints
|
28
|
+
end
|
29
|
+
|
30
|
+
# List of Kafka Broker URLs.
|
31
|
+
def kafka_servers
|
32
|
+
@kafka_servers ||= [].tap do |servers|
|
33
|
+
kafka.brokers.each do |broker|
|
34
|
+
servers << "{#{broker.hostname}}:{#{broker.port}}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Map of KafkaTopics using the requestedName as the key and the topic object as the value.
|
40
|
+
def kafka_topics
|
41
|
+
@kafka_topics ||= {}.tap do |topics|
|
42
|
+
kafka.topics.each do |topic|
|
43
|
+
next if topic.requestedName.nil?
|
44
|
+
|
45
|
+
topics[topic.requestedName] = topic
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# List of ObjectBuckets using the requestedName
|
51
|
+
def object_buckets
|
52
|
+
@object_buckets ||= {}.tap do |buckets|
|
53
|
+
objectStore.buckets.each do |bucket|
|
54
|
+
next if bucket.requestedName.nil?
|
55
|
+
|
56
|
+
buckets[bucket.requestedName] = bucket
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# Nested map using [appName][deploymentName]
|
62
|
+
# for the public services of requested applications.
|
63
|
+
def dependency_endpoints
|
64
|
+
@dependency_endpoints ||= {}.tap do |endpts|
|
65
|
+
endpoints.each do |endpoint|
|
66
|
+
next if endpoint.app.nil? || endpoint.name.nil?
|
67
|
+
|
68
|
+
endpts[endpoint.app] = {} unless endpts.include?(endpoint.app)
|
69
|
+
endpts[endpoint.app][endpoint.name] = endpoint
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# nested map using [appName][deploymentName]
|
75
|
+
# for the private services of requested applications.
|
76
|
+
def private_dependency_endpoints
|
77
|
+
@private_dependency_endpoints ||= {}.tap do |priv_endpts|
|
78
|
+
privateEndpoints.each do |endpoint|
|
79
|
+
next if endpoint.app.nil? || endpoint.name.nil?
|
80
|
+
|
81
|
+
priv_endpts[endpoint.app] = {} unless priv_endpts.include?(endpoint.app)
|
82
|
+
priv_endpts[endpoint.app][endpoint.name] = endpoint
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|