pulp_2to3_migration_client 0.12.0 → 0.12.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -4
  3. data/lib/pulp_2to3_migration_client/api_client.rb +4 -2
  4. data/lib/pulp_2to3_migration_client/configuration.rb +7 -0
  5. data/lib/pulp_2to3_migration_client/version.rb +1 -1
  6. metadata +8 -75
  7. data/build/lib/pulpcore/__init__.py +0 -2
  8. data/build/lib/pulpcore/client/__init__.py +0 -2
  9. data/build/lib/pulpcore/client/pulp_2to3_migration/__init__.py +0 -43
  10. data/build/lib/pulpcore/client/pulp_2to3_migration/api/__init__.py +0 -8
  11. data/build/lib/pulpcore/client/pulp_2to3_migration/api/migration_plans_api.py +0 -761
  12. data/build/lib/pulpcore/client/pulp_2to3_migration/api/pulp2_content_api.py +0 -350
  13. data/build/lib/pulpcore/client/pulp_2to3_migration/api/pulp2_repositories_api.py +0 -313
  14. data/build/lib/pulpcore/client/pulp_2to3_migration/api_client.py +0 -667
  15. data/build/lib/pulpcore/client/pulp_2to3_migration/configuration.py +0 -427
  16. data/build/lib/pulpcore/client/pulp_2to3_migration/exceptions.py +0 -121
  17. data/build/lib/pulpcore/client/pulp_2to3_migration/models/__init__.py +0 -26
  18. data/build/lib/pulpcore/client/pulp_2to3_migration/models/async_operation_response.py +0 -124
  19. data/build/lib/pulpcore/client/pulp_2to3_migration/models/migration_plan_run.py +0 -179
  20. data/build/lib/pulpcore/client/pulp_2to3_migration/models/paginatedpulp2to3_migration_migration_plan_response_list.py +0 -197
  21. data/build/lib/pulpcore/client/pulp_2to3_migration/models/paginatedpulp2to3_migration_pulp2_content_response_list.py +0 -197
  22. data/build/lib/pulpcore/client/pulp_2to3_migration/models/paginatedpulp2to3_migration_pulp2_repository_response_list.py +0 -197
  23. data/build/lib/pulpcore/client/pulp_2to3_migration/models/pulp2to3_migration_migration_plan.py +0 -124
  24. data/build/lib/pulpcore/client/pulp_2to3_migration/models/pulp2to3_migration_migration_plan_response.py +0 -178
  25. data/build/lib/pulpcore/client/pulp_2to3_migration/models/pulp2to3_migration_pulp2_content_response.py +0 -338
  26. data/build/lib/pulpcore/client/pulp_2to3_migration/models/pulp2to3_migration_pulp2_repository_response.py +0 -416
  27. data/build/lib/pulpcore/client/pulp_2to3_migration/rest.py +0 -292
  28. data/dist/pulp_2to3_migration-client-0.12.0.tar.gz +0 -0
  29. data/dist/pulp_2to3_migration_client-0.12.0-py3-none-any.whl +0 -0
  30. data/pulp_2to3_migration_client.egg-info/PKG-INFO +0 -15
  31. data/pulp_2to3_migration_client.egg-info/SOURCES.txt +0 -41
  32. data/pulp_2to3_migration_client.egg-info/dependency_links.txt +0 -1
  33. data/pulp_2to3_migration_client.egg-info/requires.txt +0 -4
  34. data/pulp_2to3_migration_client.egg-info/top_level.txt +0 -1
  35. data/pulpcore/__init__.py +0 -2
  36. data/pulpcore/client/__init__.py +0 -2
  37. data/pulpcore/client/pulp_2to3_migration/__init__.py +0 -43
  38. data/pulpcore/client/pulp_2to3_migration/api/__init__.py +0 -8
  39. data/pulpcore/client/pulp_2to3_migration/api/migration_plans_api.py +0 -761
  40. data/pulpcore/client/pulp_2to3_migration/api/pulp2_content_api.py +0 -350
  41. data/pulpcore/client/pulp_2to3_migration/api/pulp2_repositories_api.py +0 -313
  42. data/pulpcore/client/pulp_2to3_migration/api_client.py +0 -667
  43. data/pulpcore/client/pulp_2to3_migration/configuration.py +0 -427
  44. data/pulpcore/client/pulp_2to3_migration/exceptions.py +0 -121
  45. data/pulpcore/client/pulp_2to3_migration/models/__init__.py +0 -26
  46. data/pulpcore/client/pulp_2to3_migration/models/async_operation_response.py +0 -124
  47. data/pulpcore/client/pulp_2to3_migration/models/migration_plan_run.py +0 -179
  48. data/pulpcore/client/pulp_2to3_migration/models/paginatedpulp2to3_migration_migration_plan_response_list.py +0 -197
  49. data/pulpcore/client/pulp_2to3_migration/models/paginatedpulp2to3_migration_pulp2_content_response_list.py +0 -197
  50. data/pulpcore/client/pulp_2to3_migration/models/paginatedpulp2to3_migration_pulp2_repository_response_list.py +0 -197
  51. data/pulpcore/client/pulp_2to3_migration/models/pulp2to3_migration_migration_plan.py +0 -124
  52. data/pulpcore/client/pulp_2to3_migration/models/pulp2to3_migration_migration_plan_response.py +0 -178
  53. data/pulpcore/client/pulp_2to3_migration/models/pulp2to3_migration_pulp2_content_response.py +0 -338
  54. data/pulpcore/client/pulp_2to3_migration/models/pulp2to3_migration_pulp2_repository_response.py +0 -416
  55. data/pulpcore/client/pulp_2to3_migration/rest.py +0 -292
  56. data/requirements.txt +0 -6
  57. data/setup.cfg +0 -2
  58. data/setup.py +0 -42
  59. data/test-requirements.txt +0 -3
  60. data/test/__init__.py +0 -0
  61. data/test/test_async_operation_response.py +0 -54
  62. data/test/test_migration_plan_run.py +0 -55
  63. data/test/test_migration_plans_api.py +0 -76
  64. data/test/test_paginatedpulp2to3_migration_migration_plan_response_list.py +0 -61
  65. data/test/test_paginatedpulp2to3_migration_pulp2_content_response_list.py +0 -67
  66. data/test/test_paginatedpulp2to3_migration_pulp2_repository_response_list.py +0 -72
  67. data/test/test_pulp2_content_api.py +0 -48
  68. data/test/test_pulp2_repositories_api.py +0 -48
  69. data/test/test_pulp2to3_migration_migration_plan.py +0 -54
  70. data/test/test_pulp2to3_migration_migration_plan_response.py +0 -56
  71. data/test/test_pulp2to3_migration_pulp2_content_response.py +0 -65
  72. data/test/test_pulp2to3_migration_pulp2_repository_response.py +0 -69
  73. data/tox.ini +0 -9
@@ -1,416 +0,0 @@
1
- # coding: utf-8
2
-
3
- """
4
- Pulp 3 API
5
-
6
- Fetch, Upload, Organize, and Distribute Software Packages # noqa: E501
7
-
8
- The version of the OpenAPI document: v3
9
- Contact: pulp-list@redhat.com
10
- Generated by: https://openapi-generator.tech
11
- """
12
-
13
-
14
- import pprint
15
- import re # noqa: F401
16
-
17
- import six
18
-
19
- from pulpcore.client.pulp_2to3_migration.configuration import Configuration
20
-
21
-
22
- class Pulp2to3MigrationPulp2RepositoryResponse(object):
23
- """NOTE: This class is auto generated by OpenAPI Generator.
24
- Ref: https://openapi-generator.tech
25
-
26
- Do not edit the class manually.
27
- """
28
-
29
- """
30
- Attributes:
31
- openapi_types (dict): The key is attribute name
32
- and the value is attribute type.
33
- attribute_map (dict): The key is attribute name
34
- and the value is json key in definition.
35
- """
36
- openapi_types = {
37
- 'pulp_href': 'str',
38
- 'pulp_created': 'datetime',
39
- 'pulp2_object_id': 'str',
40
- 'pulp2_repo_id': 'str',
41
- 'pulp2_repo_type': 'str',
42
- 'is_migrated': 'bool',
43
- 'not_in_plan': 'bool',
44
- 'pulp3_repository_version': 'str',
45
- 'pulp3_remote_href': 'str',
46
- 'pulp3_publication_href': 'str',
47
- 'pulp3_distribution_hrefs': 'list[str]',
48
- 'pulp3_repository_href': 'str'
49
- }
50
-
51
- attribute_map = {
52
- 'pulp_href': 'pulp_href',
53
- 'pulp_created': 'pulp_created',
54
- 'pulp2_object_id': 'pulp2_object_id',
55
- 'pulp2_repo_id': 'pulp2_repo_id',
56
- 'pulp2_repo_type': 'pulp2_repo_type',
57
- 'is_migrated': 'is_migrated',
58
- 'not_in_plan': 'not_in_plan',
59
- 'pulp3_repository_version': 'pulp3_repository_version',
60
- 'pulp3_remote_href': 'pulp3_remote_href',
61
- 'pulp3_publication_href': 'pulp3_publication_href',
62
- 'pulp3_distribution_hrefs': 'pulp3_distribution_hrefs',
63
- 'pulp3_repository_href': 'pulp3_repository_href'
64
- }
65
-
66
- def __init__(self, pulp_href=None, pulp_created=None, pulp2_object_id=None, pulp2_repo_id=None, pulp2_repo_type=None, is_migrated=False, not_in_plan=False, pulp3_repository_version=None, pulp3_remote_href=None, pulp3_publication_href=None, pulp3_distribution_hrefs=None, pulp3_repository_href=None, local_vars_configuration=None): # noqa: E501
67
- """Pulp2to3MigrationPulp2RepositoryResponse - a model defined in OpenAPI""" # noqa: E501
68
- if local_vars_configuration is None:
69
- local_vars_configuration = Configuration()
70
- self.local_vars_configuration = local_vars_configuration
71
-
72
- self._pulp_href = None
73
- self._pulp_created = None
74
- self._pulp2_object_id = None
75
- self._pulp2_repo_id = None
76
- self._pulp2_repo_type = None
77
- self._is_migrated = None
78
- self._not_in_plan = None
79
- self._pulp3_repository_version = None
80
- self._pulp3_remote_href = None
81
- self._pulp3_publication_href = None
82
- self._pulp3_distribution_hrefs = None
83
- self._pulp3_repository_href = None
84
- self.discriminator = None
85
-
86
- if pulp_href is not None:
87
- self.pulp_href = pulp_href
88
- if pulp_created is not None:
89
- self.pulp_created = pulp_created
90
- self.pulp2_object_id = pulp2_object_id
91
- self.pulp2_repo_id = pulp2_repo_id
92
- self.pulp2_repo_type = pulp2_repo_type
93
- if is_migrated is not None:
94
- self.is_migrated = is_migrated
95
- if not_in_plan is not None:
96
- self.not_in_plan = not_in_plan
97
- self.pulp3_repository_version = pulp3_repository_version
98
- if pulp3_remote_href is not None:
99
- self.pulp3_remote_href = pulp3_remote_href
100
- if pulp3_publication_href is not None:
101
- self.pulp3_publication_href = pulp3_publication_href
102
- if pulp3_distribution_hrefs is not None:
103
- self.pulp3_distribution_hrefs = pulp3_distribution_hrefs
104
- if pulp3_repository_href is not None:
105
- self.pulp3_repository_href = pulp3_repository_href
106
-
107
- @property
108
- def pulp_href(self):
109
- """Gets the pulp_href of this Pulp2to3MigrationPulp2RepositoryResponse. # noqa: E501
110
-
111
-
112
- :return: The pulp_href of this Pulp2to3MigrationPulp2RepositoryResponse. # noqa: E501
113
- :rtype: str
114
- """
115
- return self._pulp_href
116
-
117
- @pulp_href.setter
118
- def pulp_href(self, pulp_href):
119
- """Sets the pulp_href of this Pulp2to3MigrationPulp2RepositoryResponse.
120
-
121
-
122
- :param pulp_href: The pulp_href of this Pulp2to3MigrationPulp2RepositoryResponse. # noqa: E501
123
- :type: str
124
- """
125
-
126
- self._pulp_href = pulp_href
127
-
128
- @property
129
- def pulp_created(self):
130
- """Gets the pulp_created of this Pulp2to3MigrationPulp2RepositoryResponse. # noqa: E501
131
-
132
- Timestamp of creation. # noqa: E501
133
-
134
- :return: The pulp_created of this Pulp2to3MigrationPulp2RepositoryResponse. # noqa: E501
135
- :rtype: datetime
136
- """
137
- return self._pulp_created
138
-
139
- @pulp_created.setter
140
- def pulp_created(self, pulp_created):
141
- """Sets the pulp_created of this Pulp2to3MigrationPulp2RepositoryResponse.
142
-
143
- Timestamp of creation. # noqa: E501
144
-
145
- :param pulp_created: The pulp_created of this Pulp2to3MigrationPulp2RepositoryResponse. # noqa: E501
146
- :type: datetime
147
- """
148
-
149
- self._pulp_created = pulp_created
150
-
151
- @property
152
- def pulp2_object_id(self):
153
- """Gets the pulp2_object_id of this Pulp2to3MigrationPulp2RepositoryResponse. # noqa: E501
154
-
155
-
156
- :return: The pulp2_object_id of this Pulp2to3MigrationPulp2RepositoryResponse. # noqa: E501
157
- :rtype: str
158
- """
159
- return self._pulp2_object_id
160
-
161
- @pulp2_object_id.setter
162
- def pulp2_object_id(self, pulp2_object_id):
163
- """Sets the pulp2_object_id of this Pulp2to3MigrationPulp2RepositoryResponse.
164
-
165
-
166
- :param pulp2_object_id: The pulp2_object_id of this Pulp2to3MigrationPulp2RepositoryResponse. # noqa: E501
167
- :type: str
168
- """
169
- if self.local_vars_configuration.client_side_validation and pulp2_object_id is None: # noqa: E501
170
- raise ValueError("Invalid value for `pulp2_object_id`, must not be `None`") # noqa: E501
171
- if (self.local_vars_configuration.client_side_validation and
172
- pulp2_object_id is not None and len(pulp2_object_id) > 255):
173
- raise ValueError("Invalid value for `pulp2_object_id`, length must be less than or equal to `255`") # noqa: E501
174
-
175
- self._pulp2_object_id = pulp2_object_id
176
-
177
- @property
178
- def pulp2_repo_id(self):
179
- """Gets the pulp2_repo_id of this Pulp2to3MigrationPulp2RepositoryResponse. # noqa: E501
180
-
181
-
182
- :return: The pulp2_repo_id of this Pulp2to3MigrationPulp2RepositoryResponse. # noqa: E501
183
- :rtype: str
184
- """
185
- return self._pulp2_repo_id
186
-
187
- @pulp2_repo_id.setter
188
- def pulp2_repo_id(self, pulp2_repo_id):
189
- """Sets the pulp2_repo_id of this Pulp2to3MigrationPulp2RepositoryResponse.
190
-
191
-
192
- :param pulp2_repo_id: The pulp2_repo_id of this Pulp2to3MigrationPulp2RepositoryResponse. # noqa: E501
193
- :type: str
194
- """
195
- if self.local_vars_configuration.client_side_validation and pulp2_repo_id is None: # noqa: E501
196
- raise ValueError("Invalid value for `pulp2_repo_id`, must not be `None`") # noqa: E501
197
-
198
- self._pulp2_repo_id = pulp2_repo_id
199
-
200
- @property
201
- def pulp2_repo_type(self):
202
- """Gets the pulp2_repo_type of this Pulp2to3MigrationPulp2RepositoryResponse. # noqa: E501
203
-
204
-
205
- :return: The pulp2_repo_type of this Pulp2to3MigrationPulp2RepositoryResponse. # noqa: E501
206
- :rtype: str
207
- """
208
- return self._pulp2_repo_type
209
-
210
- @pulp2_repo_type.setter
211
- def pulp2_repo_type(self, pulp2_repo_type):
212
- """Sets the pulp2_repo_type of this Pulp2to3MigrationPulp2RepositoryResponse.
213
-
214
-
215
- :param pulp2_repo_type: The pulp2_repo_type of this Pulp2to3MigrationPulp2RepositoryResponse. # noqa: E501
216
- :type: str
217
- """
218
- if self.local_vars_configuration.client_side_validation and pulp2_repo_type is None: # noqa: E501
219
- raise ValueError("Invalid value for `pulp2_repo_type`, must not be `None`") # noqa: E501
220
-
221
- self._pulp2_repo_type = pulp2_repo_type
222
-
223
- @property
224
- def is_migrated(self):
225
- """Gets the is_migrated of this Pulp2to3MigrationPulp2RepositoryResponse. # noqa: E501
226
-
227
-
228
- :return: The is_migrated of this Pulp2to3MigrationPulp2RepositoryResponse. # noqa: E501
229
- :rtype: bool
230
- """
231
- return self._is_migrated
232
-
233
- @is_migrated.setter
234
- def is_migrated(self, is_migrated):
235
- """Sets the is_migrated of this Pulp2to3MigrationPulp2RepositoryResponse.
236
-
237
-
238
- :param is_migrated: The is_migrated of this Pulp2to3MigrationPulp2RepositoryResponse. # noqa: E501
239
- :type: bool
240
- """
241
-
242
- self._is_migrated = is_migrated
243
-
244
- @property
245
- def not_in_plan(self):
246
- """Gets the not_in_plan of this Pulp2to3MigrationPulp2RepositoryResponse. # noqa: E501
247
-
248
-
249
- :return: The not_in_plan of this Pulp2to3MigrationPulp2RepositoryResponse. # noqa: E501
250
- :rtype: bool
251
- """
252
- return self._not_in_plan
253
-
254
- @not_in_plan.setter
255
- def not_in_plan(self, not_in_plan):
256
- """Sets the not_in_plan of this Pulp2to3MigrationPulp2RepositoryResponse.
257
-
258
-
259
- :param not_in_plan: The not_in_plan of this Pulp2to3MigrationPulp2RepositoryResponse. # noqa: E501
260
- :type: bool
261
- """
262
-
263
- self._not_in_plan = not_in_plan
264
-
265
- @property
266
- def pulp3_repository_version(self):
267
- """Gets the pulp3_repository_version of this Pulp2to3MigrationPulp2RepositoryResponse. # noqa: E501
268
-
269
- RepositoryVersion to be served # noqa: E501
270
-
271
- :return: The pulp3_repository_version of this Pulp2to3MigrationPulp2RepositoryResponse. # noqa: E501
272
- :rtype: str
273
- """
274
- return self._pulp3_repository_version
275
-
276
- @pulp3_repository_version.setter
277
- def pulp3_repository_version(self, pulp3_repository_version):
278
- """Sets the pulp3_repository_version of this Pulp2to3MigrationPulp2RepositoryResponse.
279
-
280
- RepositoryVersion to be served # noqa: E501
281
-
282
- :param pulp3_repository_version: The pulp3_repository_version of this Pulp2to3MigrationPulp2RepositoryResponse. # noqa: E501
283
- :type: str
284
- """
285
-
286
- self._pulp3_repository_version = pulp3_repository_version
287
-
288
- @property
289
- def pulp3_remote_href(self):
290
- """Gets the pulp3_remote_href of this Pulp2to3MigrationPulp2RepositoryResponse. # noqa: E501
291
-
292
-
293
- :return: The pulp3_remote_href of this Pulp2to3MigrationPulp2RepositoryResponse. # noqa: E501
294
- :rtype: str
295
- """
296
- return self._pulp3_remote_href
297
-
298
- @pulp3_remote_href.setter
299
- def pulp3_remote_href(self, pulp3_remote_href):
300
- """Sets the pulp3_remote_href of this Pulp2to3MigrationPulp2RepositoryResponse.
301
-
302
-
303
- :param pulp3_remote_href: The pulp3_remote_href of this Pulp2to3MigrationPulp2RepositoryResponse. # noqa: E501
304
- :type: str
305
- """
306
-
307
- self._pulp3_remote_href = pulp3_remote_href
308
-
309
- @property
310
- def pulp3_publication_href(self):
311
- """Gets the pulp3_publication_href of this Pulp2to3MigrationPulp2RepositoryResponse. # noqa: E501
312
-
313
-
314
- :return: The pulp3_publication_href of this Pulp2to3MigrationPulp2RepositoryResponse. # noqa: E501
315
- :rtype: str
316
- """
317
- return self._pulp3_publication_href
318
-
319
- @pulp3_publication_href.setter
320
- def pulp3_publication_href(self, pulp3_publication_href):
321
- """Sets the pulp3_publication_href of this Pulp2to3MigrationPulp2RepositoryResponse.
322
-
323
-
324
- :param pulp3_publication_href: The pulp3_publication_href of this Pulp2to3MigrationPulp2RepositoryResponse. # noqa: E501
325
- :type: str
326
- """
327
-
328
- self._pulp3_publication_href = pulp3_publication_href
329
-
330
- @property
331
- def pulp3_distribution_hrefs(self):
332
- """Gets the pulp3_distribution_hrefs of this Pulp2to3MigrationPulp2RepositoryResponse. # noqa: E501
333
-
334
-
335
- :return: The pulp3_distribution_hrefs of this Pulp2to3MigrationPulp2RepositoryResponse. # noqa: E501
336
- :rtype: list[str]
337
- """
338
- return self._pulp3_distribution_hrefs
339
-
340
- @pulp3_distribution_hrefs.setter
341
- def pulp3_distribution_hrefs(self, pulp3_distribution_hrefs):
342
- """Sets the pulp3_distribution_hrefs of this Pulp2to3MigrationPulp2RepositoryResponse.
343
-
344
-
345
- :param pulp3_distribution_hrefs: The pulp3_distribution_hrefs of this Pulp2to3MigrationPulp2RepositoryResponse. # noqa: E501
346
- :type: list[str]
347
- """
348
-
349
- self._pulp3_distribution_hrefs = pulp3_distribution_hrefs
350
-
351
- @property
352
- def pulp3_repository_href(self):
353
- """Gets the pulp3_repository_href of this Pulp2to3MigrationPulp2RepositoryResponse. # noqa: E501
354
-
355
-
356
- :return: The pulp3_repository_href of this Pulp2to3MigrationPulp2RepositoryResponse. # noqa: E501
357
- :rtype: str
358
- """
359
- return self._pulp3_repository_href
360
-
361
- @pulp3_repository_href.setter
362
- def pulp3_repository_href(self, pulp3_repository_href):
363
- """Sets the pulp3_repository_href of this Pulp2to3MigrationPulp2RepositoryResponse.
364
-
365
-
366
- :param pulp3_repository_href: The pulp3_repository_href of this Pulp2to3MigrationPulp2RepositoryResponse. # noqa: E501
367
- :type: str
368
- """
369
-
370
- self._pulp3_repository_href = pulp3_repository_href
371
-
372
- def to_dict(self):
373
- """Returns the model properties as a dict"""
374
- result = {}
375
-
376
- for attr, _ in six.iteritems(self.openapi_types):
377
- value = getattr(self, attr)
378
- if isinstance(value, list):
379
- result[attr] = list(map(
380
- lambda x: x.to_dict() if hasattr(x, "to_dict") else x,
381
- value
382
- ))
383
- elif hasattr(value, "to_dict"):
384
- result[attr] = value.to_dict()
385
- elif isinstance(value, dict):
386
- result[attr] = dict(map(
387
- lambda item: (item[0], item[1].to_dict())
388
- if hasattr(item[1], "to_dict") else item,
389
- value.items()
390
- ))
391
- else:
392
- result[attr] = value
393
-
394
- return result
395
-
396
- def to_str(self):
397
- """Returns the string representation of the model"""
398
- return pprint.pformat(self.to_dict())
399
-
400
- def __repr__(self):
401
- """For `print` and `pprint`"""
402
- return self.to_str()
403
-
404
- def __eq__(self, other):
405
- """Returns true if both objects are equal"""
406
- if not isinstance(other, Pulp2to3MigrationPulp2RepositoryResponse):
407
- return False
408
-
409
- return self.to_dict() == other.to_dict()
410
-
411
- def __ne__(self, other):
412
- """Returns true if both objects are not equal"""
413
- if not isinstance(other, Pulp2to3MigrationPulp2RepositoryResponse):
414
- return True
415
-
416
- return self.to_dict() != other.to_dict()
@@ -1,292 +0,0 @@
1
- # coding: utf-8
2
-
3
- """
4
- Pulp 3 API
5
-
6
- Fetch, Upload, Organize, and Distribute Software Packages # noqa: E501
7
-
8
- The version of the OpenAPI document: v3
9
- Contact: pulp-list@redhat.com
10
- Generated by: https://openapi-generator.tech
11
- """
12
-
13
-
14
- from __future__ import absolute_import
15
-
16
- import io
17
- import json
18
- import logging
19
- import re
20
- import ssl
21
-
22
- import certifi
23
- # python 2 and python 3 compatibility library
24
- import six
25
- from six.moves.urllib.parse import urlencode
26
- import urllib3
27
-
28
- from pulpcore.client.pulp_2to3_migration.exceptions import ApiException, ApiValueError
29
-
30
-
31
- logger = logging.getLogger(__name__)
32
-
33
-
34
- class RESTResponse(io.IOBase):
35
-
36
- def __init__(self, resp):
37
- self.urllib3_response = resp
38
- self.status = resp.status
39
- self.reason = resp.reason
40
- self.data = resp.data
41
-
42
- def getheaders(self):
43
- """Returns a dictionary of the response headers."""
44
- return self.urllib3_response.getheaders()
45
-
46
- def getheader(self, name, default=None):
47
- """Returns a given response header."""
48
- return self.urllib3_response.getheader(name, default)
49
-
50
-
51
- class RESTClientObject(object):
52
-
53
- def __init__(self, configuration, pools_size=4, maxsize=None):
54
- # urllib3.PoolManager will pass all kw parameters to connectionpool
55
- # https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/poolmanager.py#L75 # noqa: E501
56
- # https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/connectionpool.py#L680 # noqa: E501
57
- # maxsize is the number of requests to host that are allowed in parallel # noqa: E501
58
- # Custom SSL certificates and client certificates: http://urllib3.readthedocs.io/en/latest/advanced-usage.html # noqa: E501
59
-
60
- # cert_reqs
61
- if configuration.verify_ssl:
62
- cert_reqs = ssl.CERT_REQUIRED
63
- else:
64
- cert_reqs = ssl.CERT_NONE
65
-
66
- # ca_certs
67
- if configuration.ssl_ca_cert:
68
- ca_certs = configuration.ssl_ca_cert
69
- else:
70
- # if not set certificate file, use Mozilla's root certificates.
71
- ca_certs = certifi.where()
72
-
73
- addition_pool_args = {}
74
- if configuration.assert_hostname is not None:
75
- addition_pool_args['assert_hostname'] = configuration.assert_hostname # noqa: E501
76
-
77
- if configuration.retries is not None:
78
- addition_pool_args['retries'] = configuration.retries
79
-
80
- if maxsize is None:
81
- if configuration.connection_pool_maxsize is not None:
82
- maxsize = configuration.connection_pool_maxsize
83
- else:
84
- maxsize = 4
85
-
86
- # https pool manager
87
- if configuration.proxy:
88
- self.pool_manager = urllib3.ProxyManager(
89
- num_pools=pools_size,
90
- maxsize=maxsize,
91
- cert_reqs=cert_reqs,
92
- ca_certs=ca_certs,
93
- cert_file=configuration.cert_file,
94
- key_file=configuration.key_file,
95
- proxy_url=configuration.proxy,
96
- proxy_headers=configuration.proxy_headers,
97
- **addition_pool_args
98
- )
99
- else:
100
- self.pool_manager = urllib3.PoolManager(
101
- num_pools=pools_size,
102
- maxsize=maxsize,
103
- cert_reqs=cert_reqs,
104
- ca_certs=ca_certs,
105
- cert_file=configuration.cert_file,
106
- key_file=configuration.key_file,
107
- **addition_pool_args
108
- )
109
-
110
- def request(self, method, url, query_params=None, headers=None,
111
- body=None, post_params=None, _preload_content=True,
112
- _request_timeout=None):
113
- """Perform requests.
114
-
115
- :param method: http request method
116
- :param url: http request url
117
- :param query_params: query parameters in the url
118
- :param headers: http request headers
119
- :param body: request json body, for `application/json`
120
- :param post_params: request post parameters,
121
- `application/x-www-form-urlencoded`
122
- and `multipart/form-data`
123
- :param _preload_content: if False, the urllib3.HTTPResponse object will
124
- be returned without reading/decoding response
125
- data. Default is True.
126
- :param _request_timeout: timeout setting for this request. If one
127
- number provided, it will be total request
128
- timeout. It can also be a pair (tuple) of
129
- (connection, read) timeouts.
130
- """
131
- method = method.upper()
132
- assert method in ['GET', 'HEAD', 'DELETE', 'POST', 'PUT',
133
- 'PATCH', 'OPTIONS']
134
-
135
- if post_params and body:
136
- raise ApiValueError(
137
- "body parameter cannot be used with post_params parameter."
138
- )
139
-
140
- post_params = post_params or {}
141
- headers = headers or {}
142
-
143
- timeout = None
144
- if _request_timeout:
145
- if isinstance(_request_timeout, (int, ) if six.PY3 else (int, long)): # noqa: E501,F821
146
- timeout = urllib3.Timeout(total=_request_timeout)
147
- elif (isinstance(_request_timeout, tuple) and
148
- len(_request_timeout) == 2):
149
- timeout = urllib3.Timeout(
150
- connect=_request_timeout[0], read=_request_timeout[1])
151
-
152
- if 'Content-Type' not in headers:
153
- headers['Content-Type'] = 'application/json'
154
-
155
- try:
156
- # For `POST`, `PUT`, `PATCH`, `OPTIONS`, `DELETE`
157
- if method in ['POST', 'PUT', 'PATCH', 'OPTIONS', 'DELETE']:
158
- if query_params:
159
- url += '?' + urlencode(query_params)
160
- if re.search('json', headers['Content-Type'], re.IGNORECASE):
161
- request_body = None
162
- if body is not None:
163
- request_body = json.dumps(body)
164
- r = self.pool_manager.request(
165
- method, url,
166
- body=request_body,
167
- preload_content=_preload_content,
168
- timeout=timeout,
169
- headers=headers)
170
- elif headers['Content-Type'] == 'application/x-www-form-urlencoded': # noqa: E501
171
- r = self.pool_manager.request(
172
- method, url,
173
- fields=post_params,
174
- encode_multipart=False,
175
- preload_content=_preload_content,
176
- timeout=timeout,
177
- headers=headers)
178
- elif headers['Content-Type'] == 'multipart/form-data':
179
- # must del headers['Content-Type'], or the correct
180
- # Content-Type which generated by urllib3 will be
181
- # overwritten.
182
- del headers['Content-Type']
183
- r = self.pool_manager.request(
184
- method, url,
185
- fields=post_params,
186
- encode_multipart=True,
187
- preload_content=_preload_content,
188
- timeout=timeout,
189
- headers=headers)
190
- # Pass a `string` parameter directly in the body to support
191
- # other content types than Json when `body` argument is
192
- # provided in serialized form
193
- elif isinstance(body, str) or isinstance(body, bytes):
194
- request_body = body
195
- r = self.pool_manager.request(
196
- method, url,
197
- body=request_body,
198
- preload_content=_preload_content,
199
- timeout=timeout,
200
- headers=headers)
201
- else:
202
- # Cannot generate the request from given parameters
203
- msg = """Cannot prepare a request message for provided
204
- arguments. Please check that your arguments match
205
- declared content type."""
206
- raise ApiException(status=0, reason=msg)
207
- # For `GET`, `HEAD`
208
- else:
209
- r = self.pool_manager.request(method, url,
210
- fields=query_params,
211
- preload_content=_preload_content,
212
- timeout=timeout,
213
- headers=headers)
214
- except urllib3.exceptions.SSLError as e:
215
- msg = "{0}\n{1}".format(type(e).__name__, str(e))
216
- raise ApiException(status=0, reason=msg)
217
-
218
- if _preload_content:
219
- r = RESTResponse(r)
220
-
221
- # log response body
222
- logger.debug("response body: %s", r.data)
223
-
224
- if not 200 <= r.status <= 299:
225
- raise ApiException(http_resp=r)
226
-
227
- return r
228
-
229
- def GET(self, url, headers=None, query_params=None, _preload_content=True,
230
- _request_timeout=None):
231
- return self.request("GET", url,
232
- headers=headers,
233
- _preload_content=_preload_content,
234
- _request_timeout=_request_timeout,
235
- query_params=query_params)
236
-
237
- def HEAD(self, url, headers=None, query_params=None, _preload_content=True,
238
- _request_timeout=None):
239
- return self.request("HEAD", url,
240
- headers=headers,
241
- _preload_content=_preload_content,
242
- _request_timeout=_request_timeout,
243
- query_params=query_params)
244
-
245
- def OPTIONS(self, url, headers=None, query_params=None, post_params=None,
246
- body=None, _preload_content=True, _request_timeout=None):
247
- return self.request("OPTIONS", url,
248
- headers=headers,
249
- query_params=query_params,
250
- post_params=post_params,
251
- _preload_content=_preload_content,
252
- _request_timeout=_request_timeout,
253
- body=body)
254
-
255
- def DELETE(self, url, headers=None, query_params=None, body=None,
256
- _preload_content=True, _request_timeout=None):
257
- return self.request("DELETE", url,
258
- headers=headers,
259
- query_params=query_params,
260
- _preload_content=_preload_content,
261
- _request_timeout=_request_timeout,
262
- body=body)
263
-
264
- def POST(self, url, headers=None, query_params=None, post_params=None,
265
- body=None, _preload_content=True, _request_timeout=None):
266
- return self.request("POST", url,
267
- headers=headers,
268
- query_params=query_params,
269
- post_params=post_params,
270
- _preload_content=_preload_content,
271
- _request_timeout=_request_timeout,
272
- body=body)
273
-
274
- def PUT(self, url, headers=None, query_params=None, post_params=None,
275
- body=None, _preload_content=True, _request_timeout=None):
276
- return self.request("PUT", url,
277
- headers=headers,
278
- query_params=query_params,
279
- post_params=post_params,
280
- _preload_content=_preload_content,
281
- _request_timeout=_request_timeout,
282
- body=body)
283
-
284
- def PATCH(self, url, headers=None, query_params=None, post_params=None,
285
- body=None, _preload_content=True, _request_timeout=None):
286
- return self.request("PATCH", url,
287
- headers=headers,
288
- query_params=query_params,
289
- post_params=post_params,
290
- _preload_content=_preload_content,
291
- _request_timeout=_request_timeout,
292
- body=body)