gemfury 0.12.1 → 0.13.0
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.
- checksums.yaml +4 -4
- data/bin/fury +3 -4
- data/bin/gemfury +3 -1
- data/lib/faraday/adapter/fury_http.rb +14 -21
- data/lib/faraday/request/multipart_with_file.rb +3 -3
- data/lib/gemfury/client/filters.rb +7 -6
- data/lib/gemfury/client/middleware.rb +5 -3
- data/lib/gemfury/client.rb +44 -47
- data/lib/gemfury/command/app.rb +111 -114
- data/lib/gemfury/command/authorization.rb +14 -11
- data/lib/gemfury/command.rb +5 -3
- data/lib/gemfury/configuration.rb +10 -9
- data/lib/gemfury/const.rb +5 -2
- data/lib/gemfury/error.rb +2 -0
- data/lib/gemfury/platform.rb +4 -2
- data/lib/gemfury/tasks/release.rake +9 -8
- data/lib/gemfury/tasks.rb +3 -1
- data/lib/gemfury/version.rb +3 -1
- data/lib/gemfury.rb +11 -12
- data/lib/rubygems/commands/fury_command.rb +4 -2
- data/lib/rubygems_plugin.rb +2 -0
- metadata +57 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca072afb73e0349c3d02481d7d665f058f68b05ca287026f208c0fd8b30361a1
|
4
|
+
data.tar.gz: cf3983d68afea4c3f8dbb46ed387b12273f80d3524989a63f93e447c889b0c26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7da7f0ca97595441d0666eb19cd1dbd033e579c1cd6181a4b2804c30b2b1bc12a4b9f3b3d3196cc287db3393c09c4004fb11be0cef9ab849378369b51e88a686
|
7
|
+
data.tar.gz: c2270b3792a92fd3fe63b6230676e28bf0e7ee12f49a44e5b126f9d92491ed35476ef08fe0e078c9227963fbdaad29941dda7ff2a5ffc8e1003a2dfe246dfbf1
|
data/bin/fury
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
lib = File.expand_path('
|
4
|
+
lib = File.expand_path('../lib', __dir__)
|
4
5
|
$LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
|
5
6
|
|
6
7
|
require 'rubygems'
|
7
8
|
require 'gemfury'
|
8
9
|
require 'gemfury/command'
|
9
10
|
|
10
|
-
if defined?(Warning) && Warning.respond_to?('[]')
|
11
|
-
Warning[:deprecated] = !!ENV['DEBUG']
|
12
|
-
end
|
11
|
+
Warning[:deprecated] = !!ENV['DEBUG'] if defined?(Warning) && Warning.respond_to?('[]')
|
13
12
|
|
14
13
|
Gemfury::Command::App.start
|
data/bin/gemfury
CHANGED
@@ -1,32 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# This is a Faraday adapter that bypasses Faraday's response body
|
2
4
|
# processing and streams body to STDOUT for text requests
|
3
5
|
|
4
6
|
class Faraday::Adapter
|
5
7
|
class FuryHttp < NetHttp
|
6
|
-
def
|
7
|
-
|
8
|
-
return super if
|
9
|
-
|
10
|
-
# Stream response body to STDOUT on success
|
11
|
-
http.request(create_request(env)) do |resp|
|
12
|
-
unless resp.is_a?(Net::HTTPSuccess)
|
13
|
-
resp.body # Cache error body
|
14
|
-
else
|
15
|
-
resp.read_body do |chunk|
|
16
|
-
$stdout.print(chunk)
|
17
|
-
$stdout.flush
|
18
|
-
end
|
8
|
+
def request_with_wrapped_block(http, env, &block)
|
9
|
+
is_text = env.request_headers['Accept'] =~ /text\z/
|
10
|
+
return super if !block.nil? || !is_text
|
19
11
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
# Return response to NetHttp adapter
|
26
|
-
return resp
|
12
|
+
# Stream chunks directly to STDOUT
|
13
|
+
resp = super(http, env) do |chunk|
|
14
|
+
$stdout.print(chunk)
|
15
|
+
$stdout.flush
|
27
16
|
end
|
17
|
+
|
18
|
+
# Client sees nil body
|
19
|
+
resp.body = nil
|
20
|
+
resp
|
28
21
|
end
|
29
22
|
end
|
30
23
|
|
31
|
-
register_middleware(:
|
24
|
+
register_middleware(fury_http: FuryHttp)
|
32
25
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'faraday'
|
2
4
|
|
3
5
|
# @private
|
@@ -5,13 +7,11 @@ module Faraday
|
|
5
7
|
# @private
|
6
8
|
class Request::MultipartWithFile < Faraday::Middleware
|
7
9
|
def call(env)
|
8
|
-
|
9
10
|
if env[:body].is_a?(Hash)
|
10
11
|
|
11
12
|
# Check for IO (and IO-like objects, like Zip::InputStream) in the request,
|
12
13
|
# which represent data to be uploaded. Replace these with Faraday
|
13
14
|
env[:body].each do |key, value|
|
14
|
-
|
15
15
|
# Faraday seems to expect a few IO methods to be available, but that's all:
|
16
16
|
# https://github.com/lostisland/faraday/blob/master/lib/faraday/file_part.rb
|
17
17
|
# :length seems to be an optional one
|
@@ -21,7 +21,7 @@ module Faraday
|
|
21
21
|
#
|
22
22
|
# We attempt to make our duck typing compatible with their duck typing
|
23
23
|
if value.respond_to?(:read) && value.respond_to?(:rewind) && value.respond_to?(:close)
|
24
|
-
env[:body][key] = Faraday::
|
24
|
+
env[:body][key] = Faraday::Multipart::FilePart.new(value, mime_type(value))
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -1,18 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Gemfury
|
2
4
|
class Client
|
3
5
|
module Filters
|
6
|
+
private
|
4
7
|
|
5
|
-
private
|
6
8
|
def ensure_ready!(*args)
|
7
9
|
# Ensure authorization
|
8
|
-
|
9
|
-
|
10
|
-
end
|
10
|
+
return unless args.include?(:authorization)
|
11
|
+
raise Unauthorized unless authenticated?
|
11
12
|
end
|
12
13
|
|
13
14
|
def authenticated?
|
14
|
-
|
15
|
+
user_api_key && !user_api_key.empty?
|
15
16
|
end
|
16
17
|
end
|
17
18
|
end
|
18
|
-
end
|
19
|
+
end
|
@@ -1,15 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Gemfury
|
2
4
|
class Client
|
3
5
|
class Handle503 < Faraday::Middleware
|
4
6
|
def call(env)
|
5
|
-
# This prevents errors in ParseJson
|
7
|
+
# This prevents errors in ParseJson
|
6
8
|
@app.call(env).on_complete do |out|
|
7
9
|
out[:body] = '' if out[:status] == 503
|
8
10
|
end
|
9
11
|
end
|
10
12
|
end
|
11
13
|
|
12
|
-
class ParseJson < Faraday::
|
14
|
+
class ParseJson < Faraday::Middleware
|
13
15
|
def parse(body)
|
14
16
|
body =~ /\A\s*\z/ ? nil : MultiJson.decode(body)
|
15
17
|
end
|
@@ -20,4 +22,4 @@ module Gemfury
|
|
20
22
|
end
|
21
23
|
end
|
22
24
|
end
|
23
|
-
end
|
25
|
+
end
|
data/lib/gemfury/client.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Gemfury
|
2
4
|
class Client
|
3
5
|
include Gemfury::Client::Filters
|
@@ -5,7 +7,7 @@ module Gemfury
|
|
5
7
|
|
6
8
|
# Creates a new API
|
7
9
|
# @param options [Hash] values for attributes described in {Gemfury::Configuration}
|
8
|
-
def initialize(options={})
|
10
|
+
def initialize(options = {})
|
9
11
|
options = Gemfury.options.merge(options)
|
10
12
|
Gemfury::VALID_OPTIONS_KEYS.each do |key|
|
11
13
|
send("#{key}=", options[key])
|
@@ -34,8 +36,8 @@ module Gemfury
|
|
34
36
|
# @return [Hash]
|
35
37
|
def push_gem(file, options = {})
|
36
38
|
ensure_ready!(:authorization)
|
37
|
-
push_api = connection(:
|
38
|
-
response = push_api.post('uploads', options.merge(:
|
39
|
+
push_api = connection(url: pushpoint)
|
40
|
+
response = push_api.post('uploads', options.merge(file: file))
|
39
41
|
checked_response_body(response)
|
40
42
|
end
|
41
43
|
|
@@ -83,7 +85,7 @@ module Gemfury
|
|
83
85
|
# @return [Hash]
|
84
86
|
def login(email, password, opts = {})
|
85
87
|
ensure_ready!
|
86
|
-
opts = opts.merge(:
|
88
|
+
opts = opts.merge(email: email, password: password)
|
87
89
|
checked_response_body(connection.post('login', opts))
|
88
90
|
end
|
89
91
|
|
@@ -161,7 +163,7 @@ module Gemfury
|
|
161
163
|
def git_rebuild(repo, options = {})
|
162
164
|
ensure_ready!(:authorization)
|
163
165
|
url = "#{git_repo_path(repo)}/builds"
|
164
|
-
api = connection(:
|
166
|
+
api = connection(api_format: :text)
|
165
167
|
checked_response_body(api.post(url, options))
|
166
168
|
end
|
167
169
|
|
@@ -184,51 +186,48 @@ module Gemfury
|
|
184
186
|
def git_config_update(repo, updates, options = {})
|
185
187
|
ensure_ready!(:authorization)
|
186
188
|
path = "#{git_repo_path(repo)}/config-vars"
|
187
|
-
opts = options.merge(:
|
189
|
+
opts = options.merge(config_vars: updates)
|
188
190
|
response = connection.patch(path, opts)
|
189
191
|
checked_response_body(response)
|
190
192
|
end
|
191
193
|
|
192
|
-
|
194
|
+
private
|
195
|
+
|
193
196
|
def escape(str)
|
194
197
|
CGI.escape(str)
|
195
198
|
end
|
196
199
|
|
197
200
|
def git_repo_path(*args)
|
198
201
|
rest = args.map { |a| escape(a) }
|
199
|
-
['git/repos',
|
202
|
+
['git/repos', account || 'me'].concat(rest).join('/')
|
200
203
|
end
|
201
204
|
|
202
205
|
def connection(options = {})
|
203
206
|
# The 'Accept' HTTP header for API versioning
|
204
207
|
http_accept = begin
|
205
|
-
v = options.delete(:api_version) ||
|
208
|
+
v = options.delete(:api_version) || api_version
|
206
209
|
f = options.delete(:api_format) || :json
|
207
210
|
"application/vnd.fury.v#{v.to_i}+#{f}"
|
208
211
|
end
|
209
212
|
|
210
213
|
# Faraday client options
|
211
214
|
options = {
|
212
|
-
:
|
213
|
-
:
|
214
|
-
:
|
215
|
-
:
|
216
|
-
:
|
217
|
-
:
|
215
|
+
url: endpoint,
|
216
|
+
params: {},
|
217
|
+
headers: {
|
218
|
+
accept: http_accept,
|
219
|
+
user_agent: user_agent,
|
220
|
+
x_gem_version: Gemfury::VERSION
|
218
221
|
}.merge(options.delete(:headers) || {})
|
219
222
|
}.merge(options)
|
220
223
|
|
221
|
-
if
|
222
|
-
options[:headers][:authorization] = self.user_api_key
|
223
|
-
end
|
224
|
+
options[:headers][:authorization] = user_api_key if user_api_key
|
224
225
|
|
225
|
-
if
|
226
|
-
options[:params][:as] = self.account
|
227
|
-
end
|
226
|
+
options[:params][:as] = account if account
|
228
227
|
|
229
228
|
Faraday.new(options) do |builder|
|
230
229
|
builder.use Faraday::Request::MultipartWithFile
|
231
|
-
builder.use Faraday::
|
230
|
+
builder.use Faraday::Multipart::Middleware
|
232
231
|
builder.use Faraday::Request::UrlEncoded
|
233
232
|
builder.use ParseJson
|
234
233
|
builder.use Handle503
|
@@ -237,37 +236,35 @@ module Gemfury
|
|
237
236
|
end
|
238
237
|
|
239
238
|
def checked_response_body(response)
|
240
|
-
if response.success?
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
raise(error_class, error['message'])
|
261
|
-
end
|
239
|
+
return response.body if response.success?
|
240
|
+
|
241
|
+
error = (response.body || {})['error'] || {}
|
242
|
+
error_class = case error['type']
|
243
|
+
when 'Forbidden' then Gemfury::Forbidden
|
244
|
+
when 'GemVersionError' then Gemfury::InvalidGemVersion
|
245
|
+
when 'InvalidGemFile' then Gemfury::CorruptGemFile
|
246
|
+
when 'DupeVersion' then Gemfury::DupeVersion
|
247
|
+
else
|
248
|
+
case response.status
|
249
|
+
when 401 then Gemfury::Unauthorized
|
250
|
+
when 403 then Gemfury::Forbidden
|
251
|
+
when 404 then Gemfury::NotFound
|
252
|
+
when 409 then Gemfury::Conflict
|
253
|
+
when 503 then Gemfury::TimeoutError
|
254
|
+
else Gemfury::Error
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
raise(error_class, error['message'])
|
262
259
|
end
|
263
260
|
|
264
261
|
def s3_put_file(uri, file)
|
265
262
|
Faraday::Connection.new(uri) do |f|
|
266
263
|
f.adapter :net_http
|
267
264
|
end.put(uri, file, {
|
268
|
-
|
269
|
-
|
270
|
-
|
265
|
+
content_length: file.stat.size.to_s,
|
266
|
+
content_type: ''
|
267
|
+
})
|
271
268
|
end
|
272
269
|
end
|
273
270
|
end
|