bbk-utils 1.1.0.149110 → 1.1.0.181866
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -3
- data/lib/bbk/utils/env_helper.rb +28 -21
- data/sig/bbk/env_helper.rbs +3 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1a8c300322287bbbf395a5006d97201575d85569bee0977c0dff202ff57df2a
|
4
|
+
data.tar.gz: 546cdd733680ba4d991cf1ec2fd86029bc911983416e0b34d130a9a9ea2ac5e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93e8581c5c069019f59c42d6ba23319a3831e3a51e99ee64510a351663d9943546f786bab3b4728ea616a955d5ad2745c15a1102a40f0021cae82d2c3978eb4f
|
7
|
+
data.tar.gz: b1274cb1d916382beb6e016787e97606b454a72eff52207020a886f2b329129f3c4d76a7998b702b0f70e4014ef9a0d42b2433da7631b592f7d8d64997baa287
|
data/Gemfile.lock
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
bbk-utils (1.1.0.
|
4
|
+
bbk-utils (1.1.0.181866)
|
5
5
|
activesupport (>= 7.0)
|
6
6
|
russian
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activesupport (7.0.
|
11
|
+
activesupport (7.0.7.2)
|
12
12
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
13
|
i18n (>= 1.6, < 2)
|
14
14
|
minitest (>= 5.1)
|
@@ -48,7 +48,7 @@ GEM
|
|
48
48
|
kwalify (0.7.2)
|
49
49
|
launchy (2.5.0)
|
50
50
|
addressable (~> 2.7)
|
51
|
-
minitest (5.
|
51
|
+
minitest (5.19.0)
|
52
52
|
parallel (1.21.0)
|
53
53
|
parser (3.0.3.1)
|
54
54
|
ast (~> 2.4.1)
|
data/lib/bbk/utils/env_helper.rb
CHANGED
@@ -6,9 +6,11 @@ module BBK
|
|
6
6
|
module Utils
|
7
7
|
module EnvHelper
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
DEFAULT_DATABASE_PREFIX = 'DATABASE'
|
10
|
+
|
11
|
+
def self.prepare_database_envs(env, prefix: DEFAULT_DATABASE_PREFIX)
|
12
|
+
uri = build_uri_with_defaults(env, prefix: prefix)
|
13
|
+
apply_env_from_uri(env, uri, prefix: prefix)
|
12
14
|
env
|
13
15
|
end
|
14
16
|
|
@@ -30,38 +32,38 @@ module BBK
|
|
30
32
|
env
|
31
33
|
end
|
32
34
|
|
33
|
-
def self.build_uri_with_defaults(env)
|
34
|
-
::URI.parse(env['
|
35
|
-
uri.scheme = env.fetch('
|
36
|
-
uri.user = env.fetch('
|
37
|
-
uri.password = env.fetch('
|
38
|
-
uri.hostname = env.fetch('
|
39
|
-
uri.port = env.fetch('
|
35
|
+
def self.build_uri_with_defaults(env, prefix: DEFAULT_DATABASE_PREFIX)
|
36
|
+
::URI.parse(env[prefixed_key(prefix, 'URL')] || '').tap do |uri|
|
37
|
+
uri.scheme = env.fetch(prefixed_key(prefix, 'ADAPTER'), uri.scheme) || 'postgresql'
|
38
|
+
uri.user = env.fetch(prefixed_key(prefix, 'USER'), uri.user) || 'postgres'
|
39
|
+
uri.password = env.fetch(prefixed_key(prefix, 'PASS'), uri.password)
|
40
|
+
uri.hostname = env.fetch(prefixed_key(prefix, 'HOST'), uri.hostname) || 'db'
|
41
|
+
uri.port = env.fetch(prefixed_key(prefix, 'PORT'), uri.port) || 5432
|
40
42
|
|
41
|
-
name = env.fetch('
|
43
|
+
name = env.fetch(prefixed_key(prefix, 'NAME'), uri.path) || ''
|
42
44
|
name = "/#{name}" unless name.start_with?('/')
|
43
45
|
uri.path = name
|
44
46
|
|
45
47
|
if uri.query
|
46
48
|
params = URI.decode_www_form(uri.query).to_h
|
47
|
-
params['pool'] = env.fetch('
|
49
|
+
params['pool'] = env.fetch(prefixed_key(prefix, 'POOL'), params['pool'])
|
48
50
|
uri.query = URI.encode_www_form(params)
|
49
51
|
end
|
50
52
|
end
|
51
53
|
end
|
52
54
|
|
53
|
-
def self.apply_env_from_uri(env, uri)
|
54
|
-
env['
|
55
|
-
env['
|
56
|
-
env['
|
57
|
-
env['
|
58
|
-
env['
|
59
|
-
env['
|
60
|
-
env['
|
55
|
+
def self.apply_env_from_uri(env, uri, prefix: DEFAULT_DATABASE_PREFIX)
|
56
|
+
env[prefixed_key(prefix, 'URL')] = uri.to_s
|
57
|
+
env[prefixed_key(prefix, 'ADAPTER')] = uri.scheme
|
58
|
+
env[prefixed_key(prefix, 'USER')] = uri.user
|
59
|
+
env[prefixed_key(prefix, 'PASS')] = uri.password
|
60
|
+
env[prefixed_key(prefix, 'HOST')] = uri.hostname
|
61
|
+
env[prefixed_key(prefix, 'PORT')] = uri.port.to_s
|
62
|
+
env[prefixed_key(prefix, 'NAME')] = uri.path[1..-1]
|
61
63
|
|
62
64
|
if uri.query
|
63
65
|
params = URI.decode_www_form(uri.query).to_h
|
64
|
-
env['
|
66
|
+
env[prefixed_key(prefix, 'POOL')] = params['pool']
|
65
67
|
end
|
66
68
|
end
|
67
69
|
|
@@ -105,6 +107,11 @@ module BBK
|
|
105
107
|
env['MQ_VHOST'] = vhost
|
106
108
|
end
|
107
109
|
|
110
|
+
|
111
|
+
def self.prefixed_key(prefix, name)
|
112
|
+
[prefix, name].select(&:present?).join('_')
|
113
|
+
end
|
114
|
+
|
108
115
|
end
|
109
116
|
end
|
110
117
|
end
|
data/sig/bbk/env_helper.rbs
CHANGED
@@ -2,11 +2,11 @@ module BBK
|
|
2
2
|
module Utils
|
3
3
|
module EnvHelper
|
4
4
|
|
5
|
-
def self.prepare_database_envs: (Hash[String, untyped]|::_ENV env ) -> (Hash[String,untyped]|::_ENV)
|
5
|
+
def self.prepare_database_envs: (Hash[String, untyped]|::_ENV env, ?prefix: String) -> (Hash[String,untyped]|::_ENV)
|
6
6
|
def self.prepare_mq_envs: (Hash[String, untyped]|::_ENV env) -> (Hash[String, untyped]|::_ENV)
|
7
7
|
def self.prepare_jaeger_envs: (Hash[String, untyped]|::_ENV env) -> (Hash[String, untyped]|::_ENV)
|
8
|
-
def self.build_uri_with_defaults: (Hash[String, untyped]|::_ENV env) -> URI::Generic
|
9
|
-
def self.apply_env_from_uri: (Hash[String, untyped]|::_ENV env, URI::Generic uri) -> void
|
8
|
+
def self.build_uri_with_defaults: (Hash[String, untyped]|::_ENV env, ?prefix: String) -> URI::Generic
|
9
|
+
def self.apply_env_from_uri: (Hash[String, untyped]|::_ENV env, URI::Generic uri, ?prefix: String) -> void
|
10
10
|
def self.build_mq_uri_with_defaults: (Hash[String, untyped]|::_ENV env) -> Array[URI::Generic]
|
11
11
|
def self.apply_mq_env_from_uri: (Hash[String, untyped]|::_ENV env, Array[URI::Generic] uris) -> void
|
12
12
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bbk-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.0.
|
4
|
+
version: 1.1.0.181866
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samoilenko Yuri
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-08-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -257,7 +257,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
257
257
|
- !ruby/object:Gem::Version
|
258
258
|
version: '0'
|
259
259
|
requirements: []
|
260
|
-
rubygems_version: 3.2.
|
260
|
+
rubygems_version: 3.2.33
|
261
261
|
signing_key:
|
262
262
|
specification_version: 4
|
263
263
|
summary: Support classes for BBK stack
|