cconfig 1.3.0 → 1.3.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: 9ea29ed34d129bc2fc6180e948f2cb36e4c023bf2786c28f0292495a493ae37d
4
- data.tar.gz: 7b3e82322ca62ad505898e44fa023f38651efdb8f32fdd4360617dbdec965a88
3
+ metadata.gz: 25e896fa02704f037946c79957dd9c5b7e6b12175061439293ff5e5a81e9db03
4
+ data.tar.gz: 6887a80da282ca21f94c99527de39e185035ab0b79f5a6d7ddec1405ac11005e
5
5
  SHA512:
6
- metadata.gz: badbe8952eab5a3599ad63d76b9bc9c4a2861268c9aac261957c3829dbdbeada380e02f370b7cf176d8dbca5731b3f445e475244b8890a174fe3a2c44ac12e17
7
- data.tar.gz: f56de4c02b6870a0d7a0239b62aad54313ac63bdf75e1363a7e691c99bc62e57d49473584cfab873f3c26389ff00cb6f26f1a80c0cd52c8d55d7115df5680b23
6
+ metadata.gz: 6cddc61a22a2de01b9e55ff6672d1762801a94a6d74f2799067c62004fc518c413dd2b85bbee06bfc9ca3a3e37013a81a007e93f6cfc68cf35638f41a6769e60
7
+ data.tar.gz: 0cb7e8c92998154af72be21e8e4292d0b64c25e2560142bce558bed055db66bbc91136c6b587a86e1da90adbb64937136f93ae92c843c353b219288febef80cb
@@ -0,0 +1,31 @@
1
+ ---
2
+
3
+ name: Ruby
4
+
5
+ on:
6
+ push:
7
+ branches: ["main"]
8
+ pull_request:
9
+ branches: ["main"]
10
+
11
+ jobs:
12
+ test:
13
+ runs-on: ubuntu-latest
14
+ strategy:
15
+ matrix:
16
+ ruby-version: [2.7, 3.0, 3.1, head]
17
+
18
+ steps:
19
+ - uses: actions/checkout@v3
20
+
21
+ - name: Set up Ruby
22
+ uses: ruby/setup-ruby@v1
23
+ with:
24
+ ruby-version: ${{ matrix.ruby-version }}
25
+ bundler-cache: true
26
+
27
+ - name: Run tests
28
+ run: bundle exec rake
29
+
30
+ - name: Run rubocop
31
+ run: bundle exec rubocop
data/.rubocop.yml CHANGED
@@ -1,66 +1,92 @@
1
- require:
2
- - rubocop-rspec
1
+ ---
3
2
 
4
3
  AllCops:
5
- TargetRubyVersion: 2.3
4
+ TargetRubyVersion: 2.7
5
+
6
6
  DisplayCopNames: true
7
7
  DisplayStyleGuide: false
8
+ SuggestExtensions: false
9
+
10
+ NewCops: enable
11
+
12
+ Exclude:
13
+ - spec/**/*
14
+ - vendor/**/*
15
+
16
+ ##
17
+ # Plugins
18
+
19
+ require:
20
+ - rubocop-performance
21
+ - rubocop-rake
22
+
23
+ #
24
+ # Layout
25
+ #
8
26
 
9
- # This is a remnant of old SUSE-style alignment for hashes, The table format
10
- # looks more human readable.
27
+ # The table format is more human readable.
11
28
  Layout/HashAlignment:
12
29
  EnforcedHashRocketStyle: table
13
30
  EnforcedColonStyle: table
14
31
 
15
- # Both my last names contain non-ascii characters :) (license notice)
16
- Style/AsciiComments:
17
- Enabled: false
32
+ # The default is just too small. A limit of 100 looks reasonable.
33
+ Layout/LineLength:
34
+ Max: 100
18
35
 
19
- # Disable the block length cop for tests.
20
- Metrics/BlockLength:
21
- Enabled: true
36
+ #
37
+ # Metrics
38
+ #
39
+
40
+ # The default is just too small.
41
+ Metrics/AbcSize:
42
+ Max: 30
43
+
44
+ # We will skip it for Rake tasks.
45
+ Metrics/ClassLength:
22
46
  Exclude:
23
- - spec/**/*
47
+ - test/**/*
24
48
 
25
- # The default is just too small. A limit of 100 looks reasonable and many other
26
- # projects (including inside of SUSE) are also using this value.
27
- Metrics/LineLength:
28
- Max: 100
49
+ # We will skip it for Rake tasks.
50
+ Metrics/BlockLength:
51
+ Exclude:
52
+ - lib/tasks/**/*
53
+ - test/**/*
29
54
 
55
+ # The default is just too small.
30
56
  Metrics/MethodLength:
31
57
  Max: 20
32
58
 
33
- # This is a common SUSE configuration value: the performance difference between
34
- # single and double quotes is no longer there, and so it's better to be
35
- # consistent and force only double quotes.
36
- Style/StringLiterals:
37
- EnforcedStyle: double_quotes
59
+ #
60
+ # Style
61
+ #
38
62
 
39
- # Same as Style/StringLiterals.
40
- Style/StringLiteralsInInterpolation:
41
- EnforcedStyle: double_quotes
42
-
43
- # Sometimes we need more than one "expect" command to build our actual
44
- # expectation.
45
- RSpec/MultipleExpectations:
46
- Max: 6
47
-
48
- # Setting a more reasonable value.
49
- RSpec/ExampleLength:
50
- Max: 10
63
+ # It's not needed to add documentation for obvious modules or classes. The main
64
+ # idea is that documentation will be asked during the review process if needed.
65
+ Style/Documentation:
66
+ Enabled: false
51
67
 
52
- # Otherwise CConfig is not allowed ...
53
- RSpec/FilePath:
68
+ # This forces us to create a new object for no real reason.
69
+ Style/MultipleComparison:
54
70
  Enabled: false
55
71
 
56
- ##
57
- # Newly added cops
72
+ # There are some false positives (e.g. "module ::Module", in which we want to
73
+ # make sure there are no clashes or misunderstandings). Therefore, we just
74
+ # disable this cop.
75
+ Style/ClassAndModuleChildren:
76
+ Enabled: false
58
77
 
59
- Style/HashEachMethods:
60
- Enabled: true
78
+ # I do need to write non-ASCII words from time to time since, you know, this is
79
+ # a language application and latin words can have macrons.
80
+ Style/AsciiComments:
81
+ Enabled: false
61
82
 
62
- Style/HashTransformKeys:
63
- Enabled: true
83
+ #
84
+ # Naming
85
+ #
64
86
 
65
- Style/HashTransformValues:
66
- Enabled: true
87
+ # The default minimum length is 3, which is too long for good names like
88
+ # "js". Variables with only one letter are usually disallowed, but there are
89
+ # some names which are easy to understand (e.g. convention).
90
+ Naming/MethodParameterName:
91
+ MinNameLength: 2
92
+ AllowedNames: [_, n]
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.3.1
4
+
5
+ - Don't throw an error if the local file is empty. See
6
+ [6c464709605f](https://github.com/mssola/cconfig/commit/6c464709605f).
7
+ - rake: print config when it's been already defined. See
8
+ [b1d862551ed1](https://github.com/mssola/cconfig/commit/b1d862551ed1).
9
+ - railtie: don't fetch the name by inspecting. See
10
+ [0c87a22c324d](https://github.com/mssola/cconfig/commit/0c87a22c324d).
11
+
3
12
  ## 1.3.0
4
13
 
5
14
  - Added Ruby on Rails 6.x support. See
data/Gemfile CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- source "https://rubygems.org"
3
+ source 'https://rubygems.org'
4
4
 
5
5
  gemspec
data/Gemfile.lock CHANGED
@@ -1,47 +1,55 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cconfig (1.3.0)
4
+ cconfig (1.3.1)
5
5
  safe_yaml (~> 1.0.0, >= 1.0.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- ast (2.4.0)
11
- diff-lcs (1.3)
12
- jaro_winkler (1.5.4)
13
- parallel (1.19.1)
14
- parser (2.7.0.5)
15
- ast (~> 2.4.0)
16
- rainbow (3.0.0)
17
- rake (13.0.1)
18
- rexml (3.2.4)
19
- rspec (3.9.0)
20
- rspec-core (~> 3.9.0)
21
- rspec-expectations (~> 3.9.0)
22
- rspec-mocks (~> 3.9.0)
23
- rspec-core (3.9.1)
24
- rspec-support (~> 3.9.1)
25
- rspec-expectations (3.9.1)
10
+ ast (2.4.2)
11
+ diff-lcs (1.5.0)
12
+ json (2.6.2)
13
+ parallel (1.22.1)
14
+ parser (3.1.3.0)
15
+ ast (~> 2.4.1)
16
+ rainbow (3.1.1)
17
+ rake (13.0.6)
18
+ regexp_parser (2.6.1)
19
+ rexml (3.2.5)
20
+ rspec (3.12.0)
21
+ rspec-core (~> 3.12.0)
22
+ rspec-expectations (~> 3.12.0)
23
+ rspec-mocks (~> 3.12.0)
24
+ rspec-core (3.12.0)
25
+ rspec-support (~> 3.12.0)
26
+ rspec-expectations (3.12.0)
26
27
  diff-lcs (>= 1.2.0, < 2.0)
27
- rspec-support (~> 3.9.0)
28
- rspec-mocks (3.9.1)
28
+ rspec-support (~> 3.12.0)
29
+ rspec-mocks (3.12.0)
29
30
  diff-lcs (>= 1.2.0, < 2.0)
30
- rspec-support (~> 3.9.0)
31
- rspec-support (3.9.2)
32
- rubocop (0.80.1)
33
- jaro_winkler (~> 1.5.1)
31
+ rspec-support (~> 3.12.0)
32
+ rspec-support (3.12.0)
33
+ rubocop (1.39.0)
34
+ json (~> 2.3)
34
35
  parallel (~> 1.10)
35
- parser (>= 2.7.0.1)
36
+ parser (>= 3.1.2.1)
36
37
  rainbow (>= 2.2.2, < 4.0)
37
- rexml
38
+ regexp_parser (>= 1.8, < 3.0)
39
+ rexml (>= 3.2.5, < 4.0)
40
+ rubocop-ast (>= 1.23.0, < 2.0)
38
41
  ruby-progressbar (~> 1.7)
39
- unicode-display_width (>= 1.4.0, < 1.7)
40
- rubocop-rspec (1.38.1)
41
- rubocop (>= 0.68.1)
42
- ruby-progressbar (1.10.1)
42
+ unicode-display_width (>= 1.4.0, < 3.0)
43
+ rubocop-ast (1.23.0)
44
+ parser (>= 3.1.1.0)
45
+ rubocop-performance (1.15.1)
46
+ rubocop (>= 1.7.0, < 2.0)
47
+ rubocop-ast (>= 0.4.0)
48
+ rubocop-rake (0.6.0)
49
+ rubocop (~> 1.0)
50
+ ruby-progressbar (1.11.0)
43
51
  safe_yaml (1.0.5)
44
- unicode-display_width (1.6.1)
52
+ unicode-display_width (2.3.0)
45
53
 
46
54
  PLATFORMS
47
55
  ruby
@@ -51,8 +59,9 @@ DEPENDENCIES
51
59
  cconfig!
52
60
  rake (>= 10.0)
53
61
  rspec (>= 3.0)
54
- rubocop (~> 0.80.0)
55
- rubocop-rspec
62
+ rubocop (>= 1.0)
63
+ rubocop-performance
64
+ rubocop-rake
56
65
 
57
66
  BUNDLED WITH
58
- 1.17.3
67
+ 2.3.18
data/README.md CHANGED
@@ -1,4 +1,9 @@
1
- # CConfig [![Build Status](https://travis-ci.org/mssola/cconfig.svg?branch=master)](https://travis-ci.org/mssola/cconfig) [![Gem Version](https://badge.fury.io/rb/cconfig.svg)](https://badge.fury.io/rb/cconfig)
1
+ <p align="center">
2
+ <a href="https://github.com/mssola/cconfig/actions/workflows/ruby.yml" title="CI status for the main branch"><img src="https://github.com/mssola/cconfig/actions/workflows/ruby.yml/badge.svg?branch=main" alt="Build Status for main branch" /></a>
3
+ <a href="http://www.gnu.org/licenses/lgpl-3.0.txt" rel="nofollow"><img alt="License LGPL 3+" src="https://img.shields.io/badge/license-LGPL_3-blue.svg" style="max-width:100%;"></a>
4
+ </p>
5
+
6
+ ---
2
7
 
3
8
  CConfig (Container Config) is a container-aware configuration management
4
9
  gem. This is useful for applications that want to keep a reference configuration
@@ -115,7 +120,15 @@ Last but not least, this Railtie also offers a rake task called
115
120
  `cconfig:info`. This rake task prints to standard output the evaluated
116
121
  configuration.
117
122
 
118
- This gem supports Ruby on Rails `5.x` and `6.x`.
123
+ This gem supports Ruby on Rails `5.x`, `6.x` and `7.x`.
124
+
125
+ ## Contributing
126
+
127
+ Read the [CONTRIBUTING.md](./CONTRIBUTING.md) file.
128
+
129
+ ## [Changelog](https://pbs.twimg.com/media/DJDYCcLXcAA_eIo?format=jpg&name=small)
130
+
131
+ Read the [CHANGELOG.md](./CHANGELOG.md) file.
119
132
 
120
133
  ## License
121
134
 
@@ -124,7 +137,7 @@ This project is based on work I did for the
124
137
  gem so it can be also used for other projects that might be interested in this.
125
138
 
126
139
  ```
127
- Copyright (C) 2017-2020 Miquel Sabaté Solà <msabate@suse.com>
140
+ Copyright (C) 2017-2022 Miquel Sabaté Solà <msabate@suse.com>
128
141
 
129
142
  CConfig is free software: you can redistribute it and/or modify
130
143
  it under the terms of the GNU Lesser General Public License as published by
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (C) 2017-2020 Miquel Sabaté Solà <msabate@suse.com>
3
+ # Copyright (C) 2017-2022 Miquel Sabaté Solà <msabate@suse.com>
4
4
  #
5
5
  # This file is part of CConfig.
6
6
  #
@@ -17,8 +17,10 @@
17
17
  # You should have received a copy of the GNU Lesser General Public License
18
18
  # along with CConfig. If not, see <http://www.gnu.org/licenses/>.
19
19
 
20
- require "rspec/core/rake_task"
20
+ require 'rspec/core/rake_task'
21
21
  RSpec::Core::RakeTask.new(:spec)
22
22
 
23
23
  task default: [:spec]
24
+
25
+ desc 'Run RSpec'
24
26
  task test: :spec
data/cconfig.gemspec CHANGED
@@ -1,31 +1,32 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- lib = File.expand_path("lib", __dir__)
3
+ lib = File.expand_path('lib', __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
 
6
- require "cconfig/version"
6
+ require 'cconfig/version'
7
7
 
8
8
  Gem::Specification.new do |spec|
9
- spec.name = "cconfig"
9
+ spec.name = 'cconfig'
10
10
  spec.version = CConfig::VERSION
11
- spec.authors = ["mssola"]
12
- spec.email = ["mssola@suse.com"]
13
- spec.description = "Configuration management for container-aware applications"
14
- spec.summary = "Configuration management for container-aware applications."
15
- spec.homepage = "https://github.com/mssola/cconfig"
16
- spec.license = "LGPL-3.0"
11
+ spec.authors = ['mssola']
12
+ spec.email = ['mssola@suse.com']
13
+ spec.description = 'Configuration management for container-aware applications'
14
+ spec.summary = 'Configuration management for container-aware applications.'
15
+ spec.homepage = 'https://github.com/mssola/cconfig'
16
+ spec.license = 'LGPL-3.0'
17
17
 
18
18
  spec.files = `git ls-files`.split($RS)
19
- spec.test_files = spec.files.grep("^spec/")
20
- spec.require_paths = ["lib"]
19
+ spec.require_paths = ['lib']
21
20
 
22
- spec.required_ruby_version = ">= 2.3"
21
+ spec.required_ruby_version = '>= 2.7.0'
23
22
 
24
- spec.add_dependency "safe_yaml", "~> 1.0.0", ">= 1.0.0"
23
+ spec.add_dependency 'safe_yaml', '~> 1.0.0', '>= 1.0.0'
25
24
 
26
- spec.add_development_dependency "bundler", ">= 1.0.0"
27
- spec.add_development_dependency "rake", ">= 10.0"
28
- spec.add_development_dependency "rspec", ">= 3.0"
29
- spec.add_development_dependency "rubocop", "~> 0.80.0"
30
- spec.add_development_dependency "rubocop-rspec"
25
+ spec.add_development_dependency 'bundler', '>= 1.0.0'
26
+ spec.add_development_dependency 'rake', '>= 10.0'
27
+ spec.add_development_dependency 'rspec', '>= 3.0'
28
+ spec.add_development_dependency 'rubocop', '>= 1.0'
29
+ spec.add_development_dependency 'rubocop-performance'
30
+ spec.add_development_dependency 'rubocop-rake'
31
+ spec.metadata['rubygems_mfa_required'] = 'true'
31
32
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (C) 2017-2020 Miquel Sabaté Solà <msabate@suse.com>
3
+ # Copyright (C) 2017-2022 Miquel Sabaté Solà <msabate@suse.com>
4
4
  #
5
5
  # This file is part of CConfig.
6
6
  #
@@ -17,9 +17,9 @@
17
17
  # You should have received a copy of the GNU Lesser General Public License
18
18
  # along with CConfig. If not, see <http://www.gnu.org/licenses/>.
19
19
 
20
- require "cconfig/hash_utils"
21
- require "cconfig/errors"
22
- require "yaml"
20
+ require 'cconfig/hash_utils'
21
+ require 'cconfig/errors'
22
+ require 'yaml'
23
23
 
24
24
  module CConfig
25
25
  # Config is the main class of this library. It allows you to fetch the current
@@ -37,8 +37,8 @@ module CConfig
37
37
  # `#{prefix}_LOCAL_CONFIG_PATH` environment variable if it was set.
38
38
  def initialize(default:, local:, prefix:)
39
39
  @default = default
40
- @prefix = prefix || "cconfig"
41
- @local = ENV["#{@prefix.upcase}_LOCAL_CONFIG_PATH"] || local
40
+ @prefix = prefix || 'cconfig'
41
+ @local = ENV.fetch("#{@prefix.upcase}_LOCAL_CONFIG_PATH") { local }
42
42
  end
43
43
 
44
44
  # Returns a hash with the app configuration contained in it.
@@ -65,6 +65,8 @@ module CConfig
65
65
  if File.file?(@local)
66
66
  # Check for bad user input in the local config.yml file.
67
67
  local = YAML.load_file(@local)
68
+ return {} if local.nil?
69
+
68
70
  raise FormatError unless local.is_a?(::Hash)
69
71
 
70
72
  local
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (C) 2017-2020 Miquel Sabaté Solà <msabate@suse.com>
3
+ # Copyright (C) 2017-2022 Miquel Sabaté Solà <msabate@suse.com>
4
4
  #
5
5
  # This file is part of CConfig.
6
6
  #
@@ -21,7 +21,7 @@ module CConfig
21
21
  # FormatError is the exception to be raised when a configuration file cannot
22
22
  # be parsed.
23
23
  class FormatError < StandardError
24
- DEFAULT_MSG = "Wrong format for the config-local file!"
24
+ DEFAULT_MSG = 'Wrong format for the config-local file!'
25
25
 
26
26
  def initialize
27
27
  super(DEFAULT_MSG)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (C) 2017-2020 Miquel Sabaté Solà <msabate@suse.com>
3
+ # Copyright (C) 2017-2022 Miquel Sabaté Solà <msabate@suse.com>
4
4
  #
5
5
  # This file is part of CConfig.
6
6
  #
@@ -34,14 +34,14 @@ module CConfig
34
34
  # enabled: true
35
35
  def enabled?(feature)
36
36
  cur = self
37
- parts = feature.split(".")
37
+ parts = feature.split('.')
38
38
 
39
39
  parts.each do |part|
40
40
  cur = cur[part]
41
41
  return false if !cur || cur.empty?
42
42
  end
43
43
 
44
- cur.key?("enabled") && cur["enabled"].eql?(true)
44
+ cur.key?('enabled') && cur['enabled'].eql?(true)
45
45
  end
46
46
 
47
47
  # Returns true if the given feature is disabled or doesn't exist. This is
@@ -55,7 +55,7 @@ module CConfig
55
55
  def default_of(key)
56
56
  cur = defaults
57
57
 
58
- key.split(".").each do |part|
58
+ key.split('.').each do |part|
59
59
  cur = cur[part]
60
60
  break if cur.nil?
61
61
  end
@@ -106,8 +106,8 @@ module CConfig
106
106
  hsh.each do |k, v|
107
107
  if v.is_a?(Hash)
108
108
  hsh[k] = hide_password(v)
109
- elsif k == "password"
110
- hsh[k] = "****"
109
+ elsif k == 'password'
110
+ hsh[k] = '****'
111
111
  end
112
112
  end
113
113
  hsh
@@ -119,12 +119,12 @@ module CConfig
119
119
  # exist, it will return nil. Otherwise, it will try to cast the fetched
120
120
  # value into the proper type and return it.
121
121
  def get_env(key)
122
- env = ENV[key.upcase]
122
+ env = ENV.fetch(key.upcase, nil)
123
123
  return nil if env.nil?
124
124
 
125
125
  # Try to convert it into a boolean value.
126
- return true if env.casecmp("true").zero?
127
- return false if env.casecmp("false").zero?
126
+ return true if env.casecmp('true').zero?
127
+ return false if env.casecmp('false').zero?
128
128
 
129
129
  # Try to convert it into an integer. Otherwise just keep the string.
130
130
  begin
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (C) 2017-2020 Miquel Sabaté Solà <msabate@suse.com>
3
+ # Copyright (C) 2017-2022 Miquel Sabaté Solà <msabate@suse.com>
4
4
  #
5
5
  # This file is part of CConfig.
6
6
  #
@@ -17,7 +17,7 @@
17
17
  # You should have received a copy of the GNU Lesser General Public License
18
18
  # along with CConfig. If not, see <http://www.gnu.org/licenses/>.
19
19
 
20
- require "rails"
20
+ require 'rails'
21
21
 
22
22
  module CConfig
23
23
  # This class will set up this gem for Ruby on Rails:
@@ -27,10 +27,10 @@ module CConfig
27
27
  class Railtie < Rails::Railtie
28
28
  railtie_name :cconfig
29
29
 
30
- initializer "cconfig" do |app|
30
+ initializer 'cconfig' do |app|
31
31
  prefix = ::CConfig::Railtie.fetch_prefix(app)
32
- default = Rails.root.join("config", "config.yml")
33
- local = Rails.root.join("config", "config-local.yml")
32
+ default = Rails.root.join('config', 'config.yml')
33
+ local = Rails.root.join('config', 'config-local.yml')
34
34
  cfg = ::CConfig::Config.new(default: default, local: local, prefix: prefix)
35
35
 
36
36
  # NOTE: this is a global constant from now on. The Rails application
@@ -39,7 +39,7 @@ module CConfig
39
39
  end
40
40
 
41
41
  rake_tasks do
42
- Dir[File.join(File.dirname(__FILE__), "../tasks/*.rake")].each do |task|
42
+ Dir[File.join(File.dirname(__FILE__), '../tasks/*.rake')].each do |task|
43
43
  load task
44
44
  end
45
45
  end
@@ -49,10 +49,10 @@ module CConfig
49
49
  #
50
50
  # app contains the Rails application as given by the railtie API.
51
51
  def self.fetch_prefix(app)
52
- if ENV["CCONFIG_PREFIX"].present?
53
- ENV["CCONFIG_PREFIX"]
52
+ if ENV['CCONFIG_PREFIX'].present?
53
+ ENV['CCONFIG_PREFIX']
54
54
  elsif Rails::VERSION::MAJOR >= 6
55
- app.class.module_parent_name.inspect
55
+ app.class.module_parent_name
56
56
  else
57
57
  app.class.parent_name.inspect
58
58
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (C) 2017-2020 Miquel Sabaté Solà <msabate@suse.com>
3
+ # Copyright (C) 2017-2022 Miquel Sabaté Solà <msabate@suse.com>
4
4
  #
5
5
  # This file is part of CConfig.
6
6
  #
@@ -19,5 +19,5 @@
19
19
 
20
20
  module CConfig
21
21
  # The current version of CConfig.
22
- VERSION = "1.3.0"
22
+ VERSION = '1.3.1'
23
23
  end
data/lib/cconfig.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (C) 2017-2020 Miquel Sabaté Solà <msabate@suse.com>
3
+ # Copyright (C) 2017-2022 Miquel Sabaté Solà <msabate@suse.com>
4
4
  #
5
5
  # This file is part of CConfig.
6
6
  #
@@ -21,5 +21,5 @@
21
21
  module CConfig
22
22
  end
23
23
 
24
- require "cconfig/cconfig"
25
- require "cconfig/railtie" if defined?(Rails)
24
+ require 'cconfig/cconfig'
25
+ require 'cconfig/railtie' if defined?(Rails)
data/lib/tasks/info.rake CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (C) 2017-2020 Miquel Sabaté Solà <msabate@suse.com>
3
+ # Copyright (C) 2017-2022 Miquel Sabaté Solà <msabate@suse.com>
4
4
  #
5
5
  # This file is part of CConfig.
6
6
  #
@@ -17,12 +17,44 @@
17
17
  # You should have received a copy of the GNU Lesser General Public License
18
18
  # along with CConfig. If not, see <http://www.gnu.org/licenses/>.
19
19
 
20
+ require 'yaml'
21
+
22
+ # This is indeed identical to the `hide_password` method from the HashUtils
23
+ # module. That being said, it's easier to just repeat this simple piece of code
24
+ # than restructure things around.
25
+ def to_secure_hash(hsh)
26
+ hsh.each do |k, v|
27
+ if v.is_a?(Hash)
28
+ hsh[k] = to_secure_hash(v)
29
+ elsif k == 'password'
30
+ hsh[k] = '****'
31
+ end
32
+ end
33
+ end
34
+
20
35
  namespace :cconfig do
21
- desc "Prints the evaluated configuration"
36
+ desc 'Prints the evaluated configuration'
22
37
  task :info, [:prefix] => :environment do |_, args|
23
- prefix = args[:prefix]
24
- default = File.join(Rails.root, "config", "config.yml")
25
- local = File.join(Rails.root, "config", "config-local.yml")
38
+ # If this is a Rails application, chances are that when calling this Rake
39
+ # task the `::APP_CONFIG` variable has already been set by the Rails
40
+ # initializer.
41
+ if defined?(::APP_CONFIG)
42
+ hsh = to_secure_hash(::APP_CONFIG)
43
+ puts "Evaluated configuration:\n#{hsh.to_yaml}"
44
+ next
45
+ end
46
+
47
+ # There might be a weird case in which Rails is being used but the
48
+ # `::APP_CONFIG` variable has not been set. In these cases, try to fetch the
49
+ # application name from within Rails if a prefix was not given.
50
+ prefix = if args[:prefix].nil? && defined?(Rails)
51
+ ::CConfig::Railtie.fetch_prefix(Rails.application)
52
+ else
53
+ args[:prefix]
54
+ end
55
+
56
+ default = File.join(Rails.root, 'config', 'config.yml')
57
+ local = File.join(Rails.root, 'config', 'config-local.yml')
26
58
 
27
59
  # Note that local will change if "#{prefix.upcase}_LOCAL_CONFIG_PATH" was
28
60
  # specified.
data/spec/config_spec.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (C) 2017-2020 Miquel Sabaté Solà <msabate@suse.com>
3
+ # Copyright (C) 2017-2022 Miquel Sabaté Solà <msabate@suse.com>
4
4
  #
5
5
  # This file is part of CConfig.
6
6
  #
@@ -17,14 +17,14 @@
17
17
  # You should have received a copy of the GNU Lesser General Public License
18
18
  # along with CConfig. If not, see <http://www.gnu.org/licenses/>.
19
19
 
20
- require "cconfig/cconfig"
20
+ require 'cconfig/cconfig'
21
21
 
22
22
  # Returns a Config configured with the two given config files.
23
23
  def get_config(default, local)
24
- base = File.join(File.dirname(__FILE__), "fixtures")
24
+ base = File.join(File.dirname(__FILE__), 'fixtures')
25
25
  default = File.join(base, default)
26
26
  local = File.join(base, local)
27
- ::CConfig::Config.new(default: default, local: local, prefix: "test")
27
+ ::CConfig::Config.new(default: default, local: local, prefix: 'test')
28
28
  end
29
29
 
30
30
  describe CConfig::Config do
@@ -35,100 +35,105 @@ describe CConfig::Config do
35
35
  end
36
36
  end
37
37
 
38
- it "selects the proper local file depending of the environment variable" do
38
+ it 'selects the proper local file depending of the environment variable' do
39
39
  # Instead of bad.yml (which will raise an error on `fetch`), we will pick up
40
40
  # the local.yml file.
41
- base = File.join(File.dirname(__FILE__), "fixtures")
42
- local = File.join(base, "bad.yml")
43
- ENV["CCONFIG_LOCAL_CONFIG_PATH"] = File.join(base, "local.yml")
41
+ base = File.join(File.dirname(__FILE__), 'fixtures')
42
+ local = File.join(base, 'bad.yml')
43
+ ENV['CCONFIG_LOCAL_CONFIG_PATH'] = File.join(base, 'local.yml')
44
44
 
45
45
  # Passing nil to the prefix on purpose (see SUSE/Portus#1379)
46
- cfg = ::CConfig::Config.new(default: "config.yml", local: local, prefix: nil)
46
+ cfg = ::CConfig::Config.new(default: 'config.yml', local: local, prefix: nil)
47
47
  expect { cfg.fetch }.not_to raise_error
48
48
  end
49
49
 
50
- describe "Merging configuration values" do
51
- it "returns an empty config if neither the global nor the local were found" do
52
- cfg = get_config("", "").fetch
50
+ describe 'Merging configuration values' do
51
+ it 'returns an empty config if neither the global nor the local were found' do
52
+ cfg = get_config('', '').fetch
53
53
  expect(cfg).to be_empty
54
54
  end
55
55
 
56
- it "only uses the global if the local config was not found" do
57
- cfg = get_config("config.yml", "").fetch
58
- expect(cfg["gravatar"]["enabled"]).to be_truthy
56
+ it 'only uses the global if the local config was not found' do
57
+ cfg = get_config('config.yml', '').fetch
58
+ expect(cfg['gravatar']['enabled']).to be_truthy
59
59
  end
60
60
 
61
- it "merges both config files and work as expected" do
62
- cfg = get_config("config.yml", "local.yml").fetch
61
+ it 'merges both config files and work as expected' do
62
+ cfg = get_config('config.yml', 'local.yml').fetch
63
63
 
64
- expect(cfg).to be_enabled("gravatar")
65
- expect(cfg).to be_enabled("ldap")
66
- expect(cfg["ldap"]["hostname"]).to eq "ldap.example.com"
67
- expect(cfg["ldap"]["port"]).to eq 389
68
- expect(cfg["ldap"]["base"]).to eq "ou=users,dc=example,dc=com"
69
- expect(cfg["unknown"]).to be nil
64
+ expect(cfg).to be_enabled('gravatar')
65
+ expect(cfg).to be_enabled('ldap')
66
+ expect(cfg['ldap']['hostname']).to eq 'ldap.example.com'
67
+ expect(cfg['ldap']['port']).to eq 389
68
+ expect(cfg['ldap']['base']).to eq 'ou=users,dc=example,dc=com'
69
+ expect(cfg['unknown']).to be_nil
70
70
  end
71
71
 
72
- it "raises an error when the local file is badly formatted" do
73
- bad = get_config("config.yml", "bad.yml")
74
- msg = "Wrong format for the config-local file!"
72
+ it 'raises an error when the local file is badly formatted' do
73
+ bad = get_config('config.yml', 'bad.yml')
74
+ msg = 'Wrong format for the config-local file!'
75
75
  expect { bad.fetch }.to raise_error(::CConfig::FormatError, msg)
76
76
  end
77
77
 
78
- it "returns the proper config while hiding passwords" do
79
- cfg = get_config("config.yml", "local.yml")
78
+ it 'does not raise an error if the local file is simply empty' do
79
+ empty = get_config('config.yml', 'empty.yml')
80
+ expect { empty.fetch }.not_to raise_error
81
+ end
82
+
83
+ it 'returns the proper config while hiding passwords' do
84
+ cfg = get_config('config.yml', 'local.yml')
80
85
  fetched = cfg.fetch
81
86
  evaled = YAML.safe_load(cfg.to_s)
82
87
 
83
88
  expect(fetched).not_to eq(evaled)
84
- fetched["ldap"]["authentication"]["password"] = "****"
89
+ fetched['ldap']['authentication']['password'] = '****'
85
90
  expect(fetched).to eq(evaled)
86
91
  end
87
92
  end
88
93
 
89
- describe "#enabled?" do
90
- it "works for nested options" do
91
- cfg = get_config("config.yml", "").fetch
92
- expect(cfg.enabled?("email.smtp")).to be true
94
+ describe '#enabled?' do
95
+ it 'works for nested options' do
96
+ cfg = get_config('config.yml', '').fetch
97
+ expect(cfg.enabled?('email.smtp')).to be true
93
98
  end
94
99
 
95
- it "works with environment variables" do
96
- ENV["TEST_EMAIL_SMTP_ENABLED"] = "false"
97
- cfg = get_config("config.yml", "").fetch
98
- expect(cfg.enabled?("email.smtp")).to be false
100
+ it 'works with environment variables' do
101
+ ENV['TEST_EMAIL_SMTP_ENABLED'] = 'false'
102
+ cfg = get_config('config.yml', '').fetch
103
+ expect(cfg.enabled?('email.smtp')).to be false
99
104
  end
100
105
 
101
- it "offers the #disabled? method" do
102
- cfg = get_config("config.yml", "").fetch
103
- expect(cfg).to be_disabled("ldap")
106
+ it 'offers the #disabled? method' do
107
+ cfg = get_config('config.yml', '').fetch
108
+ expect(cfg).to be_disabled('ldap')
104
109
  end
105
110
 
106
- it "handles enabled on nested elements" do
107
- cfg = get_config("config.yml", "").fetch
108
- expect(cfg).to be_enabled("delete")
109
- expect(cfg).to be_disabled("delete.garbage_collector")
111
+ it 'handles enabled on nested elements' do
112
+ cfg = get_config('config.yml', '').fetch
113
+ expect(cfg).to be_enabled('delete')
114
+ expect(cfg).to be_disabled('delete.garbage_collector')
110
115
  end
111
116
  end
112
117
 
113
- describe "#default_of" do
114
- it "returns the default when a local file has been added" do
115
- cfg = get_config("config.yml", "local.yml").fetch
118
+ describe '#default_of' do
119
+ it 'returns the default when a local file has been added' do
120
+ cfg = get_config('config.yml', 'local.yml').fetch
116
121
 
117
- expect(cfg["ldap"]["hostname"]).to eq("ldap.example.com")
118
- expect(cfg.default_of("ldap.hostname")).to eq("ldap_hostname")
122
+ expect(cfg['ldap']['hostname']).to eq('ldap.example.com')
123
+ expect(cfg.default_of('ldap.hostname')).to eq('ldap_hostname')
119
124
  end
120
125
 
121
- it "returns the default even if an environment variable was set" do
122
- ENV["TEST_LDAP_AUTHENTICATION_BIND_DN"] = "2"
123
- cfg = get_config("config.yml", "local.yml").fetch
126
+ it 'returns the default even if an environment variable was set' do
127
+ ENV['TEST_LDAP_AUTHENTICATION_BIND_DN'] = '2'
128
+ cfg = get_config('config.yml', 'local.yml').fetch
124
129
 
125
- expect(cfg["ldap"]["authentication"]["bind_dn"]).to eq(2)
126
- expect(cfg.default_of("ldap.authentication.bind_dn")).to eq("")
130
+ expect(cfg['ldap']['authentication']['bind_dn']).to eq(2)
131
+ expect(cfg.default_of('ldap.authentication.bind_dn')).to eq('')
127
132
  end
128
133
 
129
- it "returns nil for an unknown key" do
130
- cfg = get_config("config.yml", "local.yml").fetch
131
- expect(cfg.default_of("something.that.does.not.exist")).to be_nil
134
+ it 'returns nil for an unknown key' do
135
+ cfg = get_config('config.yml', 'local.yml').fetch
136
+ expect(cfg.default_of('something.that.does.not.exist')).to be_nil
132
137
  end
133
138
  end
134
139
  end
@@ -0,0 +1 @@
1
+ ---
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (C) 2017-2020 Miquel Sabaté Solà <msabate@suse.com>
3
+ # Copyright (C) 2017-2022 Miquel Sabaté Solà <msabate@suse.com>
4
4
  #
5
5
  # This file is part of CConfig.
6
6
  #
@@ -34,45 +34,45 @@ describe ::CConfig::HashUtils do
34
34
 
35
35
  let(:default) do
36
36
  {
37
- "gravatar" => { "enabled" => true },
38
- "another" => { "enabled" => true },
39
- "ldap" => {
40
- "enabled" => false,
41
- "count" => 0,
42
- "string" => ""
37
+ 'gravatar' => { 'enabled' => true },
38
+ 'another' => { 'enabled' => true },
39
+ 'ldap' => {
40
+ 'enabled' => false,
41
+ 'count' => 0,
42
+ 'string' => ''
43
43
  }
44
44
  }.freeze
45
45
  end
46
46
 
47
47
  let(:local) do
48
48
  {
49
- "ldap" => {
50
- "enabled" => true,
51
- "count" => 1
49
+ 'ldap' => {
50
+ 'enabled' => true,
51
+ 'count' => 1
52
52
  }
53
53
  }.freeze
54
54
  end
55
55
 
56
- it "merges hashes in a strict manner while evaluating env variables first" do
57
- ENV["TEST_LDAP_COUNT"] = "2"
58
- ENV["TEST_ANOTHER_ENABLED"] = "false"
59
- ENV["TEST_LDAP_STRING"] = "string"
56
+ it 'merges hashes in a strict manner while evaluating env variables first' do
57
+ ENV['TEST_LDAP_COUNT'] = '2'
58
+ ENV['TEST_ANOTHER_ENABLED'] = 'false'
59
+ ENV['TEST_LDAP_STRING'] = 'string'
60
60
 
61
- cfg = ConfigMock.new.strict_merge_with_env_test(default: default, local: local, prefix: "test")
62
- expect(cfg["gravatar"]["enabled"]).to be true # default
63
- expect(cfg["another"]["enabled"]).to be false # env
64
- expect(cfg["ldap"]["enabled"]).to be true # local
65
- expect(cfg["ldap"]["count"]).to eq 2 # env
66
- expect(cfg["ldap"]["string"]).to eq "string" # env
61
+ cfg = ConfigMock.new.strict_merge_with_env_test(default: default, local: local, prefix: 'test')
62
+ expect(cfg['gravatar']['enabled']).to be true # default
63
+ expect(cfg['another']['enabled']).to be false # env
64
+ expect(cfg['ldap']['enabled']).to be true # local
65
+ expect(cfg['ldap']['count']).to eq 2 # env
66
+ expect(cfg['ldap']['string']).to eq 'string' # env
67
67
  end
68
68
 
69
69
  # See issue #3
70
70
  it "does not crash on nested default that doesn't exist" do
71
- cfg = ConfigMock.new.strict_merge_with_env_test(default: default, local: local, prefix: "test")
71
+ cfg = ConfigMock.new.strict_merge_with_env_test(default: default, local: local, prefix: 'test')
72
72
 
73
73
  cfg.extend(::CConfig::HashUtils::Extensions)
74
- expect(cfg).to be_enabled("gravatar")
75
- expect(cfg).not_to be_enabled("oauth.google_oauth2")
76
- expect(cfg).not_to be_enabled("something.that.does.not.exist")
74
+ expect(cfg).to be_enabled('gravatar')
75
+ expect(cfg).not_to be_enabled('oauth.google_oauth2')
76
+ expect(cfg).not_to be_enabled('something.that.does.not.exist')
77
77
  end
78
78
  end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (C) 2017-2020 Miquel Sabaté Solà <msabate@suse.com>
3
+ # Copyright (C) 2017-2022 Miquel Sabaté Solà <msabate@suse.com>
4
4
  #
5
5
  # This file is part of CConfig.
6
6
  #
@@ -17,14 +17,14 @@
17
17
  # You should have received a copy of the GNU Lesser General Public License
18
18
  # along with CConfig. If not, see <http://www.gnu.org/licenses/>.
19
19
 
20
- require "codeclimate-test-reporter"
20
+ require 'codeclimate-test-reporter'
21
21
  CodeClimate::TestReporter.start
22
22
 
23
- require "simplecov"
23
+ require 'simplecov'
24
24
 
25
25
  SimpleCov.minimum_coverage 100
26
26
  SimpleCov.start do
27
- add_group "lib", "lib"
27
+ add_group 'lib', 'lib'
28
28
  end
29
29
 
30
30
  RSpec.configure do |config|
metadata CHANGED
@@ -1,33 +1,33 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cconfig
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - mssola
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-26 00:00:00.000000000 Z
11
+ date: 2022-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: safe_yaml
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: 1.0.0
20
- - - "~>"
20
+ - - ">="
21
21
  - !ruby/object:Gem::Version
22
22
  version: 1.0.0
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - ">="
27
+ - - "~>"
28
28
  - !ruby/object:Gem::Version
29
29
  version: 1.0.0
30
- - - "~>"
30
+ - - ">="
31
31
  - !ruby/object:Gem::Version
32
32
  version: 1.0.0
33
33
  - !ruby/object:Gem::Dependency
@@ -76,18 +76,32 @@ dependencies:
76
76
  name: rubocop
77
77
  requirement: !ruby/object:Gem::Requirement
78
78
  requirements:
79
- - - "~>"
79
+ - - ">="
80
80
  - !ruby/object:Gem::Version
81
- version: 0.80.0
81
+ version: '1.0'
82
82
  type: :development
83
83
  prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
- - - "~>"
86
+ - - ">="
87
87
  - !ruby/object:Gem::Version
88
- version: 0.80.0
88
+ version: '1.0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: rubocop-performance
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
89
103
  - !ruby/object:Gem::Dependency
90
- name: rubocop-rspec
104
+ name: rubocop-rake
91
105
  requirement: !ruby/object:Gem::Requirement
92
106
  requirements:
93
107
  - - ">="
@@ -107,10 +121,9 @@ executables: []
107
121
  extensions: []
108
122
  extra_rdoc_files: []
109
123
  files:
124
+ - ".github/workflows/ruby.yml"
110
125
  - ".gitignore"
111
- - ".rspec"
112
126
  - ".rubocop.yml"
113
- - ".travis.yml"
114
127
  - CHANGELOG.md
115
128
  - CONTRIBUTING.md
116
129
  - COPYING
@@ -130,13 +143,15 @@ files:
130
143
  - spec/config_spec.rb
131
144
  - spec/fixtures/bad.yml
132
145
  - spec/fixtures/config.yml
146
+ - spec/fixtures/empty.yml
133
147
  - spec/fixtures/local.yml
134
148
  - spec/hash_utils_spec.rb
135
149
  - spec/spec_helper.rb
136
150
  homepage: https://github.com/mssola/cconfig
137
151
  licenses:
138
152
  - LGPL-3.0
139
- metadata: {}
153
+ metadata:
154
+ rubygems_mfa_required: 'true'
140
155
  post_install_message:
141
156
  rdoc_options: []
142
157
  require_paths:
@@ -145,14 +160,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
145
160
  requirements:
146
161
  - - ">="
147
162
  - !ruby/object:Gem::Version
148
- version: '2.3'
163
+ version: 2.7.0
149
164
  required_rubygems_version: !ruby/object:Gem::Requirement
150
165
  requirements:
151
166
  - - ">="
152
167
  - !ruby/object:Gem::Version
153
168
  version: '0'
154
169
  requirements: []
155
- rubygems_version: 3.0.3
170
+ rubygems_version: 3.3.7
156
171
  signing_key:
157
172
  specification_version: 4
158
173
  summary: Configuration management for container-aware applications.
data/.rspec DELETED
@@ -1 +0,0 @@
1
- --color
data/.travis.yml DELETED
@@ -1,27 +0,0 @@
1
- language: ruby
2
-
3
- cache: bundler
4
-
5
- sudo: false
6
-
7
- rvm:
8
- - 2.3
9
- - 2.4
10
- - 2.5
11
- - 2.6
12
- - 2.7
13
- - ruby-head
14
-
15
- before_install:
16
- - gem update --system
17
- - gem install bundler
18
-
19
- script:
20
- - bundle exec rspec
21
- - bundle exec rubocop -V
22
- - bundle exec rubocop -F
23
-
24
- matrix:
25
- allow_failures:
26
- - rvm: ruby-head
27
- fast_finish: true