pulp_file_client 3.69.2 → 3.70.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (154) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +10 -7
  3. data/docs/AcsFileApi.md +343 -157
  4. data/docs/AsyncOperationResponse.md +8 -7
  5. data/docs/ContentFilesApi.md +114 -64
  6. data/docs/ContentSummaryResponse.md +12 -11
  7. data/docs/DistributionsFileApi.md +385 -182
  8. data/docs/FileFileAlternateContentSource.md +14 -13
  9. data/docs/FileFileAlternateContentSourceResponse.md +22 -21
  10. data/docs/FileFileContentResponse.md +30 -29
  11. data/docs/FileFileDistribution.md +20 -19
  12. data/docs/FileFileDistributionResponse.md +32 -31
  13. data/docs/FileFilePublication.md +12 -11
  14. data/docs/FileFilePublicationResponse.md +22 -21
  15. data/docs/FileFileRemote.md +48 -47
  16. data/docs/FileFileRemoteResponse.md +48 -47
  17. data/docs/FileFileRemoteResponseHiddenFieldsInner.md +20 -0
  18. data/docs/FileFileRepository.md +20 -19
  19. data/docs/FileFileRepositoryResponse.md +32 -31
  20. data/docs/MyPermissionsResponse.md +8 -7
  21. data/docs/NestedRole.md +12 -11
  22. data/docs/NestedRoleResponse.md +12 -11
  23. data/docs/ObjectRolesResponse.md +8 -7
  24. data/docs/PaginatedRepositoryVersionResponseList.md +14 -13
  25. data/docs/PaginatedfileFileAlternateContentSourceResponseList.md +14 -13
  26. data/docs/PaginatedfileFileContentResponseList.md +14 -13
  27. data/docs/PaginatedfileFileDistributionResponseList.md +14 -13
  28. data/docs/PaginatedfileFilePublicationResponseList.md +14 -13
  29. data/docs/PaginatedfileFileRemoteResponseList.md +14 -13
  30. data/docs/PaginatedfileFileRepositoryResponseList.md +14 -13
  31. data/docs/PatchedfileFileAlternateContentSource.md +14 -13
  32. data/docs/PatchedfileFileDistribution.md +20 -19
  33. data/docs/PatchedfileFileRemote.md +48 -47
  34. data/docs/PatchedfileFileRepository.md +20 -19
  35. data/docs/PolicyEnum.md +4 -5
  36. data/docs/PublicationsFileApi.md +267 -130
  37. data/docs/RemotesFileApi.md +389 -184
  38. data/docs/Repair.md +8 -7
  39. data/docs/RepositoriesFileApi.md +444 -207
  40. data/docs/RepositoriesFileVersionsApi.md +152 -82
  41. data/docs/RepositoryAddRemoveContent.md +12 -11
  42. data/docs/RepositorySyncURL.md +10 -9
  43. data/docs/RepositoryVersionResponse.md +22 -21
  44. data/docs/SetLabel.md +10 -9
  45. data/docs/SetLabelResponse.md +10 -9
  46. data/docs/TaskGroupOperationResponse.md +8 -7
  47. data/docs/UnsetLabel.md +8 -7
  48. data/docs/UnsetLabelResponse.md +10 -9
  49. data/lib/pulp_file_client/api/acs_file_api.rb +76 -50
  50. data/lib/pulp_file_client/api/content_files_api.rb +20 -14
  51. data/lib/pulp_file_client/api/distributions_file_api.rb +89 -56
  52. data/lib/pulp_file_client/api/publications_file_api.rb +67 -47
  53. data/lib/pulp_file_client/api/remotes_file_api.rb +104 -68
  54. data/lib/pulp_file_client/api/repositories_file_api.rb +107 -66
  55. data/lib/pulp_file_client/api/repositories_file_versions_api.rb +40 -30
  56. data/lib/pulp_file_client/api_client.rb +137 -102
  57. data/lib/pulp_file_client/api_error.rb +2 -1
  58. data/lib/pulp_file_client/configuration.rb +162 -21
  59. data/lib/pulp_file_client/models/async_operation_response.rb +32 -22
  60. data/lib/pulp_file_client/models/content_summary_response.rb +36 -22
  61. data/lib/pulp_file_client/models/file_file_alternate_content_source.rb +35 -23
  62. data/lib/pulp_file_client/models/file_file_alternate_content_source_response.rb +37 -25
  63. data/lib/pulp_file_client/models/file_file_content_response.rb +34 -24
  64. data/lib/pulp_file_client/models/file_file_distribution.rb +34 -22
  65. data/lib/pulp_file_client/models/file_file_distribution_response.rb +36 -24
  66. data/lib/pulp_file_client/models/file_file_publication.rb +30 -22
  67. data/lib/pulp_file_client/models/file_file_publication_response.rb +32 -24
  68. data/lib/pulp_file_client/models/file_file_remote.rb +56 -22
  69. data/lib/pulp_file_client/models/file_file_remote_response.rb +59 -25
  70. data/lib/pulp_file_client/models/{file_file_remote_response_hidden_fields.rb → file_file_remote_response_hidden_fields_inner.rb} +37 -25
  71. data/lib/pulp_file_client/models/file_file_repository.rb +32 -22
  72. data/lib/pulp_file_client/models/file_file_repository_response.rb +34 -24
  73. data/lib/pulp_file_client/models/my_permissions_response.rb +32 -22
  74. data/lib/pulp_file_client/models/nested_role.rb +32 -22
  75. data/lib/pulp_file_client/models/nested_role_response.rb +32 -22
  76. data/lib/pulp_file_client/models/object_roles_response.rb +32 -22
  77. data/lib/pulp_file_client/models/paginated_repository_version_response_list.rb +34 -22
  78. data/lib/pulp_file_client/models/paginatedfile_file_alternate_content_source_response_list.rb +34 -22
  79. data/lib/pulp_file_client/models/paginatedfile_file_content_response_list.rb +34 -22
  80. data/lib/pulp_file_client/models/paginatedfile_file_distribution_response_list.rb +34 -22
  81. data/lib/pulp_file_client/models/paginatedfile_file_publication_response_list.rb +34 -22
  82. data/lib/pulp_file_client/models/paginatedfile_file_remote_response_list.rb +34 -22
  83. data/lib/pulp_file_client/models/paginatedfile_file_repository_response_list.rb +34 -22
  84. data/lib/pulp_file_client/models/patchedfile_file_alternate_content_source.rb +36 -24
  85. data/lib/pulp_file_client/models/patchedfile_file_distribution.rb +40 -24
  86. data/lib/pulp_file_client/models/patchedfile_file_remote.rb +62 -24
  87. data/lib/pulp_file_client/models/patchedfile_file_repository.rb +35 -23
  88. data/lib/pulp_file_client/models/policy_enum.rb +8 -4
  89. data/lib/pulp_file_client/models/repair.rb +30 -22
  90. data/lib/pulp_file_client/models/repository_add_remove_content.rb +30 -22
  91. data/lib/pulp_file_client/models/repository_sync_url.rb +30 -22
  92. data/lib/pulp_file_client/models/repository_version_response.rb +32 -24
  93. data/lib/pulp_file_client/models/set_label.rb +34 -22
  94. data/lib/pulp_file_client/models/set_label_response.rb +34 -22
  95. data/lib/pulp_file_client/models/task_group_operation_response.rb +32 -22
  96. data/lib/pulp_file_client/models/unset_label.rb +32 -22
  97. data/lib/pulp_file_client/models/unset_label_response.rb +32 -22
  98. data/lib/pulp_file_client/version.rb +2 -2
  99. data/lib/pulp_file_client.rb +2 -3
  100. data/pulp_file_client.gemspec +9 -6
  101. data/spec/api/acs_file_api_spec.rb +12 -12
  102. data/spec/api/content_files_api_spec.rb +4 -4
  103. data/spec/api/distributions_file_api_spec.rb +13 -13
  104. data/spec/api/publications_file_api_spec.rb +16 -15
  105. data/spec/api/remotes_file_api_spec.rb +20 -19
  106. data/spec/api/repositories_file_api_spec.rb +15 -15
  107. data/spec/api/repositories_file_versions_api_spec.rb +12 -11
  108. data/spec/models/async_operation_response_spec.rb +7 -12
  109. data/spec/models/content_summary_response_spec.rb +9 -14
  110. data/spec/models/file_file_alternate_content_source_response_spec.rb +14 -19
  111. data/spec/models/file_file_alternate_content_source_spec.rb +10 -15
  112. data/spec/models/file_file_content_response_spec.rb +18 -23
  113. data/spec/models/file_file_distribution_response_spec.rb +19 -24
  114. data/spec/models/file_file_distribution_spec.rb +13 -18
  115. data/spec/models/file_file_publication_response_spec.rb +14 -19
  116. data/spec/models/file_file_publication_spec.rb +9 -14
  117. data/spec/models/{file_file_remote_response_hidden_fields_spec.rb → file_file_remote_response_hidden_fields_inner_spec.rb} +11 -16
  118. data/spec/models/file_file_remote_response_spec.rb +27 -32
  119. data/spec/models/file_file_remote_spec.rb +27 -32
  120. data/spec/models/file_file_repository_response_spec.rb +19 -24
  121. data/spec/models/file_file_repository_spec.rb +13 -18
  122. data/spec/models/my_permissions_response_spec.rb +7 -12
  123. data/spec/models/nested_role_response_spec.rb +9 -14
  124. data/spec/models/nested_role_spec.rb +9 -14
  125. data/spec/models/object_roles_response_spec.rb +7 -12
  126. data/spec/models/paginated_repository_version_response_list_spec.rb +10 -15
  127. data/spec/models/paginatedfile_file_alternate_content_source_response_list_spec.rb +10 -15
  128. data/spec/models/paginatedfile_file_content_response_list_spec.rb +10 -15
  129. data/spec/models/paginatedfile_file_distribution_response_list_spec.rb +10 -15
  130. data/spec/models/paginatedfile_file_publication_response_list_spec.rb +10 -15
  131. data/spec/models/paginatedfile_file_remote_response_list_spec.rb +10 -15
  132. data/spec/models/paginatedfile_file_repository_response_list_spec.rb +10 -15
  133. data/spec/models/patchedfile_file_alternate_content_source_spec.rb +10 -15
  134. data/spec/models/patchedfile_file_distribution_spec.rb +13 -18
  135. data/spec/models/patchedfile_file_remote_spec.rb +27 -32
  136. data/spec/models/patchedfile_file_repository_spec.rb +13 -18
  137. data/spec/models/policy_enum_spec.rb +6 -11
  138. data/spec/models/repair_spec.rb +7 -12
  139. data/spec/models/repository_add_remove_content_spec.rb +9 -14
  140. data/spec/models/repository_sync_url_spec.rb +8 -13
  141. data/spec/models/repository_version_response_spec.rb +14 -19
  142. data/spec/models/set_label_response_spec.rb +8 -13
  143. data/spec/models/set_label_spec.rb +8 -13
  144. data/spec/models/task_group_operation_response_spec.rb +7 -12
  145. data/spec/models/unset_label_response_spec.rb +8 -13
  146. data/spec/models/unset_label_spec.rb +7 -12
  147. data/spec/spec_helper.rb +1 -1
  148. metadata +45 -25
  149. data/docs/FileFileContent.md +0 -27
  150. data/docs/FileFileRemoteResponseHiddenFields.md +0 -19
  151. data/lib/pulp_file_client/models/file_file_content.rb +0 -297
  152. data/spec/api_client_spec.rb +0 -188
  153. data/spec/configuration_spec.rb +0 -42
  154. data/spec/models/file_file_content_spec.rb +0 -71
@@ -6,7 +6,7 @@
6
6
  The version of the OpenAPI document: v3
7
7
  Contact: pulp-list@redhat.com
8
8
  Generated by: https://openapi-generator.tech
9
- OpenAPI Generator version: 4.3.1
9
+ Generator version: 7.10.0
10
10
 
11
11
  =end
12
12
 
@@ -14,7 +14,12 @@ require 'date'
14
14
  require 'json'
15
15
  require 'logger'
16
16
  require 'tempfile'
17
+ require 'time'
17
18
  require 'faraday'
19
+ require 'faraday/multipart' if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new('2.0')
20
+ require 'marcel'
21
+ require 'pathname'
22
+
18
23
 
19
24
  module PulpFileClient
20
25
  class ApiClient
@@ -46,51 +51,38 @@ module PulpFileClient
46
51
  # @return [Array<(Object, Integer, Hash)>] an array of 3 elements:
47
52
  # the data deserialized from response body (could be nil), response status code and response headers.
48
53
  def call_api(http_method, path, opts = {})
49
- ssl_options = {
50
- :ca_file => @config.ssl_ca_file,
51
- :verify => @config.ssl_verify,
52
- :verify_mode => @config.ssl_verify_mode,
53
- :client_cert => @config.ssl_client_cert,
54
- :client_key => @config.ssl_client_key
55
- }
56
- request_options = {
57
- :params_encoder => @config.params_encoder
58
- }
59
- connection = Faraday.new(:url => config.base_url, :ssl => ssl_options, :request => request_options) do |conn|
60
- conn.basic_auth(config.username, config.password)
61
- if opts[:header_params]["Content-Type"] == "multipart/form-data"
62
- conn.request :multipart
63
- conn.request :url_encoded
64
- end
65
- conn.adapter(Faraday.default_adapter)
66
- end
67
-
54
+ stream = nil
68
55
  begin
69
- response = connection.public_send(http_method.to_sym.downcase) do |req|
70
- build_request(http_method, path, req, opts)
56
+ response = connection(opts).public_send(http_method.to_sym.downcase) do |req|
57
+ request = build_request(http_method, path, req, opts)
58
+ stream = download_file(request) if opts[:return_type] == 'File' || opts[:return_type] == 'Binary'
71
59
  end
72
60
 
73
- if @config.debugging
74
- @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
61
+ if config.debugging
62
+ config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
75
63
  end
76
64
 
77
65
  unless response.success?
78
- if response.status == 0
66
+ if response.status == 0 && response.respond_to?(:return_message)
79
67
  # Errors from libcurl will be made visible here
80
- fail ApiError.new(:code => 0,
81
- :message => response.return_message)
68
+ fail ApiError.new(code: 0,
69
+ message: response.return_message)
82
70
  else
83
- fail ApiError.new(:code => response.status,
84
- :response_headers => response.headers,
85
- :response_body => response.body),
71
+ fail ApiError.new(code: response.status,
72
+ response_headers: response.headers,
73
+ response_body: response.body),
86
74
  response.reason_phrase
87
75
  end
88
76
  end
89
77
  rescue Faraday::TimeoutError
90
78
  fail ApiError.new('Connection timed out')
79
+ rescue Faraday::ConnectionFailed
80
+ fail ApiError.new('Connection failed')
91
81
  end
92
82
 
93
- if opts[:return_type]
83
+ if opts[:return_type] == 'File' || opts[:return_type] == 'Binary'
84
+ data = deserialize_file(response, stream)
85
+ elsif opts[:return_type]
94
86
  data = deserialize(response, opts[:return_type])
95
87
  else
96
88
  data = nil
@@ -106,9 +98,9 @@ module PulpFileClient
106
98
  # @option opts [Hash] :query_params Query parameters
107
99
  # @option opts [Hash] :form_params Query parameters
108
100
  # @option opts [Object] :body HTTP body (JSON/XML)
109
- # @return [Typhoeus::Request] A Typhoeus Request
101
+ # @return [Faraday::Request] A Faraday Request
110
102
  def build_request(http_method, path, request, opts = {})
111
- url = build_request_url(path)
103
+ url = build_request_url(path, opts)
112
104
  http_method = http_method.to_sym.downcase
113
105
 
114
106
  header_params = @default_headers.merge(opts[:header_params] || {})
@@ -117,24 +109,21 @@ module PulpFileClient
117
109
 
118
110
  update_params_for_auth! header_params, query_params, opts[:auth_names]
119
111
 
120
- req_opts = {
121
- :params_encoding => @config.params_encoding,
122
- :timeout => @config.timeout,
123
- :verbose => @config.debugging
124
- }
125
-
126
112
  if [:post, :patch, :put, :delete].include?(http_method)
127
113
  req_body = build_request_body(header_params, form_params, opts[:body])
128
- if @config.debugging
129
- @config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
114
+ if config.debugging
115
+ config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
130
116
  end
131
117
  end
132
118
  request.headers = header_params
133
119
  request.body = req_body
134
- request.options = OpenStruct.new(req_opts)
120
+
121
+ # Overload default options only if provided
122
+ request.options.params_encoder = config.params_encoder if config.params_encoder
123
+ request.options.timeout = config.timeout if config.timeout
124
+
135
125
  request.url url
136
126
  request.params = query_params
137
- download_file(request) if opts[:return_type] == 'File'
138
127
  request
139
128
  end
140
129
 
@@ -153,8 +142,7 @@ module PulpFileClient
153
142
  form_params.each do |key, value|
154
143
  case value
155
144
  when ::File, ::Tempfile
156
- # TODO hardcode to application/octet-stream, need better way to detect content type
157
- data[key] = Faraday::FilePart.new(value.path, 'application/octet-stream', value.path)
145
+ data[key] = Faraday::FilePart.new(value.path, Marcel::MimeType.for(Pathname.new(value.path)))
158
146
  when ::Array, nil
159
147
  # let Faraday handle Array and nil parameters
160
148
  data[key] = value
@@ -170,6 +158,95 @@ module PulpFileClient
170
158
  data
171
159
  end
172
160
 
161
+ def download_file(request)
162
+ stream = []
163
+
164
+ # handle streaming Responses
165
+ request.options.on_data = Proc.new do |chunk, overall_received_bytes|
166
+ stream << chunk
167
+ end
168
+
169
+ stream
170
+ end
171
+
172
+ def deserialize_file(response, stream)
173
+ body = response.body
174
+ encoding = body.encoding
175
+
176
+ # reconstruct content
177
+ content = stream.join
178
+ content = content.unpack('m').join if response.headers['Content-Transfer-Encoding'] == 'binary'
179
+ content = content.force_encoding(encoding)
180
+
181
+ # return byte stream
182
+ return content if @config.return_binary_data == true
183
+
184
+ # return file instead of binary data
185
+ content_disposition = response.headers['Content-Disposition']
186
+ if content_disposition && content_disposition =~ /filename=/i
187
+ filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
188
+ prefix = sanitize_filename(filename)
189
+ else
190
+ prefix = 'download-'
191
+ end
192
+ prefix = prefix + '-' unless prefix.end_with?('-')
193
+
194
+ tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
195
+ tempfile.write(content)
196
+ tempfile.close
197
+
198
+ config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
199
+ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
200
+ "will be deleted automatically with GC. It's also recommended to delete the temp file "\
201
+ "explicitly with `tempfile.delete`"
202
+ tempfile
203
+ end
204
+
205
+ def connection(opts)
206
+ opts[:header_params]['Content-Type'] == 'multipart/form-data' ? connection_multipart : connection_regular
207
+ end
208
+
209
+ def connection_multipart
210
+ @connection_multipart ||= build_connection do |conn|
211
+ conn.request :multipart
212
+ conn.request :url_encoded
213
+ end
214
+ end
215
+
216
+ def connection_regular
217
+ @connection_regular ||= build_connection
218
+ end
219
+
220
+ def build_connection
221
+ Faraday.new(url: config.base_url, ssl: ssl_options, proxy: config.proxy) do |conn|
222
+ basic_auth(conn)
223
+ config.configure_middleware(conn)
224
+ yield(conn) if block_given?
225
+ conn.adapter(Faraday.default_adapter)
226
+ config.configure_connection(conn)
227
+ end
228
+ end
229
+
230
+ def ssl_options
231
+ {
232
+ ca_file: config.ssl_ca_file,
233
+ verify: config.ssl_verify,
234
+ verify_mode: config.ssl_verify_mode,
235
+ client_cert: config.ssl_client_cert,
236
+ client_key: config.ssl_client_key
237
+ }
238
+ end
239
+
240
+ def basic_auth(conn)
241
+ if config.username && config.password
242
+ if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new('2.0')
243
+ conn.request(:authorization, :basic, config.username, config.password)
244
+ else
245
+ conn.request(:basic_auth, config.username, config.password)
246
+ end
247
+ end
248
+ end
249
+
173
250
  # Check if the given MIME is a JSON MIME.
174
251
  # JSON MIME examples:
175
252
  # application/json
@@ -179,7 +256,7 @@ module PulpFileClient
179
256
  # @param [String] mime MIME
180
257
  # @return [Boolean] True if the MIME is application/json
181
258
  def json_mime?(mime)
182
- (mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
259
+ (mime == '*/*') || !(mime =~ /^Application\/.*json(?!p)(;.*)?/i).nil?
183
260
  end
184
261
 
185
262
  # Deserialize the response to the given return type.
@@ -188,15 +265,10 @@ module PulpFileClient
188
265
  # @param [String] return_type some examples: "User", "Array<User>", "Hash<String, Integer>"
189
266
  def deserialize(response, return_type)
190
267
  body = response.body
191
-
192
- # handle file downloading - return the File instance processed in request callbacks
193
- # note that response body is empty when the file is written in chunks in request on_body callback
194
- return @tempfile if return_type == 'File'
195
-
196
268
  return nil if body.nil? || body.empty?
197
269
 
198
270
  # return response body directly for String return type
199
- return body if return_type == 'String'
271
+ return body.to_s if return_type == 'String'
200
272
 
201
273
  # ensuring a default content type
202
274
  content_type = response.headers['Content-Type'] || 'application/json'
@@ -206,7 +278,7 @@ module PulpFileClient
206
278
  begin
207
279
  data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
208
280
  rescue JSON::ParserError => e
209
- if %w(String Date DateTime).include?(return_type)
281
+ if %w(String Date Time).include?(return_type)
210
282
  data = body
211
283
  else
212
284
  raise e
@@ -231,9 +303,9 @@ module PulpFileClient
231
303
  data.to_f
232
304
  when 'Boolean'
233
305
  data == true
234
- when 'DateTime'
306
+ when 'Time'
235
307
  # parse date time (expecting ISO 8601 format)
236
- DateTime.parse data
308
+ Time.parse data
237
309
  when 'Date'
238
310
  # parse date time (expecting ISO 8601 format)
239
311
  Date.parse data
@@ -251,46 +323,9 @@ module PulpFileClient
251
323
  data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
252
324
  end
253
325
  else
254
- # models, e.g. Pet
255
- PulpFileClient.const_get(return_type).build_from_hash(data)
256
- end
257
- end
258
-
259
- # Save response body into a file in (the defined) temporary folder, using the filename
260
- # from the "Content-Disposition" header if provided, otherwise a random filename.
261
- # The response body is written to the file in chunks in order to handle files which
262
- # size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
263
- # process can use.
264
- #
265
- # @see Configuration#temp_folder_path
266
- def download_file(request)
267
- tempfile = nil
268
- encoding = nil
269
- request.on_headers do |response|
270
- content_disposition = response.headers['Content-Disposition']
271
- if content_disposition && content_disposition =~ /filename=/i
272
- filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
273
- prefix = sanitize_filename(filename)
274
- else
275
- prefix = 'download-'
276
- end
277
- prefix = prefix + '-' unless prefix.end_with?('-')
278
- encoding = response.body.encoding
279
- tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
280
- @tempfile = tempfile
281
- end
282
- request.on_body do |chunk|
283
- chunk.force_encoding(encoding)
284
- tempfile.write(chunk)
285
- end
286
- request.on_complete do |response|
287
- if tempfile
288
- tempfile.close
289
- @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
290
- "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
291
- "will be deleted automatically with GC. It's also recommended to delete the temp file "\
292
- "explicitly with `tempfile.delete`"
293
- end
326
+ # models (e.g. Pet) or oneOf
327
+ klass = PulpFileClient.const_get(return_type)
328
+ klass.respond_to?(:openapi_one_of) ? klass.build(data) : klass.build_from_hash(data)
294
329
  end
295
330
  end
296
331
 
@@ -300,16 +335,16 @@ module PulpFileClient
300
335
  # @param [String] filename the filename to be sanitized
301
336
  # @return [String] the sanitized filename
302
337
  def sanitize_filename(filename)
303
- filename.gsub(/.*[\/\\]/, '')
338
+ filename.split(/[\/\\]/).last
304
339
  end
305
340
 
306
- def build_request_url(path)
341
+ def build_request_url(path, opts = {})
307
342
  # Add leading and trailing slashes to path
308
343
  path = "/#{path}".gsub(/\/+/, '/')
309
- @config.base_url + path
344
+ @config.base_url(opts[:operation]) + path
310
345
  end
311
346
 
312
- # Update hearder and query params based on authentication settings.
347
+ # Update header and query params based on authentication settings.
313
348
  #
314
349
  # @param [Hash] header_params Header parameters
315
350
  # @param [Hash] query_params Query parameters
@@ -321,7 +356,7 @@ module PulpFileClient
321
356
  case auth_setting[:in]
322
357
  when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
323
358
  when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
324
- else fail ArgumentError, 'Authentication token must be in `query` of `header`'
359
+ else fail ArgumentError, 'Authentication token must be in `query` or `header`'
325
360
  end
326
361
  end
327
362
  end
@@ -348,8 +383,8 @@ module PulpFileClient
348
383
  # @param [Array] content_types array for Content-Type
349
384
  # @return [String] the Content-Type header (e.g. application/json)
350
385
  def select_header_content_type(content_types)
351
- # use application/json by default
352
- return 'application/json' if content_types.nil? || content_types.empty?
386
+ # return nil by default
387
+ return if content_types.nil? || content_types.empty?
353
388
  # use JSON when present, otherwise use the first one
354
389
  json_content_type = content_types.find { |s| json_mime?(s) }
355
390
  json_content_type || content_types.first
@@ -6,7 +6,7 @@
6
6
  The version of the OpenAPI document: v3
7
7
  Contact: pulp-list@redhat.com
8
8
  Generated by: https://openapi-generator.tech
9
- OpenAPI Generator version: 4.3.1
9
+ Generator version: 7.10.0
10
10
 
11
11
  =end
12
12
 
@@ -32,6 +32,7 @@ module PulpFileClient
32
32
  end
33
33
  else
34
34
  super arg
35
+ @message = arg
35
36
  end
36
37
  end
37
38
 
@@ -6,7 +6,7 @@
6
6
  The version of the OpenAPI document: v3
7
7
  Contact: pulp-list@redhat.com
8
8
  Generated by: https://openapi-generator.tech
9
- OpenAPI Generator version: 4.3.1
9
+ Generator version: 7.10.0
10
10
 
11
11
  =end
12
12
 
@@ -21,6 +21,18 @@ module PulpFileClient
21
21
  # Defines url base path
22
22
  attr_accessor :base_path
23
23
 
24
+ # Define server configuration index
25
+ attr_accessor :server_index
26
+
27
+ # Define server operation configuration index
28
+ attr_accessor :server_operation_index
29
+
30
+ # Default server variables
31
+ attr_accessor :server_variables
32
+
33
+ # Default server operation variables
34
+ attr_accessor :server_operation_variables
35
+
24
36
  # Defines API keys used with API Key authentications.
25
37
  #
26
38
  # @return [Hash] key: parameter name, value: parameter value (API key)
@@ -50,6 +62,16 @@ module PulpFileClient
50
62
  # Defines the access token (Bearer) used with OAuth2.
51
63
  attr_accessor :access_token
52
64
 
65
+ # Defines a Proc used to fetch or refresh access tokens (Bearer) used with OAuth2.
66
+ # Overrides the access_token if set
67
+ # @return [Proc]
68
+ attr_accessor :access_token_getter
69
+
70
+ # Set this to return data as binary instead of downloading a temp file. When enabled (set to true)
71
+ # HTTP responses with return type `File` will be returned as a stream of binary data.
72
+ # Default to false.
73
+ attr_accessor :return_binary_data
74
+
53
75
  # Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
54
76
  # details will be logged with `logger.debug` (see the `logger` attribute).
55
77
  # Default to false.
@@ -57,6 +79,14 @@ module PulpFileClient
57
79
  # @return [true, false]
58
80
  attr_accessor :debugging
59
81
 
82
+ # Set this to ignore operation servers for the API client. This is useful when you need to
83
+ # send requests to a different server than the one specified in the OpenAPI document.
84
+ # Will default to the base url defined in the spec but can be overridden by setting
85
+ # `scheme`, `host`, `base_path` directly.
86
+ # Default to false.
87
+ # @return [true, false]
88
+ attr_accessor :ignore_operation_servers
89
+
60
90
  # Defines the logger used for debugging.
61
91
  # Default to `Rails.logger` (when in Rails) or logging to STDOUT.
62
92
  #
@@ -109,18 +139,17 @@ module PulpFileClient
109
139
  # Client private key file (for client certificate)
110
140
  attr_accessor :ssl_client_key
111
141
 
142
+ ### Proxy setting
143
+ # HTTP Proxy settings
144
+ attr_accessor :proxy
145
+
112
146
  # Set this to customize parameters encoder of array parameter.
113
147
  # Default to nil. Faraday uses NestedParamsEncoder when nil.
114
148
  #
115
149
  # @see The params_encoder option of Faraday. Related source code:
116
150
  # https://github.com/lostisland/faraday/tree/main/lib/faraday/encoders
117
151
  attr_accessor :params_encoder
118
- # Set this to customize parameters encoding of array parameter with multi collectionFormat.
119
- # Default to nil.
120
- #
121
- # @see The params_encoding option of Ethon. Related source code:
122
- # https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96
123
- attr_accessor :params_encoding
152
+
124
153
 
125
154
  attr_accessor :inject_format
126
155
 
@@ -128,20 +157,28 @@ module PulpFileClient
128
157
 
129
158
  def initialize
130
159
  @scheme = 'http'
131
- @host = 'localhost'
160
+ @host = 'localhost:24817'
132
161
  @base_path = ''
162
+ @server_index = nil
163
+ @server_operation_index = {}
164
+ @server_variables = {}
165
+ @server_operation_variables = {}
133
166
  @api_key = {}
134
167
  @api_key_prefix = {}
135
- @timeout = 0
136
168
  @client_side_validation = true
137
169
  @ssl_verify = true
138
170
  @ssl_verify_mode = nil
139
171
  @ssl_ca_file = nil
140
172
  @ssl_client_cert = nil
141
173
  @ssl_client_key = nil
142
- @params_encoder = nil
174
+ @middlewares = Hash.new { |h, k| h[k] = [] }
175
+ @configure_connection_blocks = []
143
176
  @timeout = 60
177
+ # return data as binary instead of file
178
+ @return_binary_data = false
179
+ @params_encoder = nil
144
180
  @debugging = false
181
+ @ignore_operation_servers = false
145
182
  @inject_format = false
146
183
  @force_ending_format = false
147
184
  @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
@@ -174,20 +211,35 @@ module PulpFileClient
174
211
  @base_path = '' if @base_path == '/'
175
212
  end
176
213
 
177
- def base_url
178
- "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '')
214
+ # Returns base URL for specified operation based on server settings
215
+ def base_url(operation = nil)
216
+ return "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') if ignore_operation_servers
217
+ if operation_server_settings.key?(operation) then
218
+ index = server_operation_index.fetch(operation, server_index)
219
+ server_url(index.nil? ? 0 : index, server_operation_variables.fetch(operation, server_variables), operation_server_settings[operation])
220
+ else
221
+ server_index.nil? ? "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') : server_url(server_index, server_variables, nil)
222
+ end
179
223
  end
180
224
 
181
225
  # Gets API key (with prefix if set).
182
226
  # @param [String] param_name the parameter name of API key auth
183
- def api_key_with_prefix(param_name)
227
+ def api_key_with_prefix(param_name, param_alias = nil)
228
+ key = @api_key[param_name]
229
+ key = @api_key.fetch(param_alias, key) unless param_alias.nil?
184
230
  if @api_key_prefix[param_name]
185
- "#{@api_key_prefix[param_name]} #{@api_key[param_name]}"
231
+ "#{@api_key_prefix[param_name]} #{key}"
186
232
  else
187
- @api_key[param_name]
233
+ key
188
234
  end
189
235
  end
190
236
 
237
+ # Gets access_token using access_token_getter or uses the static access_token
238
+ def access_token_with_refresh
239
+ return access_token if access_token_getter.nil?
240
+ access_token_getter.call
241
+ end
242
+
191
243
  # Gets Basic Auth token string
192
244
  def basic_auth_token
193
245
  'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
@@ -210,31 +262,38 @@ module PulpFileClient
210
262
  def server_settings
211
263
  [
212
264
  {
213
- url: "http://localhost:24817/",
265
+ url: "http://localhost:24817",
214
266
  description: "No description provided",
215
267
  }
216
268
  ]
217
269
  end
218
270
 
271
+ def operation_server_settings
272
+ {
273
+ }
274
+ end
275
+
219
276
  # Returns URL based on server settings
220
277
  #
221
278
  # @param index array index of the server settings
222
279
  # @param variables hash of variable and the corresponding value
223
- def server_url(index, variables = {})
224
- servers = server_settings
280
+ def server_url(index, variables = {}, servers = nil)
281
+ servers = server_settings if servers == nil
225
282
 
226
283
  # check array index out of bound
227
- if (index < 0 || index >= servers.size)
228
- fail ArgumentError, "Invalid index #{index} when selecting the server. Must be less than #{servers.size}"
284
+ if (index.nil? || index < 0 || index >= servers.size)
285
+ fail ArgumentError, "Invalid index #{index} when selecting the server. Must not be nil and must be less than #{servers.size}"
229
286
  end
230
287
 
231
288
  server = servers[index]
232
289
  url = server[:url]
233
290
 
291
+ return url unless server.key? :variables
292
+
234
293
  # go through variable and assign a value
235
294
  server[:variables].each do |name, variable|
236
295
  if variables.key?(name)
237
- if (server[:variables][name][:enum_values].include? variables[name])
296
+ if (!server[:variables][name].key?(:enum_values) || server[:variables][name][:enum_values].include?(variables[name]))
238
297
  url.gsub! "{" + name.to_s + "}", variables[name]
239
298
  else
240
299
  fail ArgumentError, "The variable `#{name}` in the server URL has invalid value #{variables[name]}. Must be #{server[:variables][name][:enum_values]}."
@@ -247,5 +306,87 @@ module PulpFileClient
247
306
 
248
307
  url
249
308
  end
309
+
310
+ # Configure Faraday connection directly.
311
+ #
312
+ # ```
313
+ # c.configure_faraday_connection do |conn|
314
+ # conn.use Faraday::HttpCache, shared_cache: false, logger: logger
315
+ # conn.response :logger, nil, headers: true, bodies: true, log_level: :debug do |logger|
316
+ # logger.filter(/(Authorization: )(.*)/, '\1[REDACTED]')
317
+ # end
318
+ # end
319
+ #
320
+ # c.configure_faraday_connection do |conn|
321
+ # conn.adapter :typhoeus
322
+ # end
323
+ # ```
324
+ #
325
+ # @param block [Proc] `#call`able object that takes one arg, the connection
326
+ def configure_faraday_connection(&block)
327
+ @configure_connection_blocks << block
328
+ end
329
+
330
+ def configure_connection(conn)
331
+ @configure_connection_blocks.each do |block|
332
+ block.call(conn)
333
+ end
334
+ end
335
+
336
+ # Adds middleware to the stack
337
+ def use(*middleware)
338
+ set_faraday_middleware(:use, *middleware)
339
+ end
340
+
341
+ # Adds request middleware to the stack
342
+ def request(*middleware)
343
+ set_faraday_middleware(:request, *middleware)
344
+ end
345
+
346
+ # Adds response middleware to the stack
347
+ def response(*middleware)
348
+ set_faraday_middleware(:response, *middleware)
349
+ end
350
+
351
+ # Adds Faraday middleware setting information to the stack
352
+ #
353
+ # @example Use the `set_faraday_middleware` method to set middleware information
354
+ # config.set_faraday_middleware(:request, :retry, max: 3, methods: [:get, :post], retry_statuses: [503])
355
+ # config.set_faraday_middleware(:response, :logger, nil, { bodies: true, log_level: :debug })
356
+ # config.set_faraday_middleware(:use, Faraday::HttpCache, store: Rails.cache, shared_cache: false)
357
+ # config.set_faraday_middleware(:insert, 0, FaradayMiddleware::FollowRedirects, { standards_compliant: true, limit: 1 })
358
+ # config.set_faraday_middleware(:swap, 0, Faraday::Response::Logger)
359
+ # config.set_faraday_middleware(:delete, Faraday::Multipart::Middleware)
360
+ #
361
+ # @see https://github.com/lostisland/faraday/blob/v2.3.0/lib/faraday/rack_builder.rb#L92-L143
362
+ def set_faraday_middleware(operation, key, *args, &block)
363
+ unless [:request, :response, :use, :insert, :insert_before, :insert_after, :swap, :delete].include?(operation)
364
+ fail ArgumentError, "Invalid faraday middleware operation #{operation}. Must be" \
365
+ " :request, :response, :use, :insert, :insert_before, :insert_after, :swap or :delete."
366
+ end
367
+
368
+ @middlewares[operation] << [key, args, block]
369
+ end
370
+ ruby2_keywords(:set_faraday_middleware) if respond_to?(:ruby2_keywords, true)
371
+
372
+ # Set up middleware on the connection
373
+ def configure_middleware(connection)
374
+ return if @middlewares.empty?
375
+
376
+ [:request, :response, :use, :insert, :insert_before, :insert_after, :swap].each do |operation|
377
+ next unless @middlewares.key?(operation)
378
+
379
+ @middlewares[operation].each do |key, args, block|
380
+ connection.builder.send(operation, key, *args, &block)
381
+ end
382
+ end
383
+
384
+ if @middlewares.key?(:delete)
385
+ @middlewares[:delete].each do |key, _args, _block|
386
+ connection.builder.delete(key)
387
+ end
388
+ end
389
+ end
390
+
250
391
  end
251
392
  end