heirloom 0.10.1 → 0.11.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -2,3 +2,4 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ .idea/
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  ## HEAD:
2
2
 
3
+ * Add support for multiple environments
4
+ * Environment named 'default' is now the default
5
+ * Added functionality to the show command to include permissions of objects
6
+ * Updating to fog 1.10.0
7
+ * Add support for authorizing accounts using the canonical ID
8
+ * Updated catalog output to include s3 urls
9
+ * Catalog output renamed Bucket Prefix to bucket_prefix
10
+ * Catalog output renamed Region to region
11
+
3
12
  ## 0.10.1 (02/28/2013):
4
13
 
5
14
  * Minor refactoring of lib/heirloom/cipher/shared.rb
data/README.md CHANGED
@@ -25,10 +25,19 @@ gem install heirloom --no-ri --no-rdoc
25
25
  To get started, copy the sample below to ~/.heirloom.yml and update the specified fields.
26
26
 
27
27
  ```
28
+ # default environment
28
29
  aws:
29
30
  access_key: UPDATE_ME
30
31
  secret_key: UPDATE_ME
31
32
  metadata_region: us-west-1
33
+
34
+ # multiple environments can be defined and
35
+ # selected via cli with -e or --environment
36
+
37
+ # prod:
38
+ # access_key: UPDATE_ME
39
+ # secret_key: UPDATE_ME
40
+ # metadata_region: us-west-1
32
41
  ```
33
42
 
34
43
  Documentation
data/heirloom.gemspec CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
22
22
  s.add_development_dependency "rspec", '~> 2.11.0'
23
23
  s.add_development_dependency "rake"
24
24
 
25
- s.add_runtime_dependency 'fog', '~> 1.6.0'
25
+ s.add_runtime_dependency 'fog', '~> 1.10.0'
26
26
  s.add_runtime_dependency 'trollop', '= 2.0'
27
27
  s.add_runtime_dependency 'xml-simple', '~> 1.1.2'
28
28
  end
@@ -1,6 +1,7 @@
1
1
  module Heirloom
2
2
  module ACL
3
3
  class S3
4
+ include Heirloom::Utils::Email
4
5
 
5
6
  attr_accessor :accounts, :config, :logger, :region
6
7
 
@@ -41,15 +42,10 @@ module Heirloom
41
42
 
42
43
  a = Array.new
43
44
 
44
- # Add each account email as read access
45
45
  accounts.each do |g|
46
- a << {
47
- 'Grantee' => { 'EmailAddress' => g } ,
48
- 'Permission' => 'READ'
49
- }
46
+ a << { 'Grantee' => grantee(g), 'Permission' => 'READ' }
50
47
  end
51
48
 
52
- # Grand owner full access
53
49
  a << { 'Grantee' => { 'DisplayName' => name, 'ID' => id },
54
50
  'Permission' => 'FULL_CONTROL'
55
51
  }
@@ -68,6 +64,10 @@ module Heirloom
68
64
  :region => @region
69
65
  end
70
66
 
67
+ def grantee(account)
68
+ valid_email?(account) ? { 'EmailAddress' => account } : { 'ID' => account }
69
+ end
70
+
71
71
  end
72
72
  end
73
73
  end
@@ -1,6 +1,8 @@
1
1
  module Heirloom
2
2
 
3
3
  class Authorizer
4
+
5
+ include Heirloom::Utils::Email
4
6
 
5
7
  def initialize(args)
6
8
  @config = args[:config]
@@ -38,17 +40,22 @@ module Heirloom
38
40
  private
39
41
 
40
42
  def validate_format_of_accounts
43
+ status = true
44
+
41
45
  @accounts.each do |account|
42
- unless validate_email account
43
- @logger.error "#{account} is not a valid email address."
44
- return false
46
+ if valid_account?(account)
47
+ @logger.info "Using #{account} for authorization"
48
+ else
49
+ @logger.error "#{account} is not a valid account type"
50
+ status = false
45
51
  end
46
52
  end
53
+
54
+ status
47
55
  end
48
56
 
49
- def validate_email email
50
- email_pattern = (email =~ /^.*@.*\..*$/)
51
- email_pattern.nil? ? false : true
57
+ def valid_account?(account)
58
+ valid_email?(account) || account.length == 64
52
59
  end
53
60
 
54
61
  def reader
@@ -59,13 +59,35 @@ module Heirloom
59
59
  def show
60
60
  query = sdb.select "select * from `#{@domain}` where itemName() = '#{@id}'"
61
61
  items = query[@id] ? query[@id] : {}
62
- Hash.new.tap do |hash|
62
+ data = Hash.new.tap do |hash|
63
63
  items.each_pair.map do |key,value|
64
64
  hash[key] = value.first
65
65
  end
66
66
  end
67
67
  end
68
68
 
69
+ def object_acls
70
+ data = {}
71
+ regions.each do |region|
72
+ object_name = "#{@name}/#{key_name}"
73
+
74
+ bucket = get_bucket :region => region
75
+
76
+ s3_acl = AWS::S3.new :config => @config,
77
+ :region => region
78
+
79
+ object_acl = s3_acl.get_object_acl :bucket => bucket,
80
+ :object_name => object_name
81
+
82
+ object_acl.delete "Owner"
83
+ output = object_acl["AccessControlList"].map do |x|
84
+ "#{x["Grantee"]["DisplayName"]}:#{x["Permission"]}".downcase
85
+ end
86
+ data.merge!"#{region}-permissions" => output.join(', ')
87
+ end
88
+ data
89
+ end
90
+
69
91
  def key_name
70
92
  encrypted? ? "#{@id}.tar.gz.gpg" : "#{@id}.tar.gz"
71
93
  end
@@ -76,7 +76,7 @@ module Heirloom
76
76
  end
77
77
 
78
78
  def show
79
- reader.show
79
+ reader.show.merge reader.object_acls
80
80
  end
81
81
 
82
82
  def list(limit=10)
@@ -78,8 +78,8 @@ module Heirloom
78
78
  @s3.get_object(bucket_name, object_name).body
79
79
  end
80
80
 
81
- def get_bucket_acl(bucket)
82
- @s3.get_bucket_acl(bucket).body
81
+ def get_object_acl(args)
82
+ @s3.get_object_acl(args[:bucket], args[:object_name]).body
83
83
  end
84
84
 
85
85
  def get_bucket_object_versions(bucket)
@@ -43,10 +43,11 @@ Usage:
43
43
 
44
44
  heirloom authorize -n NAME -i ID -a AWS_ACCOUNT1 -a AWS_ACCOUNT2
45
45
 
46
- Note: This will replace all current authorizations with those specified and make the Heirloom private.
46
+ Note: This will replace all current authorizations with those specified and make the Heirloom private. Use the 'show' command to retrieve the existing authorizations assigned to an object.
47
+
47
48
 
48
49
  EOS
49
- opt :accounts, "AWS Account(s) email to authorize. Can be specified multiple times.", :type => :string,
50
+ opt :accounts, "AWS Account(s) email or canonical_ID to authorize. Can be specified multiple times.", :type => :string,
50
51
  :multi => true
51
52
  opt :help, "Display Help"
52
53
  opt :id, "ID of the Heirloom to authorize.", :type => :string
@@ -59,6 +60,7 @@ EOS
59
60
  :short => :none
60
61
  opt :aws_secret_key, "AWS Secret Access Key", :type => :string,
61
62
  :short => :none
63
+ opt :environment, "Environment (defined in ~/.heirloom.yml)", :type => :string
62
64
  end
63
65
  end
64
66
 
@@ -59,6 +59,7 @@ EOS
59
59
  :short => :none
60
60
  opt :aws_secret_key, "AWS Secret Access Key", :type => :string,
61
61
  :short => :none
62
+ opt :environment, "Environment (defined in ~/.heirloom.yml)", :type => :string
62
63
  end
63
64
  end
64
65
 
@@ -55,6 +55,7 @@ EOS
55
55
  :short => :none
56
56
  opt :aws_secret_key, "AWS Secret Access Key", :type => :string,
57
57
  :short => :none
58
+ opt :environment, "Environment (defined in ~/.heirloom.yml)", :type => :string
58
59
  end
59
60
  end
60
61
  end
@@ -86,6 +86,7 @@ EOS
86
86
  :short => :none
87
87
  opt :aws_secret_key, "AWS Secret Access Key", :type => :string,
88
88
  :short => :none
89
+ opt :environment, "Environment (defined in ~/.heirloom.yml)", :type => :string
89
90
  end
90
91
  end
91
92
  end
@@ -30,9 +30,15 @@ module Heirloom
30
30
 
31
31
  def details
32
32
  data = @catalog.each_pair.map do |k,v|
33
+ urls = v["regions"].map do |region|
34
+ bucket_prefix = v["bucket_prefix"].first
35
+ " #{region}-s3-url : s3://#{bucket_prefix}-#{region}/#{k}"
36
+ end
37
+
33
38
  d = k + "\n"
34
- d << " Regions : " + @catalog[k]["regions"].join(", ") + "\n"
35
- d << " Bucket Prefix : " + @catalog[k]["bucket_prefix"].first
39
+ d << " regions : " + @catalog[k]["regions"].join(", ") + "\n"
40
+ d << " bucket_prefix : " + @catalog[k]["bucket_prefix"].first + "\n"
41
+ d << urls.join("\n")
36
42
  end
37
43
  data.join "\n"
38
44
  end
@@ -39,6 +39,7 @@ module Heirloom
39
39
  def is_internal_attribute?(attribute)
40
40
  return true if is_reserved? attribute
41
41
  return true if is_endpoint? attribute
42
+ return true if are_permissions? attribute
42
43
  false
43
44
  end
44
45
 
@@ -49,6 +50,10 @@ module Heirloom
49
50
  def is_endpoint?(attribute)
50
51
  attribute.match('^.*-.*-\d*-s3|http|https-url$')
51
52
  end
53
+
54
+ def are_permissions?(attribute)
55
+ attribute.match('^.*permissions')
56
+ end
52
57
  end
53
58
  end
54
59
  end
@@ -58,6 +58,7 @@ EOS
58
58
  :short => :none
59
59
  opt :aws_secret_key, "AWS Secret Access Key", :type => :string,
60
60
  :short => :none
61
+ opt :environment, "Environment (defined in ~/.heirloom.yml)", :type => :string
61
62
  end
62
63
  end
63
64
 
@@ -88,6 +88,7 @@ Can be specified multiple times.", :type => :string,
88
88
  :short => :none
89
89
  opt :aws_secret_key, "AWS Secret Access Key", :type => :string,
90
90
  :short => :none
91
+ opt :environment, "Environment (defined in ~/.heirloom.yml)", :type => :string
91
92
  end
92
93
  end
93
94
 
@@ -5,7 +5,7 @@ module Heirloom
5
5
  def load_config(args)
6
6
  opts = args[:opts]
7
7
  logger = args[:logger]
8
- config = Config.new :logger => logger
8
+ config = Config.new :logger => logger, :environment => opts[:environment]
9
9
  config.access_key = opts[:aws_access_key] if opts[:aws_access_key]
10
10
  config.secret_key = opts[:aws_secret_key] if opts[:aws_secret_key]
11
11
  config.metadata_region = opts[:metadata_region] if opts[:metadata_region]
@@ -69,6 +69,7 @@ EOS
69
69
  :short => :none
70
70
  opt :aws_secret_key, "AWS Secret Access Key", :type => :string,
71
71
  :short => :none
72
+ opt :environment, "Environment (defined in ~/.heirloom.yml)", :type => :string
72
73
  end
73
74
  end
74
75
 
@@ -61,6 +61,7 @@ EOS
61
61
  :short => :none
62
62
  opt :aws_secret_key, "AWS Secret Access Key", :type => :string,
63
63
  :short => :none
64
+ opt :environment, "Environment (defined in ~/.heirloom.yml)", :type => :string
64
65
  end
65
66
  end
66
67
  end
@@ -72,6 +72,7 @@ EOS
72
72
  :short => :none
73
73
  opt :aws_secret_key, "AWS Secret Access Key", :type => :string,
74
74
  :short => :none
75
+ opt :environment, "Environment (defined in ~/.heirloom.yml)", :type => :string
75
76
  end
76
77
  end
77
78
 
@@ -84,7 +84,7 @@ heirloom upload -n NAME -i ID -d DIRECTORY_TO_UPLOAD
84
84
  EOS
85
85
  opt :directory, "Source directory to upload.", :type => :string
86
86
  opt :exclude, "File(s) or directorie(s) to exclude. \
87
- Can be specified multiple times.", :type => :string, :multi => true
87
+ Can be specified multiple times.", :type => :string, :multi => true, :short => "-x"
88
88
  opt :help, "Display Help"
89
89
  opt :id, "ID for Heirloom.", :type => :string
90
90
  opt :level, "Log level [debug|info|warn|error].", :type => :string,
@@ -100,6 +100,7 @@ Can be specified multiple times.", :type => :string, :multi => true
100
100
  :short => :none
101
101
  opt :aws_secret_key, "AWS Secret Access Key", :type => :string,
102
102
  :short => :none
103
+ opt :environment, "Environment (defined in ~/.heirloom.yml)", :type => :string
103
104
  end
104
105
  end
105
106
 
@@ -1,22 +1,23 @@
1
1
  module Heirloom
2
2
  class Config
3
3
 
4
- attr_accessor :access_key, :secret_key, :metadata_region, :logger
4
+ attr_accessor :access_key, :secret_key, :metadata_region, :logger, :environment
5
5
 
6
6
  def initialize(args={})
7
- @opts = args[:opts] ||= Hash.new
8
- @config = load_config_file
9
- self.logger = args[:logger] ||= HeirloomLogger.new
7
+ @opts = args[:opts] ||= Hash.new
8
+ @logger = args[:logger] ||= HeirloomLogger.new
9
+ @environment = args[:environment] ||= 'default'
10
+ @config = load_config_file
10
11
  load_config
11
12
  end
12
13
 
13
14
  def load_config
14
- self.access_key = @opts.fetch :aws_access_key,
15
- @config['access_key']
16
- self.secret_key = @opts.fetch :aws_secret_key,
17
- @config['secret_key']
18
- self.metadata_region = @opts.fetch :metadata_region,
19
- @config['metadata_region']
15
+ @access_key = @opts.fetch :aws_access_key,
16
+ @config['access_key']
17
+ @secret_key = @opts.fetch :aws_secret_key,
18
+ @config['secret_key']
19
+ @metadata_region = @opts.fetch :metadata_region,
20
+ @config['metadata_region']
20
21
  end
21
22
 
22
23
  private
@@ -26,7 +27,12 @@ module Heirloom
26
27
 
27
28
  if File.exists? config_file
28
29
  data = YAML::load File.open(config_file)
29
- data['aws']
30
+ if data.has_key? @environment
31
+ data[@environment]
32
+ else
33
+ @logger.error "Environment '#{@environment}' not found in config file."
34
+ exit 1
35
+ end
30
36
  else
31
37
  { }
32
38
  end
@@ -0,0 +1,11 @@
1
+ module Heirloom
2
+ module Utils
3
+ module Email
4
+
5
+ def valid_email?(email)
6
+ email =~ /^.*@.*\..*$/
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -1 +1,2 @@
1
1
  require 'heirloom/utils/file'
2
+ require 'heirloom/utils/email'
@@ -1,3 +1,3 @@
1
1
  module Heirloom
2
- VERSION = "0.10.1"
2
+ VERSION = "0.11.0.beta.1"
3
3
  end
@@ -12,14 +12,14 @@ describe Heirloom do
12
12
  :id => '123.tar.gz'
13
13
  end
14
14
 
15
- it "should authorize access to an archive in all regions" do
15
+ it "should authorize access to an archive in all regions for email or longid" do
16
16
  s3_acl_mock = mock 's3 acl'
17
17
  reader_mock = mock 'reader mock'
18
18
  reader_mock.stub :key_name => '123.tar.gz'
19
19
  reader_mock.should_receive(:get_bucket).exactly(2).times.
20
20
  and_return('the-bucket')
21
21
 
22
- accounts = [ "test@a.com", "a@test.com", "test@test.co", "test@test.co.uk" ]
22
+ accounts = [ "test@a.com", "a@test.com", "test@test.co", "test@test.co.uk","08b21b085ca99e70859487d685191f40d951daa0fbcb5bec51bf5ea6023e445d" ]
23
23
 
24
24
  Heirloom::Reader.should_receive(:new).
25
25
  with(:config => @config_mock,
@@ -45,12 +45,32 @@ describe Heirloom do
45
45
  should be_true
46
46
  end
47
47
 
48
- it "should exit when an account is not an email" do
48
+ it "should exit when an account is a shortid" do
49
49
  @logger_mock.should_receive(:error)
50
- @authorizer.authorize(:accounts => ['good@good.com', 'bad@blah'],
50
+ @authorizer.authorize(:accounts => [ '123456789_1234', 'good@good.com'],
51
51
  :regions => ['us-west-1', 'us-west-2']).
52
52
  should be_false
53
53
  end
54
54
 
55
+ it "should exit when a bad email is given" do
56
+ @logger_mock.should_receive(:error)
57
+ @authorizer.authorize(:accounts => ['bad@bad', 'good@good.com'],
58
+ :regions => ['us-west-1', 'us-west-2']).
59
+ should be_false
60
+ end
55
61
 
62
+ it "should exit when an id which is not long(64) or short(16)" do
63
+ @logger_mock.should_receive(:error)
64
+ @authorizer.authorize(:accounts => ['123456789_123456789_1', 'good@good.com'],
65
+ :regions => ['us-west-1', 'us-west-2']).
66
+ should be_false
67
+ end
68
+
69
+ it "should exit even when the first value is valid" do
70
+ @logger_mock.should_receive(:error)
71
+ @authorizer.authorize(:accounts => ['good@good.com', '123456789_123456789_1'],
72
+ :regions => ['us-west-1', 'us-west-2']).
73
+ should be_false
74
+ end
75
+
56
76
  end
@@ -4,10 +4,9 @@ describe Heirloom do
4
4
 
5
5
  before do
6
6
  @sdb_mock = mock 'sdb'
7
- @config_mock = double 'config'
7
+ @config_mock = mock 'config'
8
8
  @logger_stub = stub :debug => true
9
- @config_mock.should_receive(:logger).and_return @logger_stub
10
- Heirloom::AWS::SimpleDB.should_receive(:new).and_return @sdb_mock
9
+ @config_mock.stub :logger => @logger_stub
11
10
  @reader = Heirloom::Reader.new :config => @config_mock,
12
11
  :name => 'tim',
13
12
  :id => '123'
@@ -15,6 +14,7 @@ describe Heirloom do
15
14
 
16
15
  context "domain does exist" do
17
16
  before do
17
+ Heirloom::AWS::SimpleDB.stub :new => @sdb_mock
18
18
  @sdb_mock.stub :domain_exists? => true
19
19
  end
20
20
 
@@ -48,11 +48,11 @@ describe Heirloom do
48
48
 
49
49
  it "should return the bucket if it exists" do
50
50
  @sdb_mock.should_receive(:select).
51
- exactly(3).times.
51
+ at_least(:once).
52
52
  with("select * from `heirloom_tim` where itemName() = '123'").
53
- and_return( { '123' =>
54
- { 'us-west-1-s3-url' =>
55
- [ 's3://the-bucket/the-name/123.tar.gz' ]
53
+ and_return( { '123' =>
54
+ { 'us-west-1-s3-url' =>
55
+ [ 's3://the-bucket/the-name/123.tar.gz' ]
56
56
  }
57
57
  } )
58
58
  @reader.get_bucket(:region => 'us-west-1').should == 'the-bucket'
@@ -60,7 +60,6 @@ describe Heirloom do
60
60
 
61
61
  it "should return nil if the key does not exist" do
62
62
  @sdb_mock.should_receive(:select).
63
- exactly(1).times.
64
63
  with("select * from `heirloom_tim` where itemName() = '123'").
65
64
  and_return( { } )
66
65
  @reader.get_key(:region => 'us-west-1').should == nil
@@ -68,7 +67,6 @@ describe Heirloom do
68
67
 
69
68
  it "should return nil if the bucket does not exist" do
70
69
  @sdb_mock.should_receive(:select).
71
- exactly(1).times.
72
70
  with("select * from `heirloom_tim` where itemName() = '123'").
73
71
  and_return( { } )
74
72
  @reader.get_bucket(:region => 'us-west-1').should == nil
@@ -76,11 +74,11 @@ describe Heirloom do
76
74
 
77
75
  it "should return the key if it exists" do
78
76
  @sdb_mock.should_receive(:select).
79
- exactly(6).times.
77
+ at_least(:once).
80
78
  with("select * from `heirloom_tim` where itemName() = '123'").
81
- and_return( { '123' =>
82
- { 'us-west-1-s3-url' =>
83
- ['s3://the-url/the-bucket/123.tar.gz']
79
+ and_return( { '123' =>
80
+ { 'us-west-1-s3-url' =>
81
+ ['s3://the-url/the-bucket/123.tar.gz']
84
82
  }
85
83
  } )
86
84
  @reader.get_key(:region => 'us-west-1').should == 'the-bucket/123.tar.gz'
@@ -102,15 +100,14 @@ describe Heirloom do
102
100
 
103
101
  it "should return the regions the archive has been uploaded to" do
104
102
  @sdb_mock.should_receive(:select).
105
- exactly(1).times.
106
103
  with("select * from `heirloom_tim` where itemName() = '123'").
107
- and_return( { '123' =>
108
- { 'us-west-1-s3-url' =>
104
+ and_return( { '123' =>
105
+ { 'us-west-1-s3-url' =>
109
106
  ['s3://the-url-us-west-1/the-bucket/123.tar.gz'],
110
- 'build_by' =>
111
- ['user'],
112
- 'us-east-1-s3-url' =>
113
- ['s3://the-url-us-east-1/the-bucket/123.tar.gz']
107
+ 'build_by' =>
108
+ ['user'],
109
+ 'us-east-1-s3-url' =>
110
+ ['s3://the-url-us-east-1/the-bucket/123.tar.gz']
114
111
  }
115
112
  } )
116
113
  @reader.regions.should == ['us-west-1', 'us-east-1']
@@ -120,6 +117,7 @@ describe Heirloom do
120
117
 
121
118
  context "domain does not exist" do
122
119
  before do
120
+ Heirloom::AWS::SimpleDB.stub :new => @sdb_mock
123
121
  @sdb_mock.stub :domain_exists? => false
124
122
  end
125
123
 
@@ -128,4 +126,33 @@ describe Heirloom do
128
126
  end
129
127
  end
130
128
 
129
+ context "object_acl verify" do
130
+ it "should get object_acls" do
131
+ regions = ['us-west-1', 'us-west-2']
132
+ @config_mock.stub :access_key => 'the-key',
133
+ :secret_key => 'the-secret'
134
+ @reader.stub :regions => regions,
135
+ :key_name => 'mockvalue',
136
+ :get_bucket => 'mockvalue'
137
+ data = { "Owner" => { "ID" => "123", "DisplayName" => "lc" },
138
+ "AccessControlList" => [
139
+ { "Grantee" => { "ID" => "321", "DisplayName" => "rickybobby" },
140
+ "Permission" => "READ" },
141
+ { "Grantee" => { "ID" => "123", "DisplayName" => "lc" },
142
+ "Permission" => "FULL_CONTROL" }]
143
+ }
144
+ s3_stub = stub 's3', :get_object_acl => data
145
+
146
+ regions.each do |region|
147
+ Heirloom::AWS::S3.should_receive(:new).
148
+ with(:config => @config_mock,
149
+ :region => region).
150
+ and_return s3_stub
151
+ end
152
+
153
+ @reader.object_acls.should == { 'us-west-1-permissions' => 'rickybobby:read, lc:full_control',
154
+ 'us-west-2-permissions' => 'rickybobby:read, lc:full_control' }
155
+ end
156
+ end
157
+
131
158
  end
data/spec/archive_spec.rb CHANGED
@@ -104,15 +104,27 @@ describe Heirloom do
104
104
  @archive.exists?.should be_false
105
105
  end
106
106
 
107
- it "should call show method" do
108
- mock = double('Mock')
107
+ it "should call show method" do
108
+ reader_mock = mock 'reader'
109
+ show_data = { 'id' => '0.0.7',
110
+ 'encrypted' => 'true',
111
+ 'bucket_prefix' => 'rickybobby',
112
+ 'us-west-2-s3-url' => 's3://rickybobby-us-west-2/demo2/0.0.7.tar.gz.gpg'
113
+ }
114
+ object_acls_data = { 'us-west-2-perms' => 'rickybobby:read, lc:full_control',
115
+ 'us-west-1-perms' => 'rickybobby:read, lc:full_control'
116
+ }
117
+ merge_data = show_data.merge object_acls_data
118
+
109
119
  Heirloom::Reader.should_receive(:new).
110
- with(:config => @config_mock,
111
- :name => 'chef',
112
- :id => '123').
113
- and_return mock
114
- mock.should_receive(:show)
115
- @archive.show
120
+ with(:config => @config_mock,
121
+ :name => 'chef',
122
+ :id => '123').
123
+ and_return reader_mock
124
+
125
+ reader_mock.stub(:show).and_return(show_data)
126
+ reader_mock.stub(:object_acls).and_return(object_acls_data)
127
+ @archive.show.should == merge_data
116
128
  end
117
129
 
118
130
  it "should call list method" do
data/spec/aws/s3_spec.rb CHANGED
@@ -208,6 +208,16 @@ describe Heirloom do
208
208
  @s3.get_object('bucket', 'object')
209
209
  end
210
210
 
211
+ it "should get an objects acl from s3" do
212
+ body_mock = mock 'body'
213
+ @fog_mock.should_receive(:get_object_acl).
214
+ with('bucket', 'object').and_return(body_mock)
215
+ body_mock.stub :body => 'data'
216
+ @s3.get_object_acl({ :bucket => 'bucket', :object_name => 'object'}).
217
+ should == 'data'
218
+ end
219
+
220
+
211
221
  it "should set object acls" do
212
222
  @fog_mock.should_receive(:put_object_acl).
213
223
  with 'bucket', 'object', 'grants'
@@ -24,7 +24,11 @@ describe Heirloom do
24
24
 
25
25
  context "filtered" do
26
26
  it "should return the name with details" do
27
- format = "test1\n Regions : us-west-1, us-east-1\n Bucket Prefix : bp1"
27
+ format = "test1\n" +
28
+ " regions : us-west-1, us-east-1\n" +
29
+ " bucket_prefix : bp1\n" +
30
+ " us-west-1-s3-url : s3://bp1-us-west-1/test1\n" +
31
+ " us-east-1-s3-url : s3://bp1-us-east-1/test1"
28
32
  @formatter.format(:catalog => @catalog,
29
33
  :name => 'test1').should == format
30
34
  end
@@ -4,14 +4,16 @@ require 'heirloom/cli'
4
4
  describe Heirloom do
5
5
 
6
6
  before do
7
- @attributes = { 'id' => '123',
8
- 'another_data' => 'more_data',
9
- 'built_at' => 'today',
10
- 'built_by' => 'me',
11
- 'bucket_prefix' => 'bp',
12
- 'us-west-1-s3-url' => 's3',
13
- 'us-west-1-http-url' => 'http',
14
- 'us-west-1-https-url' => 'https' }
7
+ @attributes = { 'id' => '123',
8
+ 'another_data' => 'more_data',
9
+ 'built_at' => 'today',
10
+ 'built_by' => 'me',
11
+ 'bucket_prefix' => 'bp',
12
+ 'us-west-1-s3-url' => 's3',
13
+ 'us-west-1-http-url' => 'http',
14
+ 'us-west-1-https-url' => 'https',
15
+ 'us-west-1-permissions' => 'rickybobby:full-control',
16
+ 'us-west-2-permissions' => 'rickybobby:full-control' }
15
17
  end
16
18
 
17
19
  it "should remove reserved / endpoint attribs" do
@@ -74,7 +74,7 @@ describe Heirloom do
74
74
  @logger_mock = mock 'logger'
75
75
  @object = Object.new
76
76
  @object.extend Heirloom::CLI::Shared
77
- Heirloom::Config.should_receive(:new).with(:logger => @logger_mock).
77
+ Heirloom::Config.should_receive(:new).with(:logger => @logger_mock, :environment => nil).
78
78
  and_return @config_mock
79
79
  end
80
80
 
data/spec/config_spec.rb CHANGED
@@ -3,10 +3,15 @@ require 'spec_helper'
3
3
  describe Heirloom do
4
4
 
5
5
  before do
6
- @config_file = { 'aws' =>
6
+ @config_file = { 'default' =>
7
7
  { 'access_key' => 'key',
8
8
  'secret_key' => 'secret',
9
9
  'metadata_region' => 'us-west-2'
10
+ },
11
+ 'dev' =>
12
+ { 'access_key' => 'devkey',
13
+ 'secret_key' => 'devsecret',
14
+ 'metadata_region' => 'devmd'
10
15
  }
11
16
  }
12
17
  @opts = { :aws_access_key => 'optkey',
@@ -31,9 +36,9 @@ describe Heirloom do
31
36
  File.should_receive(:open).with("#{ENV['HOME']}/.heirloom.yml").
32
37
  and_return(@config_file.to_yaml)
33
38
  config = Heirloom::Config.new
34
- config.access_key.should == @config_file['aws']['access_key']
35
- config.secret_key.should == @config_file['aws']['secret_key']
36
- config.metadata_region.should == @config_file['aws']['metadata_region']
39
+ config.access_key.should == @config_file['default']['access_key']
40
+ config.secret_key.should == @config_file['default']['secret_key']
41
+ config.metadata_region.should == @config_file['default']['metadata_region']
37
42
  end
38
43
 
39
44
  it "should override config settings in file from opts" do
@@ -54,4 +59,40 @@ describe Heirloom do
54
59
  config.metadata_region.should be_nil
55
60
  end
56
61
 
62
+ it "should load a different environment if requested" do
63
+ File.stub :exists? => true
64
+ File.should_receive(:open).with("#{ENV['HOME']}/.heirloom.yml").
65
+ and_return(@config_file.to_yaml)
66
+ config = Heirloom::Config.new :environment => 'dev'
67
+ config.access_key.should == @config_file['dev']['access_key']
68
+ config.secret_key.should == @config_file['dev']['secret_key']
69
+ config.metadata_region.should == @config_file['dev']['metadata_region']
70
+ end
71
+
72
+ it "should still allow overrides with different environments" do
73
+ File.stub :exists? => true
74
+ File.should_receive(:open).with("#{ENV['HOME']}/.heirloom.yml").
75
+ and_return(@config_file.to_yaml)
76
+ opts = {
77
+ :aws_access_key => 'specialdevkey'
78
+ }
79
+
80
+ config = Heirloom::Config.new :opts => opts, :environment => 'dev'
81
+ config.access_key.should == 'specialdevkey'
82
+ config.metadata_region.should == @config_file['dev']['metadata_region']
83
+ end
84
+
85
+ it "should complain if a non-existing environment is requested" do
86
+ File.stub :exists? => true
87
+ File.should_receive(:open).with("#{ENV['HOME']}/.heirloom.yml").
88
+ and_return(@config_file.to_yaml)
89
+
90
+ logger_mock = mock 'logger'
91
+ logger_mock.should_receive(:error)
92
+
93
+ lambda {
94
+ config = Heirloom::Config.new :environment => 'missing', :logger => logger_mock
95
+ }.should raise_error SystemExit
96
+ end
97
+
57
98
  end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Heirloom::Utils::Email do
4
+ before do
5
+ @object = Object.new
6
+ @object.extend Heirloom::Utils::Email
7
+ end
8
+
9
+ it "should return that the account is a valid email " do
10
+ account = 'good@good.com'
11
+ @object.valid_email?(account).should be_true
12
+ end
13
+
14
+ it "should return that the account is a valid email " do
15
+ account = 'bad@bad'
16
+ @object.valid_email?(account).should be_false
17
+ end
18
+
19
+ end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heirloom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.1
5
- prerelease:
4
+ version: 0.11.0.beta.1
5
+ prerelease: 7
6
6
  platform: ruby
7
7
  authors:
8
8
  - Brett Weaver
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-28 00:00:00.000000000 Z
12
+ date: 2013-04-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -50,7 +50,7 @@ dependencies:
50
50
  requirements:
51
51
  - - ~>
52
52
  - !ruby/object:Gem::Version
53
- version: 1.6.0
53
+ version: 1.10.0
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
@@ -58,7 +58,7 @@ dependencies:
58
58
  requirements:
59
59
  - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: 1.6.0
61
+ version: 1.10.0
62
62
  - !ruby/object:Gem::Dependency
63
63
  name: trollop
64
64
  requirement: !ruby/object:Gem::Requirement
@@ -168,6 +168,7 @@ files:
168
168
  - lib/heirloom/uploader.rb
169
169
  - lib/heirloom/uploader/s3.rb
170
170
  - lib/heirloom/utils.rb
171
+ - lib/heirloom/utils/email.rb
171
172
  - lib/heirloom/utils/file.rb
172
173
  - lib/heirloom/version.rb
173
174
  - spec/acl/s3_spec.rb
@@ -216,6 +217,7 @@ files:
216
217
  - spec/logger_spec.rb
217
218
  - spec/spec_helper.rb
218
219
  - spec/uploader/s3_spec.rb
220
+ - spec/utils/email_spec.rb
219
221
  - spec/utils/file_spec.rb
220
222
  homepage: ''
221
223
  licenses: []
@@ -229,12 +231,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
229
231
  - - ! '>='
230
232
  - !ruby/object:Gem::Version
231
233
  version: '0'
234
+ segments:
235
+ - 0
236
+ hash: -822415306799597358
232
237
  required_rubygems_version: !ruby/object:Gem::Requirement
233
238
  none: false
234
239
  requirements:
235
- - - ! '>='
240
+ - - ! '>'
236
241
  - !ruby/object:Gem::Version
237
- version: '0'
242
+ version: 1.3.1
238
243
  requirements: []
239
244
  rubyforge_project: heirloom
240
245
  rubygems_version: 1.8.24
@@ -288,4 +293,5 @@ test_files:
288
293
  - spec/logger_spec.rb
289
294
  - spec/spec_helper.rb
290
295
  - spec/uploader/s3_spec.rb
296
+ - spec/utils/email_spec.rb
291
297
  - spec/utils/file_spec.rb