confswap 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +44 -0
- data/.travis.yml +3 -0
- data/Gemfile +13 -0
- data/Guardfile +5 -0
- data/LICENSE +202 -0
- data/README.md +63 -0
- data/Rakefile +17 -0
- data/bin/confswap +8 -0
- data/confswap.gemspec +15 -0
- data/features/overwrite_existing_file.feature +3 -0
- data/features/support/env.rb +2 -0
- data/features/support/hooks.rb +7 -0
- data/features/swap.feature +26 -0
- data/lib/confswap/command.rb +75 -0
- data/lib/confswap/conf_reader.rb +7 -0
- data/lib/confswap/env_reader.rb +7 -0
- data/lib/confswap/version.rb +3 -0
- data/lib/confswap.rb +3 -0
- data/spec/conf_reader_spec.rb +20 -0
- data/spec/env_reader_spec.rb +12 -0
- data/spec/spec_helper.rb +16 -0
- metadata +72 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1dd67f5b084096165578ad492543a3573786f49a
|
4
|
+
data.tar.gz: 82b6e68ce88949d2cfe60234fd1faf10f0e3c4c4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c47dbc00b593461e9081146e2de2e38fbaa993e1d401e4a6401b75540fd767f5a1c153d95eb2c49706d285f418149059c82f191999e860c4d8d1fbee90b2bec2
|
7
|
+
data.tar.gz: 4523d361fe485aadc40013d38eaf61f665f6582305852552f1d9a773737b88c91f8fdc15d3596675e6352f4b6860fbe60dd55b4f482887ad666be7f4bf1105ba
|
data/.gitignore
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
## Ignore bundle lock
|
2
|
+
*.lock
|
3
|
+
|
4
|
+
## My little test files
|
5
|
+
test.conf
|
6
|
+
test.conf.out
|
7
|
+
|
8
|
+
## Ignore Vim swp
|
9
|
+
*.swp
|
10
|
+
|
11
|
+
*.gem
|
12
|
+
*.rbc
|
13
|
+
/.config
|
14
|
+
/coverage/
|
15
|
+
/InstalledFiles
|
16
|
+
/pkg/
|
17
|
+
/spec/reports/
|
18
|
+
/test/tmp/
|
19
|
+
/test/version_tmp/
|
20
|
+
/tmp/
|
21
|
+
|
22
|
+
## Specific to RubyMotion:
|
23
|
+
.dat*
|
24
|
+
.repl_history
|
25
|
+
build/
|
26
|
+
|
27
|
+
## Documentation cache and generated files:
|
28
|
+
/.yardoc/
|
29
|
+
/_yardoc/
|
30
|
+
/doc/
|
31
|
+
/rdoc/
|
32
|
+
|
33
|
+
## Environment normalisation:
|
34
|
+
/.bundle/
|
35
|
+
/lib/bundler/man/
|
36
|
+
|
37
|
+
# for a library or gem, you might want to ignore these files since the code is
|
38
|
+
# intended to run in multiple environments; otherwise, check them in:
|
39
|
+
# Gemfile.lock
|
40
|
+
# .ruby-version
|
41
|
+
# .ruby-gemset
|
42
|
+
|
43
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
44
|
+
.rvmrc
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
+
the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
+
other entities that control, are controlled by, or are under common
|
17
|
+
control with that entity. For the purposes of this definition,
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
19
|
+
direction or management of such entity, whether by contract or
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
+
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
+
exercising permissions granted by this License.
|
25
|
+
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
27
|
+
including but not limited to software source code, documentation
|
28
|
+
source, and configuration files.
|
29
|
+
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
31
|
+
transformation or translation of a Source form, including but
|
32
|
+
not limited to compiled object code, generated documentation,
|
33
|
+
and conversions to other media types.
|
34
|
+
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
36
|
+
Object form, made available under the License, as indicated by a
|
37
|
+
copyright notice that is included in or attached to the work
|
38
|
+
(an example is provided in the Appendix below).
|
39
|
+
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
+
the Work and Derivative Works thereof.
|
47
|
+
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
49
|
+
the original version of the Work and any modifications or additions
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
+
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
64
|
+
subsequently incorporated within the Work.
|
65
|
+
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
72
|
+
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
+
where such license applies only to those patent claims licensable
|
79
|
+
by such Contributor that are necessarily infringed by their
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
82
|
+
institute patent litigation against any entity (including a
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
85
|
+
or contributory patent infringement, then any patent licenses
|
86
|
+
granted to You under this License for that Work shall terminate
|
87
|
+
as of the date such litigation is filed.
|
88
|
+
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
91
|
+
modifications, and in Source or Object form, provided that You
|
92
|
+
meet the following conditions:
|
93
|
+
|
94
|
+
(a) You must give any other recipients of the Work or
|
95
|
+
Derivative Works a copy of this License; and
|
96
|
+
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
98
|
+
stating that You changed the files; and
|
99
|
+
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
102
|
+
attribution notices from the Source form of the Work,
|
103
|
+
excluding those notices that do not pertain to any part of
|
104
|
+
the Derivative Works; and
|
105
|
+
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
108
|
+
include a readable copy of the attribution notices contained
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
111
|
+
of the following places: within a NOTICE text file distributed
|
112
|
+
as part of the Derivative Works; within the Source form or
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
114
|
+
within a display generated by the Derivative Works, if and
|
115
|
+
wherever such third-party notices normally appear. The contents
|
116
|
+
of the NOTICE file are for informational purposes only and
|
117
|
+
do not modify the License. You may add Your own attribution
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
120
|
+
that such additional attribution notices cannot be construed
|
121
|
+
as modifying the License.
|
122
|
+
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
124
|
+
may provide additional or different license terms and conditions
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
128
|
+
the conditions stated in this License.
|
129
|
+
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
133
|
+
this License, without any additional terms or conditions.
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
+
the terms of any separate license agreement you may have executed
|
136
|
+
with Licensor regarding such Contributions.
|
137
|
+
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
140
|
+
except as required for reasonable and customary use in describing the
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
+
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
152
|
+
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
158
|
+
incidental, or consequential damages of any character arising as a
|
159
|
+
result of this License or out of the use or inability to use the
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
162
|
+
other commercial damages or losses), even if such Contributor
|
163
|
+
has been advised of the possibility of such damages.
|
164
|
+
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
+
or other liability obligations and/or rights consistent with this
|
169
|
+
License. However, in accepting such obligations, You may act only
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
174
|
+
of your accepting any such warranty or additional liability.
|
175
|
+
|
176
|
+
END OF TERMS AND CONDITIONS
|
177
|
+
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
179
|
+
|
180
|
+
To apply the Apache License to your work, attach the following
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
182
|
+
replaced with your own identifying information. (Don't include
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
184
|
+
comment syntax for the file format. We also recommend that a
|
185
|
+
file or class name and description of purpose be included on the
|
186
|
+
same "printed page" as the copyright notice for easier
|
187
|
+
identification within third-party archives.
|
188
|
+
|
189
|
+
Copyright {yyyy} {name of copyright owner}
|
190
|
+
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192
|
+
you may not use this file except in compliance with the License.
|
193
|
+
You may obtain a copy of the License at
|
194
|
+
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
196
|
+
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200
|
+
See the License for the specific language governing permissions and
|
201
|
+
limitations under the License.
|
202
|
+
|
data/README.md
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# confswap [![Build Status](https://travis-ci.org/tlcowling/confswap.svg?branch=master)](https://travis-ci.org/tlcowling/confswap) [![Dependency Status](https://gemnasium.com/tlcowling/confswap.svg)](https://gemnasium.com/tlcowling/confswap) [![Code Climate](https://codeclimate.com/github/tlcowling/confswap/badges/gpa.svg)](https://codeclimate.com/github/tlcowling/confswap)
|
2
|
+
:cow: :cow2: :cow: :cow2: :cow: :cow2: :cow: :cow2: :cow: :cow2: :cow: :cow2: :cow: :cow2: :cow: :cow2: :cow: :cow2: :cow: :cow2: :cow: :cow2: :cow: :cow2: :cow: :cow2: :cow: :cow2: :cow:
|
3
|
+
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
A simple command line tool to take a configuration file with template placeholders and replace those placeholders with environment variables.
|
8
|
+
|
9
|
+
It appears to be taking the shape of a ruby gem...
|
10
|
+
|
11
|
+
## Introduction
|
12
|
+
|
13
|
+
This is mostly for me to use as a convenience tool when creating docker containers.
|
14
|
+
|
15
|
+
When working with elasticsearch, I have used their system for using environment variables in the config, and this has worked very well for me especially when using ENV variables with docker run.
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
Config files can use the `%{}` style to replace a token in a stirng with a variable
|
20
|
+
|
21
|
+
`export GIBLET_STATUS=active`
|
22
|
+
`export SPLENETIC_JUICE_FACTOR=10`
|
23
|
+
|
24
|
+
`example.conf|.toml|.yaml`
|
25
|
+
```
|
26
|
+
# This is a configuration file
|
27
|
+
giblet_status=%{GIBLETS_STATUS}
|
28
|
+
splenetic_juice_factor=%{SPLENETIC_JUICE_FACTOR}
|
29
|
+
```
|
30
|
+
|
31
|
+
Then run confswap on the file
|
32
|
+
|
33
|
+
## Requirements
|
34
|
+
|
35
|
+
Requires ruby version > 2.0
|
36
|
+
Bundle install the gems
|
37
|
+
|
38
|
+
## Developments
|
39
|
+
|
40
|
+
Please feel free to fork and whatnot...
|
41
|
+
|
42
|
+
Get the dependencies
|
43
|
+
``bundle install``
|
44
|
+
|
45
|
+
Run the tests
|
46
|
+
``rake spec``
|
47
|
+
|
48
|
+
### Optional:
|
49
|
+
Use guard to rerun tests as you go...
|
50
|
+
``guard``
|
51
|
+
|
52
|
+
## Tasks to do and improvement ideas
|
53
|
+
|
54
|
+
- ~~error message when config contains env variable that doesnt exist~~
|
55
|
+
- verbose command
|
56
|
+
- summary of what will change? dry-run maybe?
|
57
|
+
- test command.rb
|
58
|
+
- ~~acceptance tests~~
|
59
|
+
|
60
|
+
- internationalization :)
|
61
|
+
- document...
|
62
|
+
- diff on what has changed in a config if overwriting?
|
63
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
require 'rspec/core/rake_task'
|
4
|
+
require 'cucumber'
|
5
|
+
require 'cucumber/rake/task'
|
6
|
+
|
7
|
+
Cucumber::Rake::Task.new(:features) do |t|
|
8
|
+
t.cucumber_opts = "features --format pretty"
|
9
|
+
end
|
10
|
+
|
11
|
+
RSpec::Core::RakeTask.new(:spec)
|
12
|
+
|
13
|
+
task :default => ['spec']
|
14
|
+
task :test => ['spec','features']
|
15
|
+
|
16
|
+
rescue LoadError
|
17
|
+
end
|
data/bin/confswap
ADDED
data/confswap.gemspec
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'confswap'
|
3
|
+
s.version = '0.0.1'
|
4
|
+
s.licenses = ['APACHE2']
|
5
|
+
s.summary = "Confswap swaps conf variables!"
|
6
|
+
s.description = "Create a configuration from a template using environment variables"
|
7
|
+
s.authors = ["Tom Cowling"]
|
8
|
+
s.email = 'tom.cowling@gmail.com'
|
9
|
+
s.homepage = 'https://www.tlcowling.com/gems/confswap'
|
10
|
+
|
11
|
+
s.files = `git ls-files`.split("\n")
|
12
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
13
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
14
|
+
s.require_paths = ["lib"]
|
15
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
Feature: Confswap should swap template variables
|
2
|
+
Background:
|
3
|
+
Given a file named "/tmp/confswap/test.conf" with:
|
4
|
+
"""
|
5
|
+
# This is a test config
|
6
|
+
# that has some variables in it
|
7
|
+
%{TEST}
|
8
|
+
"""
|
9
|
+
And I set the environment variables to:
|
10
|
+
| variable | value |
|
11
|
+
| TEST | giblets |
|
12
|
+
|
13
|
+
Scenario: Test config file with placeholders rename standard
|
14
|
+
When I run `confswap /tmp/confswap/test.conf`
|
15
|
+
Then the file "/tmp/confswap/test.conf.out" should contain:
|
16
|
+
"""
|
17
|
+
giblets
|
18
|
+
"""
|
19
|
+
Scenario: Test config file specifying the output
|
20
|
+
When I run `confswap --output=/tmp/confswap/different.conf /tmp/confswap/test.conf`
|
21
|
+
Then a file named "/tmp/confswap/different.conf" should exist
|
22
|
+
And the file "/tmp/confswap/different.conf" should contain:
|
23
|
+
"""
|
24
|
+
giblets
|
25
|
+
"""
|
26
|
+
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'clamp'
|
2
|
+
require 'confswap'
|
3
|
+
|
4
|
+
module Confswap
|
5
|
+
class Command < Clamp::Command
|
6
|
+
def initialize(*args)
|
7
|
+
super(*args)
|
8
|
+
end
|
9
|
+
def help(*args)
|
10
|
+
return [
|
11
|
+
"This is confswap version #{Confswap::VERSION}",
|
12
|
+
super
|
13
|
+
].join("\n")
|
14
|
+
end
|
15
|
+
|
16
|
+
def run(*args)
|
17
|
+
super(*args)
|
18
|
+
end
|
19
|
+
|
20
|
+
def execute
|
21
|
+
|
22
|
+
if version?
|
23
|
+
puts Confswap::VERSION
|
24
|
+
return 0
|
25
|
+
end
|
26
|
+
|
27
|
+
if configuration_filename.nil?
|
28
|
+
puts 'Specify a template file or use --help for usage information'
|
29
|
+
return 0
|
30
|
+
end
|
31
|
+
|
32
|
+
if File.exists? configuration_filename
|
33
|
+
swap_config configuration_filename
|
34
|
+
return 0
|
35
|
+
else
|
36
|
+
puts "Error: Configuration template file with name #{configuration_filename} does not exist"
|
37
|
+
return 1
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def swap_config configuration_filename
|
42
|
+
output_filename_default = configuration_filename + '.out' if output_filename.nil?
|
43
|
+
|
44
|
+
configuration_template = Confswap::ConfigurationFileReader.read configuration_filename
|
45
|
+
env_variables = Confswap::EnvironmentVariableReader.read_variables
|
46
|
+
|
47
|
+
begin
|
48
|
+
output = configuration_template % env_variables
|
49
|
+
rescue KeyError => error
|
50
|
+
puts "#{error.message}. Your configuration specifies this variable, but it was not found as an environment variable."
|
51
|
+
exit(1)
|
52
|
+
end
|
53
|
+
|
54
|
+
write_file output, output_filename || output_filename_default
|
55
|
+
end
|
56
|
+
|
57
|
+
def write_file output_file_contents, output_filename
|
58
|
+
return File.write output_filename, output_file_contents unless File.exists? output_filename
|
59
|
+
|
60
|
+
if File.exists? output_filename and force?
|
61
|
+
puts "Overwriting #{output_filename}..."
|
62
|
+
File.write output_filename, output_file_contents
|
63
|
+
else
|
64
|
+
puts "#{output_filename} already exists, use the --force flag to overwrite"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
option ['-f','--force'], :flag, "Overwrite file if it already exists", :attribute_name => :force
|
69
|
+
option ['-v', '--version'], :flag, "The version of confswap you are running", :attribute_name => :version
|
70
|
+
option ['-o', '--output'], "FILE", "Specifies the filepath for the file", :attribute_name => :output_filename
|
71
|
+
option ['--verbose'], :flag, "Be more verbose"
|
72
|
+
|
73
|
+
parameter "[TEMPLATE_FILE]", "Path to the configuration file", :attribute_name => :configuration_filename
|
74
|
+
end
|
75
|
+
end
|
data/lib/confswap.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'confswap/conf_reader'
|
2
|
+
require_relative './spec_helper.rb'
|
3
|
+
|
4
|
+
describe 'Confswap::ConfigFileReader' do
|
5
|
+
before(:each) do
|
6
|
+
File.write('/tmp/test.txt', sample_config)
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should read the contents of a file specified' do
|
10
|
+
expect(Confswap::ConfigurationFileReader.read '/tmp/test.txt').to eql(sample_config)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should return nil if the file does not exist' do
|
14
|
+
expect(Confswap::ConfigurationFileReader.read '/path/does/not/exist.txt').to be_nil
|
15
|
+
end
|
16
|
+
|
17
|
+
after(:each) do
|
18
|
+
File.delete('/tmp/test.txt') if File.exists?('/tmp/test.txt')
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'confswap/env_reader'
|
2
|
+
|
3
|
+
describe 'Confswap::EnvironmentVariableReader' do
|
4
|
+
it 'should read environment variables and store them in a hash' do
|
5
|
+
env_variables = Confswap::EnvironmentVariableReader.read_variables
|
6
|
+
expect(env_variables).to be_instance_of Hash
|
7
|
+
end
|
8
|
+
it 'should store the environment variable FOO=bar in a hash' do
|
9
|
+
ENV['FOO']="bar"
|
10
|
+
expect(Confswap::EnvironmentVariableReader.read_variables).to include(:FOO => "bar")
|
11
|
+
end
|
12
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start
|
3
|
+
|
4
|
+
def sample_config
|
5
|
+
[ "# This is a sample config",
|
6
|
+
"# A bunch of lines that will be in a file",
|
7
|
+
"# Because thats what its all about",
|
8
|
+
"test=%{ITEM1}",
|
9
|
+
"test2=%{ITEM2}",
|
10
|
+
"test3=%{ITEM3}"
|
11
|
+
].join("\n")
|
12
|
+
end
|
13
|
+
|
14
|
+
def sample_variables
|
15
|
+
{ :ITEM1 => "localhost", :ITEM2 => "8.8.8.8", :ITEM3 => 1 }
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: confswap
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tom Cowling
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-16 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Create a configuration from a template using environment variables
|
14
|
+
email: tom.cowling@gmail.com
|
15
|
+
executables:
|
16
|
+
- confswap
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".gitignore"
|
21
|
+
- ".travis.yml"
|
22
|
+
- Gemfile
|
23
|
+
- Guardfile
|
24
|
+
- LICENSE
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- bin/confswap
|
28
|
+
- confswap.gemspec
|
29
|
+
- features/overwrite_existing_file.feature
|
30
|
+
- features/support/env.rb
|
31
|
+
- features/support/hooks.rb
|
32
|
+
- features/swap.feature
|
33
|
+
- lib/confswap.rb
|
34
|
+
- lib/confswap/command.rb
|
35
|
+
- lib/confswap/conf_reader.rb
|
36
|
+
- lib/confswap/env_reader.rb
|
37
|
+
- lib/confswap/version.rb
|
38
|
+
- spec/conf_reader_spec.rb
|
39
|
+
- spec/env_reader_spec.rb
|
40
|
+
- spec/spec_helper.rb
|
41
|
+
homepage: https://www.tlcowling.com/gems/confswap
|
42
|
+
licenses:
|
43
|
+
- APACHE2
|
44
|
+
metadata: {}
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
requirements: []
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 2.2.2
|
62
|
+
signing_key:
|
63
|
+
specification_version: 4
|
64
|
+
summary: Confswap swaps conf variables!
|
65
|
+
test_files:
|
66
|
+
- features/overwrite_existing_file.feature
|
67
|
+
- features/support/env.rb
|
68
|
+
- features/support/hooks.rb
|
69
|
+
- features/swap.feature
|
70
|
+
- spec/conf_reader_spec.rb
|
71
|
+
- spec/env_reader_spec.rb
|
72
|
+
- spec/spec_helper.rb
|