keyp 0.0.2 → 0.0.3

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
  SHA1:
3
- metadata.gz: b14d1fd77f310af5875fcb9ad4ccd985a04c5abc
4
- data.tar.gz: 78815bce0d5db5bb66103fb60132960256d9ba5c
3
+ metadata.gz: f6fe1096a2986fb5e0c7294dde7465399487f46f
4
+ data.tar.gz: aa53557b7a5ef2a0ddaf83c5005f653f08e1de25
5
5
  SHA512:
6
- metadata.gz: 1db7713dbf1a667967d3d5d76c7de9587cf961e6f816cd4059c7145424bcb5e9b3ec1e9129fe4ed23ebdeeb41a80e13475d7a96208fa940a1ff059a9d7accbc2
7
- data.tar.gz: 49cadf1084cfad53323fdfbc9af3d1bb238e4ab40c838dc9c937ec422df87a5bda95efcc2221821a6eb3d8e77994afb6306d355e274ae16e22b3999d1c770dd6
6
+ metadata.gz: 9728123d215cafbf15881a10b8b43b3fad95e5b6a473fea52ac42f0d28d429b20a4295a1d0fd700f8c71224182fb59c58e122ac1ca308dfab803af7f77170114
7
+ data.tar.gz: 320ce0f3a9c587b577b5d7b6dd466aac857ecf99fec6208874232324b2d79b23867b1a188d4f22e76a3eb20613156a1e8d49ef1fe33a9f7ad87dc279536acab3
data/bin/keyp CHANGED
@@ -31,11 +31,17 @@ include GLI::App
31
31
 
32
32
  # keyp create bag
33
33
 
34
- program_desc 'A command line linterface for the Keyp key/value manager'
34
+ program_desc 'A command line interface for the Keyp key:value manager'
35
35
 
36
+ desc 'The Keyp bag to use'
36
37
  flag [:b,:bag], default_value: 'default'
38
+
39
+ desc 'Enable debug mode'
37
40
  switch [:d, :debug]
38
41
 
42
+ desc 'Suppress hints: If invalid parameters are set, no suggestive feedback will be provided'
43
+ switch [:s, :suppress]
44
+
39
45
  # TODO: fix this because this implies that we either already have a bag or it will create a new one
40
46
  pre do |global_options, command, options, args|
41
47
  # initialize our store
@@ -66,13 +72,20 @@ pre do |global_options, command, options, args|
66
72
  true # hack to prevent
67
73
  end
68
74
 
75
+
76
+ desc 'Get the value for a key'
77
+ long_desc 'Shows the value for the supplied key'
69
78
  #
70
79
  # Key,value commands
71
80
  #arg_name 'keys', :multiple
72
81
  command :get do |c|
82
+ c.desc 'Shows the value for the supplied key.'
83
+
84
+ #c.switch [:v,:value]
73
85
  c.action do |global_options,options,args|
74
- puts "--- get args= #{args}" if $debug
75
- if args.length == 0
86
+
87
+ #help_now!('key is required') if args.empty?
88
+ if args.empty? && !global_options[:suppress]
76
89
  puts "Usage: keyp get KEY"
77
90
  puts "Must specify a key."
78
91
  else
@@ -90,8 +103,12 @@ end
90
103
  # any global or command parameters after the key=value will be sucked into the value
91
104
  # Se we'll need to implement values in quotes if the value contains whitespace
92
105
 
106
+ desc 'set the value for the supplied key'
107
+ long_desc 'Sets the value for the supplied key. If the key exists, the value will be overwritten'
108
+
93
109
  arg_name 'values', :multiple
94
110
  command :set do |c|
111
+ c.desc 'Set the value for the supplied key. If the key exists, the value will be overwritten'
95
112
  c.action do |global_options,options,args|
96
113
  # When/if implementing multiple key assignments
97
114
  # check args.length % 2
@@ -109,7 +126,7 @@ command :set do |c|
109
126
 
110
127
  if nvp
111
128
  $bag[nvp[:key]] = nvp[:value]
112
- else
129
+ elsif global_options[:suppress] == false
113
130
  # puts "Usage keyp set KEY1=VALUE1 [KEY2=VALUE2 ...]"
114
131
  puts "Usage: keyp set KEY=VALUE"
115
132
  end
@@ -118,6 +135,7 @@ command :set do |c|
118
135
  end
119
136
  end
120
137
 
138
+ desc 'removes the key and value for the supplied key'
121
139
  command :unset do |c|
122
140
  c.action do |global_options,options, args|
123
141
  if args.length == 0
@@ -139,8 +157,12 @@ command :unset do |c|
139
157
  end
140
158
  end
141
159
 
160
+ desc 'lists all the key:value pairs in the bag.'
142
161
  command :list do |c|
143
- c.action do
162
+ c.action do |global_options, options, args|
163
+
164
+ # TODO: implement display options
165
+
144
166
  puts "* bag:#{$bag.name}"
145
167
 
146
168
  unless $bag.empty?
@@ -156,11 +178,49 @@ command :list do |c|
156
178
  end
157
179
 
158
180
 
181
+ setup_desc = 'Creates and configures the Keyp directory'
182
+
183
+ desc setup_desc
159
184
  command :setup do |c|
185
+ c.desc setup_desc
160
186
  c.action do |global_options, options, args|
161
187
  puts "keyp setup..."
162
188
  Keyp::setup
163
- $bag = Keyp::create_store 'default'
189
+ $bag = Keyp::create_bag 'default'
190
+ end
191
+ end
192
+
193
+ command :create do |c|
194
+
195
+ c.action do |global_options, options, args|
196
+ puts "keyp create"
197
+ # TODO: add checking in case store already exists
198
+ #Keyp::create
199
+
200
+ bag = Keyp.create_bag(args[0])
201
+ if bag
202
+ puts "created Keyp bag #{bag.name}"
203
+ else
204
+ puts "Unable to create Keyp bag #{args[0]}"
205
+ end
206
+ end
207
+ end
208
+
209
+ command :delete do |c|
210
+ c.action do |global_options, options, args|
211
+ puts "delete bag is not supported at this time"
212
+ # TODO: prompt for verification
213
+ end
214
+ end
215
+
216
+ command :show do |c|
217
+ c.action do |global_options, options, args|
218
+ # TODO: implement filtering, stats (like number of items in a bag, last updated, etc)
219
+ # and just filename
220
+ bags = Keyp.bag_names
221
+ bags.each do |bag|
222
+ puts "#{bag}"
223
+ end
164
224
  end
165
225
  end
166
226
 
@@ -175,10 +235,8 @@ post do |global_options, command, options, args|
175
235
  else
176
236
  true
177
237
  end
178
-
179
-
180
-
181
238
  end
239
+
182
240
  # bag management commands
183
241
 
184
242
  # create a bag
data/keyp.gemspec CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Keyp::VERSION
9
9
  spec.authors = ["John Baldwin"]
10
10
  spec.email = ["jlbaldwin@gmail.com"]
11
- spec.summary = %q{Manage environment/machine specific key/value pairs for your Ruby application.}
12
- spec.description = spec.summary=
11
+ spec.summary = %q{Manage environment/machine specific key:value pairs for your Ruby application.}
12
+ spec.description = %q{Keyp is a key:value manager with a command line tool and library API to make managing authentication and configuration information easier.}
13
13
  spec.homepage = "https://github.com/johnbaldwin/keyp-ruby"
14
14
  spec.license = "Apache v2"
15
15
 
@@ -18,9 +18,11 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
+ spec.add_runtime_dependency 'gli', '~> 2.9'
22
+
21
23
  spec.add_development_dependency 'bundler', '~> 1.5'
22
24
  spec.add_development_dependency 'rake', '~> 10.1'
23
- spec.add_development_dependency 'gli', '~> 2.9'
25
+ #spec.add_development_dependency 'gli', '~> 2.9'
24
26
  spec.add_development_dependency 'rspec', '~> 2.14'
25
27
  spec.executables = 'keyp'
26
28
 
data/lib/keyp/cli.rb CHANGED
@@ -1,6 +1,9 @@
1
1
  module Keyp
2
2
 
3
+ ##
3
4
  # Manage the processing of command line options
5
+ # TODO: build out cli.rb to trim the exe script, keyp to its bare minimum
6
+
4
7
  class CLI
5
8
 
6
9
 
data/lib/keyp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Keyp
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/keyp.rb CHANGED
@@ -1,93 +1,164 @@
1
- require "keyp/version"
1
+ require 'keyp/version'
2
+ require 'keyp/bag'
2
3
  require 'json'
3
4
  require 'yaml'
4
5
 
6
+ ##
7
+ # This is the main module for the Keyp library
5
8
  #
6
- # TODO: build out cli.rb to trim the exe script, keyp to its bare minimum
9
+ # = Overview
10
+ #
11
+ #
12
+ # Keyp is not yet supported on Windows
13
+ #
14
+ # = Developer notes
15
+ #
16
+ # NOTE: Do not implement a copy method to explicitly copy one bag to another.
17
+ # This is too prone to undesired overwriting.
18
+ # Instead, use create and pass in the other bag as a named parameter. This way
19
+ # we express
7
20
  #
8
21
  module Keyp
9
- # Your code goes here...
10
- ORIGINAL_ENV = ENV.to_hash
11
22
 
12
- # TODO:
13
- # Put this in initializer so testing can create its own directory and not muck
14
- # up the operational default
23
+ # TODO: Revisit constants. Make a submodule for constants
24
+
25
+
26
+ ##
27
+ # Constant definitions
28
+
29
+ # Save the original environment before this module instantiates
30
+ ORIGINAL_ENV = ENV.to_hash
15
31
 
32
+ # This constant sets the default bag when one is not specified in methods that need to
33
+ # identify the bag
34
+ DEFAULT_BAG = 'default'
16
35
 
17
- KEYP_HOME = File.join(ENV['HOME'], '.keyp')
18
- DEFAULT_STORE = 'default'
36
+ # Default file extension for the bags
19
37
  DEFAULT_EXT = '.yml'
20
- # This method sets up the keyp director
21
- #def self.setup
22
- # # check if keyp directory exists. If not, set it up
23
- # unless Dir.exist?(File.join(DEFAULT_KEYP_DIRNAME))
38
+
39
+ # Permissions for the KEYP_HOME directory
40
+ DEFAULT_KEYP_DIR_PERMISSIONS = 0700
41
+
42
+ # Default home directory that keyp uses to store bags
43
+ DEFAULT_KEYP_DIR = '.keyp'
44
+
45
+ #TODO: set this
46
+ #ENV_VAR_NAME_REGEX =
47
+
48
+ # Returns the directory used by Keyp to store the key bags
24
49
  #
25
- # end
26
- #end
50
+ # By default, Keyp uses +$HOME/.keyp+ and sets permissions to 0700 to the +.keyp+ directory
51
+ #
52
+ # == Environment variable overrides
53
+ #
54
+ # You can override the default Keyp location by defining +KEYP_HOME+
55
+ #
56
+ # Keyp is currently designed to have a _per user_ configuration, but you should be able to
57
+ # set it up for system wide use if you desire.
27
58
 
59
+ # === Example
60
+ # +export KEYP_HOME=/var/lib/keyp+
61
+ #
62
+ # *Security note* If you do this *and* you are storing sensitive information, then
63
+ # it is recommended you restrict permissions
64
+ #
65
+ def self.home
66
+ ENV['KEPY_HOME'] || File.join(ENV['HOME'], DEFAULT_KEYP_DIR)
67
+ end
68
+
69
+ ##
70
+ #
71
+ # Returns the file extension that Keyp uses for bags
72
+ # Should return '.yml'
73
+ #
74
+ def self.ext
75
+ DEFAULT_EXT
76
+ end
77
+
78
+ ##
79
+ # Returns +true+ if the Keyp home diretory exists and is readable and writeable by the user
80
+ # running Keyp
28
81
  def self.configured?
29
- Dir.exist?(KEYP_HOME)
82
+ Dir.exist?(home) && File.executable?(home) &&
83
+ File.readable_real?(home) && File.writable_real?(home)
30
84
  end
31
85
 
86
+ ##
87
+ # Creates the Keyp home directory and sets permissions if the directory does not exist
88
+ # See method +Keyp::home+
89
+ # === Options
90
+ # Not options yet
32
91
  def self.setup(options ={})
33
92
 
34
93
  # check if keyp directory exists
35
94
 
36
- unless Dir.exist?(KEYP_HOME)
37
- puts "making directory #{KEYP_HOME}"
38
- Dir.mkdir(KEYP_HOME, 0700)
39
- else
40
- Puts "#{KEYP_HOME} already exists"
41
- end
42
-
43
- KEYP_HOME
44
- =begin
45
- if config_path == DEFAULT_STORE
46
- # create the default file
47
-
48
- f = File.open(DEFAULT_STORE,'w')
49
- #f.puts("default:")
50
- f.close
51
- return {}
95
+ unless Dir.exist?(home)
96
+ puts "making directory #{home}"
97
+ Dir.mkdir(home, 0700)
98
+ if Dir.exist?(home)
99
+ home
100
+ else
101
+ nil
102
+ end
52
103
  else
53
- raise "Non default stores not yet implemented"
104
+ Puts "#{home} already exists"
105
+ nil
54
106
  end
55
- =end
56
- end
57
-
58
- # NOTE: No copy method
59
- # No method to explicitly copy one bag to another
60
- # Too prone to unwanted overwriting
61
- # Instead, use create and pass in the other bag as a
62
- # named parameter
63
-
64
- # create a new bag persist
65
- # TODO: check options for a has to write to the bag
66
- def self.create(bag, options={})
67
- # two root sections in a bag
68
- # meta:
69
- # meta will contain information for use by keyp about this particular bag
70
- # such as encoding rules, case sensitivity
71
- # data:
72
107
  end
73
108
 
109
+ ##
74
110
  # Convenience method to create a new Bag
111
+ #
112
+ # ==== Parameters
113
+ #
114
+ # * +name+ - bag name. 'default' is used if no bag name is provided
115
+ # * +options+ - options are passed through to Bag.new
116
+ #
75
117
  def self.bag(name='default', options = {})
76
- keyper = Keyper.new(name, options)
77
- keyper
118
+ bag = Keyper.new(name, options)
119
+ bag
78
120
  end
79
121
 
122
+ ##
123
+ # Tells if a bag already exists for the keyp dir identified by the environment
124
+ #
125
+ def self.exist?(name)
126
+ path = bag_path(name)
127
+ File.exist? path
128
+ end
80
129
 
81
- def self.add_to_env(bag)
82
- # TODO: Add checking, upcase
83
- bag.data.each do |key,value|
84
- ENV[key] = value
85
- end
130
+ ##
131
+ # returns the absolute path for the given bag
132
+ #
133
+ #
134
+ def self.bag_path(name)
135
+ path = File.join(home,name+ext)
86
136
  end
87
137
 
88
- def self.create_store(name, options = {} )
89
- filepath = File.join(KEYP_HOME, name + DEFAULT_EXT)
138
+ ##
139
+ # Returns an array of bag names
140
+ # This method returns a list of bag names for the active Keyp repository
141
+ # The default repository is $HOME/.keyp
142
+ # If the environment variable, KEYP_HOME is set, this directory will be used.
143
+ def self.bag_names(options = {})
144
+ #TODO: enable pattern matching
145
+ bags = []
146
+ reg = Regexp.new('\\'+ext+'$')
147
+ dir = Dir.new(home)
148
+ dir.each do |f|
149
+ # Filter for only
150
+ #if /\.yml$/.match(f)
151
+ if reg.match(f)
152
+ bags << File.basename(f,ext)
153
+ end
154
+ end
155
+ bags
156
+ end
90
157
 
158
+ ##
159
+ # Creates a new bag if one does not already exist with the given name
160
+ #
161
+ def self.create_bag(name, options = {} )
91
162
  time_now = Time.now.utc.iso8601
92
163
  file_data = {}
93
164
  file_data['meta'] = {
@@ -97,8 +168,8 @@ module Keyp
97
168
  'updated_at' => time_now
98
169
  }
99
170
  file_data['data'] = nil
100
- unless File.exist? filepath
101
- File.open(filepath, 'w') do |f|
171
+ unless exist? name
172
+ File.open(bag_path(name), 'w') do |f|
102
173
  f.write file_data.to_yaml
103
174
  f.chmod(0600)
104
175
  end
@@ -108,6 +179,19 @@ module Keyp
108
179
  bag name
109
180
  end
110
181
 
182
+ ##
183
+ # Deletes the bag matching the name
184
+ # Returns true if successful, false if not
185
+ def self.delete_bag(name, options = {})
186
+ if exist? name
187
+ # TODO: add exception handling
188
+ numfiles = File.delete(bag_path(name))
189
+ true
190
+ else
191
+ false
192
+ end
193
+ end
194
+
111
195
  def self.parse_arg_string(arg_string, options={})
112
196
 
113
197
  mode = options[:token_mode] || :default
@@ -130,6 +214,12 @@ module Keyp
130
214
  nvp
131
215
  end
132
216
 
217
+ # ---------------------------------------------
218
+ # Experimental stuff
219
+
220
+ def self.set_sys_env(key, value)
221
+
222
+ end
133
223
 
134
224
  # ----------------------------------------------
135
225
 
@@ -147,8 +237,8 @@ module Keyp
147
237
  attr_reader :keypdir, :dirty
148
238
  attr_accessor :name, :data, :file_hash
149
239
 
150
- def config_path
151
- File.join(@keypdir, @name)
240
+ def keypfile
241
+ File.join(@keypdir, @name+@ext)
152
242
  end
153
243
 
154
244
  # We expect
@@ -161,20 +251,20 @@ module Keyp
161
251
  end
162
252
  # set attributes not set by params
163
253
 
164
- @keypdir ||= Keyp::KEYP_HOME
254
+ @keypdir ||= Keyp::home
165
255
  @read_only ||= false
166
- @ext ||= '.yml'
167
- @keypfile = config_path+@ext
256
+ @ext ||= Keyp::DEFAULT_EXT
257
+ #@keypfile = config_path
168
258
  # load our resource
169
259
 
170
260
  # load config file into hashes
171
261
  # not the most efficient thing, but simpler and safe enough for now
172
262
 
173
- unless File.exist? @keypfile
174
- puts "Keuper.initialize, create_store #{@keypfile}"
175
- Keyp::create_store(@keypfile)
263
+ unless File.exist? keypfile
264
+ puts "Keyper.initialize, create_bag #{keypfile}"
265
+ Keyp::create_bag(name)
176
266
  end
177
- file_data = load(@keypfile)
267
+ file_data = load(keypfile)
178
268
 
179
269
  @meta = file_data[:meta]
180
270
  @data = file_data[:data]|| {}
@@ -198,7 +288,7 @@ module Keyp
198
288
  @data[key] = value
199
289
  @dirty = true
200
290
  else
201
- raise "Keyper #{@name} is read only"
291
+ raise "Bag #{@name} is read only"
202
292
  end
203
293
  end
204
294
 
@@ -218,6 +308,65 @@ module Keyp
218
308
  @data.empty?
219
309
  end
220
310
 
311
+
312
+ ##
313
+ # Adds key/value pairs from this bag to the Ruby ENV
314
+ # NOTE: Currently in development.
315
+ # If no options are provided, then all of the bag's key/value pairs will be assigned.
316
+ #
317
+ # ==== Options
318
+ # TBD:
319
+ # +:sysvar+ Only use valid system environment vars
320
+ # +:selection+ Provide a list of keys to match
321
+ # +:overwrite+
322
+ # +:no_overwrite+ - This is enabled by default
323
+ # +:to_upper
324
+
325
+ # Returns a hash of the key/value pairs which have been set
326
+ # ==== Examples
327
+ # +add_to_env upper:+
328
+ # To assign keys matching a pattern:
329
+ # +add_to_env regex: '\A(_|[A-Z])[a-zA-Z\d]*'
330
+
331
+ def add_to_env(options = {})
332
+ # TODO: Add checking, upcase
333
+
334
+ # pattern matching valid env var
335
+ sys_env_reg = /\A(_|[a-zA-Z])\w*/
336
+ assigned = {}
337
+ overwrite = options[:overwrite] || false
338
+ pattern = options[:sysvar] if options.key?(:sysvar)
339
+
340
+ pattern ||= '(...)'
341
+
342
+ bag.data.each do |key,value|
343
+ if pattern.match(key)
344
+ # TODO: add overwrite checking
345
+ ENV[key] = value
346
+ assigned[key] = value
347
+ end
348
+ end
349
+ assigned
350
+ end
351
+
352
+
353
+ # TODO add from hash
354
+
355
+
356
+ def import(filename)
357
+ raise "import not yet supported"
358
+ end
359
+
360
+ def export(filename)
361
+ raise "export not yet supported"
362
+ end
363
+
364
+
365
+ # TODO: def to_yaml
366
+ # TODO: def to_json
367
+ # TODO: def to_s
368
+
369
+ ##
221
370
  # Give full path, attempt to load
222
371
  # sticking with YAML format for now
223
372
  # May add new file format later in which case we'll
@@ -235,7 +384,7 @@ module Keyp
235
384
  # TODO: make this hardcoded case a hash of helpers
236
385
  # TODO: Add two sections: Meta and data, then return as hash
237
386
 
238
- if file_ext.downcase == '.yml'
387
+ if file_ext.downcase == Keyp::DEFAULT_EXT
239
388
 
240
389
  # Either we are arbitrarily creating directories when
241
390
  # given a path for a file that doesn't exist
@@ -253,6 +402,9 @@ module Keyp
253
402
  { meta: file_data['meta'], data: file_data['data']||{}, file_hash: file_data.hash }
254
403
  end
255
404
 
405
+ ##
406
+ # Saves the Bag to file
407
+ #
256
408
  # NOT thread safe
257
409
  # TODO: make thread safe
258
410
  def save
@@ -268,14 +420,14 @@ module Keyp
268
420
  begin
269
421
  file_data = { 'meta' => @meta, 'data' => @data }
270
422
 
271
- if File.exist? @keypfile
272
- read_file_data = load(@keypfile)
423
+ if File.exist? keypfile
424
+ read_file_data = load(keypfile)
273
425
  unless @file_hash == read_file_data[:file_hash]
274
- raise "Will not write to #{@keypfile}\nHashes differ. Expected hash =#{@file_hash}\n" +
426
+ raise "Will not write to #{keypfile}\nHashes differ. Expected hash =#{@file_hash}\n" +
275
427
  "found hash #{read_file_data[:file_hash]}"
276
428
  end
277
429
  end
278
- File.open(@keypfile, 'w') do |f|
430
+ File.open(keypfile, 'w') do |f|
279
431
  f.write file_data.to_yaml
280
432
  end
281
433
  @dirty = false
data/spec/keyp_spec.rb CHANGED
@@ -1,30 +1,56 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Keyp do
4
- it 'should return correct version string' do
5
- #Keyp.version_string.should == "Keyp version #{Keyp::VERSION}"
6
- Keyp::VERSION.should == '0.0.1'
7
- end
8
4
 
9
- it 'should return correct default keyp dir' do
10
- # DEFAULT_KEYP_DIRNAME = ENV['KEYP_DIRNAME'] || '.keyp'
11
- Keyp::KEYP_HOME.should == File.join(ENV['HOME'], '.keyp')
12
- end
5
+ context "CONSTANTS" do
6
+ it 'should return correct version string' do
7
+ #Keyp.version_string.should == "Keyp version #{Keyp::VERSION}"
8
+ Keyp::VERSION.should == '0.0.3'
9
+ end
10
+
11
+ it 'should specify default store' do
12
+ Keyp::DEFAULT_BAG.should == 'default'
13
+ end
13
14
 
14
- it 'should specify default store' do
15
- Keyp::DEFAULT_STORE.should == 'default'
15
+ it "should specifify default store extension" do
16
+ Keyp::DEFAULT_EXT.should == '.yml'
17
+ end
18
+
19
+ it 'should specify default keyp dir' do
20
+ Keyp::DEFAULT_KEYP_DIR.should == '.keyp'
21
+ end
16
22
  end
17
- it 'should specify default store file' do
18
- Keyp::DEFAULT_STORE_FILE.should == 'default.yml'
23
+
24
+ context "Keyp directory" do
25
+ it 'should return correct default keyp dir' do
26
+ # DEFAULT_KEYP_DIRNAME = ENV['KEYP_DIRNAME'] || '.keyp'
27
+ Keyp::home.should == File.join(ENV['HOME'], '.keyp')
28
+ end
29
+
30
+ it 'should be able to override default keyp dir'
19
31
  end
20
32
 
21
- it 'should be able to override default keyp dir'
33
+ context "Bag management" do
34
+ it 'should return default bag' do
35
+ keyper = Keyp::bag
36
+ keyper.name.should == 'default'
37
+ end
38
+
39
+ it "should say a bag exists" do
40
+ # get the default bag, should create it if it doesn't exist
41
+ keyper = Keyp::bag
42
+ Keyp.exist?(keyper.name).should == true
43
+ end
44
+
45
+ it "should say a bag does not exist" do
46
+ # TODO: add bag name generation to a helper
47
+ bag_name = "grue_eats_you_when_it_is_dark_#{Time.now.strftime("%Y%m%d%H%M")}"
48
+ Keyp.exist?(bag_name).should_not == true
49
+ end
22
50
 
23
- it 'should return default bag' do
24
- keyper = Keyp::bag
25
- keyper.bag.should == 'default'
26
51
  end
27
52
 
53
+
28
54
  it 'should return a key with data member'
29
55
  it 'should return a key acting as a hash'
30
56
  it 'should allow assigning a key if not read only'
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ describe Keyp::Keyper do
4
+
5
+ context "is empty" do
6
+ before (:each) do
7
+ puts "before : is empty"
8
+ @bag = Keyp::Keyper.new 'testing123'
9
+ end
10
+
11
+ it "should return an empty hash" do
12
+
13
+ @bag.data.size.should == 0
14
+ end
15
+ #it "should have metadata" do
16
+ # @bag.meta['created_on'].should_not == nil
17
+ #end
18
+ end
19
+
20
+ context "is not empty" do
21
+ before (:each) do
22
+ puts "before : is not empty"
23
+ @bag = Keyp::Keyper.new 'grue_eats_you'
24
+ @bag['LIGHTS'] = 'out'
25
+ end
26
+ it "should return a non-empty hash" do
27
+ @bag.data.size.should > 0
28
+ end
29
+ end
30
+
31
+ context "environment variables" do
32
+ before (:each) do
33
+ # TODO: pseudo random bag name generation to a helper
34
+ bag_name = "grue_eats_you_when_it_is_dark_#{Time.now.strftime("%Y%m%d%H%M")}"
35
+ @bag = Keyp::Keyper.new bag_name
36
+ end
37
+ it "should copy all vars"
38
+ =begin
39
+ do
40
+ testvars = {
41
+ 'ALPHA' => 'First in the phonetic alphabet',
42
+ 'BRAVO' => 'Second in the phonetic alphabet',
43
+ 'CHARLIE' => 'Third in the phonetic alphabet'
44
+ }
45
+
46
+ testvars.each { |key, value| @bag[key] = value }
47
+
48
+ @bag.add_to_env
49
+ testvars.each do |key, value|
50
+ ENV[key].should_not == nil
51
+ ENV[key].should == value
52
+ end
53
+ end
54
+ =end
55
+ end
56
+ end
metadata CHANGED
@@ -1,57 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: keyp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Baldwin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-24 00:00:00.000000000 Z
11
+ date: 2014-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
14
+ name: gli
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: '1.5'
20
- type: :development
19
+ version: '2.9'
20
+ type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: '1.5'
26
+ version: '2.9'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: '10.1'
33
+ version: '1.5'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ~>
39
39
  - !ruby/object:Gem::Version
40
- version: '10.1'
40
+ version: '1.5'
41
41
  - !ruby/object:Gem::Dependency
42
- name: gli
42
+ name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ~>
46
46
  - !ruby/object:Gem::Version
47
- version: '2.9'
47
+ version: '10.1'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: '2.9'
54
+ version: '10.1'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -66,7 +66,8 @@ dependencies:
66
66
  - - ~>
67
67
  - !ruby/object:Gem::Version
68
68
  version: '2.14'
69
- description: https://github.com/johnbaldwin/keyp-ruby
69
+ description: Keyp is a key:value manager with a command line tool and library API
70
+ to make managing authentication and configuration information easier.
70
71
  email:
71
72
  - jlbaldwin@gmail.com
72
73
  executables:
@@ -85,6 +86,7 @@ files:
85
86
  - lib/keyp/cli.rb
86
87
  - lib/keyp/version.rb
87
88
  - spec/keyp_spec.rb
89
+ - spec/keyper_spec.rb
88
90
  - spec/spec_helper.rb
89
91
  homepage: https://github.com/johnbaldwin/keyp-ruby
90
92
  licenses:
@@ -109,7 +111,8 @@ rubyforge_project:
109
111
  rubygems_version: 2.2.1
110
112
  signing_key:
111
113
  specification_version: 4
112
- summary: https://github.com/johnbaldwin/keyp-ruby
114
+ summary: Manage environment/machine specific key:value pairs for your Ruby application.
113
115
  test_files:
114
116
  - spec/keyp_spec.rb
117
+ - spec/keyper_spec.rb
115
118
  - spec/spec_helper.rb