heirloom 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/heirloom/cli.rb CHANGED
@@ -9,10 +9,13 @@ build and manage artifacts
9
9
 
10
10
  Usage:
11
11
 
12
- heirloom [options] build
13
12
  heirloom list
13
+ heirloom build [options]
14
+ heirloom delete [options]
15
+ heirloom info [options]
14
16
  EOS
15
17
  opt :help, "Display Help"
18
+ opt :accounts, "CSV list of accounts to authorize", :type => :string
16
19
  opt :class, "Class of artifact. This should match the SCM repo", :type => :string
17
20
  opt :dir, "Directory which contains git repo", :type => :string
18
21
  opt :prefix, "Bucket prefix", :type => :string
@@ -26,7 +29,8 @@ EOS
26
29
  raise 'Missing required args' unless @opts[:sha] && @opts[:class]
27
30
  h = Heirloom.new :heirloom_type => @opts[:class],
28
31
  :source_dir => @opts[:dir] ||= ".",
29
- :prefix => @opts[:prefix]
32
+ :prefix => @opts[:prefix],
33
+ :accounts => @opts[:accounts].split(',')
30
34
 
31
35
  h.build_and_upload_to_s3(:sha => @opts[:sha])
32
36
  when 'list'
@@ -1,3 +1,3 @@
1
1
  module Heirloom
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/heirloom.rb CHANGED
@@ -40,15 +40,9 @@ module Heirloom
40
40
  sdb.delete args[:class], args[:sha]
41
41
  end
42
42
 
43
- def self.connect_to_sdb
44
- @access_key = ENV['AWS_ACCESS_KEY_ID']
45
- @secret_key = ENV['AWS_SECRET_ACCESS_KEY']
46
-
47
- AWS::SimpleDb.new(@access_key, @secret_key)
48
- end
49
-
50
43
  def initialize(args)
51
44
  @sdb = self.class.connect_to_sdb
45
+ @accounts = args[:accounts]
52
46
 
53
47
  self.heirloom_type = args[:heirloom_type]
54
48
  self.source_dir = args[:source_dir]
@@ -57,6 +51,7 @@ module Heirloom
57
51
 
58
52
  def build_and_upload_to_s3(args)
59
53
  get_commit args[:sha]
54
+ create_sdb_domain
60
55
  raise 'Artifact already uploaded to S3' if already_in_sdb?
61
56
  build_local_artifact
62
57
  create_sdb_record
@@ -89,7 +84,6 @@ module Heirloom
89
84
  end
90
85
 
91
86
  def create_sdb_record
92
- create_sdb_domain
93
87
  @sdb.put_attributes domain, sha, { 'built_by' => "#{user}@#{hostname}",
94
88
  'built_at' => Time.now.utc.iso8601,
95
89
  'tests' => 'pending',
@@ -111,6 +105,7 @@ module Heirloom
111
105
 
112
106
  # Connect to s3 in region of bucket
113
107
  region = options['region']
108
+ endpoint = options['endpoint']
114
109
  connection = Fog::Storage.new :provider => 'AWS',
115
110
  :aws_access_key_id => ENV['AWS_ACCESS_KEY_ID'],
116
111
  :aws_secret_access_key => ENV['AWS_SECRET_ACCESS_KEY'],
@@ -124,23 +119,50 @@ module Heirloom
124
119
  :body => File.open(artifact_path),
125
120
  :public => false
126
121
 
122
+ # Get the bucket owner name and ID
123
+ id = connection.get_bucket_acl(bucket).body['Owner']['ID']
124
+ name = connection.get_bucket_acl(bucket).body['Owner']['Name']
125
+
126
+ # Set the objects ACLs
127
+ connection.put_object_acl(bucket, "#{folder}/#{artifact}", build_bucket_grants(id, name))
128
+
127
129
  # Add the artifact location
128
130
  @sdb.put_attributes domain, sha, { "#{region}-s3-url" => "s3://#{bucket}/#{folder}/#{artifact}" }
129
131
 
130
132
  # Add the http url
131
- @sdb.put_attributes domain, sha, { "#{region}-http-url" => "http://#{bucket}/#{folder}/#{artifact}" }
133
+ @sdb.put_attributes domain, sha, { "#{region}-http-url" => "http://#{endpoint}/#{folder}/#{artifact}" }
132
134
 
133
135
  # Add the https url
134
- @sdb.put_attributes domain, sha, { "#{region}-https-url" => "https://#{bucket}/#{folder}/#{artifact}" }
136
+ @sdb.put_attributes domain, sha, { "#{region}-https-url" => "https://#{endpoint}/#{folder}/#{artifact}" }
135
137
  end
136
138
  end
137
139
 
138
140
  private
139
141
 
142
+ def build_bucket_grants(id, name)
143
+ # Creat the AccessControlList based on given accounts
144
+ a = Array.new
145
+ @accounts.each do |g|
146
+ a << {
147
+ 'Grantee' => { 'EmailAddress' => g } ,
148
+ 'Permission' => 'READ'
149
+ }
150
+ end
151
+
152
+ {
153
+ 'Owner' => {
154
+ 'DisplayName' => name,
155
+ 'ID' => id
156
+ },
157
+ 'AccessControlList' => a
158
+ }
159
+ end
160
+
140
161
  def buckets
141
162
  {
142
163
  "#{prefix}-us-west-1" => {
143
- 'region' => 'us-west-1'
164
+ 'region' => 'us-west-1',
165
+ 'endpoint' => 's3-us-west-1.amazonaws.com'
144
166
  }
145
167
  }
146
168
  end
@@ -185,5 +207,12 @@ module Heirloom
185
207
  Socket.gethostname
186
208
  end
187
209
 
210
+ def self.connect_to_sdb
211
+ @access_key = ENV['AWS_ACCESS_KEY_ID']
212
+ @secret_key = ENV['AWS_SECRET_ACCESS_KEY']
213
+
214
+ AWS::SimpleDb.new(@access_key, @secret_key)
215
+ end
216
+
188
217
  end
189
218
  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.0.1
4
+ version: 0.0.2
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-06-05 00:00:00.000000000 Z
12
+ date: 2012-06-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70129331233340 !ruby/object:Gem::Requirement
16
+ requirement: &70259568822860 !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: *70129331233340
24
+ version_requirements: *70259568822860
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: fog
27
- requirement: &70129331232880 !ruby/object:Gem::Requirement
27
+ requirement: &70259568822200 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70129331232880
35
+ version_requirements: *70259568822200
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: grit
38
- requirement: &70129331228060 !ruby/object:Gem::Requirement
38
+ requirement: &70259568821600 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70129331228060
46
+ version_requirements: *70259568821600
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: logger
49
- requirement: &70129331227600 !ruby/object:Gem::Requirement
49
+ requirement: &70259568820920 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70129331227600
57
+ version_requirements: *70259568820920
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: minitar
60
- requirement: &70129331227180 !ruby/object:Gem::Requirement
60
+ requirement: &70259568820320 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70129331227180
68
+ version_requirements: *70259568820320
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: trollop
71
- requirement: &70129331226740 !ruby/object:Gem::Requirement
71
+ requirement: &70259568819700 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '0'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *70129331226740
79
+ version_requirements: *70259568819700
80
80
  description: I help build and manage artifacts
81
81
  email:
82
82
  - brett@weav.net
@@ -109,7 +109,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
109
109
  version: '0'
110
110
  segments:
111
111
  - 0
112
- hash: 2848188182829183969
112
+ hash: -2437410671225482023
113
113
  required_rubygems_version: !ruby/object:Gem::Requirement
114
114
  none: false
115
115
  requirements:
@@ -118,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
118
  version: '0'
119
119
  segments:
120
120
  - 0
121
- hash: 2848188182829183969
121
+ hash: -2437410671225482023
122
122
  requirements: []
123
123
  rubyforge_project: heirloom
124
124
  rubygems_version: 1.8.16