vmware-vra 2.1.0 → 2.1.1

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: 65183636d3f6ae63ddfcd145b3991d9087a73282
4
- data.tar.gz: a4f5bbde07e9a7174ea9ff81f6a24d003c65df8b
3
+ metadata.gz: 2c8bf64641b851d74d4d1ce864096bdc9cd7c4a8
4
+ data.tar.gz: 90ecdf6de5c11fadeb6c3662ea193e4505c5318c
5
5
  SHA512:
6
- metadata.gz: 54e50347512573e05755e67d5b8f8747bab4a647051654fb2d7a777781263b3d9a28edc0eba6054d865bdc90792df7f0b028b8167fcabea7d560027ae2e8a9fa
7
- data.tar.gz: 04329bf410e4ca4056e8a8c885884283fc91a78c13cc3fbf2209fc38a65c511ac3f9ae35d228dc70ccf63eeda68f1f7e885b70d9e4be689a0da8874deec681ed
6
+ metadata.gz: d1cdacf633b38f21eeec6f0223809d13808187844d04e5913f19b4134fa1a92fa0fdbe118a152b8bb44ed31a51b7b35b547321d728a23e51ab61fba97943565b
7
+ data.tar.gz: dcb8daf0f3ede01d089e7a55ff7f4ce32010079e64924a7f792cc7f9714b57a7174845981f39b87dd11a4e325617eaa381d6d7102bd0d72bbe31b1c72951b015
data/.rubocop.yml CHANGED
@@ -1,14 +1,5 @@
1
- Metrics/AbcSize:
2
- Max: 30
3
- Metrics/LineLength:
4
- Max: 150
5
- Metrics/MethodLength:
6
- Max: 30
7
- Style/Documentation:
8
- Enabled: false
9
- Style/SignalException:
10
- Enabled: false
11
- Style/SpaceAroundEqualsInParameterDefault:
12
- EnforcedStyle: no_space
13
- Style/SpaceInsideBrackets:
14
- Enabled: false
1
+ AllCops:
2
+ Exclude:
3
+ - "spec/data/**/*"
4
+ - "vendor/**/*"
5
+ - "pkg/**/*"
data/CHANGELOG.md CHANGED
@@ -1,7 +1,14 @@
1
1
  # Change Log
2
2
 
3
- ## [v2.1.0](https://github.com/chef-partners/vmware-vra-gem/tree/v2.1.0)
3
+ ## [v2.2.1](https://github.com/chef-partners/vmware-vra-gem/tree/)
4
4
 
5
+ [Full Changelog](https://github.com/chef-partners/vmware-vra-gem/compare/v2.1.0...v2.1.1)
6
+
7
+ **Merged pull requests:**
8
+
9
+ - Converted to chefstyle [\#41](https://github.com/chef-partners/vmware-vra-gem/pull/41) ([jjasghar](https://github.com/jjasghar))
10
+
11
+ ## [v2.1.0](https://github.com/chef-partners/vmware-vra-gem/tree/v2.1.0) (2017-03-14)
5
12
  [Full Changelog](https://github.com/chef-partners/vmware-vra-gem/compare/v2.0.0...v2.1.0)
6
13
 
7
14
  **Merged pull requests:**
data/Gemfile CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- source 'https://rubygems.org'
2
+ source "https://rubygems.org"
3
3
 
4
4
  # Specify your gem's dependencies in vmware-vra-gem.gemspec
5
5
  gemspec
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # VMware vRA Gem
2
- [![Gem Version](https://badge.fury.io/rb/vmware-vra-gem.svg)](http://badge.fury.io/rb/vmware-vra-gem)
2
+ [![Gem Version](https://badge.fury.io/rb/vmware-vra.svg)](http://badge.fury.io/rb/vmware-vra)
3
3
  [![Build Status](https://travis-ci.org/chef-partners/vmware-vra-gem.svg?branch=master)](https://travis-ci.org/chef-partners/vmware-vra-gem)
4
4
 
5
5
  Client gem for interacting with VMware's vRealize Automation application.
data/Rakefile CHANGED
@@ -1,9 +1,12 @@
1
1
  # frozen_string_literal: true
2
- require 'bundler/gem_tasks'
3
- require 'rspec/core/rake_task'
4
- require 'rubocop/rake_task'
2
+ require "bundler/gem_tasks"
3
+ require "rspec/core/rake_task"
4
+ require "chefstyle"
5
+ require "rubocop/rake_task"
5
6
 
6
7
  RSpec::Core::RakeTask.new(:spec)
7
- RuboCop::RakeTask.new(:style)
8
+ RuboCop::RakeTask.new do |task|
9
+ task.options << "--display-cop-names"
10
+ end
8
11
 
9
- task default: [ :spec, :style ]
12
+ task default: [ :spec, :rubocop ]
data/lib/vra.rb CHANGED
@@ -17,14 +17,14 @@
17
17
  # limitations under the License.
18
18
  #
19
19
 
20
- require 'vra/catalog'
21
- require 'vra/catalog_item'
22
- require 'vra/catalog_request'
23
- require 'vra/client'
24
- require 'vra/exceptions'
25
- require 'vra/request'
26
- require 'vra/request_parameters'
27
- require 'vra/requests'
28
- require 'vra/resource'
29
- require 'vra/resources'
30
- require 'vra/version'
20
+ require "vra/catalog"
21
+ require "vra/catalog_item"
22
+ require "vra/catalog_request"
23
+ require "vra/client"
24
+ require "vra/exceptions"
25
+ require "vra/request"
26
+ require "vra/request_parameters"
27
+ require "vra/requests"
28
+ require "vra/resource"
29
+ require "vra/resources"
30
+ require "vra/version"
data/lib/vra/catalog.rb CHANGED
@@ -26,13 +26,13 @@ module Vra
26
26
  end
27
27
 
28
28
  def all_items
29
- client.http_get_paginated_array!('/catalog-service/api/consumer/catalogItems')
29
+ client.http_get_paginated_array!("/catalog-service/api/consumer/catalogItems")
30
30
  .map! { |x| Vra::CatalogItem.new(client, data: x) }
31
31
  end
32
32
 
33
33
  def entitled_items
34
- client.http_get_paginated_array!('/catalog-service/api/consumer/entitledCatalogItems')
35
- .map! { |x| Vra::CatalogItem.new(client, data: x['catalogItem']) }
34
+ client.http_get_paginated_array!("/catalog-service/api/consumer/entitledCatalogItems")
35
+ .map! { |x| Vra::CatalogItem.new(client, data: x["catalogItem"]) }
36
36
  end
37
37
 
38
38
  def request(*args)
@@ -17,7 +17,7 @@
17
17
  # limitations under the License.
18
18
  #
19
19
 
20
- require 'ffi_yajl'
20
+ require "ffi_yajl"
21
21
 
22
22
  module Vra
23
23
  class CatalogItem
@@ -28,17 +28,17 @@ module Vra
28
28
  @catalog_item_data = opts[:data]
29
29
 
30
30
  if @id.nil? && @catalog_item_data.nil?
31
- raise ArgumentError, 'must supply an id or a catalog item data hash'
31
+ raise ArgumentError, "must supply an id or a catalog item data hash"
32
32
  end
33
33
 
34
34
  if !@id.nil? && !@catalog_item_data.nil?
35
- raise ArgumentError, 'must supply an id OR a catalog item data hash, not both'
35
+ raise ArgumentError, "must supply an id OR a catalog item data hash, not both"
36
36
  end
37
37
 
38
38
  if @catalog_item_data.nil?
39
39
  fetch_catalog_item
40
40
  else
41
- @id = @catalog_item_data['id']
41
+ @id = @catalog_item_data["id"]
42
42
  end
43
43
  end
44
44
 
@@ -49,41 +49,41 @@ module Vra
49
49
  end
50
50
 
51
51
  def name
52
- @catalog_item_data['name']
52
+ @catalog_item_data["name"]
53
53
  end
54
54
 
55
55
  def description
56
- @catalog_item_data['description']
56
+ @catalog_item_data["description"]
57
57
  end
58
58
 
59
59
  def status
60
- @catalog_item_data['status']
60
+ @catalog_item_data["status"]
61
61
  end
62
62
 
63
63
  def organization
64
- return {} if @catalog_item_data['organization'].nil?
64
+ return {} if @catalog_item_data["organization"].nil?
65
65
 
66
- @catalog_item_data['organization']
66
+ @catalog_item_data["organization"]
67
67
  end
68
68
 
69
69
  def tenant_id
70
- organization['tenantRef']
70
+ organization["tenantRef"]
71
71
  end
72
72
 
73
73
  def tenant_name
74
- organization['tenantLabel']
74
+ organization["tenantLabel"]
75
75
  end
76
76
 
77
77
  def subtenant_id
78
- organization['subtenantRef']
78
+ organization["subtenantRef"]
79
79
  end
80
80
 
81
81
  def subtenant_name
82
- organization['subtenantLabel']
82
+ organization["subtenantLabel"]
83
83
  end
84
84
 
85
85
  def blueprint_id
86
- @catalog_item_data['providerBinding']['bindingId']
86
+ @catalog_item_data["providerBinding"]["bindingId"]
87
87
  end
88
88
  end
89
89
  end
@@ -23,7 +23,7 @@ module Vra
23
23
  attr_writer :subtenant_id
24
24
  attr_accessor :cpus, :memory, :requested_for, :lease_days, :notes
25
25
 
26
- def initialize(client, catalog_id, opts={})
26
+ def initialize(client, catalog_id, opts = {})
27
27
  @client = client
28
28
  @catalog_id = catalog_id
29
29
  @cpus = opts[:cpus]
@@ -64,16 +64,16 @@ module Vra
64
64
 
65
65
  def merge_payload(payload)
66
66
  hash_payload = JSON.parse(payload)
67
- blueprint_name = hash_payload['data'].select { |_k, v| v.is_a?(Hash) }.keys.first
67
+ blueprint_name = hash_payload["data"].select { |_k, v| v.is_a?(Hash) }.keys.first
68
68
 
69
- hash_payload['data'][blueprint_name]['data']['cpu'] = @cpus
70
- hash_payload['data'][blueprint_name]['data']['memory'] = @memory
71
- hash_payload['requestedFor'] = @requested_for
72
- hash_payload['data']['_leaseDays'] = @lease_days
73
- hash_payload['description'] = @notes
69
+ hash_payload["data"][blueprint_name]["data"]["cpu"] = @cpus
70
+ hash_payload["data"][blueprint_name]["data"]["memory"] = @memory
71
+ hash_payload["requestedFor"] = @requested_for
72
+ hash_payload["data"]["_leaseDays"] = @lease_days
73
+ hash_payload["description"] = @notes
74
74
 
75
75
  parameters.each do |param|
76
- hash_payload['data'][blueprint_name]['data'][param.key] = param.value
76
+ hash_payload["data"][blueprint_name]["data"][param.key] = param.value
77
77
  end
78
78
 
79
79
  JSON.pretty_generate(hash_payload)
@@ -91,7 +91,7 @@ module Vra
91
91
  raise
92
92
  end
93
93
 
94
- request_id = JSON.parse(post_response.body)['id']
94
+ request_id = JSON.parse(post_response.body)["id"]
95
95
  Vra::Request.new(client, request_id)
96
96
  end
97
97
  end
data/lib/vra/client.rb CHANGED
@@ -17,9 +17,9 @@
17
17
  # limitations under the License.
18
18
  #
19
19
 
20
- require 'ffi_yajl'
21
- require 'passwordmasker'
22
- require 'vra/http'
20
+ require "ffi_yajl"
21
+ require "passwordmasker"
22
+ require "vra/http"
23
23
 
24
24
  module Vra
25
25
  # rubocop:disable ClassLength
@@ -70,24 +70,24 @@ module Vra
70
70
 
71
71
  def bearer_token_request_body
72
72
  {
73
- 'username' => @username,
74
- 'password' => @password.value,
75
- 'tenant' => @tenant
73
+ "username" => @username,
74
+ "password" => @password.value,
75
+ "tenant" => @tenant,
76
76
  }
77
77
  end
78
78
 
79
79
  def request_headers
80
80
  headers = {}
81
- headers['Accept'] = 'application/json'
82
- headers['Content-Type'] = 'application/json'
83
- headers['Authorization'] = "Bearer #{@bearer_token.value}" unless @bearer_token.value.nil?
81
+ headers["Accept"] = "application/json"
82
+ headers["Content-Type"] = "application/json"
83
+ headers["Authorization"] = "Bearer #{@bearer_token.value}" unless @bearer_token.value.nil?
84
84
  headers
85
85
  end
86
86
 
87
87
  def authorize!
88
88
  generate_bearer_token unless authorized?
89
89
 
90
- raise Vra::Exception::Unauthorized, 'Unable to authorize against vRA' unless authorized?
90
+ raise Vra::Exception::Unauthorized, "Unable to authorize against vRA" unless authorized?
91
91
  end
92
92
 
93
93
  def authorized?
@@ -101,21 +101,21 @@ module Vra
101
101
  @bearer_token.value = nil
102
102
  validate_client_options!
103
103
 
104
- response = http_post('/identity/api/tokens',
104
+ response = http_post("/identity/api/tokens",
105
105
  FFI_Yajl::Encoder.encode(bearer_token_request_body),
106
106
  :skip_auth)
107
107
  unless response.success_ok?
108
108
  raise Vra::Exception::Unauthorized, "Unable to get bearer token: #{response.body}"
109
109
  end
110
110
 
111
- @bearer_token.value = FFI_Yajl::Parser.parse(response.body)['id']
111
+ @bearer_token.value = FFI_Yajl::Parser.parse(response.body)["id"]
112
112
  end
113
113
 
114
114
  def full_url(path)
115
115
  "#{@base_url}#{path}"
116
116
  end
117
117
 
118
- def http_fetch(method, path, skip_auth=nil)
118
+ def http_fetch(method, path, skip_auth = nil)
119
119
  authorize! unless skip_auth
120
120
 
121
121
  response = Vra::Http.execute(method: method,
@@ -128,11 +128,11 @@ module Vra
128
128
  response
129
129
  end
130
130
 
131
- def http_head(path, skip_auth=nil)
131
+ def http_head(path, skip_auth = nil)
132
132
  http_fetch(:head, path, skip_auth)
133
133
  end
134
134
 
135
- def http_get(path, skip_auth=nil)
135
+ def http_get(path, skip_auth = nil)
136
136
  http_fetch(:get, path, skip_auth)
137
137
  end
138
138
 
@@ -152,22 +152,24 @@ module Vra
152
152
 
153
153
  loop do
154
154
  response = get_parsed("#{base_path}&page=#{page}")
155
- items += response['content']
155
+ items += response["content"]
156
156
 
157
- break if page >= response['metadata']['totalPages']
157
+ break if page >= response["metadata"]["totalPages"]
158
158
  page += 1
159
159
  end
160
160
 
161
- raise Vra::Exception::DuplicateItemsDetected,
162
- 'Duplicate items were returned by the vRA API. ' \
163
- 'Increase your page size to avoid this vRA API bug. ' \
164
- 'See https://github.com/chef-partners/vmware-vra-gem#pagination ' \
165
- 'for more information.' if items.uniq!
161
+ if items.uniq!
162
+ raise Vra::Exception::DuplicateItemsDetected,
163
+ "Duplicate items were returned by the vRA API. " \
164
+ "Increase your page size to avoid this vRA API bug. " \
165
+ "See https://github.com/chef-partners/vmware-vra-gem#pagination " \
166
+ "for more information."
167
+ end
166
168
 
167
169
  items
168
170
  end
169
171
 
170
- def http_post(path, payload, skip_auth=nil)
172
+ def http_post(path, payload, skip_auth = nil)
171
173
  authorize! unless skip_auth
172
174
 
173
175
  response = Vra::Http.execute(method: :post,
@@ -200,14 +202,14 @@ module Vra
200
202
  klass: caught_exception.class,
201
203
  path: path)
202
204
 
203
- message = exception.errors.empty? ? caught_exception.message : exception.errors.join(', ')
205
+ message = exception.errors.empty? ? caught_exception.message : exception.errors.join(", ")
204
206
  raise exception, message
205
207
  end
206
208
 
207
209
  def validate_client_options!
208
- raise ArgumentError, 'Username and password are required' if @username.nil? || @password.value.nil?
209
- raise ArgumentError, 'A tenant is required' if @tenant.nil?
210
- raise ArgumentError, 'A base URL is required' if @base_url.nil?
210
+ raise ArgumentError, "Username and password are required" if @username.nil? || @password.value.nil?
211
+ raise ArgumentError, "A tenant is required" if @tenant.nil?
212
+ raise ArgumentError, "A base URL is required" if @base_url.nil?
211
213
  raise ArgumentError, "Base URL #{@base_url} is not a valid URI." unless valid_uri?(@base_url)
212
214
  end
213
215
 
@@ -17,7 +17,7 @@
17
17
  # limitations under the License.
18
18
  #
19
19
 
20
- require 'ffi_yajl'
20
+ require "ffi_yajl"
21
21
 
22
22
  module Vra
23
23
  module Exception
@@ -28,7 +28,7 @@ module Vra
28
28
 
29
29
  class HTTPError < RuntimeError
30
30
  attr_accessor :klass, :code, :body, :errors, :path
31
- def initialize(opts={})
31
+ def initialize(opts = {})
32
32
  @code = opts[:code]
33
33
  @body = opts[:body]
34
34
  @path = opts[:path]
@@ -46,10 +46,10 @@ module Vra
46
46
  end
47
47
 
48
48
  return if data.nil?
49
- return unless data['errors'].respond_to?(:each)
49
+ return unless data["errors"].respond_to?(:each)
50
50
 
51
- data['errors'].each do |error|
52
- @errors << error['systemMessage']
51
+ data["errors"].each do |error|
52
+ @errors << error["systemMessage"]
53
53
  end
54
54
  end
55
55
  end
data/lib/vra/http.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- require 'net/http'
2
+ require "net/http"
3
3
 
4
4
  module Vra
5
5
  module Http
@@ -7,7 +7,7 @@ module Vra
7
7
  request = Request.new(params)
8
8
  response = request.call
9
9
  response = response.forward(request).call until response.final?
10
- fail error(response) unless response.success?
10
+ raise error(response) unless response.success?
11
11
  response
12
12
  end
13
13
 
@@ -35,15 +35,15 @@ module Vra
35
35
  end
36
36
 
37
37
  def call
38
- uri = URI(params[:url]) || fail(':url required')
38
+ uri = URI(params[:url]) || raise(":url required")
39
39
 
40
- ssl_params = { use_ssl: uri.scheme == 'https' }
40
+ ssl_params = { use_ssl: uri.scheme == "https" }
41
41
  ssl_params[:verify_mode] = OpenSSL::SSL::VERIFY_NONE unless verify_ssl?
42
42
 
43
43
  Net::HTTP.start(uri.host, uri.port, ssl_params) do |http|
44
44
  request = http_request(params[:method], uri)
45
45
  request.initialize_http_header(params[:headers] || {})
46
- request.body = params[:payload] || ''
46
+ request.body = params[:payload] || ""
47
47
 
48
48
  Response.new(http.request(request))
49
49
  end
@@ -53,10 +53,10 @@ module Vra
53
53
  type = {
54
54
  get: Net::HTTP::Get,
55
55
  head: Net::HTTP::Head,
56
- post: Net::HTTP::Post
56
+ post: Net::HTTP::Post,
57
57
  }.fetch(method, nil)
58
58
 
59
- fail "Unknown HTTP method #{method}!" unless type
59
+ raise "Unknown HTTP method #{method}!" unless type
60
60
 
61
61
  type.new(uri)
62
62
  end
@@ -82,7 +82,7 @@ module Vra
82
82
 
83
83
  def forward(request)
84
84
  if redirect?
85
- fail Http.error(self) unless request.redirectable?
85
+ raise Http.error(self) unless request.redirectable?
86
86
  request.redirect_to(location)
87
87
  elsif see_other?
88
88
  request.see_other(location)
@@ -92,7 +92,7 @@ module Vra
92
92
  end
93
93
 
94
94
  def location
95
- @response['location']
95
+ @response["location"]
96
96
  end
97
97
 
98
98
  def body