heirloom 0.7.3 → 0.7.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ ## v0.7.4:
2
+
3
+ * Add support to read password from file
4
+
1
5
  ## v0.7.3:
2
6
 
3
7
  * Fix bug in latest_id method
@@ -33,12 +33,15 @@ module Heirloom
33
33
 
34
34
  def download
35
35
  ensure_directory :path => @opts[:output], :config => @config
36
- ensure_valid_secret :secret => @opts[:secret], :config => @config
36
+ secret = read_secret :opts => @opts,
37
+ :config => @config
38
+ ensure_valid_secret :secret => secret,
39
+ :config => @config
37
40
  archive = @archive.download :output => @opts[:output],
38
41
  :extract => @opts[:extract],
39
- :secret => @opts[:secret],
40
42
  :region => @region,
41
- :base_prefix => @base
43
+ :base_prefix => @base,
44
+ :secret => secret
42
45
  exit 1 unless archive
43
46
  end
44
47
 
@@ -73,6 +76,8 @@ EOS
73
76
  opt :region, "Region to download Heirloom.", :type => :string,
74
77
  :default => 'us-west-1'
75
78
  opt :secret, "Secret for ecrypted Heirloom.", :type => :string
79
+ opt :secret_file, "Read secret from file.", :type => :string,
80
+ :short => :none
76
81
  opt :aws_access_key, "AWS Access Key ID", :type => :string,
77
82
  :short => :none
78
83
  opt :aws_secret_key, "AWS Secret Access Key", :type => :string,
@@ -175,6 +175,23 @@ module Heirloom
175
175
  :config => args[:config]
176
176
  archive.list(1).first
177
177
  end
178
+
179
+ def read_secret(args)
180
+ opts = args[:opts]
181
+ config = args[:config]
182
+ logger = config.logger
183
+
184
+ return nil unless opts[:secret] || opts[:secret_file]
185
+
186
+ return opts[:secret] if opts[:secret]
187
+
188
+ unless File.exists? opts[:secret_file]
189
+ logger.error "Unable to read #{opts[:secret_file]}."
190
+ exit 1
191
+ end
192
+
193
+ (File.read opts[:secret_file]).chomp
194
+ end
178
195
  end
179
196
  end
180
197
  end
@@ -37,16 +37,19 @@ module Heirloom
37
37
  :config => @config
38
38
  ensure_directory :path => @opts[:directory],
39
39
  :config => @config
40
- ensure_valid_secret :secret => @opts[:secret],
40
+
41
+ secret = read_secret :opts => @opts,
42
+ :config => @config
43
+ ensure_valid_secret :secret => secret,
41
44
  :config => @config
42
45
 
43
46
  @archive.destroy if @archive.exists?
44
47
 
45
- build = @archive.build :base => @base,
46
- :directory => @opts[:directory],
47
- :exclude => @opts[:exclude],
48
- :git => @opts[:git],
49
- :secret => @opts[:secret]
48
+ build = @archive.build :base => @base,
49
+ :directory => @opts[:directory],
50
+ :exclude => @opts[:exclude],
51
+ :git => @opts[:git],
52
+ :secret => secret
50
53
 
51
54
  unless build
52
55
  @logger.error "Build failed."
@@ -86,9 +89,11 @@ Can be specified multiple times.", :type => :string, :multi => true
86
89
  opt :name, "Name of Heirloom.", :type => :string
87
90
  opt :public, "Set this Heirloom as public readable?"
88
91
  opt :secret, "Encrypt the Heirloom with given secret.", :type => :string
89
- opt :aws_access_key, "AWS Access Key ID", :type => :string,
92
+ opt :secret_file, "Read secret from file.", :type => :string,
93
+ :short => :none
94
+ opt :aws_access_key, "AWS Access Key ID", :type => :string,
90
95
  :short => :none
91
- opt :aws_secret_key, "AWS Secret Access Key", :type => :string,
96
+ opt :aws_secret_key, "AWS Secret Access Key", :type => :string,
92
97
  :short => :none
93
98
  end
94
99
  end
@@ -1,3 +1,3 @@
1
1
  module Heirloom
2
- VERSION = "0.7.3"
2
+ VERSION = "0.7.4"
3
3
  end
@@ -283,4 +283,38 @@ describe Heirloom do
283
283
 
284
284
  end
285
285
 
286
+ context "read secret from file" do
287
+ before do
288
+ @archive_mock = mock 'archive'
289
+ @logger_stub = stub 'logger', :error => true
290
+ @config_stub = stub 'config', :logger => @logger_stub
291
+ @options = { :config => @config_stub, :opts => {} }
292
+ @object = Object.new
293
+ @object.extend Heirloom::CLI::Shared
294
+ end
295
+
296
+ it "should exit if the file does not exist" do
297
+ @options[:opts][:secret_file] = '/bad/file'
298
+ File.stub :exists? => false
299
+ lambda { @object.read_secret @options }.
300
+ should raise_error SystemExit
301
+ end
302
+
303
+ it "should return the contents of the file with newline removed" do
304
+ file_mock = mock 'file'
305
+ @options[:opts][:secret_file] = '/good/file'
306
+ File.stub :exists? => true
307
+ File.should_receive(:read).
308
+ with('/good/file').
309
+ and_return "the-password\n"
310
+ @object.read_secret(@options).
311
+ should == 'the-password'
312
+ end
313
+
314
+ it "should return the password specified as secret" do
315
+ @options[:opts][:secret] = 'the-password'
316
+ @object.read_secret(@options).should == 'the-password'
317
+ end
318
+
319
+ end
286
320
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heirloom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.3
4
+ version: 0.7.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-06 00:00:00.000000000 Z
12
+ date: 2012-09-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70200792914460 !ruby/object:Gem::Requirement
16
+ requirement: &70113954151760 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70200792914460
24
+ version_requirements: *70113954151760
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: fog
27
- requirement: &70200792913840 !ruby/object:Gem::Requirement
27
+ requirement: &70113954150340 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.5.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70200792913840
35
+ version_requirements: *70113954150340
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: grit
38
- requirement: &70200792913160 !ruby/object:Gem::Requirement
38
+ requirement: &70113954149460 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 2.5.0
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70200792913160
46
+ version_requirements: *70113954149460
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: trollop
49
- requirement: &70200792912620 !ruby/object:Gem::Requirement
49
+ requirement: &70113954148360 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - =
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '2.0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70200792912620
57
+ version_requirements: *70113954148360
58
58
  description: I help build and manage building tar.gz files and deploying them into
59
59
  the cloud
60
60
  email:
@@ -184,7 +184,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
184
184
  version: '0'
185
185
  segments:
186
186
  - 0
187
- hash: 1261279561972462313
187
+ hash: 719472930190387548
188
188
  required_rubygems_version: !ruby/object:Gem::Requirement
189
189
  none: false
190
190
  requirements:
@@ -193,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
193
193
  version: '0'
194
194
  segments:
195
195
  - 0
196
- hash: 1261279561972462313
196
+ hash: 719472930190387548
197
197
  requirements: []
198
198
  rubyforge_project: heirloom
199
199
  rubygems_version: 1.8.16