cconfig 1.0.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.
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,57 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ cconfig (1.0.0rc1)
5
+ safe_yaml (~> 1.0.0, >= 1.0.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.3.0)
11
+ diff-lcs (1.3)
12
+ parallel (1.12.0)
13
+ parser (2.4.0.0)
14
+ ast (~> 2.2)
15
+ powerpack (0.1.1)
16
+ rainbow (2.2.2)
17
+ rake
18
+ rake (12.0.0)
19
+ rspec (3.6.0)
20
+ rspec-core (~> 3.6.0)
21
+ rspec-expectations (~> 3.6.0)
22
+ rspec-mocks (~> 3.6.0)
23
+ rspec-core (3.6.0)
24
+ rspec-support (~> 3.6.0)
25
+ rspec-expectations (3.6.0)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.6.0)
28
+ rspec-mocks (3.6.0)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.6.0)
31
+ rspec-support (3.6.0)
32
+ rubocop (0.49.1)
33
+ parallel (~> 1.10)
34
+ parser (>= 2.3.3.1, < 3.0)
35
+ powerpack (~> 0.1)
36
+ rainbow (>= 1.99.1, < 3.0)
37
+ ruby-progressbar (~> 1.7)
38
+ unicode-display_width (~> 1.0, >= 1.0.1)
39
+ rubocop-rspec (1.15.1)
40
+ rubocop (>= 0.42.0)
41
+ ruby-progressbar (1.8.1)
42
+ safe_yaml (1.0.4)
43
+ unicode-display_width (1.3.0)
44
+
45
+ PLATFORMS
46
+ ruby
47
+
48
+ DEPENDENCIES
49
+ bundler (>= 1.0.0)
50
+ cconfig!
51
+ rake (>= 10.0)
52
+ rspec (>= 3.0)
53
+ rubocop (~> 0.49.1)
54
+ rubocop-rspec
55
+
56
+ BUNDLED WITH
57
+ 1.15.3
@@ -0,0 +1,139 @@
1
+ # CConfig [![Build Status](https://travis-ci.org/mssola/cconfig.svg?branch=master)](https://travis-ci.org/mssola/cconfig)
2
+
3
+ CConfig (Container Config) is a container-aware configuration management
4
+ gem. This is useful for applications that want to keep a reference configuration
5
+ and add modifications to it in two different ways:
6
+
7
+ - An alternative configuration file that lists all the modifications.
8
+ - A list of environment variables that follow a given naming policy.
9
+
10
+ ## Basic usage
11
+
12
+ Let's assume that our application has a `config.yml` file that contains all the
13
+ possible configurable values with their defaults:
14
+
15
+ ```yaml
16
+ option:
17
+ enabled: true
18
+
19
+ another:
20
+ value: 5
21
+ ```
22
+
23
+ Then, you will have the following (irb prompt):
24
+
25
+ ```
26
+ >> require "cconfig/cconfig"
27
+ >> cfg = ::CConfig::Config.new(default: "config.yml", local: "", prefix: "")
28
+ >> obj = cfg.fetch
29
+ >> puts obj
30
+ => {"option"=>{"enabled"=>true}, "another"=>{"value"=>5}}
31
+ ```
32
+
33
+ Moreover, this gem also adds an `enabled?` method to this hash returned by
34
+ `#fetch`. With this method, configurable values with an `enabled` boolean value
35
+ will have this shorthand available. For example:
36
+
37
+ ```
38
+ >> obj.enabled?("option")
39
+ => true
40
+ >> obj.enabled?("another")
41
+ => false
42
+ ```
43
+
44
+ This also works for embedded configurable options. From the above example, let's
45
+ assume that we update the `config.yml` file with these contents:
46
+
47
+ ```yaml
48
+ option:
49
+ enabled: true
50
+
51
+ embedded:
52
+ enabled: false
53
+
54
+ another:
55
+ value: 5
56
+ ```
57
+
58
+ Let's also add an alternative configuration file with these contents:
59
+
60
+ ```yaml
61
+ option:
62
+ embedded:
63
+ enabled: true
64
+ ```
65
+
66
+ Then we have the following:
67
+
68
+ ```
69
+ >> cfg = ::CConfig::Config.new(default: "config.yml", local: "config-local.yml", prefix: "")
70
+ >> obj = cfg.fetch
71
+ => {"option"=>{"enabled"=>true, "embedded"=>{"enabled"=>true}}, "another"=>{"value"=>5}}
72
+ >> obj.enabled?("option.embedded")
73
+ => true
74
+ ```
75
+
76
+ As you can see, the contents from the `config-local.yml` file that are available
77
+ in the `config.yml` have been overwritten.
78
+
79
+ That being said, mounting a volume for changing some default values inside of a
80
+ Docker container is a bit of an overkill. So, instead you can use **environment
81
+ variables**. In the above example we can add an environment variable (shell prompt):
82
+
83
+ ```
84
+ $ export APPLICATION_ANOTHER_VALUE=2
85
+ ```
86
+
87
+ Then (irb prompt):
88
+
89
+ ```
90
+ >> cfg = ::CConfig::Config.new(default: "config.yml", local: "config-local.yml", prefix: "application")
91
+ >> cfg.fetch
92
+ => {"option"=>{"enabled"=>true, "embedded"=>{"enabled"=>true}}, "another"=>{"value"=>2}}
93
+ ```
94
+
95
+ Moreover, the environment variable value takes precedence over the
96
+ `config-local.yml` file.
97
+
98
+ ## Ruby on Rails integration
99
+
100
+ This gem also provides a Railtie, so it can be better used inside of a Ruby on
101
+ Rails application.
102
+
103
+ First of all, this Railtie will initialize a global constant named `APP_CONFIG`
104
+ automatically with the merged contents of the configuration files and
105
+ environment variables. Some notes:
106
+
107
+ - The *prefix* is taken from the Rails' application name. If you don't want
108
+ this, set the `CCONFIG_PREFIX` environment variable.
109
+ - The file with the default values has to be located in `config/config.yml` from
110
+ your Ruby on Rails root directory. Moreover, the other file is located in
111
+ `config/config-local.yml`, but this can be changed by setting the
112
+ `#{prefix}_LOCAL_CONFIG_PATH` environment variable.
113
+
114
+ Last but not least, this Railtie also offers a rake task called
115
+ `cconfig:info`. This rake task prints to standard output the evaluated
116
+ configuration.
117
+
118
+ ## License
119
+
120
+ This project is based on work I did for the
121
+ [Portus](https://github.com/SUSE/Portus) project. I've extracted my code into a
122
+ gem so it can be also used for other projects that might be interested in this.
123
+
124
+ ```
125
+ Copyright (C) 2017 Miquel Sabaté Solà <msabate@suse.com>
126
+
127
+ CConfig is free software: you can redistribute it and/or modify
128
+ it under the terms of the GNU Lesser General Public License as published by
129
+ the Free Software Foundation, either version 3 of the License, or
130
+ (at your option) any later version.
131
+
132
+ CConfig is distributed in the hope that it will be useful,
133
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
134
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
135
+ GNU General Public License for more details.
136
+
137
+ You should have received a copy of the GNU Lesser General Public License
138
+ along with CConfig. If not, see <http://www.gnu.org/licenses/>.
139
+ ```
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+
3
+ # Copyright (C) 2017 Miquel Sabaté Solà <msabate@suse.com>
4
+ #
5
+ # This file is part of CConfig.
6
+ #
7
+ # CConfig is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Lesser General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # CConfig is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public License
18
+ # along with CConfig. If not, see <http://www.gnu.org/licenses/>.
19
+
20
+ require "rspec/core/rake_task"
21
+ RSpec::Core::RakeTask.new(:spec)
22
+
23
+ task default: [:spec]
24
+ task test: :spec
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path("../lib", __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ require "cconfig/version"
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = "cconfig"
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"
17
+
18
+ spec.files = `git ls-files`.split($RS)
19
+ spec.test_files = spec.files.grep("^spec/")
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.required_ruby_version = ">= 2.1"
23
+
24
+ spec.add_dependency "safe_yaml", "~> 1.0.0", ">= 1.0.0"
25
+
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.49.1"
30
+ spec.add_development_dependency "rubocop-rspec"
31
+ end
@@ -0,0 +1,74 @@
1
+ # This is the shared Rubocop configuration for SUSE projects. It is maintained
2
+ # at https://github.com/SUSE/style-guides/blob/master/rubocop-suse.yml
3
+ #
4
+ # The configuration is tested and used with the Rubocop version used by Hound
5
+ # (https://houndci.com).
6
+ #
7
+ # We use the default Hound config as a baseline:
8
+ #
9
+ # https://raw.githubusercontent.com/thoughtbot/hound/master/config/style_guides/ruby.yml
10
+ #
11
+ # This file contains the rules with derive from this.
12
+
13
+ Lint/EndAlignment:
14
+ StyleGuide: https://github.com/SUSE/style-guides/blob/master/Ruby.md#lintendalignment
15
+ EnforcedStyleAlignWith: variable
16
+
17
+ Metrics/AbcSize:
18
+ StyleGuide: https://github.com/SUSE/style-guides/blob/master/Ruby.md#metricsabcsize
19
+ Max: 30
20
+
21
+ Metrics/LineLength:
22
+ StyleGuide: https://github.com/SUSE/style-guides/blob/master/Ruby.md#metricslinelength
23
+ Max: 100
24
+ # To make it possible to copy or click on URIs in the code, we allow lines
25
+ # contaning a URI to be longer than Max.
26
+ AllowURI: true
27
+ URISchemes:
28
+ - http
29
+ - https
30
+
31
+ Layout/AlignHash:
32
+ StyleGuide: https://github.com/SUSE/style-guides/blob/master/Ruby.md#stylealignhash
33
+ EnforcedHashRocketStyle: table
34
+ EnforcedColonStyle: table
35
+
36
+ Layout/AlignParameters:
37
+ StyleGuide: https://github.com/SUSE/style-guides/blob/master/Ruby.md#stylealignparameters
38
+ Enabled: false
39
+
40
+ Style/CollectionMethods:
41
+ StyleGuide: https://github.com/SUSE/style-guides/blob/master/Ruby.md#stylecollectionmethods
42
+ Enabled: false
43
+
44
+ Layout/EmptyLinesAroundBlockBody:
45
+ StyleGuide: https://github.com/SUSE/style-guides/blob/master/Ruby.md#styleemptylinesaroundblockbody
46
+ Enabled: false
47
+
48
+ Layout/MultilineOperationIndentation:
49
+ StyleGuide: https://github.com/SUSE/style-guides/blob/master/Ruby.md#stylemultilineoperationindentation
50
+ EnforcedStyle: indented
51
+
52
+ Style/StringLiterals:
53
+ StyleGuide: https://github.com/SUSE/style-guides/blob/master/Ruby.md#stylestringliterals
54
+ EnforcedStyle: double_quotes
55
+
56
+ Style/StringLiteralsInInterpolation:
57
+ StyleGuide: https://github.com/SUSE/style-guides/blob/master/Ruby.md#stylestringliteralsininterpolation
58
+ EnforcedStyle: double_quotes
59
+
60
+ Style/WordArray:
61
+ StyleGuide: https://github.com/SUSE/style-guides/blob/master/Ruby.md#deviations-from-the-upstream-style-guide
62
+ Enabled: false
63
+
64
+ Style/RegexpLiteral:
65
+ StyleGuide: https://github.com/SUSE/style-guides/blob/master/Ruby.md#deviations-from-the-upstream-style-guide
66
+ Enabled: false
67
+
68
+ Style/SignalException:
69
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#fail-method
70
+ EnforcedStyle: only_raise
71
+
72
+ Style/NumericLiterals:
73
+ StyleGuide: https://github.com/SUSE/style-guides/blob/master/Ruby.md#stylenumericliterals
74
+ Enabled: false