dockflow-sdk 0.3.0__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 (52) hide show
  1. dockflow_sdk/__init__.py +124 -0
  2. dockflow_sdk/api/__init__.py +8 -0
  3. dockflow_sdk/api/documents_api.py +1382 -0
  4. dockflow_sdk/api/tradeflows_api.py +615 -0
  5. dockflow_sdk/api/upstream_api.py +471 -0
  6. dockflow_sdk/api/widget_api.py +303 -0
  7. dockflow_sdk/api_client.py +865 -0
  8. dockflow_sdk/api_response.py +21 -0
  9. dockflow_sdk/configuration.py +658 -0
  10. dockflow_sdk/exceptions.py +218 -0
  11. dockflow_sdk/models/__init__.py +51 -0
  12. dockflow_sdk/models/container_reference.py +90 -0
  13. dockflow_sdk/models/create_tradeflows202_response.py +104 -0
  14. dockflow_sdk/models/create_tradeflows202_response_tradeflows_inner.py +90 -0
  15. dockflow_sdk/models/document_update.py +92 -0
  16. dockflow_sdk/models/document_upload.py +105 -0
  17. dockflow_sdk/models/downstream_tradeflow.py +189 -0
  18. dockflow_sdk/models/downstream_tradeflow_bill_of_lading_reference.py +138 -0
  19. dockflow_sdk/models/downstream_tradeflow_booking_reference.py +138 -0
  20. dockflow_sdk/models/downstream_tradeflow_events_inner.py +97 -0
  21. dockflow_sdk/models/downstream_tradeflow_free_time_overrides_inner.py +101 -0
  22. dockflow_sdk/models/downstream_tradeflow_mock_tracking.py +88 -0
  23. dockflow_sdk/models/downstream_tradeflow_partners_inner.py +94 -0
  24. dockflow_sdk/models/downstream_tradeflow_references.py +92 -0
  25. dockflow_sdk/models/get_document200_response.py +100 -0
  26. dockflow_sdk/models/get_document200_response_data_inner.py +133 -0
  27. dockflow_sdk/models/get_document200_response_data_inner_document_type.py +90 -0
  28. dockflow_sdk/models/get_upstream200_response.py +102 -0
  29. dockflow_sdk/models/get_upstream400_response.py +172 -0
  30. dockflow_sdk/models/inline_object.py +90 -0
  31. dockflow_sdk/models/list_document_types200_response_inner.py +90 -0
  32. dockflow_sdk/models/upload_document202_response.py +120 -0
  33. dockflow_sdk/models/upload_document400_response.py +155 -0
  34. dockflow_sdk/models/upstream_record.py +132 -0
  35. dockflow_sdk/models/upstream_record_additional_references.py +90 -0
  36. dockflow_sdk/models/upstream_record_data_quality.py +96 -0
  37. dockflow_sdk/models/upstream_record_metadata.py +105 -0
  38. dockflow_sdk/models/widget_container.py +120 -0
  39. dockflow_sdk/models/widget_country.py +100 -0
  40. dockflow_sdk/models/widget_leg.py +113 -0
  41. dockflow_sdk/models/widget_location.py +129 -0
  42. dockflow_sdk/models/widget_milestone.py +118 -0
  43. dockflow_sdk/models/widget_point.py +90 -0
  44. dockflow_sdk/models/widget_search_result.py +155 -0
  45. dockflow_sdk/models/widget_track.py +102 -0
  46. dockflow_sdk/models/widget_track_reading.py +92 -0
  47. dockflow_sdk/py.typed +0 -0
  48. dockflow_sdk/rest.py +334 -0
  49. dockflow_sdk-0.3.0.dist-info/METADATA +212 -0
  50. dockflow_sdk-0.3.0.dist-info/RECORD +52 -0
  51. dockflow_sdk-0.3.0.dist-info/WHEEL +5 -0
  52. dockflow_sdk-0.3.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,21 @@
1
+ """API response object."""
2
+
3
+ from __future__ import annotations
4
+ from typing import Optional, Generic, Mapping, TypeVar
5
+ from pydantic import Field, StrictInt, StrictBytes, BaseModel
6
+
7
+ T = TypeVar("T")
8
+
9
+ class ApiResponse(BaseModel, Generic[T]):
10
+ """
11
+ API response object
12
+ """
13
+
14
+ status_code: StrictInt = Field(description="HTTP status code")
15
+ headers: Optional[Mapping[str, str]] = Field(None, description="HTTP headers")
16
+ data: T = Field(description="Deserialized data given the data type")
17
+ raw_data: StrictBytes = Field(description="Raw data (HTTP response body)")
18
+
19
+ model_config = {
20
+ "arbitrary_types_allowed": True
21
+ }
@@ -0,0 +1,658 @@
1
+ """
2
+ Dockflow v3 API
3
+
4
+ No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5
+
6
+ The version of the OpenAPI document: 3.0.0
7
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
8
+
9
+ Do not edit the class manually.
10
+ """ # noqa: E501
11
+
12
+
13
+ import copy
14
+ import http.client as httplib
15
+ import logging
16
+ from logging import FileHandler
17
+ import multiprocessing
18
+ import ssl
19
+ import sys
20
+ from typing import Any, ClassVar, Dict, List, Literal, Optional, TypedDict, Union
21
+ from urllib.parse import urlparse
22
+ from urllib.request import getproxies
23
+ from typing_extensions import NotRequired, Self
24
+
25
+ import urllib3
26
+
27
+
28
+ JSON_SCHEMA_VALIDATION_KEYWORDS = {
29
+ 'multipleOf', 'maximum', 'exclusiveMaximum',
30
+ 'minimum', 'exclusiveMinimum', 'maxLength',
31
+ 'minLength', 'pattern', 'maxItems', 'minItems'
32
+ }
33
+
34
+ ServerVariablesT = Dict[str, str]
35
+
36
+ GenericAuthSetting = TypedDict(
37
+ "GenericAuthSetting",
38
+ {
39
+ "type": str,
40
+ "in": str,
41
+ "key": str,
42
+ "value": str,
43
+ },
44
+ )
45
+
46
+
47
+ OAuth2AuthSetting = TypedDict(
48
+ "OAuth2AuthSetting",
49
+ {
50
+ "type": Literal["oauth2"],
51
+ "in": Literal["header"],
52
+ "key": Literal["Authorization"],
53
+ "value": str,
54
+ },
55
+ )
56
+
57
+
58
+ APIKeyAuthSetting = TypedDict(
59
+ "APIKeyAuthSetting",
60
+ {
61
+ "type": Literal["api_key"],
62
+ "in": str,
63
+ "key": str,
64
+ "value": Optional[str],
65
+ },
66
+ )
67
+
68
+
69
+ BasicAuthSetting = TypedDict(
70
+ "BasicAuthSetting",
71
+ {
72
+ "type": Literal["basic"],
73
+ "in": Literal["header"],
74
+ "key": Literal["Authorization"],
75
+ "value": Optional[str],
76
+ },
77
+ )
78
+
79
+
80
+ BearerFormatAuthSetting = TypedDict(
81
+ "BearerFormatAuthSetting",
82
+ {
83
+ "type": Literal["bearer"],
84
+ "in": Literal["header"],
85
+ "format": Literal["JWT"],
86
+ "key": Literal["Authorization"],
87
+ "value": str,
88
+ },
89
+ )
90
+
91
+
92
+ BearerAuthSetting = TypedDict(
93
+ "BearerAuthSetting",
94
+ {
95
+ "type": Literal["bearer"],
96
+ "in": Literal["header"],
97
+ "key": Literal["Authorization"],
98
+ "value": str,
99
+ },
100
+ )
101
+
102
+
103
+ HTTPSignatureAuthSetting = TypedDict(
104
+ "HTTPSignatureAuthSetting",
105
+ {
106
+ "type": Literal["http-signature"],
107
+ "in": Literal["header"],
108
+ "key": Literal["Authorization"],
109
+ "value": None,
110
+ },
111
+ )
112
+
113
+
114
+ AuthSettings = TypedDict(
115
+ "AuthSettings",
116
+ {
117
+ "ApiKey": BearerAuthSetting,
118
+ },
119
+ total=False,
120
+ )
121
+
122
+
123
+ class HostSettingVariable(TypedDict):
124
+ description: str
125
+ default_value: str
126
+ enum_values: List[str]
127
+
128
+
129
+ class HostSetting(TypedDict):
130
+ url: str
131
+ description: str
132
+ variables: NotRequired[Dict[str, HostSettingVariable]]
133
+
134
+
135
+ class Configuration:
136
+ """This class contains various settings of the API client.
137
+
138
+ :param host: Base url.
139
+ :param ignore_operation_servers
140
+ Boolean to ignore operation servers for the API client.
141
+ Config will use `host` as the base url regardless of the operation servers.
142
+ :param api_key: Dict to store API key(s).
143
+ Each entry in the dict specifies an API key.
144
+ The dict key is the name of the security scheme in the OAS specification.
145
+ The dict value is the API key secret.
146
+ :param api_key_prefix: Dict to store API prefix (e.g. Bearer).
147
+ The dict key is the name of the security scheme in the OAS specification.
148
+ The dict value is an API key prefix when generating the auth data.
149
+ :param username: Username for HTTP basic authentication.
150
+ :param password: Password for HTTP basic authentication.
151
+ :param access_token: Access token.
152
+ :param server_index: Index to servers configuration.
153
+ :param server_variables: Mapping with string values to replace variables in
154
+ templated server configuration. The validation of enums is performed for
155
+ variables with defined enum values before.
156
+ :param server_operation_index: Mapping from operation ID to an index to server
157
+ configuration.
158
+ :param server_operation_variables: Mapping from operation ID to a mapping with
159
+ string values to replace variables in templated server configuration.
160
+ The validation of enums is performed for variables with defined enum
161
+ values before.
162
+ :param verify_ssl: bool - Set this to false to skip verifying SSL certificate
163
+ when calling API from https server.
164
+ :param ssl_ca_cert: str - the path to a file of concatenated CA certificates
165
+ in PEM format.
166
+ :param retries: int | urllib3.util.retry.Retry - Retry configuration.
167
+ :param ca_cert_data: verify the peer using concatenated CA certificate data
168
+ in PEM (str) or DER (bytes) format.
169
+ :param cert_file: the path to a client certificate file, for mTLS.
170
+ :param key_file: the path to a client key file, for mTLS.
171
+ :param assert_hostname: Set this to True/False to enable/disable SSL hostname verification.
172
+ :param tls_server_name: SSL/TLS Server Name Indication (SNI). Set this to the SNI value expected by the server.
173
+ :param connection_pool_maxsize: Connection pool max size. None in the constructor is coerced to 100 for async and cpu_count * 5 for sync.
174
+ :param proxy: Proxy URL.
175
+ :param no_proxy: Comma-separated hosts that bypass the proxy.
176
+ :param proxy_headers: Proxy headers.
177
+ :param proxy_ssl_context: SSL context used only for the TLS handshake with the proxy itself, independent of the destination TLS settings.
178
+ :param safe_chars_for_path_param: Safe characters for path parameter encoding.
179
+ :param client_side_validation: Enable client-side validation. Default True.
180
+ :param socket_options: Options to pass down to the underlying urllib3 socket.
181
+ :param datetime_format: Datetime format string for serialization.
182
+ :param date_format: Date format string for serialization.
183
+
184
+ :Example:
185
+ """
186
+
187
+ _default: ClassVar[Optional[Self]] = None
188
+
189
+ def __init__(
190
+ self,
191
+ host: Optional[str]=None,
192
+ api_key: Optional[Dict[str, str]]=None,
193
+ api_key_prefix: Optional[Dict[str, str]]=None,
194
+ username: Optional[str]=None,
195
+ password: Optional[str]=None,
196
+ access_token: Optional[str]=None,
197
+ server_index: Optional[int]=None,
198
+ server_variables: Optional[ServerVariablesT]=None,
199
+ server_operation_index: Optional[Dict[int, int]]=None,
200
+ server_operation_variables: Optional[Dict[int, ServerVariablesT]]=None,
201
+ ignore_operation_servers: bool=False,
202
+ ssl_ca_cert: Optional[str]=None,
203
+ retries: Optional[Union[int, urllib3.util.retry.Retry]] = None,
204
+ ca_cert_data: Optional[Union[str, bytes]] = None,
205
+ cert_file: Optional[str]=None,
206
+ key_file: Optional[str]=None,
207
+ verify_ssl: bool=True,
208
+ assert_hostname: Optional[bool]=None,
209
+ tls_server_name: Optional[str]=None,
210
+ connection_pool_maxsize: Optional[int]=None,
211
+ proxy: Optional[str]=None,
212
+ no_proxy: Optional[str]=None,
213
+ proxy_headers: Optional[Any]=None,
214
+ proxy_ssl_context: Optional[ssl.SSLContext]=None,
215
+ safe_chars_for_path_param: str='',
216
+ client_side_validation: bool=True,
217
+ socket_options: Optional[Any]=None,
218
+ datetime_format: str="%Y-%m-%dT%H:%M:%S.%f%z",
219
+ date_format: str="%Y-%m-%d",
220
+ *,
221
+ debug: Optional[bool] = None,
222
+ ) -> None:
223
+ """Constructor
224
+ """
225
+ self._base_path = "https://api.dockflow.com" if host is None else host
226
+ """Default Base url
227
+ """
228
+ self.server_index = 0 if server_index is None and host is None else server_index
229
+ self.server_operation_index = server_operation_index or {}
230
+ """Default server index
231
+ """
232
+ self.server_variables = server_variables or {}
233
+ self.server_operation_variables = server_operation_variables or {}
234
+ """Default server variables
235
+ """
236
+ self.ignore_operation_servers = ignore_operation_servers
237
+ """Ignore operation servers
238
+ """
239
+ self.temp_folder_path = None
240
+ """Temp file folder for downloading files
241
+ """
242
+ # Authentication Settings
243
+ self.api_key = {}
244
+ if api_key:
245
+ self.api_key = api_key
246
+ """dict to store API key(s)
247
+ """
248
+ self.api_key_prefix = {}
249
+ if api_key_prefix:
250
+ self.api_key_prefix = api_key_prefix
251
+ """dict to store API prefix (e.g. Bearer)
252
+ """
253
+ self.refresh_api_key_hook = None
254
+ """function hook to refresh API key if expired
255
+ """
256
+ self.username = username
257
+ """Username for HTTP basic authentication
258
+ """
259
+ self.password = password
260
+ """Password for HTTP basic authentication
261
+ """
262
+ self.access_token = access_token
263
+ """Access token
264
+ """
265
+ self.logger = {}
266
+ """Logging Settings
267
+ """
268
+ self.logger["package_logger"] = logging.getLogger("dockflow_sdk")
269
+ self.logger["urllib3_logger"] = logging.getLogger("urllib3")
270
+ self.logger_format = '%(asctime)s %(levelname)s %(message)s'
271
+ """Log format
272
+ """
273
+ self.logger_stream_handler = None
274
+ """Log stream handler
275
+ """
276
+ self.logger_file_handler: Optional[FileHandler] = None
277
+ """Log file handler
278
+ """
279
+ self.logger_file = None
280
+ """Debug file location
281
+ """
282
+ if debug is not None:
283
+ self.debug = debug
284
+ else:
285
+ self.__debug = False
286
+ """Debug switch
287
+ """
288
+
289
+ self.verify_ssl = verify_ssl
290
+ """SSL/TLS verification
291
+ Set this to false to skip verifying SSL certificate when calling API
292
+ from https server.
293
+ """
294
+ self.ssl_ca_cert = ssl_ca_cert
295
+ """Set this to customize the certificate file to verify the peer.
296
+ """
297
+ self.ca_cert_data = ca_cert_data
298
+ """Set this to verify the peer using PEM (str) or DER (bytes)
299
+ certificate data.
300
+ """
301
+ self.cert_file = cert_file
302
+ """client certificate file
303
+ """
304
+ self.key_file = key_file
305
+ """client key file
306
+ """
307
+ self.assert_hostname = assert_hostname
308
+ """Set this to True/False to enable/disable SSL hostname verification.
309
+ """
310
+ self.tls_server_name = tls_server_name
311
+ """SSL/TLS Server Name Indication (SNI)
312
+ Set this to the SNI value expected by the server.
313
+ """
314
+
315
+ self.connection_pool_maxsize = connection_pool_maxsize if connection_pool_maxsize is not None else multiprocessing.cpu_count() * 5
316
+ """urllib3 connection pool's maximum number of connections saved
317
+ per pool. None in the constructor is coerced to cpu_count * 5.
318
+ """
319
+
320
+ # urllib3 does not read proxy environment variables itself:
321
+ # https://github.com/urllib3/urllib3/issues/1785
322
+ # A proxy taken from the environment is re-resolved when the host is
323
+ # assigned; see the host setter.
324
+ self._proxy_from_env = proxy is None
325
+ if proxy is None or no_proxy is None:
326
+ proxies = getproxies()
327
+ if proxy is None:
328
+ proxy = self._env_proxy(proxies, self.host)
329
+ if no_proxy is None:
330
+ no_proxy = proxies.get("no")
331
+ self._proxy = proxy
332
+ self.no_proxy = no_proxy
333
+ """Hosts that bypass the proxy
334
+ """
335
+ self.proxy_headers = proxy_headers
336
+ """Proxy headers
337
+ """
338
+ self.proxy_ssl_context = proxy_ssl_context
339
+ """SSL context used only for the TLS handshake with the proxy itself
340
+ (e.g. an HTTPS CONNECT tunnel), independent of the destination TLS
341
+ settings above.
342
+ """
343
+ self.safe_chars_for_path_param = safe_chars_for_path_param
344
+ """Safe chars for path_param
345
+ """
346
+ self.retries = retries
347
+ """Retry configuration
348
+ """
349
+ # Enable client side validation
350
+ self.client_side_validation = client_side_validation
351
+
352
+ self.socket_options = socket_options
353
+ """Options to pass down to the underlying urllib3 socket
354
+ """
355
+
356
+ self.datetime_format = datetime_format
357
+ """datetime format
358
+ """
359
+
360
+ self.date_format = date_format
361
+ """date format
362
+ """
363
+
364
+ def __deepcopy__(self, memo: Dict[int, Any]) -> Self:
365
+ cls = self.__class__
366
+ result = cls.__new__(cls)
367
+ memo[id(self)] = result
368
+ for k, v in self.__dict__.items():
369
+ if k == 'proxy_ssl_context':
370
+ # ssl.SSLContext holds unpicklable C state and can't be deepcopied.
371
+ setattr(result, k, v)
372
+ continue
373
+ if k not in ('logger', 'logger_file_handler'):
374
+ setattr(result, k, copy.deepcopy(v, memo))
375
+ # shallow copy of loggers
376
+ result.logger = copy.copy(self.logger)
377
+ # use setter to re-create the file handler (excluded from __dict__ copy)
378
+ result.logger_file = self.logger_file
379
+
380
+ return result
381
+
382
+ def __setattr__(self, name: str, value: Any) -> None:
383
+ object.__setattr__(self, name, value)
384
+
385
+ @classmethod
386
+ def set_default(cls, default: Optional[Self]) -> None:
387
+ """Set default instance of configuration.
388
+
389
+ It stores default configuration, which can be
390
+ returned by get_default_copy method.
391
+
392
+ :param default: object of Configuration
393
+ """
394
+ cls._default = default
395
+
396
+ @classmethod
397
+ def get_default_copy(cls) -> Self:
398
+ """Deprecated. Please use `get_default` instead.
399
+
400
+ Deprecated. Please use `get_default` instead.
401
+
402
+ :return: The configuration object.
403
+ """
404
+ return cls.get_default()
405
+
406
+ @classmethod
407
+ def get_default(cls) -> Self:
408
+ """Return the default configuration.
409
+
410
+ This method returns newly created, based on default constructor,
411
+ object of Configuration class or returns a copy of default
412
+ configuration.
413
+
414
+ :return: The configuration object.
415
+ """
416
+ if cls._default is None:
417
+ cls._default = cls()
418
+ return cls._default
419
+
420
+ @property
421
+ def logger_file(self) -> Optional[str]:
422
+ """The logger file.
423
+
424
+ If the logger_file is None, then add stream handler and remove file
425
+ handler. Otherwise, add file handler and remove stream handler.
426
+
427
+ :param value: The logger_file path.
428
+ :type: str
429
+ """
430
+ return self.__logger_file
431
+
432
+ @logger_file.setter
433
+ def logger_file(self, value: Optional[str]) -> None:
434
+ """The logger file.
435
+
436
+ If the logger_file is None, then add stream handler and remove file
437
+ handler. Otherwise, add file handler and remove stream handler.
438
+
439
+ :param value: The logger_file path.
440
+ :type: str
441
+ """
442
+ self.__logger_file = value
443
+ if self.__logger_file:
444
+ # If set logging file,
445
+ # then add file handler and remove stream handler.
446
+ self.logger_file_handler = logging.FileHandler(self.__logger_file)
447
+ self.logger_file_handler.setFormatter(self.logger_formatter)
448
+ for _, logger in self.logger.items():
449
+ logger.addHandler(self.logger_file_handler)
450
+
451
+ @property
452
+ def debug(self) -> bool:
453
+ """Debug status
454
+
455
+ :param value: The debug status, True or False.
456
+ :type: bool
457
+ """
458
+ return self.__debug
459
+
460
+ @debug.setter
461
+ def debug(self, value: bool) -> None:
462
+ """Debug status
463
+
464
+ :param value: The debug status, True or False.
465
+ :type: bool
466
+ """
467
+ self.__debug = value
468
+ if self.__debug:
469
+ # if debug status is True, turn on debug logging
470
+ for _, logger in self.logger.items():
471
+ logger.setLevel(logging.DEBUG)
472
+ # turn on httplib debug
473
+ httplib.HTTPConnection.debuglevel = 1
474
+ else:
475
+ # if debug status is False, turn off debug logging,
476
+ # setting log level to default `logging.WARNING`
477
+ for _, logger in self.logger.items():
478
+ logger.setLevel(logging.WARNING)
479
+ # turn off httplib debug
480
+ httplib.HTTPConnection.debuglevel = 0
481
+
482
+ @property
483
+ def logger_format(self) -> str:
484
+ """The logger format.
485
+
486
+ The logger_formatter will be updated when sets logger_format.
487
+
488
+ :param value: The format string.
489
+ :type: str
490
+ """
491
+ return self.__logger_format
492
+
493
+ @logger_format.setter
494
+ def logger_format(self, value: str) -> None:
495
+ """The logger format.
496
+
497
+ The logger_formatter will be updated when sets logger_format.
498
+
499
+ :param value: The format string.
500
+ :type: str
501
+ """
502
+ self.__logger_format = value
503
+ self.logger_formatter = logging.Formatter(self.__logger_format)
504
+
505
+ def get_api_key_with_prefix(self, identifier: str, alias: Optional[str]=None) -> Optional[str]:
506
+ """Gets API key (with prefix if set).
507
+
508
+ :param identifier: The identifier of apiKey.
509
+ :param alias: The alternative identifier of apiKey.
510
+ :return: The token for api key authentication.
511
+ """
512
+ if self.refresh_api_key_hook is not None:
513
+ self.refresh_api_key_hook(self)
514
+ key = self.api_key.get(identifier, self.api_key.get(alias) if alias is not None else None)
515
+ if key:
516
+ prefix = self.api_key_prefix.get(
517
+ identifier, self.api_key_prefix.get(alias) if alias is not None else None)
518
+ if prefix:
519
+ return "%s %s" % (prefix, key)
520
+ else:
521
+ return key
522
+
523
+ return None
524
+
525
+ def get_basic_auth_token(self) -> Optional[str]:
526
+ """Gets HTTP basic authentication header (string).
527
+
528
+ :return: The token for basic HTTP authentication.
529
+ """
530
+ username = ""
531
+ if self.username is not None:
532
+ username = self.username
533
+ password = ""
534
+ if self.password is not None:
535
+ password = self.password
536
+
537
+ return urllib3.util.make_headers(
538
+ basic_auth=username + ':' + password
539
+ ).get('authorization')
540
+
541
+ def auth_settings(self)-> AuthSettings:
542
+ """Gets Auth Settings dict for api client.
543
+
544
+ :return: The Auth Settings information dict.
545
+ """
546
+ auth: AuthSettings = {}
547
+ if self.access_token is not None:
548
+ auth['ApiKey'] = {
549
+ 'type': 'bearer',
550
+ 'in': 'header',
551
+ 'key': 'Authorization',
552
+ 'value': 'Bearer ' + self.access_token
553
+ }
554
+ return auth
555
+
556
+ def to_debug_report(self) -> str:
557
+ """Gets the essential information for debugging.
558
+
559
+ :return: The report for debugging.
560
+ """
561
+ return "Python SDK Debug Report:\n"\
562
+ "OS: {env}\n"\
563
+ "Python Version: {pyversion}\n"\
564
+ "Version of the API: 3.0.0\n"\
565
+ "SDK Package Version: 0.3.0".\
566
+ format(env=sys.platform, pyversion=sys.version)
567
+
568
+ def get_host_settings(self) -> List[HostSetting]:
569
+ """Gets an array of host settings
570
+
571
+ :return: An array of host settings
572
+ """
573
+ return [
574
+ {
575
+ 'url': "https://api.dockflow.com",
576
+ 'description': "Production",
577
+ },
578
+ {
579
+ 'url': "https://uat.dockflow.com",
580
+ 'description': "UAT",
581
+ }
582
+ ]
583
+
584
+ def get_host_from_settings(
585
+ self,
586
+ index: Optional[int],
587
+ variables: Optional[ServerVariablesT]=None,
588
+ servers: Optional[List[HostSetting]]=None,
589
+ ) -> str:
590
+ """Gets host URL based on the index and variables
591
+ :param index: array index of the host settings
592
+ :param variables: hash of variable and the corresponding value
593
+ :param servers: an array of host settings or None
594
+ :return: URL based on host settings
595
+ """
596
+ if index is None:
597
+ return self._base_path
598
+
599
+ variables = {} if variables is None else variables
600
+ servers = self.get_host_settings() if servers is None else servers
601
+
602
+ try:
603
+ server = servers[index]
604
+ except IndexError:
605
+ raise ValueError(
606
+ "Invalid index {0} when selecting the host settings. "
607
+ "Must be less than {1}".format(index, len(servers)))
608
+
609
+ url = server['url']
610
+
611
+ # go through variables and replace placeholders
612
+ for variable_name, variable in server.get('variables', {}).items():
613
+ used_value = variables.get(
614
+ variable_name, variable['default_value'])
615
+
616
+ if 'enum_values' in variable \
617
+ and variable['enum_values'] \
618
+ and used_value not in variable['enum_values']:
619
+ raise ValueError(
620
+ "The variable `{0}` in the host URL has invalid value "
621
+ "{1}. Must be {2}.".format(
622
+ variable_name, variables[variable_name],
623
+ variable['enum_values']))
624
+
625
+ url = url.replace("{" + variable_name + "}", used_value)
626
+
627
+ return url
628
+
629
+ @property
630
+ def host(self) -> str:
631
+ """Return generated host."""
632
+ return self.get_host_from_settings(self.server_index, variables=self.server_variables)
633
+
634
+ @host.setter
635
+ def host(self, value: str) -> None:
636
+ """Fix base path."""
637
+ self._base_path = value
638
+ self.server_index = None
639
+ if self._proxy_from_env:
640
+ # the scheme-specific proxy depends on the host, which is
641
+ # commonly assigned after construction
642
+ self._proxy = self._env_proxy(getproxies(), value)
643
+
644
+ @staticmethod
645
+ def _env_proxy(proxies: Dict[str, str], host: str) -> Optional[str]:
646
+ """Pick the environment proxy that applies to `host`."""
647
+ return proxies.get(urlparse(host).scheme) or proxies.get("all")
648
+
649
+ @property
650
+ def proxy(self) -> Optional[str]:
651
+ """Proxy URL
652
+ """
653
+ return self._proxy
654
+
655
+ @proxy.setter
656
+ def proxy(self, value: Optional[str]) -> None:
657
+ self._proxy = value
658
+ self._proxy_from_env = False