aptible-auth 0.11.15 → 0.12.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 988f035b08404c743665c27fc943def97d1ef3ce
4
- data.tar.gz: 1542ad296a37085507dbcfff254bb36914d7988f
3
+ metadata.gz: 9d1a369415687169cb1c1b3e7719962c376ad90e
4
+ data.tar.gz: 76977a7c3bba157abb62d95c67a0b4acdca812e9
5
5
  SHA512:
6
- metadata.gz: ecb2f54c418c34412ab0d154f931134698f92d49c3762f9fcfd2d565d65b1ff38d886d595c8c3f81f4f4d7e3b3d39ac1b528181196c5a4df374f371dde809edc
7
- data.tar.gz: 750343384012634983eb521d2a2c0d53ed22036aaf3f9d08db2b3c94edff6109ca76575be183fd1a4360dc1fe5e38438cb3319ed6c49a7fb9f4f35122b978d59
6
+ metadata.gz: 9084781288cbb151cb96dcd37ef751e98b31f89a658dd6df2f6dc6e1cc0c4b44f084b58f99c2ec48a4b44eb99e4c2401a81924469db81e4e78aedfbf2ae90dc8
7
+ data.tar.gz: 8407ed89866dcbe80c8f691083252c6674194c5a1ed2bc2e66d154cb3a6561f8da83fb95fed56f8857b82f8ad96b7d3852aa540cf3e2e57e03755fd26d8660e5
@@ -1,7 +1,7 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.0.0
5
- - 2.1.0
6
- - 2.2.0
4
+ - "2.0"
5
+ - "2.1"
6
+ - "2.2"
7
7
  - jruby-9.0.5.0
data/Rakefile CHANGED
@@ -1,4 +1,8 @@
1
1
  require 'bundler/gem_tasks'
2
2
 
3
- require 'aptible/tasks'
4
- Aptible::Tasks.load_tasks
3
+ begin
4
+ require 'aptible/tasks'
5
+ Aptible::Tasks.load_tasks
6
+ rescue LoadError
7
+ $stderr.puts 'Skipping Aptible::Tasks initialization...'
8
+ end
@@ -60,14 +60,7 @@ module Aptible
60
60
  end
61
61
 
62
62
  def authenticate_impersonate(subject_token, subject_token_type, options)
63
- # TODO: This duplicates aptible-resource, is it worth extracting?
64
- actor_token = \
65
- case actor_token = options.delete(:token)
66
- when Aptible::Resource::Base then actor_token.access_token
67
- when Fridge::AccessToken then actor_token.to_s
68
- when String then actor_token
69
- else bearer_token
70
- end
63
+ actor_token = token_as_string(options.delete(:token)) || bearer_token
71
64
 
72
65
  # TODO: Do we want to check whether the token is non-nil at this stage?
73
66
  options[:scope] ||= 'manage'
@@ -75,6 +68,7 @@ module Aptible
75
68
  actor_token, 'urn:ietf:params:oauth:token-type:jwt',
76
69
  subject_token, subject_token_type, options
77
70
  )
71
+
78
72
  apply_oauth_response(oauth_token)
79
73
  end
80
74
 
@@ -106,10 +100,12 @@ module Aptible
106
100
  authenticate_impersonate(href, 'aptible:organization:href', options)
107
101
  elsif (email = options.delete(:user_email))
108
102
  authenticate_impersonate(email, 'aptible:user:email', options)
103
+ elsif (user_token = options.delete(:user_token))
104
+ authenticate_impersonate(
105
+ token_as_string(user_token), 'aptible:token', options
106
+ )
109
107
  else
110
- # rubocop:disable Style/SignalException
111
- fail 'Unrecognized options'
112
- # rubocop:enable Style/SignalException
108
+ raise 'Unrecognized options'
113
109
  end
114
110
  end
115
111
 
@@ -169,6 +165,19 @@ module Aptible
169
165
  # http://stackoverflow.com/questions/13747212
170
166
  private_key.n.num_bytes * 8
171
167
  end
168
+
169
+ def token_as_string(tok)
170
+ # TODO: This duplicates aptible-resource, is it worth extracting?
171
+ return nil if tok.nil?
172
+
173
+ case tok
174
+ when Aptible::Resource::Base then tok.access_token
175
+ when Fridge::AccessToken then tok.to_s
176
+ when String then tok
177
+ else
178
+ raise "Unrecognized token: #{tok.class}: #{tok}"
179
+ end
180
+ end
172
181
  end
173
182
  end
174
183
  end
@@ -1,5 +1,5 @@
1
1
  module Aptible
2
2
  module Auth
3
- VERSION = '0.11.15'.freeze
3
+ VERSION = '0.12.0'.freeze
4
4
  end
5
5
  end
@@ -31,6 +31,7 @@ describe Aptible::Auth::Token do
31
31
  Aptible::Auth::Token.any_instance.should_receive(
32
32
  :authenticate_client
33
33
  ).with 'id', 'secret', 'user@example.com', {}
34
+
34
35
  described_class.create(
35
36
  client_id: 'id',
36
37
  client_secret: 'secret',
@@ -38,6 +39,34 @@ describe Aptible::Auth::Token do
38
39
  )
39
40
  end
40
41
 
42
+ it 'should #authenticate_impersonate if passed user_href' do
43
+ Aptible::Auth::Token.any_instance.should_receive(
44
+ :authenticate_impersonate
45
+ ).with('foo.href', 'aptible:user:href', {})
46
+ described_class.create(user_href: 'foo.href')
47
+ end
48
+
49
+ it 'should #authenticate_impersonate if passed organization_href' do
50
+ Aptible::Auth::Token.any_instance.should_receive(
51
+ :authenticate_impersonate
52
+ ).with('foo.href', 'aptible:organization:href', {})
53
+ described_class.create(organization_href: 'foo.href')
54
+ end
55
+
56
+ it 'should #authenticate_impersonate if passed user_email' do
57
+ Aptible::Auth::Token.any_instance.should_receive(
58
+ :authenticate_impersonate
59
+ ).with('foo@com', 'aptible:user:email', {})
60
+ described_class.create(user_email: 'foo@com')
61
+ end
62
+
63
+ it 'should #authenticate_impersonate if passed user_token' do
64
+ Aptible::Auth::Token.any_instance.should_receive(
65
+ :authenticate_impersonate
66
+ ).with('tok tok tok', 'aptible:token', {})
67
+ described_class.create(user_token: 'tok tok tok')
68
+ end
69
+
41
70
  it 'should not alter the hash it receives' do
42
71
  options = { email: 'some email' }
43
72
  options_before = options.dup
@@ -140,7 +169,7 @@ describe Aptible::Auth::Token do
140
169
  end
141
170
  end
142
171
 
143
- describe '#authenticate_impersonate' do
172
+ describe '#authenticate_impersonate (user email)' do
144
173
  let(:args) { ['foo@bar.com', 'aptible:user:email', {}] }
145
174
  before { oauth.stub_chain(:token_exchange, :get_token) { response } }
146
175
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aptible-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.15
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frank Macreery
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-27 00:00:00.000000000 Z
11
+ date: 2017-09-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aptible-billing
@@ -221,7 +221,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
221
221
  version: '0'
222
222
  requirements: []
223
223
  rubyforge_project:
224
- rubygems_version: 2.4.8
224
+ rubygems_version: 2.6.13
225
225
  signing_key:
226
226
  specification_version: 4
227
227
  summary: Ruby client for auth.aptible.com