vmware-vra 1.0.0 → 1.1.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: 59dc63417610669ee08b3379e114b69272cc166c
4
- data.tar.gz: 47067ef3785e706540ed305c2241f0d9774d2c89
3
+ metadata.gz: 56ccef7bb2c458c16968ac45d3ba00306e0cfe39
4
+ data.tar.gz: 8023755792111c3fbebb453f3b651c6d12dde66f
5
5
  SHA512:
6
- metadata.gz: bf497f53a802a230e484b6b5b171ec2300973785a0e36000d9820f155c4328ed73b9c8e0a205765c60ad3196c263563a93e9660f14a6372a8f7f0999371015eb
7
- data.tar.gz: 1204363ea16057b658ace83d3e714c6b7cc6b980bb7e9d6dc3cb6910396b8deadaec9fcb3a2d015ac8c7e66d93d920b1f654f6d7723d0ecf7c5607a15da263c8
6
+ metadata.gz: 24cd4008b751382b4869c1a5e9abb49c35087ad0f65c29e9e2c9911a34a07ada9a31323e16c1867454ba19081b73ec788da3807b9a78d4b0d33148edd4ca2737
7
+ data.tar.gz: cd5567b6825a179d15a043d048fa5862fd88b6ee8ae3ef1a4ca4ed01acc378ee1cd1a28f148705a8c2d36ee39de2672aae72c0f1f92df471e50440c347012583
@@ -0,0 +1,6 @@
1
+ ## v1.1.0
2
+ * [pr#9](https://github.com/chef-partners/vmware-vra-gem/pull/9) Mask password and bearer token in console/debug/log output.
3
+ Thanks to [@rubytester](https://github.com/rubytester) for the idea and initial proposal to address in [pr#7](https://github.com/chef-partners/vmware-vra-gem/pull/7)
4
+
5
+ ## v1.0.0
6
+ * Initial release.
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Client gem for interacting with VMware's vRealize Automation application.
4
4
 
5
- Not all vRA functionality is included in this gem; only API calls necessary
5
+ Not all vRA functionality is included in this gem; only API calls necessary
6
6
  to interact with the catalog, requests, and existing items is included.
7
7
 
8
8
  The primary goal of this gem is to provide a reusable set of methods in order
@@ -33,7 +33,7 @@ require 'vra'
33
33
  => true
34
34
  ```
35
35
 
36
- Then, set up your client object. You will need to know your tenant ID from your vRA administrator.
36
+ Then, set up your client object. You will need to know your tenant ID from your vRA administrator.
37
37
 
38
38
  ```
39
39
  vra = Vra::Client.new(username: 'devmgr@corp.local', password: 'mypassword', tenant: 'mytenant', base_url: 'https://vra.corp.local', verify_ssl: true)
@@ -61,7 +61,7 @@ catalog_request = vra.catalog.request('a9cd6148-6e0b-4a80-ac47-f5255c52b43d', cp
61
61
  => #<Vra::CatalogRequest:0x00000003477c20 ... >
62
62
  ```
63
63
 
64
- vRA requires your sub-tenant (a.k.a. "business group") to be specified when requesting an item from the catalog. If the catalog item you are requesting is specifically created for a given business group, the gem will use that ID automatically without you needing to specify it.
64
+ vRA requires your sub-tenant (a.k.a. "business group") to be specified when requesting an item from the catalog. If the catalog item you are requesting is specifically created for a given business group, the gem will use that ID automatically without you needing to specify it.
65
65
 
66
66
  However, if there is no sub-tenant ID available for us to use, you will receive an error when you submit:
67
67
 
@@ -124,7 +124,7 @@ new_request.status
124
124
  => "SUCCESSFUL"
125
125
  ```
126
126
 
127
- When the request is successful, you can query the resources created as the result of your request. Assuming that the catalog item blueprint we requested only creates a single VM, we can get that resource and learn more information about it:
127
+ When the request is successful, you can query the resources created as the result of your request. Assuming that the catalog item blueprint we requested only creates a single VM, we can get that resource and learn more information about it:
128
128
 
129
129
  ```
130
130
  resource = request.resources.first
@@ -18,6 +18,7 @@
18
18
 
19
19
  require 'ffi_yajl'
20
20
  require 'rest-client'
21
+ require 'passwordmasker'
21
22
 
22
23
  module Vra
23
24
  # rubocop:disable ClassLength
@@ -27,10 +28,10 @@ module Vra
27
28
  def initialize(opts)
28
29
  @base_url = opts[:base_url]
29
30
  @username = opts[:username]
30
- @password = opts[:password]
31
+ @password = PasswordMasker.new(opts[:password])
31
32
  @tenant = opts[:tenant]
32
33
  @verify_ssl = opts.fetch(:verify_ssl, true)
33
- @bearer_token = nil
34
+ @bearer_token = PasswordMasker.new(nil)
34
35
 
35
36
  validate_client_options!
36
37
  end
@@ -60,7 +61,7 @@ module Vra
60
61
  def bearer_token_request_body
61
62
  {
62
63
  'username' => @username,
63
- 'password' => @password,
64
+ 'password' => @password.value,
64
65
  'tenant' => @tenant
65
66
  }
66
67
  end
@@ -69,7 +70,7 @@ module Vra
69
70
  headers = {}
70
71
  headers['Accept'] = 'application/json'
71
72
  headers['Content-Type'] = 'application/json'
72
- headers['Authorization'] = "Bearer #{@bearer_token}" unless @bearer_token.nil?
73
+ headers['Authorization'] = "Bearer #{@bearer_token.value}" unless @bearer_token.value.nil?
73
74
  headers
74
75
  end
75
76
 
@@ -80,9 +81,9 @@ module Vra
80
81
  end
81
82
 
82
83
  def authorized?
83
- return false if @bearer_token.nil?
84
+ return false if @bearer_token.value.nil?
84
85
 
85
- response = http_head("/identity/api/tokens/#{@bearer_token}", :skip_auth)
86
+ response = http_head("/identity/api/tokens/#{@bearer_token.value}", :skip_auth)
86
87
  if response.code == 204
87
88
  true
88
89
  else
@@ -91,7 +92,7 @@ module Vra
91
92
  end
92
93
 
93
94
  def generate_bearer_token
94
- @bearer_token = nil
95
+ @bearer_token.value = nil
95
96
  validate_client_options!
96
97
 
97
98
  response = http_post('/identity/api/tokens', bearer_token_request_body.to_json, :skip_auth)
@@ -99,7 +100,7 @@ module Vra
99
100
  raise Vra::Exception::Unauthorized, "Unable to get bearer token: #{response.body}"
100
101
  end
101
102
 
102
- @bearer_token = FFI_Yajl::Parser.parse(response.body)['id']
103
+ @bearer_token.value = FFI_Yajl::Parser.parse(response.body)['id']
103
104
  end
104
105
 
105
106
  def full_url(path)
@@ -191,7 +192,7 @@ module Vra
191
192
  end
192
193
 
193
194
  def validate_client_options!
194
- raise ArgumentError, 'Username and password are required' if @username.nil? || @password.nil?
195
+ raise ArgumentError, 'Username and password are required' if @username.nil? || @password.value.nil?
195
196
  raise ArgumentError, 'A tenant is required' if @tenant.nil?
196
197
  raise ArgumentError, 'A base URL is required' if @base_url.nil?
197
198
  raise ArgumentError, "Base URL #{@base_url} is not a valid URI." unless valid_uri?(@base_url)
@@ -17,5 +17,5 @@
17
17
  #
18
18
 
19
19
  module Vra
20
- VERSION = '1.0.0'
20
+ VERSION = '1.1.0'
21
21
  end
@@ -37,10 +37,16 @@ describe Vra::Client do
37
37
  end
38
38
  end
39
39
 
40
+ describe '#bearer_token_request_body' do
41
+ it 'gets the correct password from the PasswordMasker object' do
42
+ expect(client.bearer_token_request_body['password']).to eq('password')
43
+ end
44
+ end
45
+
40
46
  describe '#request_headers' do
41
47
  context 'when bearer token exists' do
42
48
  it 'has an Authorization header' do
43
- client.bearer_token = '12345'
49
+ client.bearer_token.value = '12345'
44
50
  expect(client.request_headers.key?('Authorization')).to be true
45
51
  end
46
52
  end
@@ -95,7 +101,7 @@ describe Vra::Client do
95
101
 
96
102
  context 'when token exists' do
97
103
  before(:each) do
98
- client.bearer_token = '12345'
104
+ client.bearer_token.value = '12345'
99
105
  end
100
106
 
101
107
  url = '/identity/api/tokens/12345'
@@ -147,7 +153,7 @@ describe Vra::Client do
147
153
 
148
154
  client.generate_bearer_token
149
155
 
150
- expect(client.bearer_token).to eq '12345'
156
+ expect(client.bearer_token.value).to eq '12345'
151
157
  end
152
158
  end
153
159
 
@@ -398,7 +404,7 @@ describe Vra::Client do
398
404
  describe '#validate_client_options!' do
399
405
  context 'when all required options are supplied' do
400
406
  it 'does not raise an exception' do
401
- expect { client.validate_client_options! }.not_to raise_error(ArgumentError)
407
+ expect { client.validate_client_options! }.not_to raise_error
402
408
  end
403
409
  end
404
410
 
@@ -18,8 +18,9 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ['lib']
20
20
 
21
- spec.add_dependency 'rest-client', '~> 1.8'
22
- spec.add_dependency 'ffi-yajl', '~> 2.2'
21
+ spec.add_dependency 'rest-client', '~> 1.8'
22
+ spec.add_dependency 'ffi-yajl', '~> 2.2'
23
+ spec.add_dependency 'passwordmasker', '~> 1.2'
23
24
 
24
25
  spec.add_development_dependency 'bundler', '~> 1.7'
25
26
  spec.add_development_dependency 'rake', '~> 10.0'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vmware-vra
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Leff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-07 00:00:00.000000000 Z
11
+ date: 2015-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: passwordmasker
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.2'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.2'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -117,6 +131,7 @@ extra_rdoc_files: []
117
131
  files:
118
132
  - ".gitignore"
119
133
  - ".rubocop.yml"
134
+ - CHANGELOG.md
120
135
  - Gemfile
121
136
  - LICENSE.txt
122
137
  - README.md