vsphere-automation-cis 0.3.0 → 0.4.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
  SHA256:
3
- metadata.gz: f274985c3db6e9bb80d739606d685355d3405a5169645365171e6048642877c4
4
- data.tar.gz: e3bf1c0936f6c59b5c4d08fc4a02575be75057da73205cfb2d8f5b5d3f585519
3
+ metadata.gz: 179287e2da8d59bb2209fa3cf6f35e63430b19c6964e4c032208a9656b070a27
4
+ data.tar.gz: e8ec8c9f2b8ccb5cbe0f5f6542ff4f7ea8f5de1b69dd62d6a24a5937ab590a8a
5
5
  SHA512:
6
- metadata.gz: 4a358a37ccf86e2bfe375ce924a8d458573aae58c3ed62985afb83c467affd967956e4396f93665700830dee7b4d34dffa0583db7179c072fc0dd106d12c17f3
7
- data.tar.gz: ab6429370109ff17ee4a841c4de0df89880433629964739dedf5bce1c5cd071c58310c19f001b78099440efc0fa315d13af34388a9b60fa24eb04e763707aecd
6
+ metadata.gz: 11fbb90cb17f7639b01bae7de1c96a1d81517ea877b2dbc0c59bbf1dc2eba1f842e95248056a9a713ab5c00f0d641331ceb40b862517ab6de32ba7f357f688e2
7
+ data.tar.gz: 97a18f33e9d223b6e45a1909b5e2a683049fb48af423278354acdc6751dd9e397dfdb0ffc2d0f61a2c06eb0a3d69e29f4516cbf2b68780d6910d368017c0f5b8
data/Gemfile.lock CHANGED
@@ -1,38 +1,34 @@
1
1
  PATH
2
2
  remote: ../runtime
3
3
  specs:
4
- vsphere-automation-runtime (0.3.0)
5
- typhoeus (~> 1.3)
4
+ vsphere-automation-runtime (0.4.0)
6
5
 
7
6
  PATH
8
7
  remote: .
9
8
  specs:
10
- vsphere-automation-cis (0.3.0)
11
- vsphere-automation-runtime (~> 0.3.0)
9
+ vsphere-automation-cis (0.4.0)
10
+ vsphere-automation-runtime (~> 0.4.0)
12
11
 
13
12
  GEM
14
13
  remote: https://rubygems.org/
15
14
  specs:
16
- addressable (2.6.0)
17
- public_suffix (>= 2.0.2, < 4.0)
15
+ addressable (2.7.0)
16
+ public_suffix (>= 2.0.2, < 5.0)
18
17
  ast (2.4.0)
19
18
  coderay (1.1.2)
20
19
  crack (0.4.3)
21
20
  safe_yaml (~> 1.0.0)
22
21
  diff-lcs (1.3)
23
- ethon (0.12.0)
24
- ffi (>= 1.3.0)
25
- ffi (1.11.1)
26
22
  hashdiff (1.0.0)
27
23
  jaro_winkler (1.5.3)
28
24
  method_source (0.9.2)
29
25
  parallel (1.17.0)
30
- parser (2.6.3.0)
26
+ parser (2.6.4.0)
31
27
  ast (~> 2.4.0)
32
28
  pry (0.12.2)
33
29
  coderay (~> 1.1.0)
34
30
  method_source (~> 0.9.0)
35
- public_suffix (3.1.1)
31
+ public_suffix (4.0.1)
36
32
  rainbow (3.0.0)
37
33
  rake (12.3.3)
38
34
  rspec (3.8.0)
@@ -57,11 +53,9 @@ GEM
57
53
  unicode-display_width (>= 1.4.0, < 1.7)
58
54
  ruby-progressbar (1.10.1)
59
55
  safe_yaml (1.0.5)
60
- typhoeus (1.3.1)
61
- ethon (>= 0.9.0)
62
56
  unicode-display_width (1.6.0)
63
57
  vcr (5.0.0)
64
- webmock (3.6.2)
58
+ webmock (3.7.2)
65
59
  addressable (>= 2.3.6)
66
60
  crack (>= 0.3.2)
67
61
  hashdiff (>= 0.4.0, < 2.0.0)
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  The Ruby gem for the vSphere CIS API
4
4
 
5
5
  - API version: 2.0.0
6
- - Package version: 0.3.0
6
+ - Package version: 0.4.0
7
7
 
8
8
  ## Installation
9
9
 
@@ -8,6 +8,6 @@
8
8
 
9
9
  module VSphereAutomation
10
10
  module CIS
11
- VERSION = '0.3.0'
11
+ VERSION = '0.4.0'
12
12
  end
13
13
  end
@@ -97,7 +97,6 @@ describe 'TaggingCategoryApi' do
97
97
  # unit tests for remove_from_used_by
98
98
  # Removes the {@param.name usedByEntity} from the {@link CategoryModel#usedBy} subscribers {@term set}. If the {@param.name usedByEntity} is not using this category, then this becomes a no-op. To invoke this {@term operation}, you need the modify {@link CategoryModel#usedBy} privilege on the category.
99
99
  # @param category_id The identifier of the input category.
100
- # @param action ~action&#x3D;remove-from-used-by
101
100
  # @param request_body
102
101
  # @param [Hash] opts the optional parameters
103
102
  # @return [nil]
@@ -31,7 +31,6 @@ describe 'TaggingTagApi' do
31
31
  # unit tests for add_to_used_by
32
32
  # Adds the {@param.name usedByEntity} to the {@link TagModel#usedBy} subscribers {@term set}. If the {@param.name usedByEntity} is already in the {@term set}, then this becomes a no-op. To invoke this {@term operation}, you need the modify {@link TagModel#usedBy} privilege on the tag.
33
33
  # @param tag_id The identifier of the input tag.
34
- # @param action ~action&#x3D;add-to-used-by
35
34
  # @param request_body
36
35
  # @param [Hash] opts the optional parameters
37
36
  # @return [nil]
@@ -87,7 +86,6 @@ describe 'TaggingTagApi' do
87
86
  # unit tests for list_tags_for_category
88
87
  # Enumerates all tags for the given category. To invoke this {@term operation}, you need the read privilege on the given category and the individual tags in that category.
89
88
  # @param category_id The identifier of the input category.
90
- # @param action ~action&#x3D;list-tags-for-category
91
89
  # @param [Hash] opts the optional parameters
92
90
  # @return [CisTaggingTagListTagsForCategoryResult]
93
91
  describe 'list_tags_for_category test' do
@@ -54,7 +54,6 @@ describe 'TaggingTagAssociationApi' do
54
54
  # unit tests for attach_tag_to_multiple_objects
55
55
  # Attaches the given tag to the input objects. If a tag is already attached to the object, then the individual {@term operation} is a no-op and an error will not be added to {@link BatchResult#errorMessages}. To invoke this {@term operation}, you need the attach tag privilege on the tag and the read privilege on each object.
56
56
  # @param tag_id The identifier of the input tag.
57
- # @param action ~action&#x3D;attach-tag-to-multiple-objects
58
57
  # @param request_body
59
58
  # @param [Hash] opts the optional parameters
60
59
  # @return [CisTaggingTagAssociationAttachTagToMultipleObjectsResult]
@@ -145,7 +144,6 @@ describe 'TaggingTagAssociationApi' do
145
144
 
146
145
  # unit tests for list_attached_tags_on_objects
147
146
  # Fetches the {@term list} of {@link ObjectToTags} describing the input object identifiers and the tags attached to each object. To invoke this {@term operation}, you need the read privilege on each input object. The {@link ObjectToTags#tagIds} will only contain those tags for which you have the read privilege.
148
- # @param action ~action&#x3D;list-attached-tags-on-objects
149
147
  # @param request_body
150
148
  # @param [Hash] opts the optional parameters
151
149
  # @return [CisTaggingTagAssociationListAttachedTagsOnObjectsResult]
@@ -31,7 +31,6 @@ describe 'TasksApi' do
31
31
  # unit tests for cancel
32
32
  # Cancel a running operation associated with the task. This is the best effort attempt. Operation may not be cancelled anymore once it reaches certain stage.
33
33
  # @param task Task identifier. The parameter must be an identifier for the resource type: cis.task.
34
- # @param action action&#x3D;cancel
35
34
  # @param [Hash] opts the optional parameters
36
35
  # @return [nil]
37
36
  describe 'cancel test' do
@@ -61,7 +60,7 @@ describe 'TasksApi' do
61
60
  # @option opts [Boolean] :result_spec_exclude_result If true, the result will not be included in the task information, otherwise it will be included. If unset, the result of the operation will be included in the task information.
62
61
  # @option opts [Array<String>] :filter_spec_services Identifiers of services. Tasks created by operations in these services match the filter (see CommonInfo.service). This field may be unset if Tasks.FilterSpec.tasks is specified. Currently all services must be from the same provider. If this field is unset or empty, tasks for all services will match the filter. When clients pass a value of this structure as a parameter, the field must contain identifiers for the resource type: vapi.service. When operations return a value of this structure as a result, the field will contain identifiers for the resource type: vapi.service.
63
62
  # @option opts [Array<String>] :filter_spec_status Status that a task must have to match the filter (see CommonInfo.status). If unset or empty, tasks with any status match the filter.
64
- # @option opts [Array<Object>] :filter_spec_targets Identifiers of the targets the operation for the associated task created or was performed on (see CommonInfo.target). If unset or empty, tasks associated with operations on any target match the filter.
63
+ # @option opts [Array<FilterSpecTargets>] :filter_spec_targets Identifiers of the targets the operation for the associated task created or was performed on (see CommonInfo.target). If unset or empty, tasks associated with operations on any target match the filter.
65
64
  # @option opts [Array<String>] :filter_spec_users Users who must have initiated the operation for the associated task to match the filter (see CommonInfo.user). If unset or empty, tasks associated with operations initiated by any user match the filter.
66
65
  # @return [CisTasksListResult]
67
66
  describe 'list test' do
data/spec/spec_helper.rb CHANGED
@@ -8,6 +8,9 @@
8
8
 
9
9
  # load the gem
10
10
  require 'vsphere-automation-cis'
11
+ require 'webmock/rspec'
12
+
13
+ WebMock.disable_net_connect!(allow_localhost: true)
11
14
 
12
15
  # The following was generated by the `rspec --init` command. Conventionally, all
13
16
  # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
@@ -22,8 +22,7 @@ Gem::Specification.new do |s|
22
22
  s.description = "A Ruby SDK for the vSphere REST APIs (CIS)"
23
23
  s.license = 'MIT'
24
24
  s.required_ruby_version = ">= 2.3"
25
-
26
- s.add_runtime_dependency 'vsphere-automation-runtime', '~> 0.3.0'
25
+ s.add_runtime_dependency 'vsphere-automation-runtime', '~> 0.4.0'
27
26
 
28
27
  s.add_development_dependency 'bundler', '~> 2.0'
29
28
  s.add_development_dependency 'pry', '~> 0.12.2'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vsphere-automation-cis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - J.R. Garcia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-22 00:00:00.000000000 Z
11
+ date: 2019-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: vsphere-automation-runtime
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.3.0
19
+ version: 0.4.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: 0.3.0
26
+ version: 0.4.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -227,9 +227,6 @@ files:
227
227
  - lib/vsphere-automation-cis/api/tagging_tag_api.rb
228
228
  - lib/vsphere-automation-cis/api/tagging_tag_association_api.rb
229
229
  - lib/vsphere-automation-cis/api/tasks_api.rb
230
- - lib/vsphere-automation-cis/api_client.rb
231
- - lib/vsphere-automation-cis/api_error.rb
232
- - lib/vsphere-automation-cis/configuration.rb
233
230
  - lib/vsphere-automation-cis/models/cis_session_create_result.rb
234
231
  - lib/vsphere-automation-cis/models/cis_session_info.rb
235
232
  - lib/vsphere-automation-cis/models/cis_session_result.rb
@@ -313,15 +310,12 @@ files:
313
310
  - lib/vsphere-automation-cis/models/vapi_std_errors_unsupported_error.rb
314
311
  - lib/vsphere-automation-cis/models/vapi_std_localizable_message.rb
315
312
  - lib/vsphere-automation-cis/version.rb
316
- - pkg/vsphere-automation-cis-0.2.1.gem
317
- - pkg/vsphere-automation-cis-0.2.2.gem
313
+ - pkg/vsphere-automation-cis-0.4.0.gem
318
314
  - spec/api/session_api_spec.rb
319
315
  - spec/api/tagging_category_api_spec.rb
320
316
  - spec/api/tagging_tag_api_spec.rb
321
317
  - spec/api/tagging_tag_association_api_spec.rb
322
318
  - spec/api/tasks_api_spec.rb
323
- - spec/api_client_spec.rb
324
- - spec/configuration_spec.rb
325
319
  - spec/models/cis_session_create_result_spec.rb
326
320
  - spec/models/cis_session_info_spec.rb
327
321
  - spec/models/cis_session_result_spec.rb
@@ -435,8 +429,6 @@ test_files:
435
429
  - spec/api/tagging_tag_association_api_spec.rb
436
430
  - spec/api/tagging_category_api_spec.rb
437
431
  - spec/api/tagging_tag_api_spec.rb
438
- - spec/api_client_spec.rb
439
- - spec/configuration_spec.rb
440
432
  - spec/models/cis_tagging_category_update_spec_spec.rb
441
433
  - spec/models/vapi_std_errors_invalid_argument_spec.rb
442
434
  - spec/models/cis_session_create_result_spec.rb
@@ -1,390 +0,0 @@
1
- =begin
2
- # Copyright (c) 2018-2019 VMware, Inc. All Rights Reserved.
3
- # SPDX-License-Identifier: MIT
4
-
5
- # DO NOT MODIFY. THIS CODE IS GENERATED. CHANGES WILL BE OVERWRITTEN.
6
-
7
- # cis - No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
8
-
9
- =end
10
-
11
- require 'date'
12
- require 'json'
13
- require 'logger'
14
- require 'tempfile'
15
- require 'typhoeus'
16
- require 'uri'
17
-
18
- module VSphereAutomation
19
- class ApiClient
20
- # The Configuration object holding settings to be used in the API client.
21
- attr_accessor :config
22
-
23
- # Defines the headers to be used in HTTP requests of all API calls by default.
24
- #
25
- # @return [Hash]
26
- attr_accessor :default_headers
27
-
28
- # Initializes the ApiClient
29
- # @option config [Configuration] Configuration for initializing the object, default to Configuration.default
30
- def initialize(config = Configuration.default)
31
- @config = config
32
- @user_agent = "SDK/0.3.0 Ruby/#{RUBY_VERSION} (#{Gem::Platform.local.os}; #{Gem::Platform.local.version}; #{Gem::Platform.local.cpu})"
33
- @default_headers = {
34
- 'Content-Type' => 'application/json',
35
- 'User-Agent' => @user_agent
36
- }
37
- end
38
-
39
- def self.default
40
- @@default ||= ApiClient.new
41
- end
42
-
43
- # Call an API with given options.
44
- #
45
- # @return [Array<(Object, Fixnum, Hash)>] an array of 3 elements:
46
- # the data deserialized from response body (could be nil), response status code and response headers.
47
- def call_api(http_method, path, opts = {})
48
- request = build_request(http_method, path, opts)
49
- response = request.run
50
-
51
- if @config.debugging
52
- @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
53
- end
54
-
55
- unless opts.fetch(:return_type, {}).keys.include?(response.code.to_s) || response.success?
56
- if response.timed_out?
57
- fail ApiError.new('Connection timed out')
58
- elsif response.code == 0
59
- # Errors from libcurl will be made visible here
60
- fail ApiError.new(:code => 0,
61
- :message => response.return_message)
62
- else
63
- fail ApiError.new(:code => response.code,
64
- :response_headers => response.headers,
65
- :response_body => response.body),
66
- response.status_message
67
- end
68
- end
69
-
70
- if opts[:return_type]
71
- data = deserialize(response, opts[:return_type][response.code.to_s])
72
- if path == '/com/vmware/cis/session'
73
- @config.api_key['vmware-api-session-id'] = data.value
74
- end
75
- else
76
- data = nil
77
- end
78
- return data, response.code, response.headers
79
- end
80
-
81
- # Builds the HTTP request
82
- #
83
- # @param [String] http_method HTTP method/verb (e.g. POST)
84
- # @param [String] path URL path (e.g. /account/new)
85
- # @option opts [Hash] :header_params Header parameters
86
- # @option opts [Hash] :query_params Query parameters
87
- # @option opts [Hash] :form_params Query parameters
88
- # @option opts [Object] :body HTTP body (JSON/XML)
89
- # @return [Typhoeus::Request] A Typhoeus Request
90
- def build_request(http_method, path, opts = {})
91
- url = build_request_url(path)
92
- http_method = http_method.to_sym.downcase
93
-
94
- header_params = @default_headers.merge(opts[:header_params] || {})
95
- query_params = opts[:query_params] || {}
96
- form_params = opts[:form_params] || {}
97
-
98
- update_params_for_auth! header_params, query_params, opts[:auth_names]
99
-
100
- # set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
101
- _verify_ssl_host = @config.verify_ssl_host ? 2 : 0
102
-
103
- req_opts = {
104
- :method => http_method,
105
- :headers => header_params,
106
- :params => query_params,
107
- :params_encoding => @config.params_encoding,
108
- :timeout => @config.timeout,
109
- :ssl_verifypeer => @config.verify_ssl,
110
- :ssl_verifyhost => _verify_ssl_host,
111
- :sslcert => @config.cert_file,
112
- :sslkey => @config.key_file,
113
- :verbose => @config.debugging
114
- }
115
-
116
- # set custom cert, if provided
117
- req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
118
-
119
- if [:post, :patch, :put, :delete].include?(http_method)
120
- req_body = build_request_body(header_params, form_params, opts[:body])
121
- req_opts.update :body => req_body
122
- if @config.debugging
123
- @config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
124
- end
125
- end
126
-
127
- request = Typhoeus::Request.new(url, req_opts)
128
- download_file(request) if opts[:return_type] == 'File'
129
- request
130
- end
131
-
132
- # Check if the given MIME is a JSON MIME.
133
- # JSON MIME examples:
134
- # application/json
135
- # application/json; charset=UTF8
136
- # APPLICATION/JSON
137
- # */*
138
- # @param [String] mime MIME
139
- # @return [Boolean] True if the MIME is application/json
140
- def json_mime?(mime)
141
- (mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
142
- end
143
-
144
- # Deserialize the response to the given return type.
145
- #
146
- # @param [Response] response HTTP response
147
- # @param [String] return_type some examples: "User", "Array[User]", "Hash[String,Integer]"
148
- def deserialize(response, return_type)
149
- body = response.body
150
-
151
- # handle file downloading - return the File instance processed in request callbacks
152
- # note that response body is empty when the file is written in chunks in request on_body callback
153
- return @tempfile if return_type == 'File'
154
-
155
- return nil if body.nil? || body.empty?
156
-
157
- # return response body directly for String return type
158
- return body if return_type == 'String'
159
-
160
- # ensuring a default content type
161
- content_type = response.headers['Content-Type'] || 'application/json'
162
-
163
- fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
164
-
165
- begin
166
- data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
167
- rescue JSON::ParserError => e
168
- if %w(String Date DateTime).include?(return_type)
169
- data = body
170
- else
171
- raise e
172
- end
173
- end
174
-
175
- convert_to_type data, return_type
176
- end
177
-
178
- # Convert data to the given return type.
179
- # @param [Object] data Data to be converted
180
- # @param [String] return_type Return type
181
- # @return [Mixed] Data in a particular type
182
- def convert_to_type(data, return_type)
183
- return nil if data.nil?
184
- case return_type
185
- when 'String'
186
- data.to_s
187
- when 'Integer'
188
- data.to_i
189
- when 'Float'
190
- data.to_f
191
- when 'BOOLEAN'
192
- data == true
193
- when 'DateTime'
194
- # parse date time (expecting ISO 8601 format)
195
- DateTime.parse data
196
- when 'Date'
197
- # parse date time (expecting ISO 8601 format)
198
- Date.parse data
199
- when 'Object'
200
- # generic object (usually a Hash), return directly
201
- data
202
- when /\AArray<(.+)>\z/
203
- # e.g. Array<Pet>
204
- sub_type = $1
205
- data.map { |item| convert_to_type(item, sub_type) }
206
- when /\AHash\<String, (.+)\>\z/
207
- # e.g. Hash<String, Integer>
208
- sub_type = $1
209
- {}.tap do |hash|
210
- data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
211
- end
212
- else
213
- # models, e.g. Pet
214
- VSphereAutomation.const_get(return_type).new.tap do |model|
215
- model.build_from_hash data
216
- end
217
- end
218
- end
219
-
220
- # Save response body into a file in (the defined) temporary folder, using the filename
221
- # from the "Content-Disposition" header if provided, otherwise a random filename.
222
- # The response body is written to the file in chunks in order to handle files which
223
- # size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
224
- # process can use.
225
- #
226
- # @see Configuration#temp_folder_path
227
- def download_file(request)
228
- tempfile = nil
229
- encoding = nil
230
- request.on_headers do |response|
231
- content_disposition = response.headers['Content-Disposition']
232
- if content_disposition && content_disposition =~ /filename=/i
233
- filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
234
- prefix = sanitize_filename(filename)
235
- else
236
- prefix = 'download-'
237
- end
238
- prefix = prefix + '-' unless prefix.end_with?('-')
239
- encoding = response.body.encoding
240
- tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
241
- @tempfile = tempfile
242
- end
243
- request.on_body do |chunk|
244
- chunk.force_encoding(encoding)
245
- tempfile.write(chunk)
246
- end
247
- request.on_complete do |response|
248
- tempfile.close
249
- @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
250
- "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
251
- "will be deleted automatically with GC. It's also recommended to delete the temp file "\
252
- "explicitly with `tempfile.delete`"
253
- end
254
- end
255
-
256
- # Sanitize filename by removing path.
257
- # e.g. ../../sun.gif becomes sun.gif
258
- #
259
- # @param [String] filename the filename to be sanitized
260
- # @return [String] the sanitized filename
261
- def sanitize_filename(filename)
262
- filename.gsub(/.*[\/\\]/, '')
263
- end
264
-
265
- def build_request_url(path)
266
- # Add leading and trailing slashes to path
267
- path = "/#{path}".gsub(/\/+/, '/')
268
- URI.encode(@config.base_url + path)
269
- end
270
-
271
- # Builds the HTTP request body
272
- #
273
- # @param [Hash] header_params Header parameters
274
- # @param [Hash] form_params Query parameters
275
- # @param [Object] body HTTP body (JSON/XML)
276
- # @return [String] HTTP body data in the form of string
277
- def build_request_body(header_params, form_params, body)
278
- # http form
279
- if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
280
- header_params['Content-Type'] == 'multipart/form-data'
281
- data = {}
282
- form_params.each do |key, value|
283
- case value
284
- when ::File, ::Array, nil
285
- # let typhoeus handle File, Array and nil parameters
286
- data[key] = value
287
- else
288
- data[key] = value.to_s
289
- end
290
- end
291
- elsif body
292
- data = body.is_a?(String) ? body : body.to_json
293
- else
294
- data = nil
295
- end
296
- data
297
- end
298
-
299
- # Update hearder and query params based on authentication settings.
300
- #
301
- # @param [Hash] header_params Header parameters
302
- # @param [Hash] query_params Query parameters
303
- # @param [String] auth_names Authentication scheme name
304
- def update_params_for_auth!(header_params, query_params, auth_names)
305
- Array(auth_names).each do |auth_name|
306
- auth_setting = @config.auth_settings[auth_name]
307
- next unless auth_setting
308
- case auth_setting[:in]
309
- when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
310
- when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
311
- else fail ArgumentError, 'Authentication token must be in `query` of `header`'
312
- end
313
- end
314
- end
315
-
316
- # Sets user agent in HTTP header
317
- #
318
- # @param [String] user_agent User agent (e.g. openapi-generator/ruby/1.0.0)
319
- def user_agent=(user_agent)
320
- @user_agent = user_agent
321
- @default_headers['User-Agent'] = @user_agent
322
- end
323
-
324
- # Return Accept header based on an array of accepts provided.
325
- # @param [Array] accepts array for Accept
326
- # @return [String] the Accept header (e.g. application/json)
327
- def select_header_accept(accepts)
328
- return nil if accepts.nil? || accepts.empty?
329
- # use JSON when present, otherwise use all of the provided
330
- json_accept = accepts.find { |s| json_mime?(s) }
331
- json_accept || accepts.join(',')
332
- end
333
-
334
- # Return Content-Type header based on an array of content types provided.
335
- # @param [Array] content_types array for Content-Type
336
- # @return [String] the Content-Type header (e.g. application/json)
337
- def select_header_content_type(content_types)
338
- # use application/json by default
339
- return 'application/json' if content_types.nil? || content_types.empty?
340
- # use JSON when present, otherwise use the first one
341
- json_content_type = content_types.find { |s| json_mime?(s) }
342
- json_content_type || content_types.first
343
- end
344
-
345
- # Convert object (array, hash, object, etc) to JSON string.
346
- # @param [Object] model object to be converted into JSON string
347
- # @return [String] JSON string representation of the object
348
- def object_to_http_body(model)
349
- return model if model.nil? || model.is_a?(String)
350
- local_body = nil
351
- if model.is_a?(Array)
352
- local_body = model.map { |m| object_to_hash(m) }
353
- else
354
- local_body = object_to_hash(model)
355
- end
356
- local_body.to_json
357
- end
358
-
359
- # Convert object(non-array) to hash.
360
- # @param [Object] obj object to be converted into JSON string
361
- # @return [String] JSON string representation of the object
362
- def object_to_hash(obj)
363
- if obj.respond_to?(:to_hash)
364
- obj.to_hash
365
- else
366
- obj
367
- end
368
- end
369
-
370
- # Build parameter value according to the given collection format.
371
- # @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
372
- def build_collection_param(param, collection_format)
373
- case collection_format
374
- when :csv
375
- param.join(',')
376
- when :ssv
377
- param.join(' ')
378
- when :tsv
379
- param.join("\t")
380
- when :pipes
381
- param.join('|')
382
- when :multi
383
- # return the array directly as typhoeus will handle it as expected
384
- param
385
- else
386
- fail "unknown collection format: #{collection_format.inspect}"
387
- end
388
- end
389
- end
390
- end
@@ -1,34 +0,0 @@
1
- # Copyright (c) 2018-2019 VMware, Inc. All Rights Reserved.
2
- # SPDX-License-Identifier: MIT
3
-
4
- # DO NOT MODIFY. THIS CODE IS GENERATED. CHANGES WILL BE OVERWRITTEN.
5
-
6
- # cis - No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
7
-
8
-
9
- module VSphereAutomation
10
- class ApiError < StandardError
11
- attr_reader :code, :response_headers, :response_body
12
-
13
- # Usage examples:
14
- # ApiError.new
15
- # ApiError.new("message")
16
- # ApiError.new(:code => 500, :response_headers => {}, :response_body => "")
17
- # ApiError.new(:code => 404, :message => "Not Found")
18
- def initialize(arg = nil)
19
- if arg.is_a? Hash
20
- if arg.key?(:message) || arg.key?('message')
21
- super(arg[:message] || arg['message'])
22
- else
23
- super arg
24
- end
25
-
26
- arg.each do |k, v|
27
- instance_variable_set "@#{k}", v
28
- end
29
- else
30
- super arg
31
- end
32
- end
33
- end
34
- end
@@ -1,212 +0,0 @@
1
- # Copyright (c) 2018-2019 VMware, Inc. All Rights Reserved.
2
- # SPDX-License-Identifier: MIT
3
-
4
- # DO NOT MODIFY. THIS CODE IS GENERATED. CHANGES WILL BE OVERWRITTEN.
5
-
6
- # cis - No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
7
-
8
-
9
- require 'uri'
10
-
11
- module VSphereAutomation
12
- class Configuration
13
- # Defines url scheme
14
- attr_accessor :scheme
15
-
16
- # Defines url host
17
- attr_accessor :host
18
-
19
- # Defines url base path
20
- attr_accessor :base_path
21
-
22
- # Defines API keys used with API Key authentications.
23
- #
24
- # @return [Hash] key: parameter name, value: parameter value (API key)
25
- #
26
- # @example parameter name is "api_key", API key is "xxx" (e.g. "api_key=xxx" in query string)
27
- # config.api_key['api_key'] = 'xxx'
28
- attr_accessor :api_key
29
-
30
- # Defines API key prefixes used with API Key authentications.
31
- #
32
- # @return [Hash] key: parameter name, value: API key prefix
33
- #
34
- # @example parameter name is "Authorization", API key prefix is "Token" (e.g. "Authorization: Token xxx" in headers)
35
- # config.api_key_prefix['api_key'] = 'Token'
36
- attr_accessor :api_key_prefix
37
-
38
- # Defines the username used with HTTP basic authentication.
39
- #
40
- # @return [String]
41
- attr_accessor :username
42
-
43
- # Defines the password used with HTTP basic authentication.
44
- #
45
- # @return [String]
46
- attr_accessor :password
47
-
48
- # Defines the access token (Bearer) used with OAuth2.
49
- attr_accessor :access_token
50
-
51
- # Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
52
- # details will be logged with `logger.debug` (see the `logger` attribute).
53
- # Default to false.
54
- #
55
- # @return [true, false]
56
- attr_accessor :debugging
57
-
58
- # Defines the logger used for debugging.
59
- # Default to `Rails.logger` (when in Rails) or logging to STDOUT.
60
- #
61
- # @return [#debug]
62
- attr_accessor :logger
63
-
64
- # Defines the temporary folder to store downloaded files
65
- # (for API endpoints that have file response).
66
- # Default to use `Tempfile`.
67
- #
68
- # @return [String]
69
- attr_accessor :temp_folder_path
70
-
71
- # The time limit for HTTP request in seconds.
72
- # Default to 0 (never times out).
73
- attr_accessor :timeout
74
-
75
- # Set this to false to skip client side validation in the operation.
76
- # Default to true.
77
- # @return [true, false]
78
- attr_accessor :client_side_validation
79
-
80
- ### TLS/SSL setting
81
- # Set this to false to skip verifying SSL certificate when calling API from https server.
82
- # Default to true.
83
- #
84
- # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
85
- #
86
- # @return [true, false]
87
- attr_accessor :verify_ssl
88
-
89
- ### TLS/SSL setting
90
- # Set this to false to skip verifying SSL host name
91
- # Default to true.
92
- #
93
- # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
94
- #
95
- # @return [true, false]
96
- attr_accessor :verify_ssl_host
97
-
98
- ### TLS/SSL setting
99
- # Set this to customize the certificate file to verify the peer.
100
- #
101
- # @return [String] the path to the certificate file
102
- #
103
- # @see The `cainfo` option of Typhoeus, `--cert` option of libcurl. Related source code:
104
- # https://github.com/typhoeus/typhoeus/blob/master/lib/typhoeus/easy_factory.rb#L145
105
- attr_accessor :ssl_ca_cert
106
-
107
- ### TLS/SSL setting
108
- # Client certificate file (for client certificate)
109
- attr_accessor :cert_file
110
-
111
- ### TLS/SSL setting
112
- # Client private key file (for client certificate)
113
- attr_accessor :key_file
114
-
115
- # Set this to customize parameters encoding of array parameter with multi collectionFormat.
116
- # Default to nil.
117
- #
118
- # @see The params_encoding option of Ethon. Related source code:
119
- # https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96
120
- attr_accessor :params_encoding
121
-
122
- attr_accessor :inject_format
123
-
124
- attr_accessor :force_ending_format
125
-
126
- def initialize
127
- @scheme = 'https'
128
- @host = '&lt;vcenter&gt;'
129
- @base_path = '/rest'
130
- @api_key = {}
131
- @api_key_prefix = {}
132
- @timeout = 0
133
- @client_side_validation = true
134
- @verify_ssl = true
135
- @verify_ssl_host = true
136
- @params_encoding = :multi
137
- @cert_file = nil
138
- @key_file = nil
139
- @debugging = false
140
- @inject_format = false
141
- @force_ending_format = false
142
- @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
143
-
144
- yield(self) if block_given?
145
- end
146
-
147
- # The default Configuration object.
148
- def self.default
149
- @@default ||= Configuration.new
150
- end
151
-
152
- def configure
153
- yield(self) if block_given?
154
- end
155
-
156
- def scheme=(scheme)
157
- # remove :// from scheme
158
- @scheme = scheme.sub(/:\/\//, '')
159
- end
160
-
161
- def host=(host)
162
- # remove http(s):// and anything after a slash
163
- @host = host.sub(/https?:\/\//, '').split('/').first
164
- end
165
-
166
- def base_path=(base_path)
167
- # Add leading and trailing slashes to base_path
168
- @base_path = "/#{base_path}".gsub(/\/+/, '/')
169
- @base_path = '' if @base_path == '/'
170
- end
171
-
172
- def base_url
173
- url = "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '')
174
- URI.encode(url)
175
- end
176
-
177
- # Gets API key (with prefix if set).
178
- # @param [String] param_name the parameter name of API key auth
179
- def api_key_with_prefix(param_name)
180
- if @api_key_prefix[param_name]
181
- "#{@api_key_prefix[param_name]} #{@api_key[param_name]}"
182
- else
183
- @api_key[param_name]
184
- end
185
- end
186
-
187
- # Gets Basic Auth token string
188
- def basic_auth_token
189
- 'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
190
- end
191
-
192
- # Returns Auth Settings hash for api client.
193
- def auth_settings
194
- {
195
- 'api_key' =>
196
- {
197
- type: 'api_key',
198
- in: 'header',
199
- key: 'vmware-api-session-id',
200
- value: api_key_with_prefix('vmware-api-session-id')
201
- },
202
- 'basic_auth' =>
203
- {
204
- type: 'basic',
205
- in: 'header',
206
- key: 'Authorization',
207
- value: basic_auth_token
208
- },
209
- }
210
- end
211
- end
212
- end
Binary file
Binary file
@@ -1,222 +0,0 @@
1
- # Copyright (c) 2018-2019 VMware, Inc. All Rights Reserved.
2
- # SPDX-License-Identifier: MIT
3
-
4
- # DO NOT MODIFY. THIS CODE IS GENERATED. CHANGES WILL BE OVERWRITTEN.
5
-
6
- # cis - No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
7
-
8
-
9
- require 'spec_helper'
10
-
11
- describe VSphereAutomation::ApiClient do
12
- context 'initialization' do
13
- context 'URL stuff' do
14
- context 'host' do
15
- it 'removes http from host' do
16
- VSphereAutomation.configure { |c| c.host = 'http://example.com' }
17
- expect(VSphereAutomation::Configuration.default.host).to eq('example.com')
18
- end
19
-
20
- it 'removes https from host' do
21
- VSphereAutomation.configure { |c| c.host = 'https://wookiee.com' }
22
- expect(VSphereAutomation::ApiClient.default.config.host).to eq('wookiee.com')
23
- end
24
-
25
- it 'removes trailing path from host' do
26
- VSphereAutomation.configure { |c| c.host = 'hobo.com/v4' }
27
- expect(VSphereAutomation::Configuration.default.host).to eq('hobo.com')
28
- end
29
- end
30
-
31
- context 'base_path' do
32
- it "prepends a slash to base_path" do
33
- VSphereAutomation.configure { |c| c.base_path = 'v4/dog' }
34
- expect(VSphereAutomation::Configuration.default.base_path).to eq('/v4/dog')
35
- end
36
-
37
- it "doesn't prepend a slash if one is already there" do
38
- VSphereAutomation.configure { |c| c.base_path = '/v4/dog' }
39
- expect(VSphereAutomation::Configuration.default.base_path).to eq('/v4/dog')
40
- end
41
-
42
- it "ends up as a blank string if nil" do
43
- VSphereAutomation.configure { |c| c.base_path = nil }
44
- expect(VSphereAutomation::Configuration.default.base_path).to eq('')
45
- end
46
- end
47
- end
48
- end
49
-
50
- describe 'params_encoding in #build_request' do
51
- let(:config) { VSphereAutomation::Configuration.new }
52
- let(:api_client) { VSphereAutomation::ApiClient.new(config) }
53
-
54
- it 'defaults to nil' do
55
- expect(VSphereAutomation::Configuration.default.params_encoding).to eq(nil)
56
- expect(config.params_encoding).to eq(nil)
57
-
58
- request = api_client.build_request(:get, '/test')
59
- expect(request.options[:params_encoding]).to eq(nil)
60
- end
61
-
62
- it 'can be customized' do
63
- config.params_encoding = :multi
64
- request = api_client.build_request(:get, '/test')
65
- expect(request.options[:params_encoding]).to eq(:multi)
66
- end
67
- end
68
-
69
- describe 'timeout in #build_request' do
70
- let(:config) { VSphereAutomation::Configuration.new }
71
- let(:api_client) { VSphereAutomation::ApiClient.new(config) }
72
-
73
- it 'defaults to 0' do
74
- expect(VSphereAutomation::Configuration.default.timeout).to eq(0)
75
- expect(config.timeout).to eq(0)
76
-
77
- request = api_client.build_request(:get, '/test')
78
- expect(request.options[:timeout]).to eq(0)
79
- end
80
-
81
- it 'can be customized' do
82
- config.timeout = 100
83
- request = api_client.build_request(:get, '/test')
84
- expect(request.options[:timeout]).to eq(100)
85
- end
86
- end
87
-
88
- describe '#deserialize' do
89
- it "handles Array<Integer>" do
90
- api_client = VSphereAutomation::ApiClient.new
91
- headers = { 'Content-Type' => 'application/json' }
92
- response = double('response', headers: headers, body: '[12, 34]')
93
- data = api_client.deserialize(response, 'Array<Integer>')
94
- expect(data).to be_instance_of(Array)
95
- expect(data).to eq([12, 34])
96
- end
97
-
98
- it 'handles Array<Array<Integer>>' do
99
- api_client = VSphereAutomation::ApiClient.new
100
- headers = { 'Content-Type' => 'application/json' }
101
- response = double('response', headers: headers, body: '[[12, 34], [56]]')
102
- data = api_client.deserialize(response, 'Array<Array<Integer>>')
103
- expect(data).to be_instance_of(Array)
104
- expect(data).to eq([[12, 34], [56]])
105
- end
106
-
107
- it 'handles Hash<String, String>' do
108
- api_client = VSphereAutomation::ApiClient.new
109
- headers = { 'Content-Type' => 'application/json' }
110
- response = double('response', headers: headers, body: '{"message": "Hello"}')
111
- data = api_client.deserialize(response, 'Hash<String, String>')
112
- expect(data).to be_instance_of(Hash)
113
- expect(data).to eq(:message => 'Hello')
114
- end
115
- end
116
-
117
- describe "#object_to_hash" do
118
- it 'ignores nils and includes empty arrays' do
119
- # uncomment below to test object_to_hash for model
120
- # api_client = VSphereAutomation::ApiClient.new
121
- # _model = VSphereAutomation::ModelName.new
122
- # update the model attribute below
123
- # _model.id = 1
124
- # update the expected value (hash) below
125
- # expected = {id: 1, name: '', tags: []}
126
- # expect(api_client.object_to_hash(_model)).to eq(expected)
127
- end
128
- end
129
-
130
- describe '#build_collection_param' do
131
- let(:param) { ['aa', 'bb', 'cc'] }
132
- let(:api_client) { VSphereAutomation::ApiClient.new }
133
-
134
- it 'works for csv' do
135
- expect(api_client.build_collection_param(param, :csv)).to eq('aa,bb,cc')
136
- end
137
-
138
- it 'works for ssv' do
139
- expect(api_client.build_collection_param(param, :ssv)).to eq('aa bb cc')
140
- end
141
-
142
- it 'works for tsv' do
143
- expect(api_client.build_collection_param(param, :tsv)).to eq("aa\tbb\tcc")
144
- end
145
-
146
- it 'works for pipes' do
147
- expect(api_client.build_collection_param(param, :pipes)).to eq('aa|bb|cc')
148
- end
149
-
150
- it 'works for multi' do
151
- expect(api_client.build_collection_param(param, :multi)).to eq(['aa', 'bb', 'cc'])
152
- end
153
-
154
- it 'fails for invalid collection format' do
155
- expect(proc { api_client.build_collection_param(param, :INVALID) }).to raise_error(RuntimeError, 'unknown collection format: :INVALID')
156
- end
157
- end
158
-
159
- describe '#json_mime?' do
160
- let(:api_client) { VSphereAutomation::ApiClient.new }
161
-
162
- it 'works' do
163
- expect(api_client.json_mime?(nil)).to eq false
164
- expect(api_client.json_mime?('')).to eq false
165
-
166
- expect(api_client.json_mime?('application/json')).to eq true
167
- expect(api_client.json_mime?('application/json; charset=UTF8')).to eq true
168
- expect(api_client.json_mime?('APPLICATION/JSON')).to eq true
169
-
170
- expect(api_client.json_mime?('application/xml')).to eq false
171
- expect(api_client.json_mime?('text/plain')).to eq false
172
- expect(api_client.json_mime?('application/jsonp')).to eq false
173
- end
174
- end
175
-
176
- describe '#select_header_accept' do
177
- let(:api_client) { VSphereAutomation::ApiClient.new }
178
-
179
- it 'works' do
180
- expect(api_client.select_header_accept(nil)).to be_nil
181
- expect(api_client.select_header_accept([])).to be_nil
182
-
183
- expect(api_client.select_header_accept(['application/json'])).to eq('application/json')
184
- expect(api_client.select_header_accept(['application/xml', 'application/json; charset=UTF8'])).to eq('application/json; charset=UTF8')
185
- expect(api_client.select_header_accept(['APPLICATION/JSON', 'text/html'])).to eq('APPLICATION/JSON')
186
-
187
- expect(api_client.select_header_accept(['application/xml'])).to eq('application/xml')
188
- expect(api_client.select_header_accept(['text/html', 'application/xml'])).to eq('text/html,application/xml')
189
- end
190
- end
191
-
192
- describe '#select_header_content_type' do
193
- let(:api_client) { VSphereAutomation::ApiClient.new }
194
-
195
- it 'works' do
196
- expect(api_client.select_header_content_type(nil)).to eq('application/json')
197
- expect(api_client.select_header_content_type([])).to eq('application/json')
198
-
199
- expect(api_client.select_header_content_type(['application/json'])).to eq('application/json')
200
- expect(api_client.select_header_content_type(['application/xml', 'application/json; charset=UTF8'])).to eq('application/json; charset=UTF8')
201
- expect(api_client.select_header_content_type(['APPLICATION/JSON', 'text/html'])).to eq('APPLICATION/JSON')
202
- expect(api_client.select_header_content_type(['application/xml'])).to eq('application/xml')
203
- expect(api_client.select_header_content_type(['text/plain', 'application/xml'])).to eq('text/plain')
204
- end
205
- end
206
-
207
- describe '#sanitize_filename' do
208
- let(:api_client) { VSphereAutomation::ApiClient.new }
209
-
210
- it 'works' do
211
- expect(api_client.sanitize_filename('sun')).to eq('sun')
212
- expect(api_client.sanitize_filename('sun.gif')).to eq('sun.gif')
213
- expect(api_client.sanitize_filename('../sun.gif')).to eq('sun.gif')
214
- expect(api_client.sanitize_filename('/var/tmp/sun.gif')).to eq('sun.gif')
215
- expect(api_client.sanitize_filename('./sun.gif')).to eq('sun.gif')
216
- expect(api_client.sanitize_filename('..\sun.gif')).to eq('sun.gif')
217
- expect(api_client.sanitize_filename('\var\tmp\sun.gif')).to eq('sun.gif')
218
- expect(api_client.sanitize_filename('c:\var\tmp\sun.gif')).to eq('sun.gif')
219
- expect(api_client.sanitize_filename('.\sun.gif')).to eq('sun.gif')
220
- end
221
- end
222
- end
@@ -1,38 +0,0 @@
1
- # Copyright (c) 2018-2019 VMware, Inc. All Rights Reserved.
2
- # SPDX-License-Identifier: MIT
3
-
4
- # DO NOT MODIFY. THIS CODE IS GENERATED. CHANGES WILL BE OVERWRITTEN.
5
-
6
- # cis - No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
7
-
8
-
9
- require 'spec_helper'
10
-
11
- describe VSphereAutomation::Configuration do
12
- let(:config) { VSphereAutomation::Configuration.default }
13
-
14
- before(:each) do
15
- # uncomment below to setup host and base_path
16
- # require 'URI'
17
- # uri = URI.parse("https://<vcenter>/rest")
18
- # VSphereAutomation.configure do |c|
19
- # c.host = uri.host
20
- # c.base_path = uri.path
21
- # end
22
- end
23
-
24
- describe '#base_url' do
25
- it 'should have the default value' do
26
- # uncomment below to test default value of the base path
27
- # expect(config.base_url).to eq("https://<vcenter>/rest")
28
- end
29
-
30
- it 'should remove trailing slashes' do
31
- [nil, '', '/', '//'].each do |base_path|
32
- config.base_path = base_path
33
- # uncomment below to test trailing slashes
34
- # expect(config.base_url).to eq("https://<vcenter>/rest")
35
- end
36
- end
37
- end
38
- end