configliere 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +6 -0
- data/.gitignore +38 -0
- data/LICENSE +20 -0
- data/README.textile +196 -0
- data/Rakefile +91 -0
- data/VERSION +1 -0
- data/bin/configliere +85 -0
- data/configliere.gemspec +123 -0
- data/examples/commandline_script.rb +74 -0
- data/examples/commandline_script.yaml +8 -0
- data/examples/foo.yaml +15 -0
- data/examples/simple_script.rb +23 -0
- data/examples/simple_script.yaml +5 -0
- data/lib/configliere.rb +36 -0
- data/lib/configliere/commandline.rb +102 -0
- data/lib/configliere/commandline/commands.rb +30 -0
- data/lib/configliere/commandline/options.rb +4 -0
- data/lib/configliere/config_blocks.rb +41 -0
- data/lib/configliere/core_ext.rb +1 -0
- data/lib/configliere/core_ext/hash.rb +98 -0
- data/lib/configliere/crypter.rb +72 -0
- data/lib/configliere/define.rb +151 -0
- data/lib/configliere/encrypted.rb +78 -0
- data/lib/configliere/environment.rb +38 -0
- data/lib/configliere/param.rb +97 -0
- data/lib/configliere/param_store.rb +70 -0
- data/spec/configliere/commandline_spec.rb +62 -0
- data/spec/configliere/config_blocks_spec.rb +26 -0
- data/spec/configliere/crypter_spec.rb +18 -0
- data/spec/configliere/define_spec.rb +97 -0
- data/spec/configliere/encrypted_spec.rb +71 -0
- data/spec/configliere/environment_spec.rb +23 -0
- data/spec/configliere/param_spec.rb +43 -0
- data/spec/configliere/param_store_spec.rb +81 -0
- data/spec/configliere_spec.rb +21 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +16 -0
- metadata +164 -0
data/.document
ADDED
data/.gitignore
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
## OS
|
2
|
+
.DS_Store
|
3
|
+
Icon?
|
4
|
+
nohup.out
|
5
|
+
|
6
|
+
## EDITORS
|
7
|
+
*.tmproj
|
8
|
+
tmtags
|
9
|
+
*~
|
10
|
+
\#*
|
11
|
+
.\#*
|
12
|
+
*.swp
|
13
|
+
REVISION
|
14
|
+
TAGS*
|
15
|
+
*_flymake.*
|
16
|
+
.project
|
17
|
+
.settings
|
18
|
+
|
19
|
+
## COMPILED
|
20
|
+
a.out
|
21
|
+
*.o
|
22
|
+
*.pyc
|
23
|
+
*.so
|
24
|
+
|
25
|
+
## OTHER SCM
|
26
|
+
.bzr
|
27
|
+
.hg
|
28
|
+
.svn
|
29
|
+
|
30
|
+
## PROJECT::GENERAL
|
31
|
+
coverage
|
32
|
+
rdoc
|
33
|
+
doc
|
34
|
+
pkg
|
35
|
+
.yardoc
|
36
|
+
*private*
|
37
|
+
|
38
|
+
## PROJECT::SPECIFIC
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 mrflip
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.textile
ADDED
@@ -0,0 +1,196 @@
|
|
1
|
+
h1. Configliere
|
2
|
+
|
3
|
+
Configliere provides wise, lightweight configuration management for ruby programs.
|
4
|
+
|
5
|
+
bq. So, Consigliere of mine, I think you should tell your Don what everyone knows. -- Don Corleone
|
6
|
+
|
7
|
+
You've got a script. It's got some settings. Some settings are for this module, some are for that module. Most of them don't change. Except on your laptop, where the paths are different. Or when you're in production mode. Or when you're testing from the command line.
|
8
|
+
|
9
|
+
Configliere is a no-fuss library for flexibly managing your configuration settings. Design goals:
|
10
|
+
|
11
|
+
* *Don't go outside the family*. Requires almost no external resources and almost no code in your script.
|
12
|
+
* *Don't mess with my crew*. Settings for a model over here can be done independently of settings for a model over there, and don't require asking the boss to set something up.
|
13
|
+
* *Be willing to sit down with the Five Families*. Takes settings from (at your option):
|
14
|
+
** Pre-defined defaults from constants
|
15
|
+
** Simple config files
|
16
|
+
** Environment variables
|
17
|
+
** Commandline options
|
18
|
+
** Ruby block called when all other options are in place
|
19
|
+
* *Code of Silence*. Most commandline parsers force you to pre-define all your parameters in a centralized and wordy syntax. In configliere, you pre-define nothing -- commandline parameters map directly to values in the Configliere hash.
|
20
|
+
* *Can hide your assets*. Rather than storing passwords and API keys in plain sight, configliere has a protection racket that can obscure values when stored to disk.
|
21
|
+
|
22
|
+
fuhgeddaboudit.
|
23
|
+
|
24
|
+
h2. Settings structure
|
25
|
+
|
26
|
+
Configliere settings are just a plain old normal hash.
|
27
|
+
|
28
|
+
You can define static defaults in your module
|
29
|
+
|
30
|
+
Settings.defaults({
|
31
|
+
:dest_time => '1955-11-05',
|
32
|
+
:fluxcapacitor => {
|
33
|
+
:speed => 88,
|
34
|
+
},
|
35
|
+
:delorean => {
|
36
|
+
:power_source => 'plutonium',
|
37
|
+
:roads_needed => true,
|
38
|
+
},
|
39
|
+
:username => 'marty',
|
40
|
+
:password => '',
|
41
|
+
})
|
42
|
+
|
43
|
+
Retrieve them as:
|
44
|
+
|
45
|
+
# hash keys
|
46
|
+
Config[:dest_time] #=> '1955-11-05'
|
47
|
+
# deep keys
|
48
|
+
Config[:delorean][:power_source] #=> 'plutonium'
|
49
|
+
Config[:delorean][:missing] #=> nil
|
50
|
+
Config[:delorean][:missing][:fail] #=> raises an error
|
51
|
+
# dotted keys resolve to deep keys
|
52
|
+
Config['delorean.power_source'] #=> 'plutonium'
|
53
|
+
Config['delorean.missing'] #=> nil
|
54
|
+
Config['delorean.missing.fail'] #=> nil
|
55
|
+
# method-like (can't use this with deep keys)
|
56
|
+
Settings.dest_time #=> '1955-11-05'
|
57
|
+
|
58
|
+
Configliere doesn't load any other functionality by default -- you may not want to load config files, or environment variable handling, and so forth. You can require each file directly, or call @Configliere.use@ with the mixins to require (:all to load all functionality).
|
59
|
+
|
60
|
+
Configliere.use :param_store, :define # Load config files and pre-define
|
61
|
+
Configliere.use :all # all of them
|
62
|
+
|
63
|
+
h2. Configuration files
|
64
|
+
|
65
|
+
Call Settings.read(:my_settings_group) to read a param group from the YAML global config file (Configliere::DEFAULT_CONFIG_FILE, normally ~/.configliere.yaml)
|
66
|
+
|
67
|
+
# Settings for version II.
|
68
|
+
:time_machine:
|
69
|
+
:dest_time: 2015-11-05
|
70
|
+
:delorean:
|
71
|
+
:power_source: Mr. Fusion
|
72
|
+
:roads_needed: ~
|
73
|
+
|
74
|
+
You can instead supply a path to a config file. If a bare filename (no '/') is given, configliere looks for the file in Configliere::DEFAULT_CONFIG_DIR (normally ~/.configliere). Otherwise it loads the given file.
|
75
|
+
|
76
|
+
Settings.read(:time_machine) # looks in ~/.configliere.yaml, and extracts the :time_machine group
|
77
|
+
Settings.read('/etc/time_machine.yaml') # looks in /etc/time_machine.yaml
|
78
|
+
Settings.read('time_machine.yaml') # looks in ~/.configliere/time_machine.yaml
|
79
|
+
|
80
|
+
When you read directly from a file you should leave off the top-level settings group:
|
81
|
+
|
82
|
+
# Settings for version II.
|
83
|
+
:dest_time: 2015-11-05
|
84
|
+
:delorean:
|
85
|
+
:power_source: Mr. Fusion
|
86
|
+
:roads_needed: ~
|
87
|
+
|
88
|
+
You can save defaults with
|
89
|
+
|
90
|
+
Settings.save(:time_machine) # merges into ~/.configliere.yaml, under :time_machine
|
91
|
+
Settings.save('/etc/time_machine.yaml') # overwrites /etc/time_machine.yaml
|
92
|
+
Settings.save('time_machine.yaml') # overwrites ~/.configliere/time_machine.yaml
|
93
|
+
|
94
|
+
h2. Environment Variables
|
95
|
+
|
96
|
+
Settings.use_environment 'DEST_TIME', 'TM_PASS' => 'password', 'POWER_SOURCE' => 'delorean.power_source'
|
97
|
+
|
98
|
+
As usual, dotted keys set the corresponeding nested key ('delorean.power_source' sets Config[:delorean][:power_source])
|
99
|
+
|
100
|
+
h2. Command-line parameters
|
101
|
+
|
102
|
+
# Head back
|
103
|
+
time_machine --delorean-power_source='1.21 gigawatt lightning strike' --dest_time=1985-11-05
|
104
|
+
# (in the time_machine script:)
|
105
|
+
Settings.use :commandline
|
106
|
+
|
107
|
+
Interpretation of command-line parameters:
|
108
|
+
* *name-val params*: @--param=val@ sets @Configliere[:param]@ to val.
|
109
|
+
* *boolean params*: @--param@ sets @Configliere[:param]@ to be true. --param='' sets @Configliere[:param]@ to be nil.
|
110
|
+
* *scoped params*: @--group-sub_group-param=val@ sets @Configliere[:group][:subgroup][:param]@ to val (and similarly for boolean parameters).
|
111
|
+
** A dash or dot within a parameter name scopes that parameter: @--group.sub_group.param=val@ and @--group-sub_group-param=val@ do the same thing. A _ within a parameter name is left as part of the segment.
|
112
|
+
** Only @[\w\.\-]+@ are accepted in parameter names.
|
113
|
+
* *Settings.rest*: anything else is stored, in order, in @Settings.rest@.
|
114
|
+
* *stop marker*: a @--@ alone stops parameter processing and tosses all remaining params (not including the @--@) into Settings.rest.
|
115
|
+
|
116
|
+
Here are some things you don't get:
|
117
|
+
* There are no short parameters (-r, etc).
|
118
|
+
* Apart from converting @''@ (an explicit blank string) to nil, no type coercion is performed on parameters unless requested explicitly (see below).
|
119
|
+
* No validation is performed on parameters.
|
120
|
+
* No ordering or multiplicity is preserved (you can't say @--file=this --file=that@).
|
121
|
+
|
122
|
+
If you want more, you might like the Trollop gem. If you enjoy wordy nightmares, use "getoptlog":http://linuxdevcenter.com/pub/a/linux/2003/09/18/ruby_csv.html?page=2 from the ruby standard library.
|
123
|
+
|
124
|
+
h2. Fancy Parameters
|
125
|
+
|
126
|
+
You don't have to pre-define parameters, but you can:
|
127
|
+
|
128
|
+
Settings.use :define
|
129
|
+
Settings.define :dest_time, :type => Date, :description => 'Arrival time. If only a date is given, the current time of day on that date is assumed.'
|
130
|
+
Settings.define 'delorean.power_source', :description => 'Delorean subsytem supplying power to the Flux Capacitor.'
|
131
|
+
Settings.define :password, :required => true, :obscure => true
|
132
|
+
|
133
|
+
* *:type*: converts params to a desired form. It understands Date, Time, Integer, :boolean and Symbol. :blank => nil and :blank => false. Make sure to call Settings.resolve! in your script.
|
134
|
+
* *:description* documents a param.
|
135
|
+
* *:required* marks params required.
|
136
|
+
* *:encrypted* marks params to be obscured when saved to disk. See [#Encrypted Parameters] below for caveats.
|
137
|
+
|
138
|
+
h3. Required Parameters
|
139
|
+
|
140
|
+
Any required parameter found to be nil raises an error (listing all missing params). (Make sure to call Settings.resolve! in your script.)
|
141
|
+
|
142
|
+
h3. Encrypted Parameters
|
143
|
+
|
144
|
+
bq. There are two kinds of cryptography in this world: cryptography that will
|
145
|
+
stop your kid sister from reading your files, and cryptography that will stop
|
146
|
+
major governments from reading your files. This book is about the latter.
|
147
|
+
-- Preface to Applied Cryptography by Bruce Schneier
|
148
|
+
|
149
|
+
Configliere provides the latter. Anyone with access to the script, its config files and the config file passphrase can recover the plaintext password. Still, there's a difference between having to find a paperclip and jimmy open your annoying brother's stupid journal and being able to open to any page.
|
150
|
+
|
151
|
+
h2. Ruby Block
|
152
|
+
|
153
|
+
Settings.finally do |c|
|
154
|
+
c.dest_time = (Time.now + 60) if c.username == 'einstein'
|
155
|
+
# you can use hash syntax too
|
156
|
+
c[:dest_time] = (Time.now + 60) if c[:username] == 'einstein'
|
157
|
+
end
|
158
|
+
#
|
159
|
+
# ... rest of setup
|
160
|
+
#
|
161
|
+
Settings.resolve! # the finally blocks will be called in order
|
162
|
+
|
163
|
+
Configliere 'finally' blocks are called after everything but required parameter
|
164
|
+
|
165
|
+
h2. Independent Settings
|
166
|
+
|
167
|
+
All of the above uses the Settings global variable defined in configliere.rb. However, you're free to define your own settings universe.
|
168
|
+
|
169
|
+
module MyProject
|
170
|
+
cattr_accessor :config
|
171
|
+
self.config = Configliere.new({
|
172
|
+
:helicity => 'homotopic',
|
173
|
+
:froebenius_matrix => 'unitary',
|
174
|
+
})
|
175
|
+
end
|
176
|
+
pr = proj.new
|
177
|
+
pr.config #=> {:helicity => 'homotopic', :froebenius_matrix => 'unitary' }
|
178
|
+
|
179
|
+
Values in here don't overlap with the Settings object or any other settings universe. However, every one that pulls in commandline params gets a full copy of the commandline params.
|
180
|
+
|
181
|
+
h2. Project info
|
182
|
+
|
183
|
+
h3. Note on Patches/Pull Requests
|
184
|
+
|
185
|
+
* Fork the project.
|
186
|
+
* Make your feature addition or bug fix.
|
187
|
+
* Add tests for it. This is important so I don't break it in a
|
188
|
+
future version unintentionally.
|
189
|
+
* Commit, do not mess with rakefile, version, or history.
|
190
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
191
|
+
* Send a pull request to github.com/mrflip
|
192
|
+
* Drop a line to the mailing list for infochimps open-source projects, infochimps-code@googlegroups.com
|
193
|
+
|
194
|
+
h3. Copyright
|
195
|
+
|
196
|
+
Copyright (c) 2010 mrflip. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "configliere"
|
8
|
+
gem.summary = %Q{Wise, discreet configuration management}
|
9
|
+
gem.description = %Q{ You've got a script. It's got some settings. Some settings are for this module, some are for that module. Most of them don't change. Except on your laptop, where the paths are different. Or when you're in production mode. Or when you're testing from the command line.
|
10
|
+
|
11
|
+
"" So, Consigliere of mine, I think you should tell your Don what everyone knows. "" -- Don Corleone
|
12
|
+
|
13
|
+
Configliere's wise counsel takes care of these problems. Design goals:
|
14
|
+
|
15
|
+
* *Don't go outside the family*. Requires almost no external resources and almost no code in your script.
|
16
|
+
* *Don't mess with my crew*. Settings for a model over here can be done independently of settings for a model over there, and don't require asking the boss to set something up.
|
17
|
+
* *Be willing to sit down with the Five Families*. Takes settings from (at your option):
|
18
|
+
** Pre-defined defaults from constants
|
19
|
+
** Simple config files
|
20
|
+
** Environment variables
|
21
|
+
** Commandline options
|
22
|
+
** Ruby block called when all other options are in place
|
23
|
+
* *Code of Silence*. Most commandline parsers force you to pre-define all your parameters in a centralized and wordy syntax. In configliere, you pre-define nothing -- commandline parameters map directly to values in the Configliere hash.
|
24
|
+
* *Can hide your assets*. Rather than storing passwords and API keys in plain sight, configliere has a protection racket that can obscure values when stored to disk.
|
25
|
+
|
26
|
+
fuhgeddaboudit.
|
27
|
+
} #'
|
28
|
+
gem.email = "flip@infochimps.org"
|
29
|
+
gem.homepage = "http://github.com/mrflip/configliere"
|
30
|
+
gem.authors = ["mrflip"]
|
31
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
32
|
+
gem.add_development_dependency "yard", ">= 0"
|
33
|
+
gem.add_dependency "highline", ">= 0"
|
34
|
+
gem.add_dependency "yaml", ">= 0"
|
35
|
+
gem.add_dependency "openssl", ">= 0"
|
36
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
37
|
+
end
|
38
|
+
Jeweler::GemcutterTasks.new
|
39
|
+
rescue LoadError
|
40
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
41
|
+
end
|
42
|
+
|
43
|
+
require 'spec/rake/spectask'
|
44
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
45
|
+
spec.libs << 'lib' << 'spec'
|
46
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
47
|
+
end
|
48
|
+
|
49
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
50
|
+
spec.libs << 'lib' << 'spec'
|
51
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
52
|
+
spec.rcov = true
|
53
|
+
end
|
54
|
+
|
55
|
+
task :spec => :check_dependencies
|
56
|
+
|
57
|
+
begin
|
58
|
+
require 'reek/adapters/rake_task'
|
59
|
+
Reek::RakeTask.new do |t|
|
60
|
+
t.fail_on_error = true
|
61
|
+
t.verbose = false
|
62
|
+
t.source_files = 'lib/**/*.rb'
|
63
|
+
end
|
64
|
+
rescue LoadError
|
65
|
+
task :reek do
|
66
|
+
abort "Reek is not available. In order to run reek, you must: sudo gem install reek"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
begin
|
71
|
+
require 'roodi'
|
72
|
+
require 'roodi_task'
|
73
|
+
RoodiTask.new do |t|
|
74
|
+
t.verbose = false
|
75
|
+
end
|
76
|
+
rescue LoadError
|
77
|
+
task :roodi do
|
78
|
+
abort "Roodi is not available. In order to run roodi, you must: sudo gem install roodi"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
task :default => :spec
|
83
|
+
|
84
|
+
begin
|
85
|
+
require 'yard'
|
86
|
+
YARD::Rake::YardocTask.new
|
87
|
+
rescue LoadError
|
88
|
+
task :yardoc do
|
89
|
+
abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
|
90
|
+
end
|
91
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/bin/configliere
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems' ; $: << File.dirname(__FILE__)+'/../lib'
|
3
|
+
require 'configliere'
|
4
|
+
require 'configliere/client'
|
5
|
+
require 'configliere/client/commands'
|
6
|
+
Log = Logger.new(STDERR) unless defined?(Log)
|
7
|
+
|
8
|
+
class ConfigliereScript < Configliere::CommandClient
|
9
|
+
def usage
|
10
|
+
%Q{Client for the configliere gem: manipulate configuration and passwords for automated scripts
|
11
|
+
|
12
|
+
usage: #{File.basename($0)} command handle [...--option=val...]
|
13
|
+
where
|
14
|
+
command: One of: #{COMMANDS.keys[0..-2].join(', ')} or #{COMMANDS.keys.last}
|
15
|
+
handle: Name of the configliere group (within the configliere_file) or path to a configliere YAML file.
|
16
|
+
|
17
|
+
Configuration taken from #{configliere_file} by default.}
|
18
|
+
end
|
19
|
+
|
20
|
+
def process_options! *args
|
21
|
+
super *args
|
22
|
+
self.command = options[:_rest].shift.to_sym rescue nil
|
23
|
+
self.handle = options[:_rest].shift.to_sym rescue nil
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
# ===========================================================================
|
28
|
+
#
|
29
|
+
# Commands
|
30
|
+
#
|
31
|
+
|
32
|
+
COMMANDS[:fix] = "encrypt the param"
|
33
|
+
def fix
|
34
|
+
Log.info "Fixing stored info for #{handle}"
|
35
|
+
store.fix!(handle, option_or_ask(:key))
|
36
|
+
end
|
37
|
+
COMMANDS[:encrypt] = "synonym for fix. Params are stored encrypted by default"
|
38
|
+
def encrypt() fix end
|
39
|
+
|
40
|
+
COMMANDS[:decrypt] = "Store the param as decrypted back into the file. Can be undone with 'fix'."
|
41
|
+
def decrypt
|
42
|
+
Log.info "Storing info for #{handle} in **DECRYPTED** form."
|
43
|
+
param = get(handle)
|
44
|
+
store.put_decrypted!(handle, param)
|
45
|
+
end
|
46
|
+
|
47
|
+
COMMANDS[:list] = "Show all params in the configliere file."
|
48
|
+
def list
|
49
|
+
puts "List of param names: #{store.handles.inspect}"
|
50
|
+
end
|
51
|
+
|
52
|
+
COMMANDS[:delete] = "Permanently deletes the param"
|
53
|
+
def delete
|
54
|
+
Log.info "Permanently deleting stored info for #{handle}. O, I die, Horatio."
|
55
|
+
store.delete! handle, options[:key]
|
56
|
+
end
|
57
|
+
|
58
|
+
COMMANDS[:set] = "sets values using remaining arguments from the command line. eg #{File.basename($0)} set my_program --username=bob --password=frank"
|
59
|
+
def set
|
60
|
+
param = get(handle)
|
61
|
+
param.merge! external_options
|
62
|
+
store.put handle, param
|
63
|
+
store.save!
|
64
|
+
Log.info "Stored configuration for #{handle}: #{param}"
|
65
|
+
end
|
66
|
+
|
67
|
+
COMMANDS[:change_key] = "set a new key and/or new key options. Specify the old key as usual with --key='...' and the new one with --new_key='...'"
|
68
|
+
def change_key
|
69
|
+
param = get(handle)
|
70
|
+
new_key = option_or_ask(:new_key)
|
71
|
+
new_hsh = param.to_decrypted
|
72
|
+
new_param = Configliere::Param.new(new_key, new_hsh)
|
73
|
+
store.put! handle, new_param
|
74
|
+
Log.info "Changed param key for #{handle}: #{new_param}"
|
75
|
+
end
|
76
|
+
|
77
|
+
COMMANDS[:show] = "print the decrypted information"
|
78
|
+
def show
|
79
|
+
param = get(handle)
|
80
|
+
puts "Stored info for #{handle}:\n #{param.to_s}"
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
ConfigliereScript.new.run
|
data/configliere.gemspec
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{configliere}
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["mrflip"]
|
12
|
+
s.date = %q{2010-01-06}
|
13
|
+
s.default_executable = %q{configliere}
|
14
|
+
s.description = %q{ You've got a script. It's got some settings. Some settings are for this module, some are for that module. Most of them don't change. Except on your laptop, where the paths are different. Or when you're in production mode. Or when you're testing from the command line.
|
15
|
+
|
16
|
+
"" So, Consigliere of mine, I think you should tell your Don what everyone knows. "" -- Don Corleone
|
17
|
+
|
18
|
+
Configliere's wise counsel takes care of these problems. Design goals:
|
19
|
+
|
20
|
+
* *Don't go outside the family*. Requires almost no external resources and almost no code in your script.
|
21
|
+
* *Don't mess with my crew*. Settings for a model over here can be done independently of settings for a model over there, and don't require asking the boss to set something up.
|
22
|
+
* *Be willing to sit down with the Five Families*. Takes settings from (at your option):
|
23
|
+
** Pre-defined defaults from constants
|
24
|
+
** Simple config files
|
25
|
+
** Environment variables
|
26
|
+
** Commandline options
|
27
|
+
** Ruby block called when all other options are in place
|
28
|
+
* *Code of Silence*. Most commandline parsers force you to pre-define all your parameters in a centralized and wordy syntax. In configliere, you pre-define nothing -- commandline parameters map directly to values in the Configliere hash.
|
29
|
+
* *Can hide your assets*. Rather than storing passwords and API keys in plain sight, configliere has a protection racket that can obscure values when stored to disk.
|
30
|
+
|
31
|
+
fuhgeddaboudit.
|
32
|
+
}
|
33
|
+
s.email = %q{flip@infochimps.org}
|
34
|
+
s.executables = ["configliere"]
|
35
|
+
s.extra_rdoc_files = [
|
36
|
+
"LICENSE",
|
37
|
+
"README.textile"
|
38
|
+
]
|
39
|
+
s.files = [
|
40
|
+
".document",
|
41
|
+
".gitignore",
|
42
|
+
"LICENSE",
|
43
|
+
"README.textile",
|
44
|
+
"Rakefile",
|
45
|
+
"VERSION",
|
46
|
+
"bin/configliere",
|
47
|
+
"configliere.gemspec",
|
48
|
+
"examples/commandline_script.rb",
|
49
|
+
"examples/commandline_script.yaml",
|
50
|
+
"examples/foo.yaml",
|
51
|
+
"examples/simple_script.rb",
|
52
|
+
"examples/simple_script.yaml",
|
53
|
+
"lib/configliere.rb",
|
54
|
+
"lib/configliere/commandline.rb",
|
55
|
+
"lib/configliere/commandline/commands.rb",
|
56
|
+
"lib/configliere/commandline/options.rb",
|
57
|
+
"lib/configliere/config_blocks.rb",
|
58
|
+
"lib/configliere/core_ext.rb",
|
59
|
+
"lib/configliere/core_ext/hash.rb",
|
60
|
+
"lib/configliere/crypter.rb",
|
61
|
+
"lib/configliere/define.rb",
|
62
|
+
"lib/configliere/encrypted.rb",
|
63
|
+
"lib/configliere/environment.rb",
|
64
|
+
"lib/configliere/param.rb",
|
65
|
+
"lib/configliere/param_store.rb",
|
66
|
+
"spec/configliere/commandline_spec.rb",
|
67
|
+
"spec/configliere/config_blocks_spec.rb",
|
68
|
+
"spec/configliere/crypter_spec.rb",
|
69
|
+
"spec/configliere/define_spec.rb",
|
70
|
+
"spec/configliere/encrypted_spec.rb",
|
71
|
+
"spec/configliere/environment_spec.rb",
|
72
|
+
"spec/configliere/param_spec.rb",
|
73
|
+
"spec/configliere/param_store_spec.rb",
|
74
|
+
"spec/configliere_spec.rb",
|
75
|
+
"spec/spec.opts",
|
76
|
+
"spec/spec_helper.rb"
|
77
|
+
]
|
78
|
+
s.homepage = %q{http://github.com/mrflip/configliere}
|
79
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
80
|
+
s.require_paths = ["lib"]
|
81
|
+
s.rubygems_version = %q{1.3.5}
|
82
|
+
s.summary = %q{Wise, discreet configuration management}
|
83
|
+
s.test_files = [
|
84
|
+
"spec/configliere/commandline_spec.rb",
|
85
|
+
"spec/configliere/config_blocks_spec.rb",
|
86
|
+
"spec/configliere/crypter_spec.rb",
|
87
|
+
"spec/configliere/define_spec.rb",
|
88
|
+
"spec/configliere/encrypted_spec.rb",
|
89
|
+
"spec/configliere/environment_spec.rb",
|
90
|
+
"spec/configliere/param_spec.rb",
|
91
|
+
"spec/configliere/param_store_spec.rb",
|
92
|
+
"spec/configliere_spec.rb",
|
93
|
+
"spec/spec_helper.rb",
|
94
|
+
"examples/commandline_script.rb",
|
95
|
+
"examples/simple_script.rb"
|
96
|
+
]
|
97
|
+
|
98
|
+
if s.respond_to? :specification_version then
|
99
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
100
|
+
s.specification_version = 3
|
101
|
+
|
102
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
103
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
104
|
+
s.add_development_dependency(%q<yard>, [">= 0"])
|
105
|
+
s.add_runtime_dependency(%q<highline>, [">= 0"])
|
106
|
+
s.add_runtime_dependency(%q<yaml>, [">= 0"])
|
107
|
+
s.add_runtime_dependency(%q<openssl>, [">= 0"])
|
108
|
+
else
|
109
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
110
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
111
|
+
s.add_dependency(%q<highline>, [">= 0"])
|
112
|
+
s.add_dependency(%q<yaml>, [">= 0"])
|
113
|
+
s.add_dependency(%q<openssl>, [">= 0"])
|
114
|
+
end
|
115
|
+
else
|
116
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
117
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
118
|
+
s.add_dependency(%q<highline>, [">= 0"])
|
119
|
+
s.add_dependency(%q<yaml>, [">= 0"])
|
120
|
+
s.add_dependency(%q<openssl>, [">= 0"])
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|