pulp_cookbook_client 0.1.0b9

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 (114) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +9 -0
  3. data/README.md +162 -0
  4. data/Rakefile +10 -0
  5. data/docs/AsyncOperationResponse.md +17 -0
  6. data/docs/ContentCookbooksApi.md +208 -0
  7. data/docs/ContentSummary.md +21 -0
  8. data/docs/ContentSummaryResponse.md +21 -0
  9. data/docs/CookbookCookbookDistribution.md +27 -0
  10. data/docs/CookbookCookbookDistributionResponse.md +33 -0
  11. data/docs/CookbookCookbookPackageContent.md +25 -0
  12. data/docs/CookbookCookbookPackageContentResponse.md +29 -0
  13. data/docs/CookbookCookbookPublication.md +19 -0
  14. data/docs/CookbookCookbookPublicationResponse.md +25 -0
  15. data/docs/CookbookCookbookRemote.md +59 -0
  16. data/docs/CookbookCookbookRemoteResponse.md +55 -0
  17. data/docs/CookbookCookbookRepository.md +25 -0
  18. data/docs/CookbookCookbookRepositoryResponse.md +33 -0
  19. data/docs/DistributionsCookbookApi.md +372 -0
  20. data/docs/PaginatedRepositoryVersionResponseList.md +23 -0
  21. data/docs/PaginatedcookbookCookbookDistributionResponseList.md +23 -0
  22. data/docs/PaginatedcookbookCookbookPackageContentResponseList.md +23 -0
  23. data/docs/PaginatedcookbookCookbookPublicationResponseList.md +23 -0
  24. data/docs/PaginatedcookbookCookbookRemoteResponseList.md +23 -0
  25. data/docs/PaginatedcookbookCookbookRepositoryResponseList.md +23 -0
  26. data/docs/PatchedcookbookCookbookDistribution.md +27 -0
  27. data/docs/PatchedcookbookCookbookRemote.md +59 -0
  28. data/docs/PatchedcookbookCookbookRepository.md +25 -0
  29. data/docs/PolicyEnum.md +16 -0
  30. data/docs/PublicationsCookbookApi.md +257 -0
  31. data/docs/RemotesCookbookApi.md +376 -0
  32. data/docs/RepositoriesCookbookApi.md +475 -0
  33. data/docs/RepositoriesCookbookVersionsApi.md +271 -0
  34. data/docs/RepositoryAddRemoveContent.md +21 -0
  35. data/docs/RepositorySyncURL.md +19 -0
  36. data/docs/RepositoryVersion.md +17 -0
  37. data/docs/RepositoryVersionResponse.md +27 -0
  38. data/git_push.sh +58 -0
  39. data/lib/pulp_cookbook_client/api/content_cookbooks_api.rb +264 -0
  40. data/lib/pulp_cookbook_client/api/distributions_cookbook_api.rb +457 -0
  41. data/lib/pulp_cookbook_client/api/publications_cookbook_api.rb +312 -0
  42. data/lib/pulp_cookbook_client/api/remotes_cookbook_api.rb +463 -0
  43. data/lib/pulp_cookbook_client/api/repositories_cookbook_api.rb +583 -0
  44. data/lib/pulp_cookbook_client/api/repositories_cookbook_versions_api.rb +339 -0
  45. data/lib/pulp_cookbook_client/api_client.rb +406 -0
  46. data/lib/pulp_cookbook_client/api_error.rb +57 -0
  47. data/lib/pulp_cookbook_client/configuration.rb +250 -0
  48. data/lib/pulp_cookbook_client/models/async_operation_response.rb +213 -0
  49. data/lib/pulp_cookbook_client/models/content_summary.rb +246 -0
  50. data/lib/pulp_cookbook_client/models/content_summary_response.rb +246 -0
  51. data/lib/pulp_cookbook_client/models/cookbook_cookbook_distribution.rb +308 -0
  52. data/lib/pulp_cookbook_client/models/cookbook_cookbook_distribution_response.rb +299 -0
  53. data/lib/pulp_cookbook_client/models/cookbook_cookbook_package_content.rb +287 -0
  54. data/lib/pulp_cookbook_client/models/cookbook_cookbook_package_content_response.rb +272 -0
  55. data/lib/pulp_cookbook_client/models/cookbook_cookbook_publication.rb +217 -0
  56. data/lib/pulp_cookbook_client/models/cookbook_cookbook_publication_response.rb +248 -0
  57. data/lib/pulp_cookbook_client/models/cookbook_cookbook_remote.rb +677 -0
  58. data/lib/pulp_cookbook_client/models/cookbook_cookbook_remote_response.rb +493 -0
  59. data/lib/pulp_cookbook_client/models/cookbook_cookbook_repository.rb +304 -0
  60. data/lib/pulp_cookbook_client/models/cookbook_cookbook_repository_response.rb +307 -0
  61. data/lib/pulp_cookbook_client/models/paginated_repository_version_response_list.rb +237 -0
  62. data/lib/pulp_cookbook_client/models/paginatedcookbook_cookbook_distribution_response_list.rb +237 -0
  63. data/lib/pulp_cookbook_client/models/paginatedcookbook_cookbook_package_content_response_list.rb +237 -0
  64. data/lib/pulp_cookbook_client/models/paginatedcookbook_cookbook_publication_response_list.rb +237 -0
  65. data/lib/pulp_cookbook_client/models/paginatedcookbook_cookbook_remote_response_list.rb +237 -0
  66. data/lib/pulp_cookbook_client/models/paginatedcookbook_cookbook_repository_response_list.rb +237 -0
  67. data/lib/pulp_cookbook_client/models/patchedcookbook_cookbook_distribution.rb +290 -0
  68. data/lib/pulp_cookbook_client/models/patchedcookbook_cookbook_remote.rb +659 -0
  69. data/lib/pulp_cookbook_client/models/patchedcookbook_cookbook_repository.rb +295 -0
  70. data/lib/pulp_cookbook_client/models/policy_enum.rb +37 -0
  71. data/lib/pulp_cookbook_client/models/repository_add_remove_content.rb +232 -0
  72. data/lib/pulp_cookbook_client/models/repository_sync_url.rb +220 -0
  73. data/lib/pulp_cookbook_client/models/repository_version.rb +208 -0
  74. data/lib/pulp_cookbook_client/models/repository_version_response.rb +255 -0
  75. data/lib/pulp_cookbook_client/version.rb +15 -0
  76. data/lib/pulp_cookbook_client.rb +72 -0
  77. data/pulp_cookbook_client.gemspec +39 -0
  78. data/spec/api/content_cookbooks_api_spec.rb +87 -0
  79. data/spec/api/distributions_cookbook_api_spec.rb +125 -0
  80. data/spec/api/publications_cookbook_api_spec.rb +98 -0
  81. data/spec/api/remotes_cookbook_api_spec.rb +127 -0
  82. data/spec/api/repositories_cookbook_api_spec.rb +146 -0
  83. data/spec/api/repositories_cookbook_versions_api_spec.rb +104 -0
  84. data/spec/api_client_spec.rb +188 -0
  85. data/spec/configuration_spec.rb +42 -0
  86. data/spec/models/async_operation_response_spec.rb +41 -0
  87. data/spec/models/content_summary_response_spec.rb +53 -0
  88. data/spec/models/content_summary_spec.rb +53 -0
  89. data/spec/models/cookbook_cookbook_distribution_response_spec.rb +89 -0
  90. data/spec/models/cookbook_cookbook_distribution_spec.rb +71 -0
  91. data/spec/models/cookbook_cookbook_package_content_response_spec.rb +77 -0
  92. data/spec/models/cookbook_cookbook_package_content_spec.rb +65 -0
  93. data/spec/models/cookbook_cookbook_publication_response_spec.rb +65 -0
  94. data/spec/models/cookbook_cookbook_publication_spec.rb +47 -0
  95. data/spec/models/cookbook_cookbook_remote_response_spec.rb +155 -0
  96. data/spec/models/cookbook_cookbook_remote_spec.rb +167 -0
  97. data/spec/models/cookbook_cookbook_repository_response_spec.rb +89 -0
  98. data/spec/models/cookbook_cookbook_repository_spec.rb +65 -0
  99. data/spec/models/paginated_repository_version_response_list_spec.rb +59 -0
  100. data/spec/models/paginatedcookbook_cookbook_distribution_response_list_spec.rb +59 -0
  101. data/spec/models/paginatedcookbook_cookbook_package_content_response_list_spec.rb +59 -0
  102. data/spec/models/paginatedcookbook_cookbook_publication_response_list_spec.rb +59 -0
  103. data/spec/models/paginatedcookbook_cookbook_remote_response_list_spec.rb +59 -0
  104. data/spec/models/paginatedcookbook_cookbook_repository_response_list_spec.rb +59 -0
  105. data/spec/models/patchedcookbook_cookbook_distribution_spec.rb +71 -0
  106. data/spec/models/patchedcookbook_cookbook_remote_spec.rb +167 -0
  107. data/spec/models/patchedcookbook_cookbook_repository_spec.rb +65 -0
  108. data/spec/models/policy_enum_spec.rb +35 -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/models/repository_version_spec.rb +41 -0
  113. data/spec/spec_helper.rb +111 -0
  114. metadata +251 -0
@@ -0,0 +1,406 @@
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 PulpCookbookClient
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
+ :method => http_method,
122
+ :headers => header_params,
123
+ :params => query_params,
124
+ :params_encoding => @config.params_encoding,
125
+ :timeout => @config.timeout,
126
+ :verbose => @config.debugging
127
+ }
128
+
129
+ if [:post, :patch, :put, :delete].include?(http_method)
130
+ req_body = build_request_body(header_params, form_params, opts[:body])
131
+ req_opts.update :body => req_body
132
+ if @config.debugging
133
+ @config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
134
+ end
135
+ end
136
+ request.headers = header_params
137
+ request.body = req_body
138
+ request.url url
139
+ request.params = query_params
140
+ download_file(request) if opts[:return_type] == 'File'
141
+ request
142
+ end
143
+
144
+ # Builds the HTTP request body
145
+ #
146
+ # @param [Hash] header_params Header parameters
147
+ # @param [Hash] form_params Query parameters
148
+ # @param [Object] body HTTP body (JSON/XML)
149
+ # @return [String] HTTP body data in the form of string
150
+ def build_request_body(header_params, form_params, body)
151
+ # http form
152
+ if header_params['Content-Type'] == 'application/x-www-form-urlencoded'
153
+ data = URI.encode_www_form(form_params)
154
+ elsif header_params['Content-Type'] == 'multipart/form-data'
155
+ data = {}
156
+ form_params.each do |key, value|
157
+ case value
158
+ when ::File, ::Tempfile
159
+ # TODO hardcode to application/octet-stream, need better way to detect content type
160
+ data[key] = Faraday::UploadIO.new(value.path, 'application/octet-stream', value.path)
161
+ when ::Array, nil
162
+ # let Faraday handle Array and nil parameters
163
+ data[key] = value
164
+ else
165
+ data[key] = value.to_s
166
+ end
167
+ end
168
+ elsif body
169
+ data = body.is_a?(String) ? body : body.to_json
170
+ else
171
+ data = nil
172
+ end
173
+ data
174
+ end
175
+
176
+ # Check if the given MIME is a JSON MIME.
177
+ # JSON MIME examples:
178
+ # application/json
179
+ # application/json; charset=UTF8
180
+ # APPLICATION/JSON
181
+ # */*
182
+ # @param [String] mime MIME
183
+ # @return [Boolean] True if the MIME is application/json
184
+ def json_mime?(mime)
185
+ (mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
186
+ end
187
+
188
+ # Deserialize the response to the given return type.
189
+ #
190
+ # @param [Response] response HTTP response
191
+ # @param [String] return_type some examples: "User", "Array<User>", "Hash<String, Integer>"
192
+ def deserialize(response, return_type)
193
+ body = response.body
194
+
195
+ # handle file downloading - return the File instance processed in request callbacks
196
+ # note that response body is empty when the file is written in chunks in request on_body callback
197
+ return @tempfile if return_type == 'File'
198
+
199
+ return nil if body.nil? || body.empty?
200
+
201
+ # return response body directly for String return type
202
+ return body if return_type == 'String'
203
+
204
+ # ensuring a default content type
205
+ content_type = response.headers['Content-Type'] || 'application/json'
206
+
207
+ fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
208
+
209
+ begin
210
+ data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
211
+ rescue JSON::ParserError => e
212
+ if %w(String Date DateTime).include?(return_type)
213
+ data = body
214
+ else
215
+ raise e
216
+ end
217
+ end
218
+
219
+ convert_to_type data, return_type
220
+ end
221
+
222
+ # Convert data to the given return type.
223
+ # @param [Object] data Data to be converted
224
+ # @param [String] return_type Return type
225
+ # @return [Mixed] Data in a particular type
226
+ def convert_to_type(data, return_type)
227
+ return nil if data.nil?
228
+ case return_type
229
+ when 'String'
230
+ data.to_s
231
+ when 'Integer'
232
+ data.to_i
233
+ when 'Float'
234
+ data.to_f
235
+ when 'Boolean'
236
+ data == true
237
+ when 'DateTime'
238
+ # parse date time (expecting ISO 8601 format)
239
+ DateTime.parse data
240
+ when 'Date'
241
+ # parse date time (expecting ISO 8601 format)
242
+ Date.parse data
243
+ when 'Object'
244
+ # generic object (usually a Hash), return directly
245
+ data
246
+ when /\AArray<(.+)>\z/
247
+ # e.g. Array<Pet>
248
+ sub_type = $1
249
+ data.map { |item| convert_to_type(item, sub_type) }
250
+ when /\AHash\<String, (.+)\>\z/
251
+ # e.g. Hash<String, Integer>
252
+ sub_type = $1
253
+ {}.tap do |hash|
254
+ data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
255
+ end
256
+ else
257
+ # models, e.g. Pet
258
+ PulpCookbookClient.const_get(return_type).build_from_hash(data)
259
+ end
260
+ end
261
+
262
+ # Save response body into a file in (the defined) temporary folder, using the filename
263
+ # from the "Content-Disposition" header if provided, otherwise a random filename.
264
+ # The response body is written to the file in chunks in order to handle files which
265
+ # size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
266
+ # process can use.
267
+ #
268
+ # @see Configuration#temp_folder_path
269
+ def download_file(request)
270
+ tempfile = nil
271
+ encoding = nil
272
+ request.on_headers do |response|
273
+ content_disposition = response.headers['Content-Disposition']
274
+ if content_disposition && content_disposition =~ /filename=/i
275
+ filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
276
+ prefix = sanitize_filename(filename)
277
+ else
278
+ prefix = 'download-'
279
+ end
280
+ prefix = prefix + '-' unless prefix.end_with?('-')
281
+ encoding = response.body.encoding
282
+ tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
283
+ @tempfile = tempfile
284
+ end
285
+ request.on_body do |chunk|
286
+ chunk.force_encoding(encoding)
287
+ tempfile.write(chunk)
288
+ end
289
+ request.on_complete do |response|
290
+ if tempfile
291
+ tempfile.close
292
+ @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
293
+ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
294
+ "will be deleted automatically with GC. It's also recommended to delete the temp file "\
295
+ "explicitly with `tempfile.delete`"
296
+ end
297
+ end
298
+ end
299
+
300
+ # Sanitize filename by removing path.
301
+ # e.g. ../../sun.gif becomes sun.gif
302
+ #
303
+ # @param [String] filename the filename to be sanitized
304
+ # @return [String] the sanitized filename
305
+ def sanitize_filename(filename)
306
+ filename.gsub(/.*[\/\\]/, '')
307
+ end
308
+
309
+ def build_request_url(path)
310
+ # Add leading and trailing slashes to path
311
+ path = "/#{path}".gsub(/\/+/, '/')
312
+ @config.base_url + path
313
+ end
314
+
315
+ # Update hearder and query params based on authentication settings.
316
+ #
317
+ # @param [Hash] header_params Header parameters
318
+ # @param [Hash] query_params Query parameters
319
+ # @param [String] auth_names Authentication scheme name
320
+ def update_params_for_auth!(header_params, query_params, auth_names)
321
+ Array(auth_names).each do |auth_name|
322
+ auth_setting = @config.auth_settings[auth_name]
323
+ next unless auth_setting
324
+ case auth_setting[:in]
325
+ when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
326
+ when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
327
+ else fail ArgumentError, 'Authentication token must be in `query` of `header`'
328
+ end
329
+ end
330
+ end
331
+
332
+ # Sets user agent in HTTP header
333
+ #
334
+ # @param [String] user_agent User agent (e.g. openapi-generator/ruby/1.0.0)
335
+ def user_agent=(user_agent)
336
+ @user_agent = user_agent
337
+ @default_headers['User-Agent'] = @user_agent
338
+ end
339
+
340
+ # Return Accept header based on an array of accepts provided.
341
+ # @param [Array] accepts array for Accept
342
+ # @return [String] the Accept header (e.g. application/json)
343
+ def select_header_accept(accepts)
344
+ return nil if accepts.nil? || accepts.empty?
345
+ # use JSON when present, otherwise use all of the provided
346
+ json_accept = accepts.find { |s| json_mime?(s) }
347
+ json_accept || accepts.join(',')
348
+ end
349
+
350
+ # Return Content-Type header based on an array of content types provided.
351
+ # @param [Array] content_types array for Content-Type
352
+ # @return [String] the Content-Type header (e.g. application/json)
353
+ def select_header_content_type(content_types)
354
+ # use application/json by default
355
+ return 'application/json' if content_types.nil? || content_types.empty?
356
+ # use JSON when present, otherwise use the first one
357
+ json_content_type = content_types.find { |s| json_mime?(s) }
358
+ json_content_type || content_types.first
359
+ end
360
+
361
+ # Convert object (array, hash, object, etc) to JSON string.
362
+ # @param [Object] model object to be converted into JSON string
363
+ # @return [String] JSON string representation of the object
364
+ def object_to_http_body(model)
365
+ return model if model.nil? || model.is_a?(String)
366
+ local_body = nil
367
+ if model.is_a?(Array)
368
+ local_body = model.map { |m| object_to_hash(m) }
369
+ else
370
+ local_body = object_to_hash(model)
371
+ end
372
+ local_body.to_json
373
+ end
374
+
375
+ # Convert object(non-array) to hash.
376
+ # @param [Object] obj object to be converted into JSON string
377
+ # @return [String] JSON string representation of the object
378
+ def object_to_hash(obj)
379
+ if obj.respond_to?(:to_hash)
380
+ obj.to_hash
381
+ else
382
+ obj
383
+ end
384
+ end
385
+
386
+ # Build parameter value according to the given collection format.
387
+ # @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
388
+ def build_collection_param(param, collection_format)
389
+ case collection_format
390
+ when :csv
391
+ param.join(',')
392
+ when :ssv
393
+ param.join(' ')
394
+ when :tsv
395
+ param.join("\t")
396
+ when :pipes
397
+ param.join('|')
398
+ when :multi
399
+ # return the array directly as typhoeus will handle it as expected
400
+ param
401
+ else
402
+ fail "unknown collection format: #{collection_format.inspect}"
403
+ end
404
+ end
405
+ end
406
+ 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 PulpCookbookClient
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,250 @@
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 PulpCookbookClient
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
+ @debugging = false
144
+ @inject_format = false
145
+ @force_ending_format = false
146
+ @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
147
+
148
+ yield(self) if block_given?
149
+ end
150
+
151
+ # The default Configuration object.
152
+ def self.default
153
+ @@default ||= Configuration.new
154
+ end
155
+
156
+ def configure
157
+ yield(self) if block_given?
158
+ end
159
+
160
+ def scheme=(scheme)
161
+ # remove :// from scheme
162
+ @scheme = scheme.sub(/:\/\//, '')
163
+ end
164
+
165
+ def host=(host)
166
+ # remove http(s):// and anything after a slash
167
+ @host = host.sub(/https?:\/\//, '').split('/').first
168
+ end
169
+
170
+ def base_path=(base_path)
171
+ # Add leading and trailing slashes to base_path
172
+ @base_path = "/#{base_path}".gsub(/\/+/, '/')
173
+ @base_path = '' if @base_path == '/'
174
+ end
175
+
176
+ def base_url
177
+ "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '')
178
+ end
179
+
180
+ # Gets API key (with prefix if set).
181
+ # @param [String] param_name the parameter name of API key auth
182
+ def api_key_with_prefix(param_name)
183
+ if @api_key_prefix[param_name]
184
+ "#{@api_key_prefix[param_name]} #{@api_key[param_name]}"
185
+ else
186
+ @api_key[param_name]
187
+ end
188
+ end
189
+
190
+ # Gets Basic Auth token string
191
+ def basic_auth_token
192
+ 'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
193
+ end
194
+
195
+ # Returns Auth Settings hash for api client.
196
+ def auth_settings
197
+ {
198
+ 'basicAuth' =>
199
+ {
200
+ type: 'basic',
201
+ in: 'header',
202
+ key: 'Authorization',
203
+ value: basic_auth_token
204
+ },
205
+ }
206
+ end
207
+
208
+ # Returns an array of Server setting
209
+ def server_settings
210
+ [
211
+ {
212
+ url: "https://pulp/",
213
+ description: "No description provided",
214
+ }
215
+ ]
216
+ end
217
+
218
+ # Returns URL based on server settings
219
+ #
220
+ # @param index array index of the server settings
221
+ # @param variables hash of variable and the corresponding value
222
+ def server_url(index, variables = {})
223
+ servers = server_settings
224
+
225
+ # check array index out of bound
226
+ if (index < 0 || index >= servers.size)
227
+ fail ArgumentError, "Invalid index #{index} when selecting the server. Must be less than #{servers.size}"
228
+ end
229
+
230
+ server = servers[index]
231
+ url = server[:url]
232
+
233
+ # go through variable and assign a value
234
+ server[:variables].each do |name, variable|
235
+ if variables.key?(name)
236
+ if (server[:variables][name][:enum_values].include? variables[name])
237
+ url.gsub! "{" + name.to_s + "}", variables[name]
238
+ else
239
+ fail ArgumentError, "The variable `#{name}` in the server URL has invalid value #{variables[name]}. Must be #{server[:variables][name][:enum_values]}."
240
+ end
241
+ else
242
+ # use default value
243
+ url.gsub! "{" + name.to_s + "}", server[:variables][name][:default_value]
244
+ end
245
+ end
246
+
247
+ url
248
+ end
249
+ end
250
+ end