dpl 1.7.23.travis.1059.4 → 1.7.23.travis.1061.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/Gemfile +1 -1
- data/README.md +0 -1
- data/lib/dpl/provider/s3.rb +20 -14
- data/spec/provider/s3_spec.rb +53 -32
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NzQ0ZWU2YzNjNDkwMzMwMzZjZGNiYzk5MzgwMGEzNTc4OTQzOGMzZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YzU5OGU5YzQxODllMTZjMmRhZGNiM2MyYmVhNmU4N2EwZmY4ZTQyNQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YjA2MTQ0NDU1OTZiMjY4MjBmZTA3ZWYwMmRhZGFkNmIxOGNhOGEzNDliMWU3
|
10
|
+
YWI0MjlhNDcxMzA2ZGJhZWY3MGJiYWM2ZDY4M2FiODIwMjAwMzg1MjQyYTRl
|
11
|
+
MTRiMjFjMTM1NGRmMjE4ZTVlZGRkOTAyMDE5ZmZjN2ZkN2U4NDE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OWZkZGE0N2MyZWFmMWQ0ZTEzYjYyNGY5NGNmMzNkNTRiMzg4NDNkYjA2N2E4
|
14
|
+
M2UyMzE1NWM3NDMyNDdmZWQ0ZTBmYTZjZWMwODM4MDQzZWJmOTRhNzJiZGJi
|
15
|
+
MWUyNTZmZGRhMDYyZWY4NTQ3N2UzNjkyMjE4OWQ0Njk2ODhmNzE=
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -331,7 +331,6 @@ For authentication you can also use Travis CI secure environment variable:
|
|
331
331
|
* **secret-access-key**: AWS Secret Key. Can be obtained from [here](https://console.aws.amazon.com/iam/home?#security_credential).
|
332
332
|
* **bucket**: S3 Bucket.
|
333
333
|
* **region**: S3 Region. Defaults to us-east-1.
|
334
|
-
* **endpoint**: S3 Endpoint. Defaults to s3.amazonaws.com.
|
335
334
|
* **upload-dir**: S3 directory to upload to. Defaults to root directory.
|
336
335
|
* **local-dir**: Local directory to upload from. Can be set from a global perspective (~/travis/build) or relative perspective (build) Defaults to project root.
|
337
336
|
* **detect-encoding**: Set HTTP header `Content-Encoding` for files compressed with `gzip` and `compress` utilities. Defaults to not set.
|
data/lib/dpl/provider/s3.rb
CHANGED
@@ -3,11 +3,11 @@ require 'json'
|
|
3
3
|
module DPL
|
4
4
|
class Provider
|
5
5
|
class S3 < Provider
|
6
|
-
requires 'aws-sdk
|
6
|
+
requires 'aws-sdk'
|
7
7
|
requires 'mime-types'
|
8
8
|
|
9
9
|
def api
|
10
|
-
@api ||=
|
10
|
+
@api ||= ::Aws::S3::Resource.new(s3_options)
|
11
11
|
end
|
12
12
|
|
13
13
|
def needs_key?
|
@@ -15,7 +15,7 @@ module DPL
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def check_app
|
18
|
-
|
18
|
+
log 'Warning: The endpoint option is no longer used and can be removed.' if options[:endpoint]
|
19
19
|
end
|
20
20
|
|
21
21
|
def access_key_id
|
@@ -26,12 +26,14 @@ module DPL
|
|
26
26
|
options[:secret_access_key] || context.env['AWS_SECRET_ACCESS_KEY'] || raise(Error, "missing secret_access_key")
|
27
27
|
end
|
28
28
|
|
29
|
-
def
|
30
|
-
|
29
|
+
def s3_options
|
30
|
+
{
|
31
|
+
region: options[:region] || 'us-east-1',
|
32
|
+
credentials: ::Aws::Credentials.new(access_key_id, secret_access_key)
|
33
|
+
}
|
31
34
|
end
|
32
35
|
|
33
36
|
def check_auth
|
34
|
-
setup_auth
|
35
37
|
log "Logging in with Access Key: #{option(:access_key_id)[-4..-1].rjust(20, '*')}"
|
36
38
|
end
|
37
39
|
|
@@ -47,29 +49,33 @@ module DPL
|
|
47
49
|
content_type = MIME::Types.type_for(filename).first.to_s
|
48
50
|
opts = { :content_type => content_type }.merge(encoding_option_for(filename))
|
49
51
|
opts[:cache_control] = get_option_value_by_filename(options[:cache_control], filename) if options[:cache_control]
|
50
|
-
opts[:acl] = options[:acl] if options[:acl]
|
52
|
+
opts[:acl] = options[:acl].gsub(/_/, '-') if options[:acl]
|
51
53
|
opts[:expires] = get_option_value_by_filename(options[:expires], filename) if options[:expires]
|
52
54
|
unless File.directory?(filename)
|
53
55
|
log "uploading %p" % filename
|
54
|
-
api.
|
56
|
+
api.bucket(option(:bucket)).object(upload_path(filename)).upload_file(filename, opts)
|
55
57
|
end
|
56
58
|
end
|
57
59
|
end
|
58
60
|
|
59
61
|
if suffix = options[:index_document_suffix]
|
60
|
-
api.
|
61
|
-
|
62
|
-
|
62
|
+
api.bucket(option(:bucket)).website.put(
|
63
|
+
website_configuration: {
|
64
|
+
index_document: {
|
65
|
+
suffix: suffix
|
66
|
+
}
|
67
|
+
}
|
68
|
+
)
|
63
69
|
end
|
64
70
|
end
|
65
71
|
|
66
72
|
def deploy
|
67
73
|
super
|
68
|
-
rescue
|
74
|
+
rescue ::Aws::S3::Errors::InvalidAccessKeyId
|
69
75
|
raise Error, "Invalid S3 Access Key Id, Stopping Deploy"
|
70
|
-
rescue
|
76
|
+
rescue ::Aws::S3::Errors::ChecksumError
|
71
77
|
raise Error, "Aws Secret Key does not match Access Key Id, Stopping Deploy"
|
72
|
-
rescue
|
78
|
+
rescue ::Aws::S3::Errors::AccessDenied
|
73
79
|
raise Error, "Oops, It looks like you tried to write to a bucket that isn't yours or doesn't exist yet. Please create the bucket before trying to write to it."
|
74
80
|
end
|
75
81
|
|
data/spec/provider/s3_spec.rb
CHANGED
@@ -4,17 +4,56 @@ require 'dpl/provider/s3'
|
|
4
4
|
|
5
5
|
describe DPL::Provider::S3 do
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
subject :provider do
|
8
|
+
described_class.new(DummyContext.new, :access_key_id => 'qwertyuiopasdfghjklz', :secret_access_key => 'qwertyuiopasdfghjklzqwertyuiopasdfghjklz', :bucket => 'my-bucket')
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '#s3_options' do
|
12
|
+
context 'without region' do
|
13
|
+
example do
|
14
|
+
options = provider.s3_options
|
15
|
+
expect(options[:region]).to eq('us-east-1')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'with region' do
|
20
|
+
example do
|
21
|
+
region = 'us-west-1'
|
22
|
+
provider.options.update(:region => region)
|
23
|
+
options = provider.s3_options
|
24
|
+
expect(options[:region]).to eq(region)
|
25
|
+
end
|
26
|
+
end
|
9
27
|
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe DPL::Provider::S3 do
|
31
|
+
|
32
|
+
access_key_id = 'qwertyuiopasdfghjklz'
|
33
|
+
secret_access_key = 'qwertyuiopasdfghjklzqwertyuiopasdfghjklz'
|
34
|
+
region = 'us-east-1'
|
35
|
+
bucket = 'my-bucket'
|
36
|
+
|
37
|
+
client_options = {
|
38
|
+
stub_responses: true,
|
39
|
+
region: region,
|
40
|
+
credentials: Aws::Credentials.new(access_key_id, secret_access_key)
|
41
|
+
}
|
10
42
|
|
11
43
|
subject :provider do
|
12
|
-
described_class.new(DummyContext.new,
|
44
|
+
described_class.new(DummyContext.new, {
|
45
|
+
access_key_id: access_key_id,
|
46
|
+
secret_access_key: secret_access_key,
|
47
|
+
bucket: bucket
|
48
|
+
})
|
49
|
+
end
|
50
|
+
|
51
|
+
before :each do
|
52
|
+
provider.stub(:s3_options).and_return(client_options)
|
13
53
|
end
|
14
54
|
|
15
55
|
describe "#check_auth" do
|
16
56
|
example do
|
17
|
-
expect(provider).to receive(:setup_auth)
|
18
57
|
expect(provider).to receive(:log).with("Logging in with Access Key: ****************jklz")
|
19
58
|
provider.check_auth
|
20
59
|
end
|
@@ -35,19 +74,6 @@ describe DPL::Provider::S3 do
|
|
35
74
|
end
|
36
75
|
end
|
37
76
|
|
38
|
-
describe "#setup_auth" do
|
39
|
-
example "Without :region" do
|
40
|
-
expect(AWS).to receive(:config).with(:access_key_id => 'qwertyuiopasdfghjklz', :secret_access_key => 'qwertyuiopasdfghjklzqwertyuiopasdfghjklz', :region => 'us-east-1').once.and_call_original
|
41
|
-
provider.setup_auth
|
42
|
-
end
|
43
|
-
example "With :region" do
|
44
|
-
provider.options.update(:region => 'us-west-2')
|
45
|
-
|
46
|
-
expect(AWS).to receive(:config).with(:access_key_id => 'qwertyuiopasdfghjklz', :secret_access_key => 'qwertyuiopasdfghjklzqwertyuiopasdfghjklz', :region => 'us-west-2').once
|
47
|
-
provider.setup_auth
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
77
|
describe "#needs_key?" do
|
52
78
|
example do
|
53
79
|
expect(provider.needs_key?).to eq(false)
|
@@ -69,14 +95,14 @@ describe DPL::Provider::S3 do
|
|
69
95
|
|
70
96
|
example "Sends MIME type" do
|
71
97
|
expect(Dir).to receive(:glob).and_yield(__FILE__)
|
72
|
-
expect_any_instance_of(
|
98
|
+
expect_any_instance_of(Aws::S3::Object).to receive(:upload_file).with(anything(), hash_including(:content_type => 'application/x-ruby'))
|
73
99
|
provider.push_app
|
74
100
|
end
|
75
101
|
|
76
102
|
example "Sets Cache and Expiration" do
|
77
103
|
provider.options.update(:cache_control => "max-age=99999999", :expires => "2012-12-21 00:00:00 -0000")
|
78
104
|
expect(Dir).to receive(:glob).and_yield(__FILE__)
|
79
|
-
expect_any_instance_of(
|
105
|
+
expect_any_instance_of(Aws::S3::Object).to receive(:upload_file).with(anything(), hash_including(:cache_control => 'max-age=99999999', :expires => '2012-12-21 00:00:00 -0000'))
|
80
106
|
provider.push_app
|
81
107
|
end
|
82
108
|
|
@@ -84,9 +110,8 @@ describe DPL::Provider::S3 do
|
|
84
110
|
option_list = []
|
85
111
|
provider.options.update(:cache_control => ["max-age=99999999", "no-cache" => ["foo.html", "bar.txt"], "max-age=9999" => "*.txt"], :expires => ["2012-12-21 00:00:00 -0000", "1970-01-01 00:00:00 -0000" => "*.html"])
|
86
112
|
expect(Dir).to receive(:glob).and_yield("foo.html").and_yield("bar.txt").and_yield("baz.js")
|
87
|
-
|
88
|
-
|
89
|
-
option_list << { key: key, options: options }
|
113
|
+
allow_any_instance_of(Aws::S3::Object).to receive(:upload_file) do |obj, _data, options|
|
114
|
+
option_list << { key: obj.key, options: options }
|
90
115
|
end
|
91
116
|
provider.push_app
|
92
117
|
expect(option_list).to match_array([
|
@@ -99,13 +124,14 @@ describe DPL::Provider::S3 do
|
|
99
124
|
example "Sets ACL" do
|
100
125
|
provider.options.update(:acl => "public_read")
|
101
126
|
expect(Dir).to receive(:glob).and_yield(__FILE__)
|
102
|
-
expect_any_instance_of(
|
127
|
+
expect_any_instance_of(Aws::S3::Object).to receive(:upload_file).with(anything(), hash_including(:acl => "public-read"))
|
103
128
|
provider.push_app
|
104
129
|
end
|
105
130
|
|
106
131
|
example "Sets Website Index Document" do
|
107
132
|
provider.options.update(:index_document_suffix => "test/index.html")
|
108
133
|
expect(Dir).to receive(:glob).and_yield(__FILE__)
|
134
|
+
expect_any_instance_of(Aws::S3::BucketWebsite).to receive(:put).with(:website_configuration => { :index_document => { :suffix => "test/index.html" } })
|
109
135
|
provider.push_app
|
110
136
|
end
|
111
137
|
|
@@ -114,8 +140,7 @@ describe DPL::Provider::S3 do
|
|
114
140
|
provider.options.update(:detect_encoding => true)
|
115
141
|
expect(Dir).to receive(:glob).and_yield(path)
|
116
142
|
expect(provider).to receive(:`).at_least(1).times.with("file #{path}").and_return('gzip compressed')
|
117
|
-
|
118
|
-
expect_any_instance_of(AWS::S3::ObjectCollection).to receive(:create).with(anything(), anything(), hash_including(:content_encoding => 'gzip'))
|
143
|
+
expect_any_instance_of(Aws::S3::Object).to receive(:upload_file).with(anything(), hash_including(:content_encoding => 'gzip'))
|
119
144
|
provider.push_app
|
120
145
|
end
|
121
146
|
|
@@ -126,15 +151,11 @@ describe DPL::Provider::S3 do
|
|
126
151
|
end
|
127
152
|
end
|
128
153
|
|
129
|
-
describe "#
|
130
|
-
example "Without Endpoint" do
|
131
|
-
expect(AWS::S3).to receive(:new).with(:endpoint => 's3.amazonaws.com')
|
132
|
-
provider.api
|
133
|
-
end
|
154
|
+
describe "#check_app" do
|
134
155
|
example "With Endpoint" do
|
135
156
|
provider.options.update(:endpoint => 's3test.com.s3-website-us-west-2.amazonaws.com')
|
136
|
-
expect(
|
137
|
-
provider.
|
157
|
+
expect(provider).to receive(:log).with('Warning: The endpoint option is no longer used and can be removed.')
|
158
|
+
provider.check_app
|
138
159
|
end
|
139
160
|
end
|
140
161
|
end
|