bosh_cli 1.3262.4.0 → 1.3262.24.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8718536f3eccb1b0f29ae676a81f97e50cb6bd86
4
- data.tar.gz: 7d6ebca5dd49fed4d8875c9a3a907a798eee1286
3
+ metadata.gz: e0588eb80816d2db4f95840efdc4a7de31900ee4
4
+ data.tar.gz: a5b05788b11633f4c985cd1564ae8adeefd93aea
5
5
  SHA512:
6
- metadata.gz: 6b0f6ef5e92521dfde9a6dfc2dc767bb75c52a805f0411ebf6ac9562aba1543c34633ad8c8e5135ff1ba0a0736378110f1e64980741a0de9c34b9042abeb70a4
7
- data.tar.gz: 34c1ec2f541ee538161aac4a0bf527dbc18487ea62a71822aedcdaed880a8792116c7bf635ea4ea574606e91bf497a2ede4e78b65dbb9229c7e52c2becbaa69a
6
+ metadata.gz: a7000791e05139b905b0584509b4656923bb0ddc86767f677a084d95ac36712c755f756c80d1d6da47701fc73f2cdbfc88f56a4aa5755ea53553650b378fcaaf
7
+ data.tar.gz: 0c8b145b1ee67477285a33acdbabc636bef4540e247aaf266833004094d3bf976c510a01fcd3ad0812ee75de67024067d6c081ad9b8ca29476aa5f6a472dded2
@@ -13,6 +13,11 @@ module Bosh
13
13
  def authorization_header
14
14
  @token_provider.token
15
15
  end
16
+
17
+ def refresh
18
+ @token_provider.refresh
19
+ true
20
+ end
16
21
  end
17
22
 
18
23
  class BasicCredentials
@@ -28,6 +33,10 @@ module Bosh
28
33
  def authorization_header
29
34
  'Basic ' + Base64.encode64("#{@username}:#{@password}").strip
30
35
  end
36
+
37
+ def refresh
38
+ false
39
+ end
31
40
  end
32
41
  end
33
42
  end
@@ -881,14 +881,32 @@ module Bosh
881
881
  end
882
882
 
883
883
  if @credentials
884
+ @credentials.refresh unless payload.nil?
884
885
  headers['Authorization'] = @credentials.authorization_header
885
886
  end
886
887
 
887
- http_client.request(method, uri, {
888
+ response = http_client.request(method, uri, {
888
889
  :body => payload,
889
890
  :header => headers,
890
891
  }, &block)
891
892
 
893
+ if !response.nil? && response.code == 401
894
+ if !payload.nil?
895
+ return response
896
+ end
897
+
898
+ if @credentials.nil? || !@credentials.refresh
899
+ raise AuthError
900
+ end
901
+
902
+ headers['Authorization'] = @credentials.authorization_header
903
+ response = http_client.request(method, uri, {
904
+ :body => payload,
905
+ :header => headers,
906
+ }, &block)
907
+ end
908
+
909
+ response
892
910
  rescue URI::Error,
893
911
  SocketError,
894
912
  Errno::ECONNREFUSED,
@@ -17,17 +17,22 @@ module Bosh
17
17
  access_info.auth_header if access_info
18
18
  end
19
19
 
20
+ def refresh
21
+ get_access_info(true)
22
+ nil
23
+ end
24
+
20
25
  def username
21
26
  get_access_info.username
22
27
  end
23
28
 
24
29
  private
25
30
 
26
- def get_access_info
31
+ def get_access_info(force_refresh = false)
27
32
  if @auth_info.client_auth?
28
- client_access_info
33
+ client_access_info(force_refresh)
29
34
  else
30
- password_access_info
35
+ password_access_info(force_refresh)
31
36
  end
32
37
  end
33
38
 
@@ -35,26 +40,28 @@ module Bosh
35
40
  @uaa_client ||= Bosh::Cli::Client::Uaa::Client.new(@target, @auth_info, @config)
36
41
  end
37
42
 
38
- def client_access_info
39
- if !@client_access_info.nil? && @client_access_info.was_issued_for?(@auth_info.client_id)
40
- @client_access_info = refresh_if_needed(@client_access_info)
43
+ def client_access_info(force_refresh = false)
44
+ if !@access_info.nil? && @access_info.was_issued_for?(@auth_info.client_id)
45
+ @access_info = refresh_if_needed(@access_info, force_refresh)
41
46
  else
42
- @client_access_info = uaa_client.access_info({})
47
+ @access_info = uaa_client.access_info({})
43
48
  end
44
49
  end
45
50
 
46
- def password_access_info
47
- config_access_token = @config.access_token(@target)
48
- return nil unless config_access_token
51
+ def password_access_info(force_refresh = false)
52
+ if @access_info.nil?
53
+ config_access_token = @config.access_token(@target)
54
+ return nil unless config_access_token
49
55
 
50
- access_info = PasswordAccessInfo.create(config_access_token, @config.refresh_token(@target), @token_decoder)
51
- return nil unless access_info
56
+ @access_info = PasswordAccessInfo.create(config_access_token, @config.refresh_token(@target), @token_decoder)
57
+ return nil unless @access_info
58
+ end
52
59
 
53
- refresh_if_needed(access_info)
60
+ @access_info = refresh_if_needed(@access_info, force_refresh)
54
61
  end
55
62
 
56
- def refresh_if_needed(access_info)
57
- if access_info.expires_soon?
63
+ def refresh_if_needed(access_info, force_refresh = false)
64
+ if access_info.expires_soon? || force_refresh
58
65
  uaa_client.refresh(access_info)
59
66
  else
60
67
  access_info
@@ -1,5 +1,5 @@
1
1
  module Bosh
2
2
  module Cli
3
- VERSION = '1.3262.4.0'
3
+ VERSION = '1.3262.24.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bosh_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3262.4.0
4
+ version: 1.3262.24.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - VMware
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-20 00:00:00.000000000 Z
11
+ date: 2016-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bosh_common
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.3262.4.0
19
+ version: 1.3262.24.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.3262.4.0
26
+ version: 1.3262.24.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bosh-template
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.3262.4.0
33
+ version: 1.3262.24.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: 1.3262.4.0
40
+ version: 1.3262.24.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: cf-uaa-lib
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -128,14 +128,14 @@ dependencies:
128
128
  requirements:
129
129
  - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: 1.3262.4.0
131
+ version: 1.3262.24.0
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: 1.3262.4.0
138
+ version: 1.3262.24.0
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: net-ssh
141
141
  requirement: !ruby/object:Gem::Requirement