consul_application_settings 1.0.0 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b20ecf9e1eb2ea05e41f729b69082093305d3ce5291d8fb45a64f185ba8ae44f
4
- data.tar.gz: ce5d16eb80ae0a9c0be78dda05d06e350546328d737ae1dd65309120f17fa814
3
+ metadata.gz: 686e4efaf1dd51db8fdb6ade9ec5622a080d2d1a84db1c78b1c66dd19444e3f5
4
+ data.tar.gz: 8eba55e8bf3b905ba24e5f069b55b0dafd8c4374e98ee7fea5ed2feede597703
5
5
  SHA512:
6
- metadata.gz: eac2795525ed07225d749c836781c5f9bebdfcaa55a8490d4cdca4ce2463db3130cd94e081cd87bd808743d7d1acf29729ccb5002000d5efc79a76b87a57bc0a
7
- data.tar.gz: ed28b56badd89cbf5097ac4d061eadd43e7aa1da37aefec1693d5b17b4bb78996e9cc8c9f4b38564b6c0383ea77ac65f89c8b66bb4e7ba4af8c7e8c7820dc2d7
6
+ metadata.gz: 447e52e8cceef44793db9de2977fc2facb752fc1232f6975eb73af38bd189458ebfc3287a7cde383da3d41f6ed744bf791c1f7079f3d8f91616dca0779dc54ef
7
+ data.tar.gz: e22c374ec16003f67bcf520943fcde6b00084178225c332d80df1fa6d34602c96bbce9c7b59a8290c68f197ba5ee8de444945ee9fda85d53b18667bd34428635
@@ -39,13 +39,15 @@ jobs:
39
39
  - name: Set up Dependencies
40
40
  run: bundle install --path vendor/bundle
41
41
 
42
- - name: Run Tests
43
- uses: paambaati/codeclimate-action@v2.3.0
42
+ - name: Run specs
44
43
  env:
45
44
  COVERAGE: true
46
- CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
47
- with:
48
- coverageCommand: ./bin/rspec
45
+ run: bundle exec rspec
46
+
47
+ - name: Upload coverage
48
+ env:
49
+ CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
50
+ run: bash <(curl -s https://codecov.io/bash)
49
51
 
50
52
  release:
51
53
  runs-on: ubuntu-latest
data/.simplecov CHANGED
@@ -1 +1,6 @@
1
- SimpleCov.start if ENV["COVERAGE"]
1
+ if ENV["COVERAGE"]
2
+ require 'simplecov'
3
+ require 'codecov'
4
+ SimpleCov.start
5
+ SimpleCov.formatter = SimpleCov::Formatter::Codecov
6
+ end
data/CHANGELOG.md CHANGED
@@ -1,5 +1,42 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [3.0.1]
4
+ ### Fixes
5
+ - Fix exception when preloading settings without consul
6
+
7
+ ## [3.0.0]
8
+ ### Breaking Changes
9
+ - Use Preloaded Consul Settings Provider by default
10
+ ### New features
11
+ - Configurable setting providers
12
+ - Preloaded Consul Settings Provider to prioritize performance over consistency
13
+ - Performance tests in spec
14
+ - Benchmarking script
15
+ ### Fixes
16
+ - Return nil instead of empty hash when reading missing setting from file
17
+ - Return nil instead of empty string when reading missing value from Consul
18
+ - Add missing load method on Settings Reader to create object with narrow scope
19
+
20
+ ## [2.1.1]
21
+ ### Changes
22
+ - Update Diplomat to latest version
23
+
24
+ ## [2.1.0]
25
+ ### Fixes
26
+ - Return nil for unknown keys
27
+
28
+ ## [2.0.0]
29
+ ### Breaking Changes
30
+ - Change default naming for setting files
31
+
32
+ ## [1.0.0]
33
+ ### Features
34
+ - Add support for second settings file (local settings for development)
35
+
36
+ ## [0.1.4]
37
+ ### Fixes
38
+ - Clone values before returning
39
+
3
40
  ## [0.1.3]
4
41
  ### Fixes
5
42
  - Add `Diplomat::PathNotFound` to the list of caught exceptions
@@ -22,7 +59,14 @@
22
59
  - Support deep settings search
23
60
  - Support nested configs
24
61
 
25
- [Unreleased]: https://github.com/matic-insurance/consul_application_settings/compare/0.1.3...HEAD
62
+ [Unreleased]: https://github.com/matic-insurance/consul_application_settings/compare/3.0.1...HEAD
63
+ [3.0.1]: https://github.com/matic-insurance/consul_application_settings/compare/3.0.0...3.0.1
64
+ [3.0.0]: https://github.com/matic-insurance/consul_application_settings/compare/2.0.0...3.0.0
65
+ [2.1.1]: https://github.com/matic-insurance/consul_application_settings/compare/2.1.0...2.1.1
66
+ [2.1.0]: https://github.com/matic-insurance/consul_application_settings/compare/2.0.0...2.1.0
67
+ [2.0.0]: https://github.com/matic-insurance/consul_application_settings/compare/1.0.0...2.0.0
68
+ [1.0.0]: https://github.com/matic-insurance/consul_application_settings/compare/0.1.4...1.0.0
69
+ [0.1.4]: https://github.com/matic-insurance/consul_application_settings/compare/0.1.3...0.1.4
26
70
  [0.1.3]: https://github.com/matic-insurance/consul_application_settings/compare/0.1.2...0.1.3
27
71
  [0.1.2]: https://github.com/matic-insurance/consul_application_settings/compare/0.1.1...0.1.2
28
72
  [0.1.1]: https://github.com/matic-insurance/consul_application_settings/compare/0.1.0...0.1.1
data/Gemfile.lock CHANGED
@@ -2,22 +2,27 @@ PATH
2
2
  remote: .
3
3
  specs:
4
4
  consul_application_settings (0.0.0)
5
- diplomat (~> 2.1.3)
5
+ diplomat (~> 2.5.1)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
10
  ast (2.4.0)
11
+ codecov (0.4.3)
12
+ simplecov (>= 0.15, < 0.22)
11
13
  deep_merge (1.2.1)
12
14
  diff-lcs (1.3)
13
- diplomat (2.1.3)
14
- deep_merge (~> 1.0, >= 1.0.1)
15
- faraday (~> 0.9)
15
+ diplomat (2.5.1)
16
+ deep_merge (~> 1.2)
17
+ faraday (>= 0.9)
16
18
  docile (1.3.1)
17
- faraday (0.17.3)
19
+ faraday (1.3.0)
20
+ faraday-net_http (~> 1.0)
18
21
  multipart-post (>= 1.2, < 3)
22
+ ruby2_keywords
23
+ faraday-net_http (1.0.1)
19
24
  jaro_winkler (1.5.2)
20
- json (2.2.0)
25
+ json (2.3.1)
21
26
  multipart-post (2.1.1)
22
27
  parallel (1.16.2)
23
28
  parser (2.6.2.0)
@@ -49,6 +54,7 @@ GEM
49
54
  rubocop-rspec (1.32.0)
50
55
  rubocop (>= 0.60.0)
51
56
  ruby-progressbar (1.10.0)
57
+ ruby2_keywords (0.0.4)
52
58
  simplecov (0.16.1)
53
59
  docile (~> 1.1)
54
60
  json (>= 1.8, < 3)
@@ -61,6 +67,7 @@ PLATFORMS
61
67
 
62
68
  DEPENDENCIES
63
69
  bundler (~> 2.0)
70
+ codecov (~> 0.4)
64
71
  consul_application_settings!
65
72
  rake (~> 13.0)
66
73
  rspec (~> 3.0)
data/README.md CHANGED
@@ -1,8 +1,7 @@
1
1
  # ConsulApplicationSettings
2
2
 
3
3
  ![Build Status](https://github.com/matic-insurance/consul_application_settings/workflows/ci/badge.svg?branch=master)
4
- [![Test Coverage](https://api.codeclimate.com/v1/badges/b0eaebcf83898535ea4e/test_coverage)](https://codeclimate.com/github/matic-insurance/consul_application_settings/test_coverage)
5
- [![Maintainability](https://api.codeclimate.com/v1/badges/b0eaebcf83898535ea4e/maintainability)](https://codeclimate.com/github/matic-insurance/consul_application_settings/maintainability)
4
+ [![Test Coverage](https://codecov.io/gh/matic-insurance/consul_application_settings/branch/master/graph/badge.svg?token=5E8NA8EE8L)](https://codecov.io/gh/matic-insurance/consul_application_settings)
6
5
 
7
6
  Gem that simplifies usage of Consul (via [Diplomat gem](https://github.com/WeAreFarmGeek/diplomat))
8
7
  to host application settings. Gem provides defaults via yaml files and other utilities
@@ -46,6 +45,11 @@ ConsulApplicationSettings.configure do |config|
46
45
  config.local_file_path = Rails.root.join('config/my_settings.local.yml')
47
46
  # Specify whether exceprion should be thrown on Consul connection errors. Default: false
48
47
  config.disable_consul_connection_errors = true
48
+ # Specify setting providers. Default: [ConsulApplicationSettings::Providers::ConsulPreloaded, ConsulApplicationSettings::Providers::LocalStorage]
49
+ config.settings_providers = [
50
+ ConsulApplicationSettings::Providers::Consul,
51
+ ConsulApplicationSettings::Providers::LocalStorage
52
+ ]
49
53
  end
50
54
 
51
55
  APP_SETTINGS = ConsulApplicationSettings.load
@@ -140,6 +144,10 @@ All Gem configurations
140
144
  | base_file_path | no | 'config/application_settings.yml' | String | Path to the file with base settings |
141
145
  | local_file_path | no | 'config/application_settings.local.yml' | String | Path to the file with local settings overriding the base settings |
142
146
  | disable_consul_connection_errors | no | true | Boolean | Do not raise exception when consul is not available (useful for development) |
147
+ | settings_providers | no | Array(Provider) | Array | Specify custom setting provider lists |
148
+
149
+ ### Performance vs Consistency
150
+ To be defined in future iterations on Consul Providers
143
151
 
144
152
  ## Development
145
153
 
data/bin/benchmark ADDED
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'consul_application_settings'
5
+ require 'benchmark'
6
+
7
+ ITERATIONS = 1000
8
+
9
+ def kill_consul
10
+ `pgrep consul | xargs kill`
11
+ end
12
+
13
+ def start_consul
14
+ spawn('consul agent -dev -node machine > /dev/null 2>&1')
15
+ end
16
+
17
+ def application_settings(providers)
18
+ file = 'spec/fixtures/base_application_settings.yml'
19
+ ConsulApplicationSettings.configure do |config|
20
+ config.settings_providers = providers
21
+ end
22
+ ConsulApplicationSettings.load(file)
23
+ end
24
+
25
+ def benchmark_gem
26
+ Benchmark.bm(20) do |x|
27
+ x.report('Real Time Consul') do
28
+ ca = application_settings([
29
+ ConsulApplicationSettings::Providers::Consul,
30
+ ConsulApplicationSettings::Providers::LocalStorage
31
+ ])
32
+ ITERATIONS.times { ca.get('application/name') }
33
+ end
34
+
35
+ x.report('Preloaded Consul') do
36
+ ca = application_settings([
37
+ ConsulApplicationSettings::Providers::ConsulPreloaded,
38
+ ConsulApplicationSettings::Providers::LocalStorage
39
+ ])
40
+ ITERATIONS.times { ca.get('application/name') }
41
+ end
42
+
43
+ x.report('File Only') do
44
+ ca = application_settings([
45
+ ConsulApplicationSettings::Providers::ConsulPreloaded
46
+ ])
47
+ ITERATIONS.times { ca.get('application/name') }
48
+ end
49
+ end
50
+ end
51
+
52
+ puts '-' * 80
53
+ puts 'Benchmark without consul agent'
54
+ kill_consul
55
+ benchmark_gem
56
+
57
+
58
+ puts '-' * 80
59
+ puts 'Benchmark with consul agent running'
60
+ start_consul
61
+ benchmark_gem
62
+
63
+ kill_consul
@@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
29
29
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
30
  spec.require_paths = ['lib']
31
31
 
32
- spec.add_dependency 'diplomat', '~> 2.1.3'
32
+ spec.add_dependency 'diplomat', '~> 2.5.1'
33
33
 
34
34
  spec.add_development_dependency 'bundler', '~> 2.0'
35
35
  spec.add_development_dependency 'rake', '~> 13.0'
@@ -37,4 +37,5 @@ Gem::Specification.new do |spec|
37
37
  spec.add_development_dependency 'rubocop', '~> 0.66'
38
38
  spec.add_development_dependency 'rubocop-rspec', '~> 1.32.0'
39
39
  spec.add_development_dependency 'simplecov', '~> 0.16'
40
+ spec.add_development_dependency 'codecov', '~> 0.4'
40
41
  end
@@ -1,8 +1,10 @@
1
1
  require 'consul_application_settings/version'
2
+ require 'consul_application_settings/providers/abstract'
3
+ require 'consul_application_settings/providers/consul'
4
+ require 'consul_application_settings/providers/consul_preloaded'
5
+ require 'consul_application_settings/providers/local_storage'
2
6
  require 'consul_application_settings/configuration'
3
- require 'consul_application_settings/consul_provider'
4
- require 'consul_application_settings/file_provider'
5
- require 'consul_application_settings/settings_provider'
7
+ require 'consul_application_settings/reader'
6
8
  require 'consul_application_settings/utils'
7
9
 
8
10
  # The gem provides possibility to load settings from Consul and automatically fall back to data stored in file system
@@ -21,6 +23,6 @@ module ConsulApplicationSettings
21
23
  end
22
24
 
23
25
  def self.load(path = '')
24
- SettingsProvider.new(path, config)
26
+ Reader.new(path, config)
25
27
  end
26
28
  end
@@ -1,14 +1,19 @@
1
1
  module ConsulApplicationSettings
2
2
  # All gem configuration settings
3
3
  class Configuration
4
- DEFAULT_BASE_FILE_PATH = 'config/application_settings.yml'.freeze
5
- DEFAULT_LOCAL_FILE_PATH = 'config/application_settings.local.yml'.freeze
6
- attr_accessor :base_file_path, :local_file_path, :disable_consul_connection_errors
4
+ DEFAULT_BASE_FILE_PATH = 'config/app_settings.yml'.freeze
5
+ DEFAULT_LOCAL_FILE_PATH = 'config/app_settings.local.yml'.freeze
6
+ DEFAULT_PROVIDERS = [
7
+ ConsulApplicationSettings::Providers::ConsulPreloaded,
8
+ ConsulApplicationSettings::Providers::LocalStorage
9
+ ]
10
+ attr_accessor :base_file_path, :local_file_path, :disable_consul_connection_errors, :settings_providers
7
11
 
8
12
  def initialize
9
13
  @base_file_path = DEFAULT_BASE_FILE_PATH
10
14
  @local_file_path = DEFAULT_LOCAL_FILE_PATH
11
15
  @disable_consul_connection_errors = true
16
+ @settings_providers = DEFAULT_PROVIDERS
12
17
  end
13
18
  end
14
19
  end
@@ -0,0 +1,25 @@
1
+ module ConsulApplicationSettings
2
+ module Providers
3
+ # Abstract class with basic functionality
4
+ class Abstract
5
+ def initialize(base_path, config)
6
+ @base_path, @config = base_path, config
7
+ end
8
+
9
+ def get(path)
10
+ raise NotImplementedError
11
+ end
12
+
13
+ protected
14
+
15
+ def absolute_key_path(path)
16
+ ConsulApplicationSettings::Utils.generate_path(@base_path, path)
17
+ end
18
+
19
+ def get_value_from_hash(path, data)
20
+ parts = ConsulApplicationSettings::Utils.decompose_path(path)
21
+ data.dig(*parts).clone
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,24 @@
1
+ require 'diplomat'
2
+
3
+ module ConsulApplicationSettings
4
+ module Providers
5
+ # Provides access to settings stored in Consul
6
+ class Consul < Abstract
7
+ def get(path)
8
+ full_path = absolute_key_path(path)
9
+ value = get_from_consul(full_path)
10
+ ConsulApplicationSettings::Utils.cast_consul_value(value)
11
+ end
12
+
13
+ private
14
+
15
+ def get_from_consul(path)
16
+ Diplomat::Kv.get(path, {})
17
+ rescue Diplomat::KeyNotFound
18
+ return nil
19
+ rescue SystemCallError, Faraday::ConnectionFailed, Diplomat::PathNotFound => e
20
+ raise e unless @config.disable_consul_connection_errors
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,27 @@
1
+ module ConsulApplicationSettings
2
+ module Providers
3
+ # Provides access to settings stored in Consul. Loads them once
4
+ class ConsulPreloaded < Abstract
5
+ def initialize(base_path, config)
6
+ super
7
+ @data = get_all_from_consul
8
+ end
9
+
10
+ def get(path)
11
+ value = get_value_from_hash(absolute_key_path(path), @data)
12
+ ConsulApplicationSettings::Utils.cast_consul_value(value)
13
+ end
14
+
15
+ protected
16
+
17
+ def get_all_from_consul
18
+ Diplomat::Kv.get_all(@base_path, { convert_to_hash: true })
19
+ rescue Diplomat::KeyNotFound
20
+ {}
21
+ rescue SystemCallError, Faraday::ConnectionFailed, Diplomat::PathNotFound => e
22
+ raise e unless @config.disable_consul_connection_errors
23
+ {}
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,42 @@
1
+ require 'yaml'
2
+
3
+ module ConsulApplicationSettings
4
+ module Providers
5
+ # Provides access to settings stored in file system with support of base and local files
6
+ class LocalStorage < Abstract
7
+ def initialize(base_path, config)
8
+ super
9
+ @data = load
10
+ end
11
+
12
+ def get(path)
13
+ get_value_from_hash(absolute_key_path(path), @data)
14
+ end
15
+
16
+ private
17
+
18
+ def load
19
+ base_yml = read_yml(base_file_path)
20
+ local_yml = read_yml(local_file_path)
21
+ DeepMerge.deep_merge!(local_yml, base_yml, preserve_unmergeables: false, overwrite_arrays: true,
22
+ merge_nil_values: true)
23
+ end
24
+
25
+ def base_file_path
26
+ @config.base_file_path
27
+ end
28
+
29
+ def local_file_path
30
+ @config.local_file_path
31
+ end
32
+
33
+ def read_yml(path)
34
+ return {} unless File.exist?(path)
35
+
36
+ YAML.safe_load(IO.read(path))
37
+ rescue Psych::SyntaxError, Errno::ENOENT => e
38
+ raise ConsulApplicationSettings::Error, "Cannot read settings file at #{path}: #{e.message}"
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,25 @@
1
+ module ConsulApplicationSettings
2
+ # Provides access to settings stored in Consul or in file system
3
+ class Reader
4
+ def initialize(base_path, config)
5
+ @base_path = base_path
6
+ @config = config
7
+ @providers = config.settings_providers.map { |provider| provider.new(base_path, config) }
8
+ end
9
+
10
+ def get(path)
11
+ @providers.each do |provider|
12
+ value = provider.get(path)
13
+ return value unless value.nil?
14
+ end
15
+ nil
16
+ end
17
+
18
+ alias [] get
19
+
20
+ def load(sub_path)
21
+ new_path = ConsulApplicationSettings::Utils.generate_path(@base_path, sub_path)
22
+ self.class.new(new_path, @config)
23
+ end
24
+ end
25
+ end
@@ -6,6 +6,7 @@ module ConsulApplicationSettings
6
6
 
7
7
  class << self
8
8
  def cast_consul_value(value)
9
+ return nil if value.nil?
9
10
  return false if value == 'false'
10
11
  return true if value == 'true'
11
12
 
@@ -1,3 +1,3 @@
1
1
  module ConsulApplicationSettings
2
- VERSION = '1.0.0'.freeze
2
+ VERSION = '3.0.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: consul_application_settings
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Volodymyr Mykhailyk
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-21 00:00:00.000000000 Z
11
+ date: 2021-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: diplomat
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.1.3
19
+ version: 2.5.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 2.1.3
26
+ version: 2.5.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0.16'
111
+ - !ruby/object:Gem::Dependency
112
+ name: codecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.4'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.4'
111
125
  description: |-
112
126
  Gem that simplifies usage of Consul (via Diplomat gem) to host application settings.
113
127
  Gem provides defaults and utilities
@@ -117,7 +131,6 @@ executables: []
117
131
  extensions: []
118
132
  extra_rdoc_files: []
119
133
  files:
120
- - ".codeclimate.yml"
121
134
  - ".github/workflows/main.yml"
122
135
  - ".gitignore"
123
136
  - ".rspec"
@@ -130,15 +143,18 @@ files:
130
143
  - LICENSE.txt
131
144
  - README.md
132
145
  - Rakefile
146
+ - bin/benchmark
133
147
  - bin/console
134
148
  - bin/rspec
135
149
  - bin/setup
136
150
  - consul_application_settings.gemspec
137
151
  - lib/consul_application_settings.rb
138
152
  - lib/consul_application_settings/configuration.rb
139
- - lib/consul_application_settings/consul_provider.rb
140
- - lib/consul_application_settings/file_provider.rb
141
- - lib/consul_application_settings/settings_provider.rb
153
+ - lib/consul_application_settings/providers/abstract.rb
154
+ - lib/consul_application_settings/providers/consul.rb
155
+ - lib/consul_application_settings/providers/consul_preloaded.rb
156
+ - lib/consul_application_settings/providers/local_storage.rb
157
+ - lib/consul_application_settings/reader.rb
142
158
  - lib/consul_application_settings/utils.rb
143
159
  - lib/consul_application_settings/version.rb
144
160
  homepage: https://github.com/matic-insurance/consul_application_settings
@@ -163,7 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
163
179
  - !ruby/object:Gem::Version
164
180
  version: '0'
165
181
  requirements: []
166
- rubygems_version: 3.0.3
182
+ rubygems_version: 3.0.3.1
167
183
  signing_key:
168
184
  specification_version: 4
169
185
  summary: Application settings via Consul with yaml defaults
data/.codeclimate.yml DELETED
@@ -1,15 +0,0 @@
1
- version: 2
2
- plugins:
3
- # disabled before git-legal supports bundler 2 https://github.com/kmewhort/git.legal-codeclimate/issues/6
4
- # git-legal:
5
- # enabled: true
6
- rubocop:
7
- enabled: true
8
- channel: rubocop-0-73
9
- config:
10
- file: ".rubocop.yml"
11
- bundler-audit:
12
- enabled: true
13
- exclude_patterns:
14
- - "spec/"
15
- - "*.gemspec"
@@ -1,33 +0,0 @@
1
- require 'diplomat'
2
-
3
- module ConsulApplicationSettings
4
- # Provides access to settings stored in Consul
5
- class ConsulProvider
6
- def initialize(base_path, config)
7
- @base_path = base_path
8
- @config = config
9
- end
10
-
11
- def get(path)
12
- value = fetch_value(path)
13
- ConsulApplicationSettings::Utils.cast_consul_value(value)
14
- end
15
-
16
- private
17
-
18
- def fetch_value(path)
19
- full_path = generate_full_path(path)
20
- Diplomat::Kv.get(full_path, {}, :return)
21
- rescue SystemCallError, Faraday::ConnectionFailed, Diplomat::PathNotFound => e
22
- raise e unless disable_consul_connection_errors?
23
- end
24
-
25
- def generate_full_path(path)
26
- ConsulApplicationSettings::Utils.generate_path(@base_path, path)
27
- end
28
-
29
- def disable_consul_connection_errors?
30
- @config.disable_consul_connection_errors
31
- end
32
- end
33
- end
@@ -1,54 +0,0 @@
1
- require 'yaml'
2
-
3
- module ConsulApplicationSettings
4
- # Provides access to settings stored in file system with support of base and local files
5
- class FileProvider
6
- def initialize(base_path, config)
7
- @base_path = base_path
8
- @config = config
9
- load
10
- end
11
-
12
- def get(path)
13
- read_path(path).clone
14
- end
15
-
16
- private
17
-
18
- def load
19
- base_yml = read_yml(base_file_path)
20
- local_yml = read_yml(local_file_path)
21
- @data = DeepMerge.deep_merge!(local_yml, base_yml, preserve_unmergeables: false, overwrite_arrays: true,
22
- merge_nil_values: true)
23
- end
24
-
25
- def base_file_path
26
- @config.base_file_path
27
- end
28
-
29
- def local_file_path
30
- @config.local_file_path
31
- end
32
-
33
- def read_yml(path)
34
- return {} unless File.exist?(path)
35
-
36
- YAML.safe_load(IO.read(path))
37
- rescue Psych::SyntaxError, Errno::ENOENT => e
38
- raise ConsulApplicationSettings::Error, "Cannot read settings file at #{path}: #{e.message}"
39
- end
40
-
41
- def read_path(path)
42
- full_path = ConsulApplicationSettings::Utils.generate_path(@base_path, path)
43
- parts = ConsulApplicationSettings::Utils.decompose_path(full_path)
44
- parts.reduce(@data, &method(:read_value))
45
- end
46
-
47
- def read_value(hash, key)
48
- raise ConsulApplicationSettings::Error, 'reading arrays not implemented' if hash.is_a? Array
49
- return {} if hash.nil?
50
-
51
- hash.fetch(key.to_s)
52
- end
53
- end
54
- end
@@ -1,16 +0,0 @@
1
- module ConsulApplicationSettings
2
- # Provides access to settings stored in Consul or in file system
3
- class SettingsProvider
4
- def initialize(base_path, config)
5
- @consul_provider = ConsulProvider.new(base_path, config)
6
- @file_provider = FileProvider.new(base_path, config)
7
- end
8
-
9
- def get(path)
10
- consul_value = @consul_provider.get(path)
11
- !consul_value.nil? && consul_value != '' ? consul_value : @file_provider.get(path)
12
- end
13
-
14
- alias [] get
15
- end
16
- end