vsphere-automation-content 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: e98366bb020ae8ec5bd039b37a95823347ce7dd315e330dd453984fc5850a45f
4
- data.tar.gz: 06f0ff2aeb603145065048bc929ce0b19455dfdcb2b14d3b8f9043e591463a50
3
+ metadata.gz: 78f6b35831e4eb59d6a72b98a44cfe39a9da8e1516d4a83aca215703449d363d
4
+ data.tar.gz: 9ccefaa1e93441875e02b92e0a2e40c41ecceadb6a55734b9e6703cb1e59507f
5
5
  SHA512:
6
- metadata.gz: 659e3294f30e95bc60814879b1ca5b08020d59cd0bd6b20fc64192b2f4f01a793264ed02ada6c5a062ce6ff83a1961e7b590d01c842dca118bb9ebece238d609
7
- data.tar.gz: 88d5db50ea3f3d4ead2c289cd3db9d0430f3292cfe564b2d1b7da7f06c026483872ed0c5261bea20145611673e875adc2c2198dcebfd09fd8280a82340752ef9
6
+ metadata.gz: 37a9fda73fbc2f33fe22cb36fbb44655afddf9cd1917493ce02bc561bd47bd7e6a090c16b5b4dc0b5f5f09cfdc5386564e6ed63e98e2d18fec0e9607f84035a0
7
+ data.tar.gz: 19a8bf09d00606e2b3c2171394b4fadab8b833594fc334678f5c2a50947079039248fc18bac4eb1d4c8691f548da2c8487a57d0bad7128a93209eabb89b91940
data/Gemfile.lock CHANGED
@@ -1,45 +1,41 @@
1
1
  PATH
2
2
  remote: ../cis
3
3
  specs:
4
- vsphere-automation-cis (0.3.0)
5
- vsphere-automation-runtime (~> 0.3.0)
4
+ vsphere-automation-cis (0.4.0)
5
+ vsphere-automation-runtime (~> 0.4.0)
6
6
 
7
7
  PATH
8
8
  remote: ../runtime
9
9
  specs:
10
- vsphere-automation-runtime (0.3.0)
11
- typhoeus (~> 1.3)
10
+ vsphere-automation-runtime (0.4.0)
12
11
 
13
12
  PATH
14
13
  remote: .
15
14
  specs:
16
- vsphere-automation-content (0.3.0)
17
- vsphere-automation-cis (~> 0.3.0)
18
- vsphere-automation-runtime (~> 0.3.0)
15
+ vsphere-automation-content (0.4.0)
16
+ vsphere-automation-cis (~> 0.4.0)
17
+ vsphere-automation-runtime (~> 0.4.0)
19
18
 
20
19
  GEM
21
20
  remote: https://rubygems.org/
22
21
  specs:
23
- addressable (2.6.0)
24
- public_suffix (>= 2.0.2, < 4.0)
22
+ addressable (2.7.0)
23
+ public_suffix (>= 2.0.2, < 5.0)
25
24
  ast (2.4.0)
26
25
  coderay (1.1.2)
27
26
  crack (0.4.3)
28
27
  safe_yaml (~> 1.0.0)
29
28
  diff-lcs (1.3)
30
- ethon (0.12.0)
31
- ffi (>= 1.3.0)
32
- ffi (1.11.1)
33
29
  hashdiff (1.0.0)
34
30
  jaro_winkler (1.5.3)
35
31
  method_source (0.9.2)
36
32
  parallel (1.17.0)
37
- parser (2.6.3.0)
33
+ parser (2.6.4.0)
38
34
  ast (~> 2.4.0)
39
35
  pry (0.12.2)
40
36
  coderay (~> 1.1.0)
41
37
  method_source (~> 0.9.0)
42
- public_suffix (3.1.1)
38
+ public_suffix (4.0.1)
43
39
  rainbow (3.0.0)
44
40
  rake (12.3.3)
45
41
  rspec (3.8.0)
@@ -64,11 +60,9 @@ GEM
64
60
  unicode-display_width (>= 1.4.0, < 1.7)
65
61
  ruby-progressbar (1.10.1)
66
62
  safe_yaml (1.0.5)
67
- typhoeus (1.3.1)
68
- ethon (>= 0.9.0)
69
63
  unicode-display_width (1.6.0)
70
64
  vcr (5.0.0)
71
- webmock (3.6.2)
65
+ webmock (3.7.2)
72
66
  addressable (>= 2.3.6)
73
67
  crack (>= 0.3.2)
74
68
  hashdiff (>= 0.4.0, < 2.0.0)
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  The Ruby gem for the vSphere Content 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 Content
11
- VERSION = '0.3.0'
11
+ VERSION = '0.4.0'
12
12
  end
13
13
  end
@@ -30,7 +30,6 @@ describe 'ConfigurationApi' do
30
30
 
31
31
  # unit tests for get
32
32
  # Retrieves the current configuration values.
33
- # @param action ~action&#x3D;get
34
33
  # @param [Hash] opts the optional parameters
35
34
  # @return [ContentConfigurationResult]
36
35
  describe 'get test' do
@@ -30,7 +30,6 @@ describe 'LibraryApi' do
30
30
 
31
31
  # unit tests for find
32
32
  # Returns a list of all the visible (as determined by authorization policy) libraries matching the requested {@link Library.FindSpec}.
33
- # @param action ~action&#x3D;find
34
33
  # @param request_body
35
34
  # @param [Hash] opts the optional parameters
36
35
  # @return [ContentLibraryFindResult]
@@ -31,7 +31,6 @@ describe 'LibraryItemApi' do
31
31
  # unit tests for copy
32
32
  # Copies a library item. &lt;p&gt; Copying a library item allows a duplicate to be made within the same or different library. The copy occurs by first creating a new library item, whose identifier is returned. The content of the library item is then copied asynchronously. This copy can be tracked as a task. &lt;p&gt; If the copy fails, Content Library Service will roll back the copy by deleting any content that was already copied, and removing the new library item. A failure during rollback may require manual cleanup by an administrator. &lt;p&gt; A library item cannot be copied into a subscribed library.
33
33
  # @param source_library_item_id Identifier of the existing library item from which the content will be copied.
34
- # @param action ~action&#x3D;copy
35
34
  # @param request_body
36
35
  # @param [Hash] opts the optional parameters
37
36
  # @return [ContentLibraryItemCopyResult]
@@ -99,7 +98,6 @@ describe 'LibraryItemApi' do
99
98
  # unit tests for publish
100
99
  # Publishes the library item to specified subscriptions of the library. If no subscriptions are specified, then publishes the library item to all subscriptions of the library.
101
100
  # @param library_item_id Library item identifier.
102
- # @param action ~action&#x3D;publish
103
101
  # @param request_body
104
102
  # @param [Hash] opts the optional parameters
105
103
  # @return [nil]
@@ -64,7 +64,6 @@ describe 'LibraryItemDownloadSessionApi' do
64
64
  # unit tests for fail
65
65
  # Terminates the download session with a client specified error message. &lt;p&gt; This is useful in transmitting client side failures (for example, not being able to download a file) to the server side.
66
66
  # @param download_session_id Identifier of the download session to fail.
67
- # @param action ~action&#x3D;fail
68
67
  # @param request_body
69
68
  # @param [Hash] opts the optional parameters
70
69
  # @return [nil]
@@ -54,7 +54,6 @@ describe 'LibraryItemDownloadsessionFileApi' do
54
54
  # unit tests for prepare
55
55
  # Requests a file to be prepared for download.
56
56
  # @param download_session_id Identifier of the download session.
57
- # @param action ~action&#x3D;prepare
58
57
  # @param request_body
59
58
  # @param [Hash] opts the optional parameters
60
59
  # @return [ContentLibraryItemDownloadsessionFilePrepareResult]
@@ -31,7 +31,6 @@ describe 'LibraryItemFileApi' do
31
31
  # unit tests for get
32
32
  # Retrieves the information for a single file in a library item by its name.
33
33
  # @param library_item_id Identifier of the library item whose file information should be returned.
34
- # @param action ~action&#x3D;get
35
34
  # @param request_body
36
35
  # @param [Hash] opts the optional parameters
37
36
  # @return [ContentLibraryItemFileResult]
@@ -31,7 +31,6 @@ describe 'LibraryItemStorageApi' do
31
31
  # unit tests for get
32
32
  # Retrieves the storage information for a specific file in a library item.
33
33
  # @param library_item_id Identifier of the library item whose storage information should be retrieved.
34
- # @param action ~action&#x3D;get
35
34
  # @param request_body
36
35
  # @param [Hash] opts the optional parameters
37
36
  # @return [ContentLibraryItemStorageResult]
@@ -42,7 +42,6 @@ describe 'LibraryItemUpdateSessionApi' do
42
42
  # unit tests for complete
43
43
  # Completes the update session. This indicates that the client has finished making all the changes required to the underlying library item. If the client is pushing the content to the server, the library item will be updated once this call returns. If the server is pulling the content, the call may return before the changes become visible. In that case, the client can track the session to know when the server is done. &lt;p&gt; This {@term operation} requires the session to be in the {@link UpdateSessionModel.State#ACTIVE} state. &lt;p&gt; Depending on the type of the library item associated with this session, a type adapter may be invoked to verify the validity of the files uploaded. The user can explicitly validate the session before completing the session by using the {@link content.library.item.updatesession.File#validate} {@term operation}. &lt;p&gt; Modifications are not visible to other clients unless the session is completed and all necessary files have been received.
44
44
  # @param update_session_id Identifier of the update session that should be completed.
45
- # @param action ~action&#x3D;complete
46
45
  # @param [Hash] opts the optional parameters
47
46
  # @return [nil]
48
47
  describe 'complete test' do
@@ -31,7 +31,6 @@ describe 'LibraryItemUpdatesessionFileApi' do
31
31
  # unit tests for add
32
32
  # Requests file content to be changed (either created, or updated). Depending on the source type of the file, this {@term operation} will either return an upload endpoint where the client can push the content, or the server will pull from the provided source endpoint. If a file with the same name already exists in this session, this {@term operation} will be used to update the content of the existing file. &lt;p&gt; When importing a file directly from storage, where the source endpoint is a file or datastore URI, you will need to have the ContentLibrary.ReadStorage privilege on the library item. If the file is located in the same directory as the library storage backing folder, the server will move the file instead of copying it, thereby allowing instantaneous import of files for efficient backup and restore scenarios. In all other cases, a copy is performed rather than a move.
33
33
  # @param update_session_id Identifier of the update session to be modified.
34
- # @param action ~action&#x3D;add
35
34
  # @param request_body
36
35
  # @param [Hash] opts the optional parameters
37
36
  # @return [ContentLibraryItemUpdatesessionFileAddResult]
@@ -31,7 +31,6 @@ describe 'LibrarySubscribedItemApi' do
31
31
  # unit tests for evict
32
32
  # Evicts the cached content of a library item in a subscribed library. &lt;p&gt; This {@term operation} allows the cached content of a library item to be removed to free up storage capacity. This {@term operation} will only work when a library item is synchronized on-demand. When a library is not synchronized on-demand, it always attempts to keep its cache up-to-date with the published source. Evicting the library item will set {@link ItemModel#cached} to false.
33
33
  # @param library_item_id Identifier of the library item whose content should be evicted.
34
- # @param action ~action&#x3D;evict
35
34
  # @param [Hash] opts the optional parameters
36
35
  # @return [nil]
37
36
  describe 'evict test' do
@@ -74,7 +74,6 @@ describe 'LocalLibraryApi' do
74
74
  # unit tests for publish
75
75
  # Publishes the library to specified subscriptions. If no subscriptions are specified, then publishes the library to all its subscriptions.
76
76
  # @param library_id Identifier of the published library.
77
- # @param action ~action&#x3D;publish
78
77
  # @param [Hash] opts the optional parameters
79
78
  # @option opts [ContentLocalLibraryPublish] :request_body
80
79
  # @return [nil]
@@ -96,7 +96,6 @@ describe 'SubscribedLibraryApi' do
96
96
  # unit tests for sync
97
97
  # Forces the synchronization of the subscribed library. &lt;p&gt; Synchronizing a subscribed library forcefully with this {@term operation} will perform the same synchronization behavior as would run periodically for the library. The {@link SubscriptionInfo#onDemand} setting is respected. Calling this {@term operation} on a library that is already in the process of synchronizing will have no effect.
98
98
  # @param library_id Identifier of the subscribed library to synchronize.
99
- # @param action ~action&#x3D;sync
100
99
  # @param [Hash] opts the optional parameters
101
100
  # @return [nil]
102
101
  describe 'sync test' do
data/spec/spec_helper.rb CHANGED
@@ -8,6 +8,9 @@
8
8
 
9
9
  # load the gem
10
10
  require 'vsphere-automation-content'
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,9 +22,8 @@ Gem::Specification.new do |s|
22
22
  s.description = "A Ruby SDK for the vSphere APIs (Content)"
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'
27
- s.add_runtime_dependency 'vsphere-automation-cis', '~> 0.3.0'
25
+ s.add_runtime_dependency 'vsphere-automation-runtime', '~> 0.4.0'
26
+ s.add_runtime_dependency 'vsphere-automation-cis', '~> 0.4.0'
28
27
 
29
28
  s.add_development_dependency 'bundler', '~> 2.0'
30
29
  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-content
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,28 +16,28 @@ 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: vsphere-automation-cis
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.3.0
33
+ version: 0.4.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: 0.3.0
40
+ version: 0.4.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -326,9 +326,6 @@ files:
326
326
  - lib/vsphere-automation-content/api/library_subscriptions_api.rb
327
327
  - lib/vsphere-automation-content/api/local_library_api.rb
328
328
  - lib/vsphere-automation-content/api/subscribed_library_api.rb
329
- - lib/vsphere-automation-content/api_client.rb
330
- - lib/vsphere-automation-content/api_error.rb
331
- - lib/vsphere-automation-content/configuration.rb
332
329
  - lib/vsphere-automation-content/models/content_configuration_model.rb
333
330
  - lib/vsphere-automation-content/models/content_configuration_result.rb
334
331
  - lib/vsphere-automation-content/models/content_configuration_update.rb
@@ -481,8 +478,7 @@ files:
481
478
  - lib/vsphere-automation-content/models/vapi_std_errors_unsupported_error.rb
482
479
  - lib/vsphere-automation-content/models/vapi_std_localizable_message.rb
483
480
  - lib/vsphere-automation-content/version.rb
484
- - pkg/vsphere-automation-content-0.2.1.gem
485
- - pkg/vsphere-automation-content-0.2.2.gem
481
+ - pkg/vsphere-automation-content-0.4.0.gem
486
482
  - spec/api/configuration_api_spec.rb
487
483
  - spec/api/library_api_spec.rb
488
484
  - spec/api/library_item_api_spec.rb
@@ -496,8 +492,6 @@ files:
496
492
  - spec/api/library_subscriptions_api_spec.rb
497
493
  - spec/api/local_library_api_spec.rb
498
494
  - spec/api/subscribed_library_api_spec.rb
499
- - spec/api_client_spec.rb
500
- - spec/configuration_spec.rb
501
495
  - spec/models/content_configuration_model_spec.rb
502
496
  - spec/models/content_configuration_result_spec.rb
503
497
  - spec/models/content_configuration_update_spec.rb
@@ -688,8 +682,6 @@ test_files:
688
682
  - spec/api/library_item_file_api_spec.rb
689
683
  - spec/api/library_item_download_session_api_spec.rb
690
684
  - spec/api/library_item_downloadsession_file_api_spec.rb
691
- - spec/api_client_spec.rb
692
- - spec/configuration_spec.rb
693
685
  - spec/models/content_library_item_file_list_result_spec.rb
694
686
  - spec/models/content_library_find_result_spec.rb
695
687
  - spec/models/content_library_item_downloadsession_file_list_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
- # content - VMware vSphere® Content Library empowers vSphere Admins to effectively manage VM templates, vApps, ISO images and scripts with ease.
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
- # content - VMware vSphere® Content Library empowers vSphere Admins to effectively manage VM templates, vApps, ISO images and scripts with ease.
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
- # content - VMware vSphere® Content Library empowers vSphere Admins to effectively manage VM templates, vApps, ISO images and scripts with ease.
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
@@ -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
- # content - VMware vSphere® Content Library empowers vSphere Admins to effectively manage VM templates, vApps, ISO images and scripts with ease.
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
- # content - VMware vSphere® Content Library empowers vSphere Admins to effectively manage VM templates, vApps, ISO images and scripts with ease.
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