pulp_gem_client 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +9 -0
  3. data/README.md +160 -0
  4. data/Rakefile +10 -0
  5. data/docs/AsyncOperationResponse.md +17 -0
  6. data/docs/ContentGemApi.md +210 -0
  7. data/docs/ContentSummaryResponse.md +21 -0
  8. data/docs/DistributionsGemApi.md +382 -0
  9. data/docs/GemGemContent.md +21 -0
  10. data/docs/GemGemContentResponse.md +35 -0
  11. data/docs/GemGemDistribution.md +31 -0
  12. data/docs/GemGemDistributionResponse.md +37 -0
  13. data/docs/GemGemPublication.md +19 -0
  14. data/docs/GemGemPublicationResponse.md +23 -0
  15. data/docs/GemGemRemote.md +63 -0
  16. data/docs/GemGemRemoteResponse.md +61 -0
  17. data/docs/GemGemRemoteResponseHiddenFields.md +19 -0
  18. data/docs/GemGemRepository.md +25 -0
  19. data/docs/GemGemRepositoryResponse.md +33 -0
  20. data/docs/PaginatedRepositoryVersionResponseList.md +23 -0
  21. data/docs/PaginatedgemGemContentResponseList.md +23 -0
  22. data/docs/PaginatedgemGemDistributionResponseList.md +23 -0
  23. data/docs/PaginatedgemGemPublicationResponseList.md +23 -0
  24. data/docs/PaginatedgemGemRemoteResponseList.md +23 -0
  25. data/docs/PaginatedgemGemRepositoryResponseList.md +23 -0
  26. data/docs/PatchedgemGemDistribution.md +31 -0
  27. data/docs/PatchedgemGemRemote.md +63 -0
  28. data/docs/PatchedgemGemRepository.md +25 -0
  29. data/docs/PolicyEnum.md +16 -0
  30. data/docs/PublicationsGemApi.md +263 -0
  31. data/docs/RemotesGemApi.md +380 -0
  32. data/docs/Repair.md +17 -0
  33. data/docs/RepositoriesGemApi.md +502 -0
  34. data/docs/RepositoriesGemVersionsApi.md +273 -0
  35. data/docs/RepositoryAddRemoveContent.md +21 -0
  36. data/docs/RepositorySyncURL.md +19 -0
  37. data/docs/RepositoryVersionResponse.md +27 -0
  38. data/lib/pulp_gem_client/api/content_gem_api.rb +259 -0
  39. data/lib/pulp_gem_client/api/distributions_gem_api.rb +476 -0
  40. data/lib/pulp_gem_client/api/publications_gem_api.rb +325 -0
  41. data/lib/pulp_gem_client/api/remotes_gem_api.rb +473 -0
  42. data/lib/pulp_gem_client/api/repositories_gem_api.rb +628 -0
  43. data/lib/pulp_gem_client/api/repositories_gem_versions_api.rb +346 -0
  44. data/lib/pulp_gem_client/api_client.rb +403 -0
  45. data/lib/pulp_gem_client/api_error.rb +57 -0
  46. data/lib/pulp_gem_client/configuration.rb +251 -0
  47. data/lib/pulp_gem_client/models/async_operation_response.rb +213 -0
  48. data/lib/pulp_gem_client/models/content_summary_response.rb +246 -0
  49. data/lib/pulp_gem_client/models/gem_gem_content.rb +228 -0
  50. data/lib/pulp_gem_client/models/gem_gem_content_response.rb +303 -0
  51. data/lib/pulp_gem_client/models/gem_gem_distribution.rb +333 -0
  52. data/lib/pulp_gem_client/models/gem_gem_distribution_response.rb +324 -0
  53. data/lib/pulp_gem_client/models/gem_gem_publication.rb +217 -0
  54. data/lib/pulp_gem_client/models/gem_gem_publication_response.rb +236 -0
  55. data/lib/pulp_gem_client/models/gem_gem_remote.rb +704 -0
  56. data/lib/pulp_gem_client/models/gem_gem_remote_response.rb +532 -0
  57. data/lib/pulp_gem_client/models/gem_gem_remote_response_hidden_fields.rb +215 -0
  58. data/lib/pulp_gem_client/models/gem_gem_repository.rb +306 -0
  59. data/lib/pulp_gem_client/models/gem_gem_repository_response.rb +309 -0
  60. data/lib/pulp_gem_client/models/paginated_repository_version_response_list.rb +237 -0
  61. data/lib/pulp_gem_client/models/paginatedgem_gem_content_response_list.rb +237 -0
  62. data/lib/pulp_gem_client/models/paginatedgem_gem_distribution_response_list.rb +237 -0
  63. data/lib/pulp_gem_client/models/paginatedgem_gem_publication_response_list.rb +237 -0
  64. data/lib/pulp_gem_client/models/paginatedgem_gem_remote_response_list.rb +237 -0
  65. data/lib/pulp_gem_client/models/paginatedgem_gem_repository_response_list.rb +237 -0
  66. data/lib/pulp_gem_client/models/patchedgem_gem_distribution.rb +315 -0
  67. data/lib/pulp_gem_client/models/patchedgem_gem_remote.rb +686 -0
  68. data/lib/pulp_gem_client/models/patchedgem_gem_repository.rb +297 -0
  69. data/lib/pulp_gem_client/models/policy_enum.rb +37 -0
  70. data/lib/pulp_gem_client/models/repair.rb +209 -0
  71. data/lib/pulp_gem_client/models/repository_add_remove_content.rb +232 -0
  72. data/lib/pulp_gem_client/models/repository_sync_url.rb +220 -0
  73. data/lib/pulp_gem_client/models/repository_version_response.rb +255 -0
  74. data/lib/pulp_gem_client/version.rb +15 -0
  75. data/lib/pulp_gem_client.rb +72 -0
  76. data/pulp_gem_client.gemspec +39 -0
  77. data/spec/api/content_gem_api_spec.rb +88 -0
  78. data/spec/api/distributions_gem_api_spec.rb +130 -0
  79. data/spec/api/publications_gem_api_spec.rb +101 -0
  80. data/spec/api/remotes_gem_api_spec.rb +129 -0
  81. data/spec/api/repositories_gem_api_spec.rb +160 -0
  82. data/spec/api/repositories_gem_versions_api_spec.rb +105 -0
  83. data/spec/api_client_spec.rb +188 -0
  84. data/spec/configuration_spec.rb +42 -0
  85. data/spec/models/async_operation_response_spec.rb +41 -0
  86. data/spec/models/content_summary_response_spec.rb +53 -0
  87. data/spec/models/gem_gem_content_response_spec.rb +95 -0
  88. data/spec/models/gem_gem_content_spec.rb +53 -0
  89. data/spec/models/gem_gem_distribution_response_spec.rb +101 -0
  90. data/spec/models/gem_gem_distribution_spec.rb +83 -0
  91. data/spec/models/gem_gem_publication_response_spec.rb +59 -0
  92. data/spec/models/gem_gem_publication_spec.rb +47 -0
  93. data/spec/models/gem_gem_remote_response_hidden_fields_spec.rb +47 -0
  94. data/spec/models/gem_gem_remote_response_spec.rb +173 -0
  95. data/spec/models/gem_gem_remote_spec.rb +179 -0
  96. data/spec/models/gem_gem_repository_response_spec.rb +89 -0
  97. data/spec/models/gem_gem_repository_spec.rb +65 -0
  98. data/spec/models/paginated_repository_version_response_list_spec.rb +59 -0
  99. data/spec/models/paginatedgem_gem_content_response_list_spec.rb +59 -0
  100. data/spec/models/paginatedgem_gem_distribution_response_list_spec.rb +59 -0
  101. data/spec/models/paginatedgem_gem_publication_response_list_spec.rb +59 -0
  102. data/spec/models/paginatedgem_gem_remote_response_list_spec.rb +59 -0
  103. data/spec/models/paginatedgem_gem_repository_response_list_spec.rb +59 -0
  104. data/spec/models/patchedgem_gem_distribution_spec.rb +83 -0
  105. data/spec/models/patchedgem_gem_remote_spec.rb +179 -0
  106. data/spec/models/patchedgem_gem_repository_spec.rb +65 -0
  107. data/spec/models/policy_enum_spec.rb +35 -0
  108. data/spec/models/repair_spec.rb +41 -0
  109. data/spec/models/repository_add_remove_content_spec.rb +53 -0
  110. data/spec/models/repository_sync_url_spec.rb +47 -0
  111. data/spec/models/repository_version_response_spec.rb +71 -0
  112. data/spec/spec_helper.rb +111 -0
  113. metadata +250 -0
@@ -0,0 +1,403 @@
1
+ =begin
2
+ #Pulp 3 API
3
+
4
+ #Fetch, Upload, Organize, and Distribute Software Packages
5
+
6
+ The version of the OpenAPI document: v3
7
+ Contact: pulp-list@redhat.com
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 4.3.1
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'json'
15
+ require 'logger'
16
+ require 'tempfile'
17
+ require 'faraday'
18
+
19
+ module PulpGemClient
20
+ class ApiClient
21
+ # The Configuration object holding settings to be used in the API client.
22
+ attr_accessor :config
23
+
24
+ # Defines the headers to be used in HTTP requests of all API calls by default.
25
+ #
26
+ # @return [Hash]
27
+ attr_accessor :default_headers
28
+
29
+ # Initializes the ApiClient
30
+ # @option config [Configuration] Configuration for initializing the object, default to Configuration.default
31
+ def initialize(config = Configuration.default)
32
+ @config = config
33
+ @user_agent = "OpenAPI-Generator/#{VERSION}/ruby"
34
+ @default_headers = {
35
+ 'Content-Type' => 'application/json',
36
+ 'User-Agent' => @user_agent
37
+ }
38
+ end
39
+
40
+ def self.default
41
+ @@default ||= ApiClient.new
42
+ end
43
+
44
+ # Call an API with given options.
45
+ #
46
+ # @return [Array<(Object, Integer, Hash)>] an array of 3 elements:
47
+ # the data deserialized from response body (could be nil), response status code and response headers.
48
+ 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
+
68
+ begin
69
+ response = connection.public_send(http_method.to_sym.downcase) do |req|
70
+ build_request(http_method, path, req, opts)
71
+ end
72
+
73
+ if @config.debugging
74
+ @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
75
+ end
76
+
77
+ unless response.success?
78
+ if response.status == 0
79
+ # Errors from libcurl will be made visible here
80
+ fail ApiError.new(:code => 0,
81
+ :message => response.return_message)
82
+ else
83
+ fail ApiError.new(:code => response.status,
84
+ :response_headers => response.headers,
85
+ :response_body => response.body),
86
+ response.reason_phrase
87
+ end
88
+ end
89
+ rescue Faraday::TimeoutError
90
+ fail ApiError.new('Connection timed out')
91
+ end
92
+
93
+ if opts[:return_type]
94
+ data = deserialize(response, opts[:return_type])
95
+ else
96
+ data = nil
97
+ end
98
+ return data, response.status, response.headers
99
+ end
100
+
101
+ # Builds the HTTP request
102
+ #
103
+ # @param [String] http_method HTTP method/verb (e.g. POST)
104
+ # @param [String] path URL path (e.g. /account/new)
105
+ # @option opts [Hash] :header_params Header parameters
106
+ # @option opts [Hash] :query_params Query parameters
107
+ # @option opts [Hash] :form_params Query parameters
108
+ # @option opts [Object] :body HTTP body (JSON/XML)
109
+ # @return [Typhoeus::Request] A Typhoeus Request
110
+ def build_request(http_method, path, request, opts = {})
111
+ url = build_request_url(path)
112
+ http_method = http_method.to_sym.downcase
113
+
114
+ header_params = @default_headers.merge(opts[:header_params] || {})
115
+ query_params = opts[:query_params] || {}
116
+ form_params = opts[:form_params] || {}
117
+
118
+ update_params_for_auth! header_params, query_params, opts[:auth_names]
119
+
120
+ req_opts = {
121
+ :params_encoding => @config.params_encoding,
122
+ :timeout => @config.timeout,
123
+ :verbose => @config.debugging
124
+ }
125
+
126
+ if [:post, :patch, :put, :delete].include?(http_method)
127
+ 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"
130
+ end
131
+ end
132
+ request.headers = header_params
133
+ request.body = req_body
134
+ request.options = OpenStruct.new(req_opts)
135
+ request.url url
136
+ request.params = query_params
137
+ download_file(request) if opts[:return_type] == 'File'
138
+ request
139
+ end
140
+
141
+ # Builds the HTTP request body
142
+ #
143
+ # @param [Hash] header_params Header parameters
144
+ # @param [Hash] form_params Query parameters
145
+ # @param [Object] body HTTP body (JSON/XML)
146
+ # @return [String] HTTP body data in the form of string
147
+ def build_request_body(header_params, form_params, body)
148
+ # http form
149
+ if header_params['Content-Type'] == 'application/x-www-form-urlencoded'
150
+ data = URI.encode_www_form(form_params)
151
+ elsif header_params['Content-Type'] == 'multipart/form-data'
152
+ data = {}
153
+ form_params.each do |key, value|
154
+ case value
155
+ 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)
158
+ when ::Array, nil
159
+ # let Faraday handle Array and nil parameters
160
+ data[key] = value
161
+ else
162
+ data[key] = value.to_s
163
+ end
164
+ end
165
+ elsif body
166
+ data = body.is_a?(String) ? body : body.to_json
167
+ else
168
+ data = nil
169
+ end
170
+ data
171
+ end
172
+
173
+ # Check if the given MIME is a JSON MIME.
174
+ # JSON MIME examples:
175
+ # application/json
176
+ # application/json; charset=UTF8
177
+ # APPLICATION/JSON
178
+ # */*
179
+ # @param [String] mime MIME
180
+ # @return [Boolean] True if the MIME is application/json
181
+ def json_mime?(mime)
182
+ (mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
183
+ end
184
+
185
+ # Deserialize the response to the given return type.
186
+ #
187
+ # @param [Response] response HTTP response
188
+ # @param [String] return_type some examples: "User", "Array<User>", "Hash<String, Integer>"
189
+ def deserialize(response, return_type)
190
+ 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
+ return nil if body.nil? || body.empty?
197
+
198
+ # return response body directly for String return type
199
+ return body if return_type == 'String'
200
+
201
+ # ensuring a default content type
202
+ content_type = response.headers['Content-Type'] || 'application/json'
203
+
204
+ fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
205
+
206
+ begin
207
+ data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
208
+ rescue JSON::ParserError => e
209
+ if %w(String Date DateTime).include?(return_type)
210
+ data = body
211
+ else
212
+ raise e
213
+ end
214
+ end
215
+
216
+ convert_to_type data, return_type
217
+ end
218
+
219
+ # Convert data to the given return type.
220
+ # @param [Object] data Data to be converted
221
+ # @param [String] return_type Return type
222
+ # @return [Mixed] Data in a particular type
223
+ def convert_to_type(data, return_type)
224
+ return nil if data.nil?
225
+ case return_type
226
+ when 'String'
227
+ data.to_s
228
+ when 'Integer'
229
+ data.to_i
230
+ when 'Float'
231
+ data.to_f
232
+ when 'Boolean'
233
+ data == true
234
+ when 'DateTime'
235
+ # parse date time (expecting ISO 8601 format)
236
+ DateTime.parse data
237
+ when 'Date'
238
+ # parse date time (expecting ISO 8601 format)
239
+ Date.parse data
240
+ when 'Object'
241
+ # generic object (usually a Hash), return directly
242
+ data
243
+ when /\AArray<(.+)>\z/
244
+ # e.g. Array<Pet>
245
+ sub_type = $1
246
+ data.map { |item| convert_to_type(item, sub_type) }
247
+ when /\AHash\<String, (.+)\>\z/
248
+ # e.g. Hash<String, Integer>
249
+ sub_type = $1
250
+ {}.tap do |hash|
251
+ data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
252
+ end
253
+ else
254
+ # models, e.g. Pet
255
+ PulpGemClient.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
294
+ end
295
+ end
296
+
297
+ # Sanitize filename by removing path.
298
+ # e.g. ../../sun.gif becomes sun.gif
299
+ #
300
+ # @param [String] filename the filename to be sanitized
301
+ # @return [String] the sanitized filename
302
+ def sanitize_filename(filename)
303
+ filename.gsub(/.*[\/\\]/, '')
304
+ end
305
+
306
+ def build_request_url(path)
307
+ # Add leading and trailing slashes to path
308
+ path = "/#{path}".gsub(/\/+/, '/')
309
+ @config.base_url + path
310
+ end
311
+
312
+ # Update hearder and query params based on authentication settings.
313
+ #
314
+ # @param [Hash] header_params Header parameters
315
+ # @param [Hash] query_params Query parameters
316
+ # @param [String] auth_names Authentication scheme name
317
+ def update_params_for_auth!(header_params, query_params, auth_names)
318
+ Array(auth_names).each do |auth_name|
319
+ auth_setting = @config.auth_settings[auth_name]
320
+ next unless auth_setting
321
+ case auth_setting[:in]
322
+ when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
323
+ when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
324
+ else fail ArgumentError, 'Authentication token must be in `query` of `header`'
325
+ end
326
+ end
327
+ end
328
+
329
+ # Sets user agent in HTTP header
330
+ #
331
+ # @param [String] user_agent User agent (e.g. openapi-generator/ruby/1.0.0)
332
+ def user_agent=(user_agent)
333
+ @user_agent = user_agent
334
+ @default_headers['User-Agent'] = @user_agent
335
+ end
336
+
337
+ # Return Accept header based on an array of accepts provided.
338
+ # @param [Array] accepts array for Accept
339
+ # @return [String] the Accept header (e.g. application/json)
340
+ def select_header_accept(accepts)
341
+ return nil if accepts.nil? || accepts.empty?
342
+ # use JSON when present, otherwise use all of the provided
343
+ json_accept = accepts.find { |s| json_mime?(s) }
344
+ json_accept || accepts.join(',')
345
+ end
346
+
347
+ # Return Content-Type header based on an array of content types provided.
348
+ # @param [Array] content_types array for Content-Type
349
+ # @return [String] the Content-Type header (e.g. application/json)
350
+ def select_header_content_type(content_types)
351
+ # use application/json by default
352
+ return 'application/json' if content_types.nil? || content_types.empty?
353
+ # use JSON when present, otherwise use the first one
354
+ json_content_type = content_types.find { |s| json_mime?(s) }
355
+ json_content_type || content_types.first
356
+ end
357
+
358
+ # Convert object (array, hash, object, etc) to JSON string.
359
+ # @param [Object] model object to be converted into JSON string
360
+ # @return [String] JSON string representation of the object
361
+ def object_to_http_body(model)
362
+ return model if model.nil? || model.is_a?(String)
363
+ local_body = nil
364
+ if model.is_a?(Array)
365
+ local_body = model.map { |m| object_to_hash(m) }
366
+ else
367
+ local_body = object_to_hash(model)
368
+ end
369
+ local_body.to_json
370
+ end
371
+
372
+ # Convert object(non-array) to hash.
373
+ # @param [Object] obj object to be converted into JSON string
374
+ # @return [String] JSON string representation of the object
375
+ def object_to_hash(obj)
376
+ if obj.respond_to?(:to_hash)
377
+ obj.to_hash
378
+ else
379
+ obj
380
+ end
381
+ end
382
+
383
+ # Build parameter value according to the given collection format.
384
+ # @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
385
+ def build_collection_param(param, collection_format)
386
+ case collection_format
387
+ when :csv
388
+ param.join(',')
389
+ when :ssv
390
+ param.join(' ')
391
+ when :tsv
392
+ param.join("\t")
393
+ when :pipes
394
+ param.join('|')
395
+ when :multi
396
+ # return the array directly as typhoeus will handle it as expected
397
+ param
398
+ else
399
+ fail "unknown collection format: #{collection_format.inspect}"
400
+ end
401
+ end
402
+ end
403
+ end
@@ -0,0 +1,57 @@
1
+ =begin
2
+ #Pulp 3 API
3
+
4
+ #Fetch, Upload, Organize, and Distribute Software Packages
5
+
6
+ The version of the OpenAPI document: v3
7
+ Contact: pulp-list@redhat.com
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 4.3.1
10
+
11
+ =end
12
+
13
+ module PulpGemClient
14
+ class ApiError < StandardError
15
+ attr_reader :code, :response_headers, :response_body
16
+
17
+ # Usage examples:
18
+ # ApiError.new
19
+ # ApiError.new("message")
20
+ # ApiError.new(:code => 500, :response_headers => {}, :response_body => "")
21
+ # ApiError.new(:code => 404, :message => "Not Found")
22
+ def initialize(arg = nil)
23
+ if arg.is_a? Hash
24
+ if arg.key?(:message) || arg.key?('message')
25
+ super(arg[:message] || arg['message'])
26
+ else
27
+ super arg
28
+ end
29
+
30
+ arg.each do |k, v|
31
+ instance_variable_set "@#{k}", v
32
+ end
33
+ else
34
+ super arg
35
+ end
36
+ end
37
+
38
+ # Override to_s to display a friendly error message
39
+ def to_s
40
+ message
41
+ end
42
+
43
+ def message
44
+ if @message.nil?
45
+ msg = "Error message: the server returns an error"
46
+ else
47
+ msg = @message
48
+ end
49
+
50
+ msg += "\nHTTP status code: #{code}" if code
51
+ msg += "\nResponse headers: #{response_headers}" if response_headers
52
+ msg += "\nResponse body: #{response_body}" if response_body
53
+
54
+ msg
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,251 @@
1
+ =begin
2
+ #Pulp 3 API
3
+
4
+ #Fetch, Upload, Organize, and Distribute Software Packages
5
+
6
+ The version of the OpenAPI document: v3
7
+ Contact: pulp-list@redhat.com
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 4.3.1
10
+
11
+ =end
12
+
13
+ module PulpGemClient
14
+ class Configuration
15
+ # Defines url scheme
16
+ attr_accessor :scheme
17
+
18
+ # Defines url host
19
+ attr_accessor :host
20
+
21
+ # Defines url base path
22
+ attr_accessor :base_path
23
+
24
+ # Defines API keys used with API Key authentications.
25
+ #
26
+ # @return [Hash] key: parameter name, value: parameter value (API key)
27
+ #
28
+ # @example parameter name is "api_key", API key is "xxx" (e.g. "api_key=xxx" in query string)
29
+ # config.api_key['api_key'] = 'xxx'
30
+ attr_accessor :api_key
31
+
32
+ # Defines API key prefixes used with API Key authentications.
33
+ #
34
+ # @return [Hash] key: parameter name, value: API key prefix
35
+ #
36
+ # @example parameter name is "Authorization", API key prefix is "Token" (e.g. "Authorization: Token xxx" in headers)
37
+ # config.api_key_prefix['api_key'] = 'Token'
38
+ attr_accessor :api_key_prefix
39
+
40
+ # Defines the username used with HTTP basic authentication.
41
+ #
42
+ # @return [String]
43
+ attr_accessor :username
44
+
45
+ # Defines the password used with HTTP basic authentication.
46
+ #
47
+ # @return [String]
48
+ attr_accessor :password
49
+
50
+ # Defines the access token (Bearer) used with OAuth2.
51
+ attr_accessor :access_token
52
+
53
+ # Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
54
+ # details will be logged with `logger.debug` (see the `logger` attribute).
55
+ # Default to false.
56
+ #
57
+ # @return [true, false]
58
+ attr_accessor :debugging
59
+
60
+ # Defines the logger used for debugging.
61
+ # Default to `Rails.logger` (when in Rails) or logging to STDOUT.
62
+ #
63
+ # @return [#debug]
64
+ attr_accessor :logger
65
+
66
+ # Defines the temporary folder to store downloaded files
67
+ # (for API endpoints that have file response).
68
+ # Default to use `Tempfile`.
69
+ #
70
+ # @return [String]
71
+ attr_accessor :temp_folder_path
72
+
73
+ # The time limit for HTTP request in seconds.
74
+ # Default to 0 (never times out).
75
+ attr_accessor :timeout
76
+
77
+ # Set this to false to skip client side validation in the operation.
78
+ # Default to true.
79
+ # @return [true, false]
80
+ attr_accessor :client_side_validation
81
+
82
+ ### TLS/SSL setting
83
+ # Set this to false to skip verifying SSL certificate when calling API from https server.
84
+ # Default to true.
85
+ #
86
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
87
+ #
88
+ # @return [true, false]
89
+ attr_accessor :ssl_verify
90
+
91
+ ### TLS/SSL setting
92
+ # Any `OpenSSL::SSL::` constant (see https://ruby-doc.org/stdlib-2.5.1/libdoc/openssl/rdoc/OpenSSL/SSL.html)
93
+ #
94
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
95
+ #
96
+ attr_accessor :ssl_verify_mode
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
+ attr_accessor :ssl_ca_file
103
+
104
+ ### TLS/SSL setting
105
+ # Client certificate file (for client certificate)
106
+ attr_accessor :ssl_client_cert
107
+
108
+ ### TLS/SSL setting
109
+ # Client private key file (for client certificate)
110
+ attr_accessor :ssl_client_key
111
+
112
+ # Set this to customize parameters encoder of array parameter.
113
+ # Default to nil. Faraday uses NestedParamsEncoder when nil.
114
+ #
115
+ # @see The params_encoder option of Faraday. Related source code:
116
+ # https://github.com/lostisland/faraday/tree/main/lib/faraday/encoders
117
+ 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
124
+
125
+ attr_accessor :inject_format
126
+
127
+ attr_accessor :force_ending_format
128
+
129
+ def initialize
130
+ @scheme = 'https'
131
+ @host = 'pulp'
132
+ @base_path = ''
133
+ @api_key = {}
134
+ @api_key_prefix = {}
135
+ @timeout = 0
136
+ @client_side_validation = true
137
+ @ssl_verify = true
138
+ @ssl_verify_mode = nil
139
+ @ssl_ca_file = nil
140
+ @ssl_client_cert = nil
141
+ @ssl_client_key = nil
142
+ @params_encoder = nil
143
+ @timeout = 60
144
+ @debugging = false
145
+ @inject_format = false
146
+ @force_ending_format = false
147
+ @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
148
+
149
+ yield(self) if block_given?
150
+ end
151
+
152
+ # The default Configuration object.
153
+ def self.default
154
+ @@default ||= Configuration.new
155
+ end
156
+
157
+ def configure
158
+ yield(self) if block_given?
159
+ end
160
+
161
+ def scheme=(scheme)
162
+ # remove :// from scheme
163
+ @scheme = scheme.sub(/:\/\//, '')
164
+ end
165
+
166
+ def host=(host)
167
+ # remove http(s):// and anything after a slash
168
+ @host = host.sub(/https?:\/\//, '').split('/').first
169
+ end
170
+
171
+ def base_path=(base_path)
172
+ # Add leading and trailing slashes to base_path
173
+ @base_path = "/#{base_path}".gsub(/\/+/, '/')
174
+ @base_path = '' if @base_path == '/'
175
+ end
176
+
177
+ def base_url
178
+ "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '')
179
+ end
180
+
181
+ # Gets API key (with prefix if set).
182
+ # @param [String] param_name the parameter name of API key auth
183
+ def api_key_with_prefix(param_name)
184
+ if @api_key_prefix[param_name]
185
+ "#{@api_key_prefix[param_name]} #{@api_key[param_name]}"
186
+ else
187
+ @api_key[param_name]
188
+ end
189
+ end
190
+
191
+ # Gets Basic Auth token string
192
+ def basic_auth_token
193
+ 'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
194
+ end
195
+
196
+ # Returns Auth Settings hash for api client.
197
+ def auth_settings
198
+ {
199
+ 'basicAuth' =>
200
+ {
201
+ type: 'basic',
202
+ in: 'header',
203
+ key: 'Authorization',
204
+ value: basic_auth_token
205
+ },
206
+ }
207
+ end
208
+
209
+ # Returns an array of Server setting
210
+ def server_settings
211
+ [
212
+ {
213
+ url: "https://pulp/",
214
+ description: "No description provided",
215
+ }
216
+ ]
217
+ end
218
+
219
+ # Returns URL based on server settings
220
+ #
221
+ # @param index array index of the server settings
222
+ # @param variables hash of variable and the corresponding value
223
+ def server_url(index, variables = {})
224
+ servers = server_settings
225
+
226
+ # 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}"
229
+ end
230
+
231
+ server = servers[index]
232
+ url = server[:url]
233
+
234
+ # go through variable and assign a value
235
+ server[:variables].each do |name, variable|
236
+ if variables.key?(name)
237
+ if (server[:variables][name][:enum_values].include? variables[name])
238
+ url.gsub! "{" + name.to_s + "}", variables[name]
239
+ else
240
+ fail ArgumentError, "The variable `#{name}` in the server URL has invalid value #{variables[name]}. Must be #{server[:variables][name][:enum_values]}."
241
+ end
242
+ else
243
+ # use default value
244
+ url.gsub! "{" + name.to_s + "}", server[:variables][name][:default_value]
245
+ end
246
+ end
247
+
248
+ url
249
+ end
250
+ end
251
+ end