pidginhost-sdk 0.2.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 (224) hide show
  1. pidginhost_sdk/__init__.py +467 -0
  2. pidginhost_sdk/api/__init__.py +14 -0
  3. pidginhost_sdk/api/account_api.py +10267 -0
  4. pidginhost_sdk/api/billing_api.py +9644 -0
  5. pidginhost_sdk/api/cloud_api.py +43062 -0
  6. pidginhost_sdk/api/dedicated_api.py +2838 -0
  7. pidginhost_sdk/api/domain_api.py +10505 -0
  8. pidginhost_sdk/api/freedns_api.py +3440 -0
  9. pidginhost_sdk/api/hosting_api.py +1674 -0
  10. pidginhost_sdk/api/kubernetes_api.py +31395 -0
  11. pidginhost_sdk/api/schema_api.py +605 -0
  12. pidginhost_sdk/api/support_api.py +4324 -0
  13. pidginhost_sdk/api_client.py +806 -0
  14. pidginhost_sdk/api_response.py +21 -0
  15. pidginhost_sdk/client.py +50 -0
  16. pidginhost_sdk/configuration.py +617 -0
  17. pidginhost_sdk/exceptions.py +219 -0
  18. pidginhost_sdk/models/__init__.py +217 -0
  19. pidginhost_sdk/models/activate_free_dns.py +93 -0
  20. pidginhost_sdk/models/activate_free_dns_response.py +92 -0
  21. pidginhost_sdk/models/activity_log_entry.py +90 -0
  22. pidginhost_sdk/models/activity_log_response.py +96 -0
  23. pidginhost_sdk/models/add_server_response.py +88 -0
  24. pidginhost_sdk/models/address.py +116 -0
  25. pidginhost_sdk/models/api_token_create.py +105 -0
  26. pidginhost_sdk/models/api_token_list.py +121 -0
  27. pidginhost_sdk/models/attach_ipv4.py +88 -0
  28. pidginhost_sdk/models/attach_ipv6.py +88 -0
  29. pidginhost_sdk/models/attach_volume.py +88 -0
  30. pidginhost_sdk/models/cancel_service_response.py +90 -0
  31. pidginhost_sdk/models/change_billing_cycle.py +88 -0
  32. pidginhost_sdk/models/change_billing_cycle_response.py +90 -0
  33. pidginhost_sdk/models/change_company.py +93 -0
  34. pidginhost_sdk/models/change_company_response.py +95 -0
  35. pidginhost_sdk/models/change_password.py +89 -0
  36. pidginhost_sdk/models/check_availability.py +89 -0
  37. pidginhost_sdk/models/cluster_add.py +104 -0
  38. pidginhost_sdk/models/cluster_add_response.py +88 -0
  39. pidginhost_sdk/models/cluster_detail.py +148 -0
  40. pidginhost_sdk/models/cluster_package.py +104 -0
  41. pidginhost_sdk/models/cluster_type.py +104 -0
  42. pidginhost_sdk/models/cluster_type_enum.py +38 -0
  43. pidginhost_sdk/models/company.py +111 -0
  44. pidginhost_sdk/models/connect_vm_request.py +88 -0
  45. pidginhost_sdk/models/connect_vm_response.py +90 -0
  46. pidginhost_sdk/models/connected_vm.py +92 -0
  47. pidginhost_sdk/models/connected_vms_response.py +96 -0
  48. pidginhost_sdk/models/console_token.py +90 -0
  49. pidginhost_sdk/models/contact_type_enum.py +40 -0
  50. pidginhost_sdk/models/contacts_update.py +91 -0
  51. pidginhost_sdk/models/contacts_update_response.py +88 -0
  52. pidginhost_sdk/models/country_enum.py +290 -0
  53. pidginhost_sdk/models/deactivate_free_dns.py +91 -0
  54. pidginhost_sdk/models/deactivate_free_dns_response.py +88 -0
  55. pidginhost_sdk/models/dedicated_rdns.py +91 -0
  56. pidginhost_sdk/models/dedicated_server.py +136 -0
  57. pidginhost_sdk/models/delete_record.py +88 -0
  58. pidginhost_sdk/models/delete_record_response.py +90 -0
  59. pidginhost_sdk/models/department.py +94 -0
  60. pidginhost_sdk/models/deposit.py +138 -0
  61. pidginhost_sdk/models/deposit_create.py +88 -0
  62. pidginhost_sdk/models/deposit_status_enum.py +40 -0
  63. pidginhost_sdk/models/destroy_protection.py +88 -0
  64. pidginhost_sdk/models/detach_ipv4.py +88 -0
  65. pidginhost_sdk/models/detach_ipv4_response.py +88 -0
  66. pidginhost_sdk/models/detach_ipv6.py +88 -0
  67. pidginhost_sdk/models/detach_ipv6_response.py +88 -0
  68. pidginhost_sdk/models/detach_volume.py +88 -0
  69. pidginhost_sdk/models/disconnect_vm_request.py +88 -0
  70. pidginhost_sdk/models/disconnect_vm_response.py +90 -0
  71. pidginhost_sdk/models/dns_record.py +154 -0
  72. pidginhost_sdk/models/dns_record_create.py +121 -0
  73. pidginhost_sdk/models/dns_record_create_type_enum.py +43 -0
  74. pidginhost_sdk/models/dns_record_mutate_response.py +94 -0
  75. pidginhost_sdk/models/domain.py +152 -0
  76. pidginhost_sdk/models/domain_cancel_response.py +90 -0
  77. pidginhost_sdk/models/domain_create.py +93 -0
  78. pidginhost_sdk/models/domain_registrant.py +131 -0
  79. pidginhost_sdk/models/email_history.py +107 -0
  80. pidginhost_sdk/models/feature_upgrade_request.py +90 -0
  81. pidginhost_sdk/models/feature_upgrade_response.py +90 -0
  82. pidginhost_sdk/models/features_enum.py +41 -0
  83. pidginhost_sdk/models/firewall_rule.py +119 -0
  84. pidginhost_sdk/models/firewall_rule_direction_enum.py +38 -0
  85. pidginhost_sdk/models/firewall_rules_set.py +114 -0
  86. pidginhost_sdk/models/firewall_rules_set_status_enum.py +39 -0
  87. pidginhost_sdk/models/free_dns_domain.py +98 -0
  88. pidginhost_sdk/models/funds_balance_response.py +122 -0
  89. pidginhost_sdk/models/funds_log.py +117 -0
  90. pidginhost_sdk/models/fw_policy_out_enum.py +39 -0
  91. pidginhost_sdk/models/hosting_change_password_response.py +88 -0
  92. pidginhost_sdk/models/hosting_service.py +136 -0
  93. pidginhost_sdk/models/http_route.py +129 -0
  94. pidginhost_sdk/models/invoice_detail.py +199 -0
  95. pidginhost_sdk/models/invoice_list.py +164 -0
  96. pidginhost_sdk/models/kube_upgrade_response.py +88 -0
  97. pidginhost_sdk/models/kube_version_enum.py +39 -0
  98. pidginhost_sdk/models/lb_firewall_rule.py +122 -0
  99. pidginhost_sdk/models/lb_firewall_rule_action_enum.py +39 -0
  100. pidginhost_sdk/models/lb_firewall_rule_direction_enum.py +38 -0
  101. pidginhost_sdk/models/low_balance_settings.py +114 -0
  102. pidginhost_sdk/models/nameservers_update.py +89 -0
  103. pidginhost_sdk/models/nameservers_update_response.py +88 -0
  104. pidginhost_sdk/models/node_metrics_response.py +100 -0
  105. pidginhost_sdk/models/node_rrd_response.py +90 -0
  106. pidginhost_sdk/models/notification_settings_response.py +115 -0
  107. pidginhost_sdk/models/operation_enum.py +46 -0
  108. pidginhost_sdk/models/os_image.py +108 -0
  109. pidginhost_sdk/models/paginated_api_token_list_list.py +112 -0
  110. pidginhost_sdk/models/paginated_cluster_detail_list.py +112 -0
  111. pidginhost_sdk/models/paginated_cluster_type_list.py +112 -0
  112. pidginhost_sdk/models/paginated_company_list.py +112 -0
  113. pidginhost_sdk/models/paginated_dedicated_server_list.py +112 -0
  114. pidginhost_sdk/models/paginated_deposit_list.py +112 -0
  115. pidginhost_sdk/models/paginated_domain_list.py +112 -0
  116. pidginhost_sdk/models/paginated_domain_registrant_list.py +112 -0
  117. pidginhost_sdk/models/paginated_email_history_list.py +112 -0
  118. pidginhost_sdk/models/paginated_funds_log_list.py +112 -0
  119. pidginhost_sdk/models/paginated_hosting_service_list.py +112 -0
  120. pidginhost_sdk/models/paginated_invoice_list_list.py +112 -0
  121. pidginhost_sdk/models/paginated_lb_firewall_rule_list.py +112 -0
  122. pidginhost_sdk/models/paginated_os_image_list.py +112 -0
  123. pidginhost_sdk/models/paginated_private_network_list.py +112 -0
  124. pidginhost_sdk/models/paginated_public_ipv4_list.py +112 -0
  125. pidginhost_sdk/models/paginated_public_ipv6_list.py +112 -0
  126. pidginhost_sdk/models/paginated_resource_pool_list.py +112 -0
  127. pidginhost_sdk/models/paginated_resource_pool_node_list.py +112 -0
  128. pidginhost_sdk/models/paginated_server_list.py +112 -0
  129. pidginhost_sdk/models/paginated_server_product_list.py +112 -0
  130. pidginhost_sdk/models/paginated_service_list_list.py +112 -0
  131. pidginhost_sdk/models/paginated_snapshot_list.py +112 -0
  132. pidginhost_sdk/models/paginated_ssh_key_list.py +112 -0
  133. pidginhost_sdk/models/paginated_storage_product_list.py +112 -0
  134. pidginhost_sdk/models/paginated_subscription_list.py +112 -0
  135. pidginhost_sdk/models/paginated_ticket_list_list.py +112 -0
  136. pidginhost_sdk/models/paginated_tld_list.py +112 -0
  137. pidginhost_sdk/models/patched_cluster_detail.py +151 -0
  138. pidginhost_sdk/models/patched_company.py +111 -0
  139. pidginhost_sdk/models/patched_domain.py +152 -0
  140. pidginhost_sdk/models/patched_domain_registrant.py +131 -0
  141. pidginhost_sdk/models/patched_firewall_rule.py +119 -0
  142. pidginhost_sdk/models/patched_firewall_rules_set.py +114 -0
  143. pidginhost_sdk/models/patched_http_route.py +129 -0
  144. pidginhost_sdk/models/patched_lb_firewall_rule.py +122 -0
  145. pidginhost_sdk/models/patched_private_network.py +112 -0
  146. pidginhost_sdk/models/patched_profile.py +107 -0
  147. pidginhost_sdk/models/patched_resource_pool.py +113 -0
  148. pidginhost_sdk/models/patched_ssh_key.py +101 -0
  149. pidginhost_sdk/models/patched_tcp_route.py +125 -0
  150. pidginhost_sdk/models/patched_udp_route.py +125 -0
  151. pidginhost_sdk/models/patched_volume.py +107 -0
  152. pidginhost_sdk/models/pay_with_funds_response.py +98 -0
  153. pidginhost_sdk/models/power_action.py +89 -0
  154. pidginhost_sdk/models/power_action_action_enum.py +40 -0
  155. pidginhost_sdk/models/power_action_response.py +88 -0
  156. pidginhost_sdk/models/power_management.py +88 -0
  157. pidginhost_sdk/models/power_management_request.py +89 -0
  158. pidginhost_sdk/models/power_management_request_action_enum.py +40 -0
  159. pidginhost_sdk/models/priority3cd_enum.py +39 -0
  160. pidginhost_sdk/models/private_network.py +112 -0
  161. pidginhost_sdk/models/private_network_add_host.py +90 -0
  162. pidginhost_sdk/models/private_network_remove_host.py +88 -0
  163. pidginhost_sdk/models/profile.py +104 -0
  164. pidginhost_sdk/models/public_interface.py +110 -0
  165. pidginhost_sdk/models/public_ipv4.py +114 -0
  166. pidginhost_sdk/models/public_ipv6.py +114 -0
  167. pidginhost_sdk/models/rdns_update_response.py +88 -0
  168. pidginhost_sdk/models/reinstall.py +88 -0
  169. pidginhost_sdk/models/reinstall_response.py +88 -0
  170. pidginhost_sdk/models/remove_server_response.py +88 -0
  171. pidginhost_sdk/models/renew_domain.py +89 -0
  172. pidginhost_sdk/models/resource_pool.py +113 -0
  173. pidginhost_sdk/models/resource_pool_add.py +91 -0
  174. pidginhost_sdk/models/resource_pool_add_response.py +88 -0
  175. pidginhost_sdk/models/resource_pool_node.py +96 -0
  176. pidginhost_sdk/models/retry_provision.py +88 -0
  177. pidginhost_sdk/models/reverse_dns.py +89 -0
  178. pidginhost_sdk/models/scope_enum.py +38 -0
  179. pidginhost_sdk/models/server.py +130 -0
  180. pidginhost_sdk/models/server_add.py +128 -0
  181. pidginhost_sdk/models/server_add_response.py +88 -0
  182. pidginhost_sdk/models/server_product.py +104 -0
  183. pidginhost_sdk/models/server_product_upgrade.py +88 -0
  184. pidginhost_sdk/models/server_upgrade_response.py +88 -0
  185. pidginhost_sdk/models/server_usage_response.py +96 -0
  186. pidginhost_sdk/models/service.py +153 -0
  187. pidginhost_sdk/models/service_list.py +132 -0
  188. pidginhost_sdk/models/snapshot.py +104 -0
  189. pidginhost_sdk/models/snapshot_create.py +100 -0
  190. pidginhost_sdk/models/snapshot_create_queued.py +88 -0
  191. pidginhost_sdk/models/snapshot_delete_queued.py +88 -0
  192. pidginhost_sdk/models/snapshot_rollback_queued.py +88 -0
  193. pidginhost_sdk/models/source_enum.py +38 -0
  194. pidginhost_sdk/models/ssh_key.py +101 -0
  195. pidginhost_sdk/models/status03c_enum.py +43 -0
  196. pidginhost_sdk/models/status63a_enum.py +44 -0
  197. pidginhost_sdk/models/status_a57_enum.py +48 -0
  198. pidginhost_sdk/models/status_ef2_enum.py +40 -0
  199. pidginhost_sdk/models/storage_product.py +129 -0
  200. pidginhost_sdk/models/subscription.py +142 -0
  201. pidginhost_sdk/models/subscription_status_enum.py +40 -0
  202. pidginhost_sdk/models/talos_upgrade_response.py +88 -0
  203. pidginhost_sdk/models/tcp_route.py +125 -0
  204. pidginhost_sdk/models/threshold_type_enum.py +39 -0
  205. pidginhost_sdk/models/ticket_close_response.py +90 -0
  206. pidginhost_sdk/models/ticket_create.py +110 -0
  207. pidginhost_sdk/models/ticket_create_priority_enum.py +39 -0
  208. pidginhost_sdk/models/ticket_detail.py +125 -0
  209. pidginhost_sdk/models/ticket_list.py +117 -0
  210. pidginhost_sdk/models/ticket_reopen_response.py +90 -0
  211. pidginhost_sdk/models/ticket_reply.py +95 -0
  212. pidginhost_sdk/models/ticket_reply_response.py +88 -0
  213. pidginhost_sdk/models/tld.py +146 -0
  214. pidginhost_sdk/models/toggle_auto_payment_response.py +90 -0
  215. pidginhost_sdk/models/transfer_ro_domain.py +91 -0
  216. pidginhost_sdk/models/type2fa_enum.py +38 -0
  217. pidginhost_sdk/models/udp_route.py +125 -0
  218. pidginhost_sdk/models/volume.py +107 -0
  219. pidginhost_sdk/py.typed +0 -0
  220. pidginhost_sdk/rest.py +264 -0
  221. pidginhost_sdk-0.2.0.dist-info/METADATA +805 -0
  222. pidginhost_sdk-0.2.0.dist-info/RECORD +224 -0
  223. pidginhost_sdk-0.2.0.dist-info/WHEEL +5 -0
  224. pidginhost_sdk-0.2.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,50 @@
1
+ """
2
+ PidginHost API Client
3
+
4
+ Simple wrapper around the generated SDK.
5
+
6
+ Usage:
7
+ from pidginhost_sdk.client import PidginHost
8
+
9
+ client = PidginHost("your-api-token")
10
+ servers = client.cloud.cloud_servers_list()
11
+ keys = client.account.account_ssh_keys_list()
12
+ """
13
+
14
+ from pidginhost_sdk.api.account_api import AccountApi
15
+ from pidginhost_sdk.api.cloud_api import CloudApi
16
+ from pidginhost_sdk.api.domain_api import DomainApi
17
+ from pidginhost_sdk.api.kubernetes_api import KubernetesApi
18
+ from pidginhost_sdk.api_client import ApiClient
19
+ from pidginhost_sdk.configuration import Configuration
20
+
21
+
22
+ class PidginHost:
23
+ """PidginHost API client.
24
+
25
+ Args:
26
+ token: API authentication token.
27
+ host: Override the default API host.
28
+ """
29
+
30
+ def __init__(self, token: str, host: str | None = None):
31
+ self._configuration = Configuration()
32
+ if host is not None:
33
+ self._configuration.host = host
34
+ self._configuration.api_key["tokenAuth"] = token
35
+ self._configuration.api_key_prefix["tokenAuth"] = "Token"
36
+ self._api_client = ApiClient(self._configuration)
37
+
38
+ self.account = AccountApi(self._api_client)
39
+ self.cloud = CloudApi(self._api_client)
40
+ self.domain = DomainApi(self._api_client)
41
+ self.kubernetes = KubernetesApi(self._api_client)
42
+
43
+ def close(self):
44
+ self._api_client.close()
45
+
46
+ def __enter__(self):
47
+ return self
48
+
49
+ def __exit__(self, *args):
50
+ self.close()
@@ -0,0 +1,617 @@
1
+ """
2
+ Pidgin Host API
3
+
4
+ The Pidgin Host API allows you to manage Services and resources within the Pidgin Host cloud in a simple, programmatic way using conventional HTTP requests. All of the functionality that you are familiar with in the Pidgin Host control panel is also available through the API, allowing you to script the complex actions that your situation requires.
5
+
6
+ The version of the OpenAPI document: 1.0.0 (v1)
7
+ Contact: support@pidginhost.com
8
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
9
+
10
+ Do not edit the class manually.
11
+ """ # noqa: E501
12
+
13
+
14
+ import copy
15
+ import http.client as httplib
16
+ import logging
17
+ from logging import FileHandler
18
+ import multiprocessing
19
+ import sys
20
+ from typing import Any, ClassVar, Dict, List, Literal, Optional, TypedDict, Union
21
+ from typing_extensions import NotRequired, Self
22
+
23
+ import urllib3
24
+
25
+
26
+ JSON_SCHEMA_VALIDATION_KEYWORDS = {
27
+ 'multipleOf', 'maximum', 'exclusiveMaximum',
28
+ 'minimum', 'exclusiveMinimum', 'maxLength',
29
+ 'minLength', 'pattern', 'maxItems', 'minItems'
30
+ }
31
+
32
+ ServerVariablesT = Dict[str, str]
33
+
34
+ GenericAuthSetting = TypedDict(
35
+ "GenericAuthSetting",
36
+ {
37
+ "type": str,
38
+ "in": str,
39
+ "key": str,
40
+ "value": str,
41
+ },
42
+ )
43
+
44
+
45
+ OAuth2AuthSetting = TypedDict(
46
+ "OAuth2AuthSetting",
47
+ {
48
+ "type": Literal["oauth2"],
49
+ "in": Literal["header"],
50
+ "key": Literal["Authorization"],
51
+ "value": str,
52
+ },
53
+ )
54
+
55
+
56
+ APIKeyAuthSetting = TypedDict(
57
+ "APIKeyAuthSetting",
58
+ {
59
+ "type": Literal["api_key"],
60
+ "in": str,
61
+ "key": str,
62
+ "value": Optional[str],
63
+ },
64
+ )
65
+
66
+
67
+ BasicAuthSetting = TypedDict(
68
+ "BasicAuthSetting",
69
+ {
70
+ "type": Literal["basic"],
71
+ "in": Literal["header"],
72
+ "key": Literal["Authorization"],
73
+ "value": Optional[str],
74
+ },
75
+ )
76
+
77
+
78
+ BearerFormatAuthSetting = TypedDict(
79
+ "BearerFormatAuthSetting",
80
+ {
81
+ "type": Literal["bearer"],
82
+ "in": Literal["header"],
83
+ "format": Literal["JWT"],
84
+ "key": Literal["Authorization"],
85
+ "value": str,
86
+ },
87
+ )
88
+
89
+
90
+ BearerAuthSetting = TypedDict(
91
+ "BearerAuthSetting",
92
+ {
93
+ "type": Literal["bearer"],
94
+ "in": Literal["header"],
95
+ "key": Literal["Authorization"],
96
+ "value": str,
97
+ },
98
+ )
99
+
100
+
101
+ HTTPSignatureAuthSetting = TypedDict(
102
+ "HTTPSignatureAuthSetting",
103
+ {
104
+ "type": Literal["http-signature"],
105
+ "in": Literal["header"],
106
+ "key": Literal["Authorization"],
107
+ "value": None,
108
+ },
109
+ )
110
+
111
+
112
+ AuthSettings = TypedDict(
113
+ "AuthSettings",
114
+ {
115
+ "cookieAuth": APIKeyAuthSetting,
116
+ "tokenAuth": APIKeyAuthSetting,
117
+ },
118
+ total=False,
119
+ )
120
+
121
+
122
+ class HostSettingVariable(TypedDict):
123
+ description: str
124
+ default_value: str
125
+ enum_values: List[str]
126
+
127
+
128
+ class HostSetting(TypedDict):
129
+ url: str
130
+ description: str
131
+ variables: NotRequired[Dict[str, HostSettingVariable]]
132
+
133
+
134
+ class Configuration:
135
+ """This class contains various settings of the API client.
136
+
137
+ :param host: Base url.
138
+ :param ignore_operation_servers
139
+ Boolean to ignore operation servers for the API client.
140
+ Config will use `host` as the base url regardless of the operation servers.
141
+ :param api_key: Dict to store API key(s).
142
+ Each entry in the dict specifies an API key.
143
+ The dict key is the name of the security scheme in the OAS specification.
144
+ The dict value is the API key secret.
145
+ :param api_key_prefix: Dict to store API prefix (e.g. Bearer).
146
+ The dict key is the name of the security scheme in the OAS specification.
147
+ The dict value is an API key prefix when generating the auth data.
148
+ :param username: Username for HTTP basic authentication.
149
+ :param password: Password for HTTP basic authentication.
150
+ :param access_token: Access token.
151
+ :param server_index: Index to servers configuration.
152
+ :param server_variables: Mapping with string values to replace variables in
153
+ templated server configuration. The validation of enums is performed for
154
+ variables with defined enum values before.
155
+ :param server_operation_index: Mapping from operation ID to an index to server
156
+ configuration.
157
+ :param server_operation_variables: Mapping from operation ID to a mapping with
158
+ string values to replace variables in templated server configuration.
159
+ The validation of enums is performed for variables with defined enum
160
+ values before.
161
+ :param ssl_ca_cert: str - the path to a file of concatenated CA certificates
162
+ in PEM format.
163
+ :param retries: int | urllib3.util.retry.Retry - Retry configuration.
164
+ :param ca_cert_data: verify the peer using concatenated CA certificate data
165
+ in PEM (str) or DER (bytes) format.
166
+ :param cert_file: the path to a client certificate file, for mTLS.
167
+ :param key_file: the path to a client key file, for mTLS.
168
+
169
+ :Example:
170
+
171
+ API Key Authentication Example.
172
+ Given the following security scheme in the OpenAPI specification:
173
+ components:
174
+ securitySchemes:
175
+ cookieAuth: # name for the security scheme
176
+ type: apiKey
177
+ in: cookie
178
+ name: JSESSIONID # cookie name
179
+
180
+ You can programmatically set the cookie:
181
+
182
+ conf = pidginhost_sdk.Configuration(
183
+ api_key={'cookieAuth': 'abc123'}
184
+ api_key_prefix={'cookieAuth': 'JSESSIONID'}
185
+ )
186
+
187
+ The following cookie will be added to the HTTP request:
188
+ Cookie: JSESSIONID abc123
189
+ """
190
+
191
+ _default: ClassVar[Optional[Self]] = None
192
+
193
+ def __init__(
194
+ self,
195
+ host: Optional[str]=None,
196
+ api_key: Optional[Dict[str, str]]=None,
197
+ api_key_prefix: Optional[Dict[str, str]]=None,
198
+ username: Optional[str]=None,
199
+ password: Optional[str]=None,
200
+ access_token: Optional[str]=None,
201
+ server_index: Optional[int]=None,
202
+ server_variables: Optional[ServerVariablesT]=None,
203
+ server_operation_index: Optional[Dict[int, int]]=None,
204
+ server_operation_variables: Optional[Dict[int, ServerVariablesT]]=None,
205
+ ignore_operation_servers: bool=False,
206
+ ssl_ca_cert: Optional[str]=None,
207
+ retries: Optional[Union[int, Any]] = None,
208
+ ca_cert_data: Optional[Union[str, bytes]] = None,
209
+ cert_file: Optional[str]=None,
210
+ key_file: Optional[str]=None,
211
+ *,
212
+ debug: Optional[bool] = None,
213
+ ) -> None:
214
+ """Constructor
215
+ """
216
+ self._base_path = "https://www.pidginhost.com" if host is None else host
217
+ """Default Base url
218
+ """
219
+ self.server_index = 0 if server_index is None and host is None else server_index
220
+ self.server_operation_index = server_operation_index or {}
221
+ """Default server index
222
+ """
223
+ self.server_variables = server_variables or {}
224
+ self.server_operation_variables = server_operation_variables or {}
225
+ """Default server variables
226
+ """
227
+ self.ignore_operation_servers = ignore_operation_servers
228
+ """Ignore operation servers
229
+ """
230
+ self.temp_folder_path = None
231
+ """Temp file folder for downloading files
232
+ """
233
+ # Authentication Settings
234
+ self.api_key = {}
235
+ if api_key:
236
+ self.api_key = api_key
237
+ """dict to store API key(s)
238
+ """
239
+ self.api_key_prefix = {}
240
+ if api_key_prefix:
241
+ self.api_key_prefix = api_key_prefix
242
+ """dict to store API prefix (e.g. Bearer)
243
+ """
244
+ self.refresh_api_key_hook = None
245
+ """function hook to refresh API key if expired
246
+ """
247
+ self.username = username
248
+ """Username for HTTP basic authentication
249
+ """
250
+ self.password = password
251
+ """Password for HTTP basic authentication
252
+ """
253
+ self.access_token = access_token
254
+ """Access token
255
+ """
256
+ self.logger = {}
257
+ """Logging Settings
258
+ """
259
+ self.logger["package_logger"] = logging.getLogger("pidginhost_sdk")
260
+ self.logger["urllib3_logger"] = logging.getLogger("urllib3")
261
+ self.logger_format = '%(asctime)s %(levelname)s %(message)s'
262
+ """Log format
263
+ """
264
+ self.logger_stream_handler = None
265
+ """Log stream handler
266
+ """
267
+ self.logger_file_handler: Optional[FileHandler] = None
268
+ """Log file handler
269
+ """
270
+ self.logger_file = None
271
+ """Debug file location
272
+ """
273
+ if debug is not None:
274
+ self.debug = debug
275
+ else:
276
+ self.__debug = False
277
+ """Debug switch
278
+ """
279
+
280
+ self.verify_ssl = True
281
+ """SSL/TLS verification
282
+ Set this to false to skip verifying SSL certificate when calling API
283
+ from https server.
284
+ """
285
+ self.ssl_ca_cert = ssl_ca_cert
286
+ """Set this to customize the certificate file to verify the peer.
287
+ """
288
+ self.ca_cert_data = ca_cert_data
289
+ """Set this to verify the peer using PEM (str) or DER (bytes)
290
+ certificate data.
291
+ """
292
+ self.cert_file = cert_file
293
+ """client certificate file
294
+ """
295
+ self.key_file = key_file
296
+ """client key file
297
+ """
298
+ self.assert_hostname = None
299
+ """Set this to True/False to enable/disable SSL hostname verification.
300
+ """
301
+ self.tls_server_name = None
302
+ """SSL/TLS Server Name Indication (SNI)
303
+ Set this to the SNI value expected by the server.
304
+ """
305
+
306
+ self.connection_pool_maxsize = multiprocessing.cpu_count() * 5
307
+ """urllib3 connection pool's maximum number of connections saved
308
+ per pool. urllib3 uses 1 connection as default value, but this is
309
+ not the best value when you are making a lot of possibly parallel
310
+ requests to the same host, which is often the case here.
311
+ cpu_count * 5 is used as default value to increase performance.
312
+ """
313
+
314
+ self.proxy: Optional[str] = None
315
+ """Proxy URL
316
+ """
317
+ self.proxy_headers = None
318
+ """Proxy headers
319
+ """
320
+ self.safe_chars_for_path_param = ''
321
+ """Safe chars for path_param
322
+ """
323
+ self.retries = retries
324
+ """Retry configuration
325
+ """
326
+ # Enable client side validation
327
+ self.client_side_validation = True
328
+
329
+ self.socket_options = None
330
+ """Options to pass down to the underlying urllib3 socket
331
+ """
332
+
333
+ self.datetime_format = "%Y-%m-%dT%H:%M:%S.%f%z"
334
+ """datetime format
335
+ """
336
+
337
+ self.date_format = "%Y-%m-%d"
338
+ """date format
339
+ """
340
+
341
+ def __deepcopy__(self, memo: Dict[int, Any]) -> Self:
342
+ cls = self.__class__
343
+ result = cls.__new__(cls)
344
+ memo[id(self)] = result
345
+ for k, v in self.__dict__.items():
346
+ if k not in ('logger', 'logger_file_handler'):
347
+ setattr(result, k, copy.deepcopy(v, memo))
348
+ # shallow copy of loggers
349
+ result.logger = copy.copy(self.logger)
350
+ # use setters to configure loggers
351
+ result.logger_file = self.logger_file
352
+ result.debug = self.debug
353
+ return result
354
+
355
+ def __setattr__(self, name: str, value: Any) -> None:
356
+ object.__setattr__(self, name, value)
357
+
358
+ @classmethod
359
+ def set_default(cls, default: Optional[Self]) -> None:
360
+ """Set default instance of configuration.
361
+
362
+ It stores default configuration, which can be
363
+ returned by get_default_copy method.
364
+
365
+ :param default: object of Configuration
366
+ """
367
+ cls._default = default
368
+
369
+ @classmethod
370
+ def get_default_copy(cls) -> Self:
371
+ """Deprecated. Please use `get_default` instead.
372
+
373
+ Deprecated. Please use `get_default` instead.
374
+
375
+ :return: The configuration object.
376
+ """
377
+ return cls.get_default()
378
+
379
+ @classmethod
380
+ def get_default(cls) -> Self:
381
+ """Return the default configuration.
382
+
383
+ This method returns newly created, based on default constructor,
384
+ object of Configuration class or returns a copy of default
385
+ configuration.
386
+
387
+ :return: The configuration object.
388
+ """
389
+ if cls._default is None:
390
+ cls._default = cls()
391
+ return cls._default
392
+
393
+ @property
394
+ def logger_file(self) -> Optional[str]:
395
+ """The logger file.
396
+
397
+ If the logger_file is None, then add stream handler and remove file
398
+ handler. Otherwise, add file handler and remove stream handler.
399
+
400
+ :param value: The logger_file path.
401
+ :type: str
402
+ """
403
+ return self.__logger_file
404
+
405
+ @logger_file.setter
406
+ def logger_file(self, value: Optional[str]) -> None:
407
+ """The logger file.
408
+
409
+ If the logger_file is None, then add stream handler and remove file
410
+ handler. Otherwise, add file handler and remove stream handler.
411
+
412
+ :param value: The logger_file path.
413
+ :type: str
414
+ """
415
+ self.__logger_file = value
416
+ if self.__logger_file:
417
+ # If set logging file,
418
+ # then add file handler and remove stream handler.
419
+ self.logger_file_handler = logging.FileHandler(self.__logger_file)
420
+ self.logger_file_handler.setFormatter(self.logger_formatter)
421
+ for _, logger in self.logger.items():
422
+ logger.addHandler(self.logger_file_handler)
423
+
424
+ @property
425
+ def debug(self) -> bool:
426
+ """Debug status
427
+
428
+ :param value: The debug status, True or False.
429
+ :type: bool
430
+ """
431
+ return self.__debug
432
+
433
+ @debug.setter
434
+ def debug(self, value: bool) -> None:
435
+ """Debug status
436
+
437
+ :param value: The debug status, True or False.
438
+ :type: bool
439
+ """
440
+ self.__debug = value
441
+ if self.__debug:
442
+ # if debug status is True, turn on debug logging
443
+ for _, logger in self.logger.items():
444
+ logger.setLevel(logging.DEBUG)
445
+ # turn on httplib debug
446
+ httplib.HTTPConnection.debuglevel = 1
447
+ else:
448
+ # if debug status is False, turn off debug logging,
449
+ # setting log level to default `logging.WARNING`
450
+ for _, logger in self.logger.items():
451
+ logger.setLevel(logging.WARNING)
452
+ # turn off httplib debug
453
+ httplib.HTTPConnection.debuglevel = 0
454
+
455
+ @property
456
+ def logger_format(self) -> str:
457
+ """The logger format.
458
+
459
+ The logger_formatter will be updated when sets logger_format.
460
+
461
+ :param value: The format string.
462
+ :type: str
463
+ """
464
+ return self.__logger_format
465
+
466
+ @logger_format.setter
467
+ def logger_format(self, value: str) -> None:
468
+ """The logger format.
469
+
470
+ The logger_formatter will be updated when sets logger_format.
471
+
472
+ :param value: The format string.
473
+ :type: str
474
+ """
475
+ self.__logger_format = value
476
+ self.logger_formatter = logging.Formatter(self.__logger_format)
477
+
478
+ def get_api_key_with_prefix(self, identifier: str, alias: Optional[str]=None) -> Optional[str]:
479
+ """Gets API key (with prefix if set).
480
+
481
+ :param identifier: The identifier of apiKey.
482
+ :param alias: The alternative identifier of apiKey.
483
+ :return: The token for api key authentication.
484
+ """
485
+ if self.refresh_api_key_hook is not None:
486
+ self.refresh_api_key_hook(self)
487
+ key = self.api_key.get(identifier, self.api_key.get(alias) if alias is not None else None)
488
+ if key:
489
+ prefix = self.api_key_prefix.get(identifier)
490
+ if prefix:
491
+ return "%s %s" % (prefix, key)
492
+ else:
493
+ return key
494
+
495
+ return None
496
+
497
+ def get_basic_auth_token(self) -> Optional[str]:
498
+ """Gets HTTP basic authentication header (string).
499
+
500
+ :return: The token for basic HTTP authentication.
501
+ """
502
+ username = ""
503
+ if self.username is not None:
504
+ username = self.username
505
+ password = ""
506
+ if self.password is not None:
507
+ password = self.password
508
+
509
+ return urllib3.util.make_headers(
510
+ basic_auth=username + ':' + password
511
+ ).get('authorization')
512
+
513
+ def auth_settings(self)-> AuthSettings:
514
+ """Gets Auth Settings dict for api client.
515
+
516
+ :return: The Auth Settings information dict.
517
+ """
518
+ auth: AuthSettings = {}
519
+ if 'cookieAuth' in self.api_key:
520
+ auth['cookieAuth'] = {
521
+ 'type': 'api_key',
522
+ 'in': 'cookie',
523
+ 'key': 'sessionid',
524
+ 'value': self.get_api_key_with_prefix(
525
+ 'cookieAuth',
526
+ ),
527
+ }
528
+ if 'tokenAuth' in self.api_key:
529
+ auth['tokenAuth'] = {
530
+ 'type': 'api_key',
531
+ 'in': 'header',
532
+ 'key': 'Authorization',
533
+ 'value': self.get_api_key_with_prefix(
534
+ 'tokenAuth',
535
+ ),
536
+ }
537
+ return auth
538
+
539
+ def to_debug_report(self) -> str:
540
+ """Gets the essential information for debugging.
541
+
542
+ :return: The report for debugging.
543
+ """
544
+ return "Python SDK Debug Report:\n"\
545
+ "OS: {env}\n"\
546
+ "Python Version: {pyversion}\n"\
547
+ "Version of the API: 1.0.0 (v1)\n"\
548
+ "SDK Package Version: 0.2.0".\
549
+ format(env=sys.platform, pyversion=sys.version)
550
+
551
+ def get_host_settings(self) -> List[HostSetting]:
552
+ """Gets an array of host settings
553
+
554
+ :return: An array of host settings
555
+ """
556
+ return [
557
+ {
558
+ 'url': "https://www.pidginhost.com",
559
+ 'description': "PRODUCTION",
560
+ }
561
+ ]
562
+
563
+ def get_host_from_settings(
564
+ self,
565
+ index: Optional[int],
566
+ variables: Optional[ServerVariablesT]=None,
567
+ servers: Optional[List[HostSetting]]=None,
568
+ ) -> str:
569
+ """Gets host URL based on the index and variables
570
+ :param index: array index of the host settings
571
+ :param variables: hash of variable and the corresponding value
572
+ :param servers: an array of host settings or None
573
+ :return: URL based on host settings
574
+ """
575
+ if index is None:
576
+ return self._base_path
577
+
578
+ variables = {} if variables is None else variables
579
+ servers = self.get_host_settings() if servers is None else servers
580
+
581
+ try:
582
+ server = servers[index]
583
+ except IndexError:
584
+ raise ValueError(
585
+ "Invalid index {0} when selecting the host settings. "
586
+ "Must be less than {1}".format(index, len(servers)))
587
+
588
+ url = server['url']
589
+
590
+ # go through variables and replace placeholders
591
+ for variable_name, variable in server.get('variables', {}).items():
592
+ used_value = variables.get(
593
+ variable_name, variable['default_value'])
594
+
595
+ if 'enum_values' in variable \
596
+ and variable['enum_values'] \
597
+ and used_value not in variable['enum_values']:
598
+ raise ValueError(
599
+ "The variable `{0}` in the host URL has invalid value "
600
+ "{1}. Must be {2}.".format(
601
+ variable_name, variables[variable_name],
602
+ variable['enum_values']))
603
+
604
+ url = url.replace("{" + variable_name + "}", used_value)
605
+
606
+ return url
607
+
608
+ @property
609
+ def host(self) -> str:
610
+ """Return generated host."""
611
+ return self.get_host_from_settings(self.server_index, variables=self.server_variables)
612
+
613
+ @host.setter
614
+ def host(self, value: str) -> None:
615
+ """Fix base path."""
616
+ self._base_path = value
617
+ self.server_index = None