gemfury 0.5.0.beta1 → 0.5.0.beta3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MGE5MzY5NTE3MGFhMjRiMzhjNDk3MzY2MmFiZTZiMTM4OGEzZDkzZA==
4
+ Mzg2MzBkYmE1NzI0OGIwMjY1NWZhNTMzYjk2MDIxNDk2NWI5Nzc3MA==
5
5
  data.tar.gz: !binary |-
6
- ZDg3MWFmZTA2MTViOGYwNTllZjRhZmY5YWViNWVjMTcwOThlNTdmZA==
6
+ YTllNGYyM2EzMDFiMjg0OGU4YzI5ZjU0YzFhNDFjMDY2MjJmYjkwOQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NjU4NTU0ZDExMjgyZjllY2FjZGViNmUzM2FiMzc4N2NlODQ4MGY4YzYwMGEy
10
- OGM2NGRkMDQyZWNhNzY3ZTFiYzJiZmZjZDAzYzE5Y2Q5MTNmNTIxNGNmOTJm
11
- MWNkMWVjYTQ3Y2RiZGQzMjFkMTNmOGNhYTZjNWU2YmVlYmUxMDA=
9
+ NjY2Mzc1OTc0ZjQ1MWIzYjJhMGQ2ZDkxMmE2ODkyYjQyMmIwZjc0ZjZiMDMz
10
+ NzdlNzQ1OGE3M2E1ZjJiYjJmNTJkN2E4ODM2NTlmNjdlYjRiMDQ2ZDgyYzdk
11
+ MWU1ODY1OTdiMTM0YTIzMTdhOGI4YWMxM2RlNmI1ZGNhNTMxMTY=
12
12
  data.tar.gz: !binary |-
13
- MWM2OTk4M2I2YjE3Y2QxNjNjMzJlMzA5OTE4NTc0Y2RiODNhYWRkMmZiYmM4
14
- YmQzMzUxMzRhM2ZjZjcyMGY1NmQ2N2Q0MDBjNTQ3MTA1MzhiNTA3ODRlNWE2
15
- OTRhODA0NWNiZjdhMDJiYjg2ZDk0NTZjYzRlNzU5MGE2OTI3N2Y=
13
+ YjUwNDQyMjA1ZTVlZjcwNjc4NzY0NGY4NzEzM2UwYmM4ODY0MTE0MzIzYjZh
14
+ MzdhMWFiZjVhY2Q5YTc1MDM2ZDg3ZjE4NTBhZWRmYWM4YWM5ZmJmZWUxNWU2
15
+ YjUyMjc3YTA5M2U0ZDQ1ZDgwOWM5ZTA5N2M0OWM2ZjliN2RkZmQ=
data/lib/gemfury.rb CHANGED
@@ -1,6 +1,6 @@
1
- gem "netrc", "~> 0.7.7"
2
- gem "multi_json", "~> 1.0"
1
+ gem "multi_json", "~> 1.10"
3
2
  gem "faraday", ">= 0.9.0", "< 0.10.0.pre"
3
+ gem "netrc", "~> 0.10.0"
4
4
 
5
5
  require 'cgi'
6
6
  require 'uri'
@@ -29,7 +29,7 @@ module Gemfury
29
29
  Gemfury::Client.new(options)
30
30
  end
31
31
 
32
- # Delegate to Twitter::Client
32
+ # Delegate to Gemfury::Client
33
33
  def method_missing(method, *args, &block)
34
34
  return super unless new.respond_to?(method)
35
35
  new.send(method, *args, &block)
@@ -23,8 +23,7 @@ module Gemfury
23
23
  ensure_ready!(:authorization)
24
24
 
25
25
  # Generate upload link
26
- headers = { :accept => "application/vnd.fury.v2+json" }
27
- api2 = connection(:headers => headers)
26
+ api2 = connection(:api_version => 2)
28
27
  response = api2.post('uploads')
29
28
  checked_response_body(response)
30
29
 
@@ -123,14 +122,20 @@ module Gemfury
123
122
  end
124
123
 
125
124
  def connection(options = {})
125
+ # The 'Accept' HTTP header for API versioning
126
+ http_accept = begin
127
+ v = options.delete(:api_version) || self.api_version
128
+ "application/vnd.fury.v#{v.to_i}+json"
129
+ end
130
+
131
+ # Faraday client options
126
132
  options = {
127
133
  :url => self.endpoint,
128
- :ssl => { :verify => false },
129
134
  :params => {},
130
135
  :headers => {
131
- :user_agent => user_agent,
136
+ :accept => http_accept,
137
+ :user_agent => self.user_agent,
132
138
  :x_gem_version => Gemfury::VERSION,
133
- :accept => self.http_accept || 'application/json',
134
139
  }.merge(options.delete(:headers) || {})
135
140
  }.merge(options)
136
141
 
@@ -161,6 +166,7 @@ module Gemfury
161
166
  when 401 then Gemfury::Unauthorized
162
167
  when 403 then Gemfury::Forbidden
163
168
  when 404 then Gemfury::NotFound
169
+ when 409 then Gemfury::Conflict
164
170
  when 503 then Gemfury::TimeoutError
165
171
  when 400
166
172
  case error['type']
@@ -4,6 +4,7 @@ class Gemfury::Command::App < Thor
4
4
 
5
5
  # Impersonation
6
6
  class_option :as, :desc => 'Access an account other than your own'
7
+ class_option :api_token, :desc => 'API token to use for commands'
7
8
 
8
9
  map "-v" => :version
9
10
  desc "version", "Show Gemfury version", :hide => true
@@ -11,18 +12,7 @@ class Gemfury::Command::App < Thor
11
12
  shell.say Gemfury::VERSION
12
13
  end
13
14
 
14
- desc "whoami", "Show current user"
15
- def whoami
16
- if !has_credentials?
17
- shell.say %Q(You are not logged in), :green
18
- else
19
- with_checks_and_rescues do
20
- me = client.account_info['username']
21
- shell.say %Q(You are logged in as "#{me}"), :green
22
- end
23
- end
24
- end
25
-
15
+ ### PACKAGE MANAGEMENT ###
26
16
  desc "push FILE", "Upload a new version of a package"
27
17
  def push(*gems)
28
18
  with_checks_and_rescues do
@@ -64,6 +54,7 @@ class Gemfury::Command::App < Thor
64
54
  end
65
55
  end
66
56
 
57
+ ### AUTHENTICATION ###
67
58
  desc "logout", "Remove Gemfury credentials"
68
59
  def logout
69
60
  if !has_credentials?
@@ -74,6 +65,21 @@ class Gemfury::Command::App < Thor
74
65
  end
75
66
  end
76
67
 
68
+ desc "login", "Populate Gemfury credentials"
69
+ def login
70
+ with_checks_and_rescues do
71
+ me = client.account_info['name']
72
+ shell.say %Q(You are logged in as "#{me}"), :green
73
+ end
74
+ end
75
+
76
+ desc "whoami", "Show current user"
77
+ def whoami
78
+ has_credentials? ? self.login : begin
79
+ shell.say %Q(You are not logged in), :green
80
+ end
81
+ end
82
+
77
83
  ### COLLABORATION MANAGEMENT ###
78
84
  map "sharing:add" => 'sharing_add'
79
85
  map "sharing:remove" => 'sharing_remove'
@@ -167,6 +173,7 @@ private
167
173
  end
168
174
 
169
175
  def with_checks_and_rescues(&block)
176
+ @user_api_key = options[:api_token] if options[:api_token]
170
177
  with_authorization(&block)
171
178
  rescue Gemfury::InvalidGemVersion => e
172
179
  shell.say "You have a deprecated Gemfury client", :red
@@ -175,6 +182,8 @@ private
175
182
  else
176
183
  shell.say %q(No problem. You can also run "gem update gemfury")
177
184
  end
185
+ rescue Gemfury::Conflict => e
186
+ die!("Oops! Locked for another user. Try again later.", e)
178
187
  rescue Gemfury::Forbidden => e
179
188
  die!("Oops! You're not allowed to access this", e)
180
189
  rescue Gemfury::NotFound => e
@@ -3,19 +3,19 @@ module Gemfury::Command::Authorization
3
3
 
4
4
  def wipe_credentials!
5
5
  FileUtils.rm(config_path, :force => true) # never raises exception
6
- netrc_conf.delete(netrc_host)
6
+ each_netrc_host { |h| netrc_conf.delete(h) }
7
7
  netrc_conf.save
8
8
  end
9
9
 
10
10
  def has_credentials?
11
- !!netrc_conf[netrc_host] ||
11
+ !!netrc_conf[netrc_api_host] ||
12
12
  read_config_file.key?(:gemfury_api_key)
13
13
  end
14
14
 
15
15
  private
16
16
  def with_authorization(&block)
17
- # Load up the credentials
18
- load_credentials!
17
+ # Load up the credentials if user_api_key is not already set
18
+ load_credentials! if @user_api_key.nil?
19
19
 
20
20
  # Attempt the operation and prompt user in case of
21
21
  # lack of authorization or a 401 response from the server
@@ -49,14 +49,13 @@ private
49
49
 
50
50
  def load_credentials!
51
51
  # Get credentials from ~/.netrc
52
- email, @user_api_key = netrc_conf[netrc_host]
52
+ email, @user_api_key = netrc_conf[netrc_api_host]
53
53
  # Legacy loading from ~/.gem/gemfury
54
- conf = read_config_file
55
- @user_api_key = conf[:gemfury_api_key] if conf[:gemfury_api_key]
54
+ @user_api_key ||= read_config_file[:gemfury_api_key]
56
55
  end
57
56
 
58
57
  def write_credentials!(email)
59
- netrc_conf[netrc_host] = email, @user_api_key
58
+ each_netrc_host { |h| netrc_conf[h] = email, @user_api_key }
60
59
  netrc_conf.save
61
60
  end
62
61
 
@@ -68,7 +67,13 @@ private
68
67
  @netrc ||= Netrc.read
69
68
  end
70
69
 
71
- def netrc_host
70
+ def netrc_api_host
72
71
  URI.parse(client.endpoint).host
73
72
  end
73
+
74
+ def each_netrc_host
75
+ [:endpoint, :gitpoint].each do |c|
76
+ yield(URI.parse(client.send(c)).host)
77
+ end
78
+ end
74
79
  end
@@ -6,8 +6,9 @@ module Gemfury
6
6
  :user_api_key,
7
7
  :adapter,
8
8
  :endpoint,
9
+ :gitpoint,
9
10
  :user_agent,
10
- :http_accept,
11
+ :api_version,
11
12
  :account].freeze
12
13
 
13
14
  # The adapter that will be used to connect if none is set
@@ -16,11 +17,14 @@ module Gemfury
16
17
  # The endpoint that will be used to connect if none is set
17
18
  DEFAULT_ENDPOINT = 'https://api.fury.io/'.freeze
18
19
 
20
+ # The HTTP endpoint for git repo (used for .netrc credentials)
21
+ DEFAULT_GITPOINT = 'https://git.fury.io/'.freeze
22
+
19
23
  # The value sent in the 'User-Agent' header if none is set
20
24
  DEFAULT_USER_AGENT = "Gemfury RubyGem #{Gemfury::VERSION}".freeze
21
25
 
22
- # The value sent in the 'Accept' header for versioning
23
- DEFAULT_HTTP_ACCEPT = "application/vnd.fury.v1+json".freeze
26
+ # Default API version
27
+ DEFAULT_API_VERSION = 1
24
28
 
25
29
  # Default user API key
26
30
  DEFAULT_API_KEY = nil
@@ -53,8 +57,9 @@ module Gemfury
53
57
  self.user_api_key = DEFAULT_API_KEY
54
58
  self.adapter = DEFAULT_ADAPTER
55
59
  self.endpoint = DEFAULT_ENDPOINT
60
+ self.gitpoint = DEFAULT_GITPOINT
56
61
  self.user_agent = DEFAULT_USER_AGENT
57
- self.http_accept = DEFAULT_HTTP_ACCEPT
62
+ self.api_version = DEFAULT_API_VERSION
58
63
  self.account = DEFAULT_ACCOUNT
59
64
  self
60
65
  end
data/lib/gemfury/error.rb CHANGED
@@ -11,6 +11,9 @@ module Gemfury
11
11
  # Client is not allowed to perform this operation
12
12
  Forbidden = Class.new(Error)
13
13
 
14
+ # Account is locked for another operation
15
+ Conflict = Class.new(Error)
16
+
14
17
  # Returned if something is not found
15
18
  NotFound = Class.new(Error)
16
19
 
@@ -1,3 +1,3 @@
1
1
  module Gemfury
2
- VERSION = '0.5.0.beta1'
2
+ VERSION = '0.5.0.beta3'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gemfury
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0.beta1
4
+ version: 0.5.0.beta3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Rykov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-02 00:00:00.000000000 Z
11
+ date: 2015-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: highline
@@ -30,28 +30,28 @@ dependencies:
30
30
  requirements:
31
31
  - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: 0.7.7
33
+ version: 0.10.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ~>
39
39
  - !ruby/object:Gem::Version
40
- version: 0.7.7
40
+ version: 0.10.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: multi_json
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ~>
46
46
  - !ruby/object:Gem::Version
47
- version: '1.0'
47
+ version: '1.10'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: '1.0'
54
+ version: '1.10'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: thor
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -146,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
146
  version: 1.3.1
147
147
  requirements: []
148
148
  rubyforge_project:
149
- rubygems_version: 2.4.5
149
+ rubygems_version: 2.4.6
150
150
  signing_key:
151
151
  specification_version: 4
152
152
  summary: Cloud Gem Server for your private RubyGems