simple-s3 0.0.8 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/simple-s3 +1 -1
- data/lib/simple-s3/simple-s3.rb +70 -2
- data/lib/simple-s3/version.rb +1 -1
- data/simple-s3.gem +0 -0
- metadata +2 -2
data/bin/simple-s3
CHANGED
data/lib/simple-s3/simple-s3.rb
CHANGED
|
@@ -9,12 +9,30 @@ class SimpleS3
|
|
|
9
9
|
@config
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
+
def self.default_exclude_files
|
|
13
|
+
['simple-s3.yml', '.git', '.rvmrc', 'Gemfile', 'Gemfile.lock', '.gitignore', '.gitmodules']
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.s3_access_key
|
|
17
|
+
self.config['s3_access_key']
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def self.s3_secret_key
|
|
21
|
+
self.config['s3_secret_key']
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def self.run!
|
|
25
|
+
self.upload!
|
|
26
|
+
self.invalidate!
|
|
27
|
+
end
|
|
28
|
+
|
|
12
29
|
def self.upload!
|
|
13
30
|
@config = config
|
|
14
31
|
bucket = @config['bucket'].to_s
|
|
15
32
|
raise 'Simple-S3: Bucket not defined' if bucket.length == 0
|
|
16
33
|
|
|
17
34
|
exclude = @config['exclude_files'] || []
|
|
35
|
+
exclude |= self.default_exclude_files
|
|
18
36
|
inc = @config['include_files'] || './**/*'
|
|
19
37
|
metadata = @config['metadata'] || {}
|
|
20
38
|
metadata[:access] ||= 'public-read'
|
|
@@ -32,8 +50,8 @@ class SimpleS3
|
|
|
32
50
|
raise 'Simple-S3: No files found' if files.length == 0
|
|
33
51
|
|
|
34
52
|
AWS::S3::Base.establish_connection!(
|
|
35
|
-
:access_key_id =>
|
|
36
|
-
:secret_access_key =>
|
|
53
|
+
:access_key_id => self.s3_access_key
|
|
54
|
+
:secret_access_key => self.s3_secret_key
|
|
37
55
|
)
|
|
38
56
|
|
|
39
57
|
files.each do |file|
|
|
@@ -50,4 +68,54 @@ class SimpleS3
|
|
|
50
68
|
puts "Simple-S3: Upload Completed!"
|
|
51
69
|
end
|
|
52
70
|
|
|
71
|
+
def invalidate!
|
|
72
|
+
@config = config
|
|
73
|
+
distribution = @config['cloudfront_distribution_id']
|
|
74
|
+
return if distribution.nil?
|
|
75
|
+
|
|
76
|
+
aws_account = self.s3_access_key
|
|
77
|
+
aws_secret = self.s3_secret_key
|
|
78
|
+
|
|
79
|
+
path = ['/','/*','/**/*']
|
|
80
|
+
|
|
81
|
+
date = Time.now.strftime("%a, %d %b %Y %H:%M:%S %Z")
|
|
82
|
+
digest = Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha1'), aws_secret, date)).strip
|
|
83
|
+
uri = URI.parse("https://cloudfront.amazonaws.com/2012-07-01/distribution/#{distribution}/invalidation")
|
|
84
|
+
|
|
85
|
+
path_xml = ''
|
|
86
|
+
path.each do |p|
|
|
87
|
+
path_xml += '<Path>'+p+'</Path>'
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
req = Net::HTTP::Post.new(uri.path)
|
|
91
|
+
req.initialize_http_header({
|
|
92
|
+
'x-amz-date' => date,
|
|
93
|
+
'Content-Type' => 'text/xml',
|
|
94
|
+
'Authorization' => "AWS %s:%s" % [aws_account, digest]
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
xml = '<InvalidationBatch xmlns="http://cloudfront.amazonaws.com/doc/2012-07-01/">' +
|
|
98
|
+
' <Paths>' +
|
|
99
|
+
' <Quantity>' + path.length.to_s + '</Quantity>' +
|
|
100
|
+
' <Items>' +
|
|
101
|
+
path_xml +
|
|
102
|
+
' </Items>' +
|
|
103
|
+
' </Paths>' +
|
|
104
|
+
' <CallerReference>SOMETHING_SPECIAL_' + Time.now.utc.to_i.to_s + '</CallerReference>' +
|
|
105
|
+
'</InvalidationBatch>'
|
|
106
|
+
req.body = xml
|
|
107
|
+
|
|
108
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
109
|
+
http.use_ssl = true
|
|
110
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
111
|
+
res = http.request(req)
|
|
112
|
+
|
|
113
|
+
# it was successful if response code was a 201
|
|
114
|
+
if res.code == '201'
|
|
115
|
+
puts 'Simple-S3: Invalidation Successful'
|
|
116
|
+
else
|
|
117
|
+
raise res.body.to_s
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
53
121
|
end
|
data/lib/simple-s3/version.rb
CHANGED
data/simple-s3.gem
CHANGED
|
Binary file
|