vmware-vra 3.0.0 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/vra/client.rb +16 -6
- data/lib/vra/version.rb +1 -1
- data/spec/client_spec.rb +18 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95e805c8c8d6fd5228962ffa907ce07409b60022e29166ba970194e0aa61cc42
|
4
|
+
data.tar.gz: 49beb545bf435a61aefccf06daa25629ccd991363dc9ca7546e3a15996cca362
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de450415be0060fb3aef5d796e407bf9fedfb79b0f83a003d702073ee7aaa06508a5758191916d4c522c42348d166c01c23f8671221c2b8cd66b5e4b839177e7
|
7
|
+
data.tar.gz: ade68fa3e927d199c2c263bd1fcc918c21ea8c9aa52703ab74092461e9719c442294064c1410fc890c27d90908be089d21340141c11814db04cbccf3d1e4710a
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,8 @@
|
|
1
1
|
# Change Log
|
2
|
+
## [3.0.1](https://github.com/chef-partners/vmware-vra-gem/tree/v3.0.1) (2022-01-25)
|
3
|
+
[Full Changelog](https://github.com/chef-partners/vmware-vra-gem/compare/v3.0.0...v3.0.1)
|
4
|
+
|
5
|
+
- Fix access token workflow to work with VRA8
|
2
6
|
|
3
7
|
## [3.0.0](https://github.com/chef-partners/vmware-vra-gem/tree/v3.0.0) (2022-01-18)
|
4
8
|
[Full Changelog](https://github.com/chef-partners/vmware-vra-gem/compare/v2.7.2...v3.0.0)
|
data/lib/vra/client.rb
CHANGED
@@ -23,7 +23,8 @@ require 'vra/http'
|
|
23
23
|
|
24
24
|
module Vra
|
25
25
|
class Client
|
26
|
-
|
26
|
+
REFRESH_TOKEN_URL = '/csp/gateway/am/api/login?access_token'
|
27
|
+
ACCESS_TOKEN_URL = '/iaas/api/login'
|
27
28
|
ROLES_URL = '/csp/gateway/am/api/loggedin/user/orgs'
|
28
29
|
|
29
30
|
attr_accessor :page_size
|
@@ -106,17 +107,26 @@ module Vra
|
|
106
107
|
end
|
107
108
|
|
108
109
|
def generate_access_token
|
110
|
+
@refresh_token.value = nil
|
109
111
|
@access_token.value = nil
|
110
112
|
validate_client_options!
|
111
113
|
|
112
|
-
|
114
|
+
# VRA 8 has a two-step authentication process - This probably breaks VRA7, who knows?!?
|
115
|
+
# First step: Sending Username/Password to get a Refresh Token
|
116
|
+
refresh_response = http_post(REFRESH_TOKEN_URL,
|
113
117
|
FFI_Yajl::Encoder.encode(token_params),
|
114
118
|
:skip_auth)
|
115
|
-
raise Vra::Exception::Unauthorized, "Unable to get the
|
119
|
+
raise Vra::Exception::Unauthorized, "Unable to get the refresh token: #{refresh_response.body}" unless refresh_response.success_ok?
|
116
120
|
|
117
|
-
|
118
|
-
@
|
119
|
-
|
121
|
+
refresh_response_body = FFI_Yajl::Parser.parse(refresh_response.body)
|
122
|
+
@refresh_token.value = refresh_response_body['refresh_token']
|
123
|
+
|
124
|
+
# Second Step: Sending the refresh token to a separate endpoint to get an Access Token
|
125
|
+
access_response = http_post(ACCESS_TOKEN_URL, "{ \"refreshToken\": \"#{@refresh_token.value}\" }", :skip_auth)
|
126
|
+
raise Vra::Exception::Unauthorized, "Unable to get the access token: #{access_response.body}" unless access_response.success_ok?
|
127
|
+
|
128
|
+
access_response_body = FFI_Yajl::Parser.parse(access_response.body)
|
129
|
+
@access_token.value = access_response_body['token']
|
120
130
|
end
|
121
131
|
|
122
132
|
def full_url(path)
|
data/lib/vra/version.rb
CHANGED
data/spec/client_spec.rb
CHANGED
@@ -54,7 +54,7 @@ describe Vra::Client do
|
|
54
54
|
end
|
55
55
|
|
56
56
|
describe '#request_headers' do
|
57
|
-
context 'when
|
57
|
+
context 'when access token exists' do
|
58
58
|
it 'has an Authorization header' do
|
59
59
|
client.access_token = '12345'
|
60
60
|
expect(client.request_headers.key?('csp-auth-token')).to be true
|
@@ -131,7 +131,7 @@ describe Vra::Client do
|
|
131
131
|
end
|
132
132
|
end
|
133
133
|
|
134
|
-
describe '#
|
134
|
+
describe '#generate_access_token' do
|
135
135
|
let(:payload) do
|
136
136
|
{
|
137
137
|
username: 'user@corp.local',
|
@@ -148,23 +148,37 @@ describe Vra::Client do
|
|
148
148
|
}.to_json
|
149
149
|
end
|
150
150
|
|
151
|
+
let(:refresh_response_body) { { token: '123456' }.to_json }
|
152
|
+
|
151
153
|
it 'posts to the tokens API endpoint' do
|
152
154
|
response = double('response', code: 200, body: success_response, success_ok?: true)
|
155
|
+
refresh_response = double('response', code: 200, body: refresh_response_body, success_ok?: true)
|
156
|
+
# First request to generate the refresh token
|
153
157
|
expect(Vra::Http).to receive(:execute)
|
154
158
|
.with(method: :post,
|
155
|
-
url: client.full_url(described_class::
|
159
|
+
url: client.full_url(described_class::REFRESH_TOKEN_URL),
|
156
160
|
payload: payload,
|
157
161
|
headers: anything,
|
158
162
|
verify_ssl: true)
|
159
163
|
.and_return(response)
|
160
164
|
|
165
|
+
# Second request to generate access token
|
166
|
+
expect(Vra::Http).to receive(:execute)
|
167
|
+
.with(method: :post,
|
168
|
+
url: client.full_url(described_class::ACCESS_TOKEN_URL),
|
169
|
+
payload: "{ \"refreshToken\": \"654321\" }",
|
170
|
+
headers: anything,
|
171
|
+
verify_ssl: true)
|
172
|
+
.and_return(refresh_response)
|
173
|
+
|
161
174
|
client.generate_access_token
|
162
175
|
end
|
163
176
|
|
164
177
|
context 'when token is generated successfully' do
|
165
178
|
it 'sets the token' do
|
166
179
|
response = double('response', code: 200, body: success_response, success_ok?: true)
|
167
|
-
|
180
|
+
refresh_response = double('response', code: 200, body: refresh_response_body, success_ok?: true)
|
181
|
+
allow(Vra::Http).to receive(:execute).twice.and_return(response, refresh_response)
|
168
182
|
|
169
183
|
client.generate_access_token
|
170
184
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vmware-vra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Leff
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2022-01-
|
12
|
+
date: 2022-01-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ffi-yajl
|