dpl-gcs 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e14c571c93de4e88b7fd3a80596502b757ef3ee3
4
+ data.tar.gz: 8900b14daabf9b6bf71ed10f437376781be2d32d
5
+ SHA512:
6
+ metadata.gz: 64d51116daf10282869c04c14e953f759bd05ccbacc845f707a7cc31a69068b23009eda10fd74009437836c6a2ea3e08c3b756f02fc9624cbc79af8e564b16df
7
+ data.tar.gz: 2ec17b876e674bf38ce40391bc3884bb1071ca4d9b0c65054bb6744d1aad175d2676e6f40c5f9a4a6ad3deb59c6a5c2809e37679041d45987808644fc516b721
@@ -0,0 +1,3 @@
1
+ require './gemspec_helper'
2
+
3
+ gemspec_for 'gcs', [['gstore'], ['mime-types', '~> 2.0']]
@@ -0,0 +1,58 @@
1
+ require 'kconv'
2
+ require 'gstore'
3
+ require 'mime-types'
4
+
5
+ module DPL
6
+ class Provider
7
+ class GCS < Provider
8
+ def needs_key?
9
+ false
10
+ end
11
+
12
+ def client
13
+ @client ||= GStore::Client.new(
14
+ :access_key => option(:access_key_id),
15
+ :secret_key => option(:secret_access_key)
16
+ )
17
+ end
18
+
19
+ def check_auth
20
+ log "Logging in with Access Key: #{option(:access_key_id)[-4..-1].rjust(20, '*')}"
21
+ end
22
+
23
+ def upload_path(filename)
24
+ [options[:upload_dir], filename].compact.join("/")
25
+ end
26
+
27
+ def push_app
28
+ glob_args = ["**/*"]
29
+ glob_args << File::FNM_DOTMATCH if options[:dot_match]
30
+ Dir.chdir(options.fetch(:local_dir, Dir.pwd)) do
31
+ Dir.glob(*glob_args) do |filename|
32
+ next if File.directory?(filename)
33
+ content_type = MIME::Types.type_for(filename).first.to_s
34
+ opts = { :"Content-Type" => content_type }.merge(encoding_option_for(filename))
35
+ opts["Cache-Control"] = options[:cache_control] if options[:cache_control]
36
+ opts["x-goog-acl"] = options[:acl] if options[:acl]
37
+
38
+ client.put_object(
39
+ option(:bucket),
40
+ upload_path(filename),
41
+ { :data => File.read(filename), :headers => opts }
42
+ )
43
+ end
44
+ end
45
+ end
46
+
47
+ private
48
+ def encoding_option_for(path)
49
+ if detect_encoding? && encoding_for(path)
50
+ {"Content-Encoding" => encoding_for(path)}
51
+ else
52
+ {}
53
+ end
54
+ end
55
+
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,115 @@
1
+ require 'spec_helper'
2
+ require 'dpl/provider/gcs'
3
+
4
+ describe DPL::Provider::GCS do
5
+
6
+ subject :provider do
7
+ described_class.new(DummyContext.new, :access_key_id => 'qwertyuiopasdfghjklz', :secret_access_key => 'qwertyuiopasdfghjklzqwertyuiopasdfghjklz', :bucket => 'my-bucket')
8
+ end
9
+
10
+ describe "#check_auth" do
11
+ example do
12
+ expect(provider).to receive(:log).with("Logging in with Access Key: ****************jklz")
13
+ provider.check_auth
14
+ end
15
+ end
16
+
17
+ describe "#needs_key?" do
18
+ example do
19
+ expect(provider.needs_key?).to eq(false)
20
+ end
21
+ end
22
+
23
+ describe "#upload_path" do
24
+ example "Without: :upload_dir" do
25
+ filename = "testfile.file"
26
+
27
+ expect(provider.upload_path(filename)).to eq("testfile.file")
28
+ end
29
+
30
+ example "With :upload_dir" do
31
+ provider.options.update(:upload_dir => 'BUILD3')
32
+ filename = "testfile.file"
33
+
34
+ expect(provider.upload_path(filename)).to eq("BUILD3/testfile.file")
35
+ end
36
+ end
37
+
38
+ describe "#push_app" do
39
+ example "Without local_dir" do
40
+ expect(Dir).to receive(:chdir).with(Dir.pwd)
41
+ provider.push_app
42
+ end
43
+
44
+ example "With local_dir" do
45
+ provider.options.update(:local_dir => 'BUILD')
46
+
47
+ expect(Dir).to receive(:chdir).with('BUILD')
48
+ provider.push_app
49
+ end
50
+
51
+ example "Sends MIME type" do
52
+ expect(Dir).to receive(:glob).and_yield(__FILE__)
53
+ expect_any_instance_of(GStore::Client).to receive(:put_object).with(
54
+ anything(),
55
+ anything(),
56
+ hash_including(:headers => {:"Content-Type" => 'application/x-ruby'})
57
+ )
58
+ provider.push_app
59
+ end
60
+
61
+ example "Sets Cache" do
62
+ provider.options.update(:cache_control => "max-age=99999999")
63
+ expect(Dir).to receive(:glob).and_yield(__FILE__)
64
+ expect_any_instance_of(GStore::Client).to receive(:put_object).with(
65
+ anything(),
66
+ anything(),
67
+ hash_including(:headers => hash_including("Cache-Control" => 'max-age=99999999'))
68
+ )
69
+ provider.push_app
70
+ end
71
+
72
+ example "Sets ACL" do
73
+ provider.options.update(:acl => "public-read")
74
+ expect(Dir).to receive(:glob).and_yield(__FILE__)
75
+ expect_any_instance_of(GStore::Client).to receive(:put_object).with(
76
+ anything(),
77
+ anything(),
78
+ hash_including(:headers => hash_including("x-goog-acl" => 'public-read'))
79
+ )
80
+ provider.push_app
81
+ end
82
+
83
+ example "when detect_encoding is set" do
84
+ path = 'foo.js'
85
+ provider.options.update(:detect_encoding => true)
86
+ expect(Dir).to receive(:glob).and_yield(path)
87
+ expect(provider).to receive(:`).at_least(1).times.with("file '#{path}'").and_return('gzip compressed')
88
+ expect(File).to receive(:read).with(path).and_return("")
89
+ expect_any_instance_of(GStore::Client).to receive(:put_object).with(
90
+ anything(),
91
+ anything(),
92
+ hash_including(:headers => hash_including("Content-Encoding" => 'gzip'))
93
+ )
94
+ provider.push_app
95
+ end
96
+
97
+ example "With dot_match" do
98
+ provider.options.update(:dot_match => true)
99
+
100
+ expect(Dir).to receive(:glob).with('**/*', File::FNM_DOTMATCH)
101
+ provider.push_app
102
+ end
103
+
104
+ end
105
+
106
+ describe '#client' do
107
+ example do
108
+ expect(GStore::Client).to receive(:new).with(
109
+ :access_key => 'qwertyuiopasdfghjklz',
110
+ :secret_key => 'qwertyuiopasdfghjklzqwertyuiopasdfghjklz'
111
+ )
112
+ provider.client
113
+ end
114
+ end
115
+ end
metadata ADDED
@@ -0,0 +1,187 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dpl-gcs
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.9.0
5
+ platform: ruby
6
+ authors:
7
+ - Konstantin Haase
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-03-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dpl
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.9.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.9.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: gstore
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mime-types
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-its
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: json_pure
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: tins
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: coveralls
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: highline
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: deploy tool abstraction for clients
154
+ email: konstantin.mailinglists@googlemail.com
155
+ executables: []
156
+ extensions: []
157
+ extra_rdoc_files: []
158
+ files:
159
+ - dpl-gcs.gemspec
160
+ - lib/dpl/provider/gcs.rb
161
+ - spec/provider/gcs_spec.rb
162
+ homepage: https://github.com/travis-ci/dpl
163
+ licenses:
164
+ - MIT
165
+ metadata: {}
166
+ post_install_message:
167
+ rdoc_options: []
168
+ require_paths:
169
+ - lib
170
+ required_ruby_version: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ version: '2.2'
175
+ required_rubygems_version: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - ">="
178
+ - !ruby/object:Gem::Version
179
+ version: '0'
180
+ requirements: []
181
+ rubyforge_project:
182
+ rubygems_version: 2.6.13
183
+ signing_key:
184
+ specification_version: 4
185
+ summary: deploy tool
186
+ test_files:
187
+ - spec/provider/gcs_spec.rb