clowder-common-ruby 0.2.6 → 0.3.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 +4 -4
- data/README.md +4 -0
- data/bin/bump_version +9 -0
- data/bin/schema.json +1 -1
- data/lib/clowder-common-ruby/engine.rb +7 -0
- data/lib/clowder-common-ruby/rails_config.rb +176 -0
- data/lib/clowder-common-ruby/version.rb +1 -1
- metadata +10 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5a31730c5274d307ff7d9ef22f75d2e70a6c5ca44fb66d26f8b7eee4affdd7f
|
4
|
+
data.tar.gz: a70f87a031e547234e2f4d4049702147624127b6ff8e4824e320b1dea69dd7b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a50970cfbc1d9dc96547f358c598043db05a71be2420e1a4094f7b437b0af49666a7480aac53566df579230859158b567ba6e7a98b007bb5aa8ae28e2d86a5ae
|
7
|
+
data.tar.gz: 8583447351853c20a44d0d8eacc0a31e6f93c1a2db24f83caa2b24f0caf6da68ced490aedce016aa0256d544f29351e890933f66ff811d92a9bbca3b643c4319
|
data/README.md
CHANGED
@@ -47,6 +47,10 @@ The ``clowder`` library also comes with several other helpers
|
|
47
47
|
|
48
48
|
See [test.json](test.json) for all available values
|
49
49
|
|
50
|
+
### Usage in Rails
|
51
|
+
|
52
|
+
In Rails applications, requiring the ```clowder-common-ruby/engine``` will run the initializer, the output of which will be accessible under ```Settings```.
|
53
|
+
|
50
54
|
### Kafka Topics
|
51
55
|
|
52
56
|
Topics are structured as a hash `<requested_name> => <name>`
|
data/bin/bump_version
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
text = File.read('../lib/clowder-common-ruby/version.rb')
|
4
|
+
|
5
|
+
patch = text.sub(/^.*'\d+\.\d+\.(\d+)'.*$/m, '\1').to_i
|
6
|
+
|
7
|
+
File.open('../lib/clowder-common-ruby/version.rb', 'w') do |f|
|
8
|
+
f.write text.sub(/^(.*'\d+\.\d+\.)\d+('.*)$/m, "\\1#{patch + 1}\\2")
|
9
|
+
end
|
data/bin/schema.json
CHANGED
@@ -0,0 +1,176 @@
|
|
1
|
+
require 'clowder-common-ruby'
|
2
|
+
|
3
|
+
module ClowderCommonRuby
|
4
|
+
class RailsConfig
|
5
|
+
class << self
|
6
|
+
# Rails configuration hash
|
7
|
+
def to_h
|
8
|
+
config = ClowderCommonRuby::Config.load
|
9
|
+
|
10
|
+
{
|
11
|
+
kafka: configure_kafka(config),
|
12
|
+
logging: configure_cloudwatch(config),
|
13
|
+
redis: configure_redis(config),
|
14
|
+
endpoints: configure_endpoints(config, :dependency_endpoints),
|
15
|
+
private_endpoints: configure_endpoints(config, :private_dependency_endpoints),
|
16
|
+
database: configure_database(config),
|
17
|
+
prometheus_exporter_port: config&.metricsPort,
|
18
|
+
tls_ca_path: config.tlsCAPath,
|
19
|
+
web_port: config.webPort
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
# Short path for db config
|
24
|
+
def db_config
|
25
|
+
config = ClowderCommonRuby::Config.load
|
26
|
+
|
27
|
+
configure_database(config)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
# Kafka configuration hash
|
33
|
+
def configure_kafka(config)
|
34
|
+
# In case there are no kafka brokers, an empty string is ensured in place of ':'
|
35
|
+
build_kafka_security(config).merge(
|
36
|
+
brokers: build_kafka_brokers(config) || '',
|
37
|
+
topics: build_kafka_topics(config)
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Kafka security settings hash
|
42
|
+
def build_kafka_security(config)
|
43
|
+
server_config = config.kafka.brokers[0]
|
44
|
+
authtype = server_config&.dig('authtype')
|
45
|
+
cacert = server_config&.dig('cacert')
|
46
|
+
|
47
|
+
return { security_protocol: 'plaintext' } unless authtype
|
48
|
+
|
49
|
+
unless authtype == 'sasl'
|
50
|
+
raise "Unsupported Kafka security protocol '#{authtype}'"
|
51
|
+
end
|
52
|
+
|
53
|
+
{
|
54
|
+
sasl_username: server_config&.dig('sasl', 'username'),
|
55
|
+
sasl_password: server_config&.dig('sasl', 'password'),
|
56
|
+
sasl_mechanism: server_config&.dig('sasl', 'saslMechanism'),
|
57
|
+
security_protocol: server_config&.dig('sasl', 'securityProtocol'),
|
58
|
+
ssl_ca_location: build_kafka_certificate(cacert)
|
59
|
+
}.compact
|
60
|
+
# In case build_kafka_certificate returns nil, ssl_ca_location is removed from the hash with compact
|
61
|
+
end
|
62
|
+
|
63
|
+
# Gives location of ssl certificate and makes sure it exists
|
64
|
+
def build_kafka_certificate(cacert)
|
65
|
+
return unless cacert.present?
|
66
|
+
|
67
|
+
kafka_config[:ssl_ca_location] = Rails.root.join('tmp', 'kafka_ca.crt')
|
68
|
+
|
69
|
+
write_temporary_file(kafka_config[:ssl_ca_location], cacert)
|
70
|
+
|
71
|
+
kafka_config[:ssl_ca_location]
|
72
|
+
end
|
73
|
+
|
74
|
+
# Kafka brokers list
|
75
|
+
def build_kafka_brokers(config)
|
76
|
+
config.kafka.brokers&.map do |broker|
|
77
|
+
"#{broker.hostname}:#{broker.port}"
|
78
|
+
end&.join(',')
|
79
|
+
end
|
80
|
+
|
81
|
+
# Kafka topics hash
|
82
|
+
def build_kafka_topics(config)
|
83
|
+
config.kafka.topics&.each_with_object({}) do |topic, obj|
|
84
|
+
k = "#{topic.name.sub(/^platform./, '')}".parameterize.underscore.to_sym
|
85
|
+
obj[k] = topic.name
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# Redis configuration hash
|
90
|
+
def configure_redis(config)
|
91
|
+
inMemoryDb = config&.dig('inMemoryDb')
|
92
|
+
redis_url = "redis://#{inMemoryDb.dig('hostname')}:#{inMemoryDb.dig('port')}"
|
93
|
+
|
94
|
+
{
|
95
|
+
url: redis_url,
|
96
|
+
password: inMemoryDb.dig('password')
|
97
|
+
}
|
98
|
+
end
|
99
|
+
|
100
|
+
# Cloudwatch configuration hash
|
101
|
+
def configure_cloudwatch(config)
|
102
|
+
cloudwatch = config.logging&.cloudwatch
|
103
|
+
|
104
|
+
{
|
105
|
+
region: cloudwatch&.region,
|
106
|
+
log_group: cloudwatch&.logGroup,
|
107
|
+
log_stream: Socket.gethostname,
|
108
|
+
type: config.logging&.type,
|
109
|
+
credentials: {
|
110
|
+
access_key_id: cloudwatch&.accessKeyId,
|
111
|
+
secret_access_key: cloudwatch&.secretAccessKey
|
112
|
+
}
|
113
|
+
}
|
114
|
+
end
|
115
|
+
|
116
|
+
# All endpoints' configuration hash
|
117
|
+
def configure_endpoints(config, field)
|
118
|
+
config.try(field)&.each_with_object({}) do |(name, endpoint), obj|
|
119
|
+
service = endpoint.dig('service')
|
120
|
+
|
121
|
+
next unless service
|
122
|
+
|
123
|
+
key = name.underscore.to_sym
|
124
|
+
obj[key] = build_endpoint(config, service)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
# Endpoint configuration hash
|
129
|
+
def build_endpoint(config, endpoint)
|
130
|
+
scheme = config.tlsCAPath ? 'https' : 'http'
|
131
|
+
port = config.tlsCAPath ? endpoint.tlsPort : endpoint.port
|
132
|
+
host = "#{endpoint.hostname}:#{port}"
|
133
|
+
|
134
|
+
{
|
135
|
+
scheme: scheme,
|
136
|
+
host: host,
|
137
|
+
url: "#{scheme}://#{host}"
|
138
|
+
}
|
139
|
+
end
|
140
|
+
|
141
|
+
# Database configuration hash
|
142
|
+
def configure_database(config)
|
143
|
+
{
|
144
|
+
database: config.database.name,
|
145
|
+
username: config.database.username,
|
146
|
+
password: config.database.password,
|
147
|
+
host: config.database.hostname,
|
148
|
+
port: config.database.port,
|
149
|
+
admin_username: config.database.adminUsername,
|
150
|
+
admin_password: config.database.adminPassword,
|
151
|
+
rds_ca: config.database.rdsCa,
|
152
|
+
ssl_mode: config.database.sslMode,
|
153
|
+
ssl_root_cert: build_database_certificate(config.database.rdsCa)
|
154
|
+
}
|
155
|
+
end
|
156
|
+
|
157
|
+
# Gives location of database ssl certificate and makes sure it exists
|
158
|
+
def build_database_certificate(rdsca)
|
159
|
+
return unless rdsca.present?
|
160
|
+
|
161
|
+
db_config = Rails.root.join('tmp', 'rdsCa')
|
162
|
+
|
163
|
+
write_temporary_file(db_config, rdsca)
|
164
|
+
|
165
|
+
db_config
|
166
|
+
end
|
167
|
+
|
168
|
+
# Creates and writes file if it doesn't exist
|
169
|
+
def write_temporary_file(path, content)
|
170
|
+
File.open(path, 'w') do |f|
|
171
|
+
f.write(content)
|
172
|
+
end unless File.exist?(path)
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clowder-common-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Red Hat Developers
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-06-
|
11
|
+
date: 2023-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: This is a ruby interface for preparing Clowder variables.
|
14
|
-
email:
|
14
|
+
email:
|
15
15
|
executables: []
|
16
16
|
extensions: []
|
17
17
|
extra_rdoc_files: []
|
@@ -19,11 +19,14 @@ files:
|
|
19
19
|
- LICENSE.txt
|
20
20
|
- README.md
|
21
21
|
- Rakefile
|
22
|
+
- bin/bump_version
|
22
23
|
- bin/json_schema_ruby
|
23
24
|
- bin/ruby_class_converter.rb
|
24
25
|
- bin/schema.json
|
25
26
|
- lib/clowder-common-ruby.rb
|
26
27
|
- lib/clowder-common-ruby/config.rb
|
28
|
+
- lib/clowder-common-ruby/engine.rb
|
29
|
+
- lib/clowder-common-ruby/rails_config.rb
|
27
30
|
- lib/clowder-common-ruby/test.rb
|
28
31
|
- lib/clowder-common-ruby/types.rb
|
29
32
|
- lib/clowder-common-ruby/version.rb
|
@@ -33,7 +36,7 @@ homepage: https://github.com/RedHatInsights/clowder-common-ruby
|
|
33
36
|
licenses:
|
34
37
|
- Apache-2.0
|
35
38
|
metadata: {}
|
36
|
-
post_install_message:
|
39
|
+
post_install_message:
|
37
40
|
rdoc_options: []
|
38
41
|
require_paths:
|
39
42
|
- lib
|
@@ -48,8 +51,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
48
51
|
- !ruby/object:Gem::Version
|
49
52
|
version: '0'
|
50
53
|
requirements: []
|
51
|
-
rubygems_version: 3.3.
|
52
|
-
signing_key:
|
54
|
+
rubygems_version: 3.3.5
|
55
|
+
signing_key:
|
53
56
|
specification_version: 4
|
54
57
|
summary: Supporting files and libraries for Clowder environmental variables.
|
55
58
|
test_files: []
|