redis_env_config 0.2.0 → 0.2.1

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
  SHA256:
3
- metadata.gz: 24f11f185c93707cdb41a37a66dba88d5dda19586b39a3d680a1857b41c15766
4
- data.tar.gz: 980bd45813949c7169bfbd519faa6b0b8fd6a60460eb00ec207b81d988b0b55e
3
+ metadata.gz: 9a7711d7e6e5264858d741615d79a27e8467537a386dfad533e0a0974516f21c
4
+ data.tar.gz: 4c930d355310b7a345ac822d0c5a933d94a71133718824771d952512d8b0798a
5
5
  SHA512:
6
- metadata.gz: 0d994d6ab30ad5c41cb51ff30c234fde0634de2465276378b6875d515aa946cabc89f85a4404bfa9b3a6e368b48a9c30c3a83a112b80959ca75016bff135215d
7
- data.tar.gz: 294331e8c3d8680c4f9fc1b27d2be078d374e4227a3b5c13a02c1abbbf73ed10052f1981db56508c95eac252901cbd7c0acbf4770ccb05835216f5cf554eb828
6
+ metadata.gz: 1aebc053fbff250e16fd8f158c1c42e36193dd28fb498a46bfa31ce2f8759e0343fafae585e63c2a0cdf04a72ddf700c9da0307bb6b4b057277c535d429f57d6
7
+ data.tar.gz: 6636ea77b07d90b4b568f6f12ec121c32c94f7064657005550368b97e83a03d68c6a2ab3780242b28c9a2fa45653d6707b07ffea7c0c7a19ad659fe256bfb0eb
@@ -1,9 +1,10 @@
1
1
  require "redis_env_config/version"
2
- require "redis"
3
2
 
4
3
  class RedisEnvConfig
5
4
  class Error < StandardError; end
6
5
 
6
+ CA_FILE_LOCK = Mutex.new unless defined?(CA_FILE_LOCK)
7
+
7
8
  def initialize(env: ENV)
8
9
  @config = {}
9
10
  @config[:url] = env["REDIS_URL"] if env["REDIS_URL"]
@@ -15,10 +16,9 @@ class RedisEnvConfig
15
16
  key = env["REDIS_KEY"] or raise Error, "missing environment variable REDIS_KEY"
16
17
  x[:key] = OpenSSL::PKey::RSA.new(key)
17
18
  x[:ca_file] = env["REDIS_CA_FILE"] or raise Error, "missing environment variable REDIS_CA_FILE"
18
- if env["REDIS_CA"] and !File.exist?(x[:ca_file])
19
- File.open(x[:ca_file], "w") { |io| io.write(env["REDIS_CA"]) }
20
- end
19
+ @ca = env["REDIS_CA"] if env["REDIS_CA"]
21
20
  end
21
+ assure_redis_ca_file
22
22
  end
23
23
  end
24
24
 
@@ -26,4 +26,14 @@ class RedisEnvConfig
26
26
  @config.dup
27
27
  end
28
28
 
29
+ private
30
+
31
+ def assure_redis_ca_file
32
+ CA_FILE_LOCK.synchronize do
33
+ if @ca and !File.exist?(@config[:ssl_params][:ca_file])
34
+ File.open(@config[:ssl_params][:ca_file], "w") { |io| io.write(@ca) }
35
+ end
36
+ end
37
+ end
38
+
29
39
  end
@@ -1,3 +1,3 @@
1
1
  class RedisEnvConfig
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis_env_config
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sheldon Hearn