development-framework-cli 1.7.3__py3-none-any.whl

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 (71) hide show
  1. development_framework_cli-1.7.3.dist-info/METADATA +141 -0
  2. development_framework_cli-1.7.3.dist-info/RECORD +71 -0
  3. development_framework_cli-1.7.3.dist-info/WHEEL +4 -0
  4. development_framework_cli-1.7.3.dist-info/entry_points.txt +2 -0
  5. development_framework_cli-1.7.3.dist-info/licenses/LICENSE +21 -0
  6. dm_cli/__init__.py +1 -0
  7. dm_cli/cli.py +180 -0
  8. dm_cli/command_group/__init__.py +0 -0
  9. dm_cli/command_group/data_source.py +176 -0
  10. dm_cli/command_group/entities.py +116 -0
  11. dm_cli/dmss.py +104 -0
  12. dm_cli/dmss_api/__init__.py +27 -0
  13. dm_cli/dmss_api/api/__init__.py +3 -0
  14. dm_cli/dmss_api/api/access_control_api.py +349 -0
  15. dm_cli/dmss_api/api/attribute_api.py +175 -0
  16. dm_cli/dmss_api/api/blob_api.py +344 -0
  17. dm_cli/dmss_api/api/blueprint_api.py +326 -0
  18. dm_cli/dmss_api/api/datasource_api.py +448 -0
  19. dm_cli/dmss_api/api/default_api.py +4439 -0
  20. dm_cli/dmss_api/api/document_api.py +922 -0
  21. dm_cli/dmss_api/api/entity_api.py +464 -0
  22. dm_cli/dmss_api/api/export_api.py +313 -0
  23. dm_cli/dmss_api/api/file_api.py +197 -0
  24. dm_cli/dmss_api/api/health_check_api.py +160 -0
  25. dm_cli/dmss_api/api/lookup_table_api.py +323 -0
  26. dm_cli/dmss_api/api/meta_api.py +185 -0
  27. dm_cli/dmss_api/api/personal_access_token_api.py +433 -0
  28. dm_cli/dmss_api/api/reference_api.py +174 -0
  29. dm_cli/dmss_api/api/search_api.py +183 -0
  30. dm_cli/dmss_api/api/whoami_api.py +163 -0
  31. dm_cli/dmss_api/api_client.py +896 -0
  32. dm_cli/dmss_api/apis/__init__.py +32 -0
  33. dm_cli/dmss_api/configuration.py +482 -0
  34. dm_cli/dmss_api/exceptions.py +158 -0
  35. dm_cli/dmss_api/model/__init__.py +5 -0
  36. dm_cli/dmss_api/model/access_control_list.py +287 -0
  37. dm_cli/dmss_api/model/access_level.py +290 -0
  38. dm_cli/dmss_api/model/acl.py +287 -0
  39. dm_cli/dmss_api/model/data_source_information.py +282 -0
  40. dm_cli/dmss_api/model/data_source_request.py +281 -0
  41. dm_cli/dmss_api/model/dependency.py +294 -0
  42. dm_cli/dmss_api/model/entity.py +275 -0
  43. dm_cli/dmss_api/model/error_response.py +278 -0
  44. dm_cli/dmss_api/model/export_meta_response.py +277 -0
  45. dm_cli/dmss_api/model/get_blueprint_response.py +280 -0
  46. dm_cli/dmss_api/model/lookup.py +283 -0
  47. dm_cli/dmss_api/model/pat_data.py +299 -0
  48. dm_cli/dmss_api/model/recipe.py +311 -0
  49. dm_cli/dmss_api/model/recipe_attribute.py +304 -0
  50. dm_cli/dmss_api/model/reference.py +280 -0
  51. dm_cli/dmss_api/model/reference_entity.py +288 -0
  52. dm_cli/dmss_api/model/repository.py +317 -0
  53. dm_cli/dmss_api/model/repository_type.py +290 -0
  54. dm_cli/dmss_api/model/storage_attribute.py +295 -0
  55. dm_cli/dmss_api/model/storage_data_types.py +292 -0
  56. dm_cli/dmss_api/model/storage_recipe.py +293 -0
  57. dm_cli/dmss_api/model_utils.py +2057 -0
  58. dm_cli/dmss_api/models/__init__.py +29 -0
  59. dm_cli/dmss_api/rest.py +358 -0
  60. dm_cli/domain.py +166 -0
  61. dm_cli/enums.py +48 -0
  62. dm_cli/import_entity.py +128 -0
  63. dm_cli/import_package.py +173 -0
  64. dm_cli/package_tree_from_zip.py +120 -0
  65. dm_cli/state.py +12 -0
  66. dm_cli/utils/__init__.py +0 -0
  67. dm_cli/utils/file_structure.py +31 -0
  68. dm_cli/utils/reference.py +129 -0
  69. dm_cli/utils/resolve_local_ids.py +142 -0
  70. dm_cli/utils/utils.py +161 -0
  71. dm_cli/utils/zip.py +70 -0
@@ -0,0 +1,32 @@
1
+
2
+ # flake8: noqa
3
+
4
+ # Import all APIs into this package.
5
+ # If you have many APIs here with many many models used in each API this may
6
+ # raise a `RecursionError`.
7
+ # In order to avoid this, import only the API that you directly need like:
8
+ #
9
+ # from dm_cli.dmss_api.api.access_control_api import AccessControlApi
10
+ #
11
+ # or import this package, but before doing it, use:
12
+ #
13
+ # import sys
14
+ # sys.setrecursionlimit(n)
15
+
16
+ # Import APIs into API package:
17
+ from dm_cli.dmss_api.api.access_control_api import AccessControlApi
18
+ from dm_cli.dmss_api.api.attribute_api import AttributeApi
19
+ from dm_cli.dmss_api.api.blob_api import BlobApi
20
+ from dm_cli.dmss_api.api.blueprint_api import BlueprintApi
21
+ from dm_cli.dmss_api.api.datasource_api import DatasourceApi
22
+ from dm_cli.dmss_api.api.default_api import DefaultApi
23
+ from dm_cli.dmss_api.api.document_api import DocumentApi
24
+ from dm_cli.dmss_api.api.entity_api import EntityApi
25
+ from dm_cli.dmss_api.api.export_api import ExportApi
26
+ from dm_cli.dmss_api.api.file_api import FileApi
27
+ from dm_cli.dmss_api.api.health_check_api import HealthCheckApi
28
+ from dm_cli.dmss_api.api.lookup_table_api import LookupTableApi
29
+ from dm_cli.dmss_api.api.meta_api import MetaApi
30
+ from dm_cli.dmss_api.api.personal_access_token_api import PersonalAccessTokenApi
31
+ from dm_cli.dmss_api.api.search_api import SearchApi
32
+ from dm_cli.dmss_api.api.whoami_api import WhoamiApi
@@ -0,0 +1,482 @@
1
+ """
2
+ Data Modelling Storage Service
3
+
4
+ API for basic data modelling interaction # noqa: E501
5
+
6
+ The version of the OpenAPI document: 1.3.0
7
+ Generated by: https://openapi-generator.tech
8
+ """
9
+
10
+
11
+ import copy
12
+ import logging
13
+ import multiprocessing
14
+ import sys
15
+ from http import client as http_client
16
+
17
+ import urllib3
18
+
19
+ from dm_cli.dmss_api.exceptions import ApiValueError
20
+
21
+ JSON_SCHEMA_VALIDATION_KEYWORDS = {
22
+ 'multipleOf', 'maximum', 'exclusiveMaximum',
23
+ 'minimum', 'exclusiveMinimum', 'maxLength',
24
+ 'minLength', 'pattern', 'maxItems', 'minItems'
25
+ }
26
+
27
+ class Configuration(object):
28
+ """NOTE: This class is auto generated by OpenAPI Generator
29
+
30
+ Ref: https://openapi-generator.tech
31
+ Do not edit the class manually.
32
+
33
+ :param host: Base url
34
+ :param api_key: Dict to store API key(s).
35
+ Each entry in the dict specifies an API key.
36
+ The dict key is the name of the security scheme in the OAS specification.
37
+ The dict value is the API key secret.
38
+ :param api_key_prefix: Dict to store API prefix (e.g. Bearer)
39
+ The dict key is the name of the security scheme in the OAS specification.
40
+ The dict value is an API key prefix when generating the auth data.
41
+ :param username: Username for HTTP basic authentication
42
+ :param password: Password for HTTP basic authentication
43
+ :param discard_unknown_keys: Boolean value indicating whether to discard
44
+ unknown properties. A server may send a response that includes additional
45
+ properties that are not known by the client in the following scenarios:
46
+ 1. The OpenAPI document is incomplete, i.e. it does not match the server
47
+ implementation.
48
+ 2. The client was generated using an older version of the OpenAPI document
49
+ and the server has been upgraded since then.
50
+ If a schema in the OpenAPI document defines the additionalProperties attribute,
51
+ then all undeclared properties received by the server are injected into the
52
+ additional properties map. In that case, there are undeclared properties, and
53
+ nothing to discard.
54
+ :param disabled_client_side_validations (string): Comma-separated list of
55
+ JSON schema validation keywords to disable JSON schema structural validation
56
+ rules. The following keywords may be specified: multipleOf, maximum,
57
+ exclusiveMaximum, minimum, exclusiveMinimum, maxLength, minLength, pattern,
58
+ maxItems, minItems.
59
+ By default, the validation is performed for data generated locally by the client
60
+ and data received from the server, independent of any validation performed by
61
+ the server side. If the input data does not satisfy the JSON schema validation
62
+ rules specified in the OpenAPI document, an exception is raised.
63
+ If disabled_client_side_validations is set, structural validation is
64
+ disabled. This can be useful to troubleshoot data validation problem, such as
65
+ when the OpenAPI document validation rules do not match the actual API data
66
+ received by the server.
67
+ :param server_index: Index to servers configuration.
68
+ :param server_variables: Mapping with string values to replace variables in
69
+ templated server configuration. The validation of enums is performed for
70
+ variables with defined enum values before.
71
+ :param server_operation_index: Mapping from operation ID to an index to server
72
+ configuration.
73
+ :param server_operation_variables: Mapping from operation ID to a mapping with
74
+ string values to replace variables in templated server configuration.
75
+ The validation of enums is performed for variables with defined enum values before.
76
+ :param ssl_ca_cert: str - the path to a file of concatenated CA certificates
77
+ in PEM format
78
+
79
+ :Example:
80
+
81
+ API Key Authentication Example.
82
+ Given the following security scheme in the OpenAPI specification:
83
+ components:
84
+ securitySchemes:
85
+ cookieAuth: # name for the security scheme
86
+ type: apiKey
87
+ in: cookie
88
+ name: JSESSIONID # cookie name
89
+
90
+ You can programmatically set the cookie:
91
+
92
+ conf = dmss_api.Configuration(
93
+ api_key={'cookieAuth': 'abc123'}
94
+ api_key_prefix={'cookieAuth': 'JSESSIONID'}
95
+ )
96
+
97
+ The following cookie will be added to the HTTP request:
98
+ Cookie: JSESSIONID abc123
99
+ """
100
+
101
+ _default = None
102
+
103
+ def __init__(self, host=None,
104
+ api_key=None, api_key_prefix=None,
105
+ access_token=None,
106
+ username=None, password=None,
107
+ discard_unknown_keys=False,
108
+ disabled_client_side_validations="",
109
+ server_index=None, server_variables=None,
110
+ server_operation_index=None, server_operation_variables=None,
111
+ ssl_ca_cert=None,
112
+ ):
113
+ """Constructor
114
+ """
115
+ self._base_path = "http://localhost" if host is None else host
116
+ """Default Base url
117
+ """
118
+ self.server_index = 0 if server_index is None and host is None else server_index
119
+ self.server_operation_index = server_operation_index or {}
120
+ """Default server index
121
+ """
122
+ self.server_variables = server_variables or {}
123
+ self.server_operation_variables = server_operation_variables or {}
124
+ """Default server variables
125
+ """
126
+ self.temp_folder_path = None
127
+ """Temp file folder for downloading files
128
+ """
129
+ # Authentication Settings
130
+ self.access_token = access_token
131
+ self.api_key = {}
132
+ if api_key:
133
+ self.api_key = api_key
134
+ """dict to store API key(s)
135
+ """
136
+ self.api_key_prefix = {}
137
+ if api_key_prefix:
138
+ self.api_key_prefix = api_key_prefix
139
+ """dict to store API prefix (e.g. Bearer)
140
+ """
141
+ self.refresh_api_key_hook = None
142
+ """function hook to refresh API key if expired
143
+ """
144
+ self.username = username
145
+ """Username for HTTP basic authentication
146
+ """
147
+ self.password = password
148
+ """Password for HTTP basic authentication
149
+ """
150
+ self.discard_unknown_keys = discard_unknown_keys
151
+ self.disabled_client_side_validations = disabled_client_side_validations
152
+ self.logger = {}
153
+ """Logging Settings
154
+ """
155
+ self.logger["package_logger"] = logging.getLogger("dmss_api")
156
+ self.logger["urllib3_logger"] = logging.getLogger("urllib3")
157
+ self.logger_format = '%(asctime)s %(levelname)s %(message)s'
158
+ """Log format
159
+ """
160
+ self.logger_stream_handler = None
161
+ """Log stream handler
162
+ """
163
+ self.logger_file_handler = None
164
+ """Log file handler
165
+ """
166
+ self.logger_file = None
167
+ """Debug file location
168
+ """
169
+ self.debug = False
170
+ """Debug switch
171
+ """
172
+
173
+ self.verify_ssl = True
174
+ """SSL/TLS verification
175
+ Set this to false to skip verifying SSL certificate when calling API
176
+ from https server.
177
+ """
178
+ self.ssl_ca_cert = ssl_ca_cert
179
+ """Set this to customize the certificate file to verify the peer.
180
+ """
181
+ self.cert_file = None
182
+ """client certificate file
183
+ """
184
+ self.key_file = None
185
+ """client key file
186
+ """
187
+ self.assert_hostname = None
188
+ """Set this to True/False to enable/disable SSL hostname verification.
189
+ """
190
+
191
+ self.connection_pool_maxsize = multiprocessing.cpu_count() * 5
192
+ """urllib3 connection pool's maximum number of connections saved
193
+ per pool. urllib3 uses 1 connection as default value, but this is
194
+ not the best value when you are making a lot of possibly parallel
195
+ requests to the same host, which is often the case here.
196
+ cpu_count * 5 is used as default value to increase performance.
197
+ """
198
+
199
+ self.proxy = None
200
+ """Proxy URL
201
+ """
202
+ self.no_proxy = None
203
+ """bypass proxy for host in the no_proxy list.
204
+ """
205
+ self.proxy_headers = None
206
+ """Proxy headers
207
+ """
208
+ self.safe_chars_for_path_param = ''
209
+ """Safe chars for path_param
210
+ """
211
+ self.retries = None
212
+ """Adding retries to override urllib3 default value 3
213
+ """
214
+ # Enable client side validation
215
+ self.client_side_validation = True
216
+
217
+ # Options to pass down to the underlying urllib3 socket
218
+ self.socket_options = None
219
+
220
+ def __deepcopy__(self, memo):
221
+ cls = self.__class__
222
+ result = cls.__new__(cls)
223
+ memo[id(self)] = result
224
+ for k, v in self.__dict__.items():
225
+ if k not in ('logger', 'logger_file_handler'):
226
+ setattr(result, k, copy.deepcopy(v, memo))
227
+ # shallow copy of loggers
228
+ result.logger = copy.copy(self.logger)
229
+ # use setters to configure loggers
230
+ result.logger_file = self.logger_file
231
+ result.debug = self.debug
232
+ return result
233
+
234
+ def __setattr__(self, name, value):
235
+ object.__setattr__(self, name, value)
236
+ if name == 'disabled_client_side_validations':
237
+ s = set(filter(None, value.split(',')))
238
+ for v in s:
239
+ if v not in JSON_SCHEMA_VALIDATION_KEYWORDS:
240
+ raise ApiValueError(
241
+ "Invalid keyword: '{0}''".format(v))
242
+ self._disabled_client_side_validations = s
243
+
244
+ @classmethod
245
+ def set_default(cls, default):
246
+ """Set default instance of configuration.
247
+
248
+ It stores default configuration, which can be
249
+ returned by get_default_copy method.
250
+
251
+ :param default: object of Configuration
252
+ """
253
+ cls._default = copy.deepcopy(default)
254
+
255
+ @classmethod
256
+ def get_default_copy(cls):
257
+ """Return new instance of configuration.
258
+
259
+ This method returns newly created, based on default constructor,
260
+ object of Configuration class or returns a copy of default
261
+ configuration passed by the set_default method.
262
+
263
+ :return: The configuration object.
264
+ """
265
+ if cls._default is not None:
266
+ return copy.deepcopy(cls._default)
267
+ return Configuration()
268
+
269
+ @property
270
+ def logger_file(self):
271
+ """The logger file.
272
+
273
+ If the logger_file is None, then add stream handler and remove file
274
+ handler. Otherwise, add file handler and remove stream handler.
275
+
276
+ :param value: The logger_file path.
277
+ :type: str
278
+ """
279
+ return self.__logger_file
280
+
281
+ @logger_file.setter
282
+ def logger_file(self, value):
283
+ """The logger file.
284
+
285
+ If the logger_file is None, then add stream handler and remove file
286
+ handler. Otherwise, add file handler and remove stream handler.
287
+
288
+ :param value: The logger_file path.
289
+ :type: str
290
+ """
291
+ self.__logger_file = value
292
+ if self.__logger_file:
293
+ # If set logging file,
294
+ # then add file handler and remove stream handler.
295
+ self.logger_file_handler = logging.FileHandler(self.__logger_file)
296
+ self.logger_file_handler.setFormatter(self.logger_formatter)
297
+ for _, logger in self.logger.items():
298
+ logger.addHandler(self.logger_file_handler)
299
+
300
+ @property
301
+ def debug(self):
302
+ """Debug status
303
+
304
+ :param value: The debug status, True or False.
305
+ :type: bool
306
+ """
307
+ return self.__debug
308
+
309
+ @debug.setter
310
+ def debug(self, value):
311
+ """Debug status
312
+
313
+ :param value: The debug status, True or False.
314
+ :type: bool
315
+ """
316
+ self.__debug = value
317
+ if self.__debug:
318
+ # if debug status is True, turn on debug logging
319
+ for _, logger in self.logger.items():
320
+ logger.setLevel(logging.DEBUG)
321
+ # turn on http_client debug
322
+ http_client.HTTPConnection.debuglevel = 1
323
+ else:
324
+ # if debug status is False, turn off debug logging,
325
+ # setting log level to default `logging.WARNING`
326
+ for _, logger in self.logger.items():
327
+ logger.setLevel(logging.WARNING)
328
+ # turn off http_client debug
329
+ http_client.HTTPConnection.debuglevel = 0
330
+
331
+ @property
332
+ def logger_format(self):
333
+ """The logger format.
334
+
335
+ The logger_formatter will be updated when sets logger_format.
336
+
337
+ :param value: The format string.
338
+ :type: str
339
+ """
340
+ return self.__logger_format
341
+
342
+ @logger_format.setter
343
+ def logger_format(self, value):
344
+ """The logger format.
345
+
346
+ The logger_formatter will be updated when sets logger_format.
347
+
348
+ :param value: The format string.
349
+ :type: str
350
+ """
351
+ self.__logger_format = value
352
+ self.logger_formatter = logging.Formatter(self.__logger_format)
353
+
354
+ def get_api_key_with_prefix(self, identifier, alias=None):
355
+ """Gets API key (with prefix if set).
356
+
357
+ :param identifier: The identifier of apiKey.
358
+ :param alias: The alternative identifier of apiKey.
359
+ :return: The token for api key authentication.
360
+ """
361
+ if self.refresh_api_key_hook is not None:
362
+ self.refresh_api_key_hook(self)
363
+ key = self.api_key.get(identifier, self.api_key.get(alias) if alias is not None else None)
364
+ if key:
365
+ prefix = self.api_key_prefix.get(identifier)
366
+ if prefix:
367
+ return "%s %s" % (prefix, key)
368
+ else:
369
+ return key
370
+
371
+ def get_basic_auth_token(self):
372
+ """Gets HTTP basic authentication header (string).
373
+
374
+ :return: The token for basic HTTP authentication.
375
+ """
376
+ username = ""
377
+ if self.username is not None:
378
+ username = self.username
379
+ password = ""
380
+ if self.password is not None:
381
+ password = self.password
382
+ return urllib3.util.make_headers(
383
+ basic_auth=username + ':' + password
384
+ ).get('authorization')
385
+
386
+ def auth_settings(self):
387
+ """Gets Auth Settings dict for api client.
388
+
389
+ :return: The Auth Settings information dict.
390
+ """
391
+ auth = {}
392
+ if 'APIKeyHeader' in self.api_key:
393
+ auth['APIKeyHeader'] = {
394
+ 'type': 'api_key',
395
+ 'in': 'header',
396
+ 'key': 'Access-Key',
397
+ 'value': self.get_api_key_with_prefix(
398
+ 'APIKeyHeader',
399
+ ),
400
+ }
401
+ if self.access_token is not None:
402
+ auth['OAuth2AuthorizationCodeBearer'] = {
403
+ 'type': 'oauth2',
404
+ 'in': 'header',
405
+ 'key': 'Authorization',
406
+ 'value': 'Bearer ' + self.access_token
407
+ }
408
+ return auth
409
+
410
+ def to_debug_report(self):
411
+ """Gets the essential information for debugging.
412
+
413
+ :return: The report for debugging.
414
+ """
415
+ return "Python SDK Debug Report:\n"\
416
+ "OS: {env}\n"\
417
+ "Python Version: {pyversion}\n"\
418
+ "Version of the API: 1.3.0\n"\
419
+ "SDK Package Version: 1.0.0".\
420
+ format(env=sys.platform, pyversion=sys.version)
421
+
422
+ def get_host_settings(self):
423
+ """Gets an array of host settings
424
+
425
+ :return: An array of host settings
426
+ """
427
+ return [
428
+ {
429
+ 'url': "",
430
+ 'description': "No description provided",
431
+ }
432
+ ]
433
+
434
+ def get_host_from_settings(self, index, variables=None, servers=None):
435
+ """Gets host URL based on the index and variables
436
+ :param index: array index of the host settings
437
+ :param variables: hash of variable and the corresponding value
438
+ :param servers: an array of host settings or None
439
+ :return: URL based on host settings
440
+ """
441
+ if index is None:
442
+ return self._base_path
443
+
444
+ variables = {} if variables is None else variables
445
+ servers = self.get_host_settings() if servers is None else servers
446
+
447
+ try:
448
+ server = servers[index]
449
+ except IndexError:
450
+ raise ValueError(
451
+ "Invalid index {0} when selecting the host settings. "
452
+ "Must be less than {1}".format(index, len(servers)))
453
+
454
+ url = server['url']
455
+
456
+ # go through variables and replace placeholders
457
+ for variable_name, variable in server.get('variables', {}).items():
458
+ used_value = variables.get(
459
+ variable_name, variable['default_value'])
460
+
461
+ if 'enum_values' in variable \
462
+ and used_value not in variable['enum_values']:
463
+ raise ValueError(
464
+ "The variable `{0}` in the host URL has invalid value "
465
+ "{1}. Must be {2}.".format(
466
+ variable_name, variables[variable_name],
467
+ variable['enum_values']))
468
+
469
+ url = url.replace("{" + variable_name + "}", used_value)
470
+
471
+ return url
472
+
473
+ @property
474
+ def host(self):
475
+ """Return generated host."""
476
+ return self.get_host_from_settings(self.server_index, variables=self.server_variables)
477
+
478
+ @host.setter
479
+ def host(self, value):
480
+ """Fix base path."""
481
+ self._base_path = value
482
+ self.server_index = None
@@ -0,0 +1,158 @@
1
+ """
2
+ Data Modelling Storage Service
3
+
4
+ API for basic data modelling interaction # noqa: E501
5
+
6
+ The version of the OpenAPI document: 1.3.0
7
+ Generated by: https://openapi-generator.tech
8
+ """
9
+
10
+
11
+ class OpenApiException(Exception):
12
+ """The base exception class for all OpenAPIExceptions"""
13
+
14
+
15
+ class ApiTypeError(OpenApiException, TypeError):
16
+ def __init__(self, msg, path_to_item=None, valid_classes=None,
17
+ key_type=None):
18
+ """ Raises an exception for TypeErrors
19
+
20
+ Args:
21
+ msg (str): the exception message
22
+
23
+ Keyword Args:
24
+ path_to_item (list): a list of keys an indices to get to the
25
+ current_item
26
+ None if unset
27
+ valid_classes (tuple): the primitive classes that current item
28
+ should be an instance of
29
+ None if unset
30
+ key_type (bool): False if our value is a value in a dict
31
+ True if it is a key in a dict
32
+ False if our item is an item in a list
33
+ None if unset
34
+ """
35
+ self.path_to_item = path_to_item
36
+ self.valid_classes = valid_classes
37
+ self.key_type = key_type
38
+ full_msg = msg
39
+ if path_to_item:
40
+ full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
41
+ super(ApiTypeError, self).__init__(full_msg)
42
+
43
+
44
+ class ApiValueError(OpenApiException, ValueError):
45
+ def __init__(self, msg, path_to_item=None):
46
+ """
47
+ Args:
48
+ msg (str): the exception message
49
+
50
+ Keyword Args:
51
+ path_to_item (list) the path to the exception in the
52
+ received_data dict. None if unset
53
+ """
54
+
55
+ self.path_to_item = path_to_item
56
+ full_msg = msg
57
+ if path_to_item:
58
+ full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
59
+ super(ApiValueError, self).__init__(full_msg)
60
+
61
+
62
+ class ApiAttributeError(OpenApiException, AttributeError):
63
+ def __init__(self, msg, path_to_item=None):
64
+ """
65
+ Raised when an attribute reference or assignment fails.
66
+
67
+ Args:
68
+ msg (str): the exception message
69
+
70
+ Keyword Args:
71
+ path_to_item (None/list) the path to the exception in the
72
+ received_data dict
73
+ """
74
+ self.path_to_item = path_to_item
75
+ full_msg = msg
76
+ if path_to_item:
77
+ full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
78
+ super(ApiAttributeError, self).__init__(full_msg)
79
+
80
+
81
+ class ApiKeyError(OpenApiException, KeyError):
82
+ def __init__(self, msg, path_to_item=None):
83
+ """
84
+ Args:
85
+ msg (str): the exception message
86
+
87
+ Keyword Args:
88
+ path_to_item (None/list) the path to the exception in the
89
+ received_data dict
90
+ """
91
+ self.path_to_item = path_to_item
92
+ full_msg = msg
93
+ if path_to_item:
94
+ full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
95
+ super(ApiKeyError, self).__init__(full_msg)
96
+
97
+
98
+ class ApiException(OpenApiException):
99
+
100
+ def __init__(self, status=None, reason=None, http_resp=None):
101
+ if http_resp:
102
+ self.status = http_resp.status
103
+ self.reason = http_resp.reason
104
+ self.body = http_resp.data
105
+ self.headers = http_resp.getheaders()
106
+ else:
107
+ self.status = status
108
+ self.reason = reason
109
+ self.body = None
110
+ self.headers = None
111
+
112
+ def __str__(self):
113
+ """Custom error messages for exception"""
114
+ error_message = "Status Code: {0}\n"\
115
+ "Reason: {1}\n".format(self.status, self.reason)
116
+ if self.headers:
117
+ error_message += "HTTP response headers: {0}\n".format(
118
+ self.headers)
119
+
120
+ if self.body:
121
+ error_message += "HTTP response body: {0}\n".format(self.body)
122
+
123
+ return error_message
124
+
125
+
126
+ class NotFoundException(ApiException):
127
+
128
+ def __init__(self, status=None, reason=None, http_resp=None):
129
+ super(NotFoundException, self).__init__(status, reason, http_resp)
130
+
131
+
132
+ class UnauthorizedException(ApiException):
133
+
134
+ def __init__(self, status=None, reason=None, http_resp=None):
135
+ super(UnauthorizedException, self).__init__(status, reason, http_resp)
136
+
137
+
138
+ class ForbiddenException(ApiException):
139
+
140
+ def __init__(self, status=None, reason=None, http_resp=None):
141
+ super(ForbiddenException, self).__init__(status, reason, http_resp)
142
+
143
+
144
+ class ServiceException(ApiException):
145
+
146
+ def __init__(self, status=None, reason=None, http_resp=None):
147
+ super(ServiceException, self).__init__(status, reason, http_resp)
148
+
149
+
150
+ def render_path(path_to_item):
151
+ """Returns a string representation of a path"""
152
+ result = ""
153
+ for pth in path_to_item:
154
+ if isinstance(pth, int):
155
+ result += "[{0}]".format(pth)
156
+ else:
157
+ result += "['{0}']".format(pth)
158
+ return result
@@ -0,0 +1,5 @@
1
+ # we can not import model classes here because that would create a circular
2
+ # reference which would not work in python2
3
+ # do not import all models into this module because that uses a lot of memory and stack frames
4
+ # if you need the ability to import all models from one package, import them with
5
+ # from dm_cli.dmss_api.models import ModelA, ModelB