catocli 2.0.4__py3-none-any.whl → 2.0.5__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.
Potentially problematic release.
This version of catocli might be problematic. Click here for more details.
- build/lib/catocli/Utils/clidriver.py +268 -0
- build/lib/catocli/Utils/profile_manager.py +188 -0
- build/lib/catocli/Utils/version_checker.py +192 -0
- build/lib/catocli/__init__.py +2 -0
- build/lib/catocli/__main__.py +12 -0
- build/lib/catocli/parsers/configure/__init__.py +115 -0
- build/lib/catocli/parsers/configure/configure.py +307 -0
- build/lib/catocli/parsers/custom/__init__.py +57 -0
- build/lib/catocli/parsers/custom/customLib.py +561 -0
- build/lib/catocli/parsers/custom/export_rules/__init__.py +42 -0
- build/lib/catocli/parsers/custom/export_rules/export_rules.py +234 -0
- build/lib/catocli/parsers/custom/export_sites/__init__.py +21 -0
- build/lib/catocli/parsers/custom/export_sites/export_sites.py +372 -0
- build/lib/catocli/parsers/custom/import_rules_to_tf/__init__.py +58 -0
- build/lib/catocli/parsers/custom/import_rules_to_tf/import_rules_to_tf.py +451 -0
- build/lib/catocli/parsers/custom/import_sites_to_tf/__init__.py +45 -0
- build/lib/catocli/parsers/custom/import_sites_to_tf/import_sites_to_tf.py +891 -0
- build/lib/catocli/parsers/mutation_accountManagement/__init__.py +48 -0
- build/lib/catocli/parsers/mutation_admin/__init__.py +48 -0
- build/lib/catocli/parsers/mutation_container/__init__.py +138 -0
- build/lib/catocli/parsers/mutation_hardware/__init__.py +22 -0
- build/lib/catocli/parsers/mutation_policy/__init__.py +1305 -0
- build/lib/catocli/parsers/mutation_sandbox/__init__.py +35 -0
- build/lib/catocli/parsers/mutation_site/__init__.py +373 -0
- build/lib/catocli/parsers/mutation_sites/__init__.py +373 -0
- build/lib/catocli/parsers/mutation_xdr/__init__.py +48 -0
- build/lib/catocli/parsers/parserApiClient.py +513 -0
- build/lib/catocli/parsers/query_accountBySubdomain/__init__.py +16 -0
- build/lib/catocli/parsers/query_accountManagement/__init__.py +16 -0
- build/lib/catocli/parsers/query_accountMetrics/__init__.py +16 -0
- build/lib/catocli/parsers/query_accountRoles/__init__.py +16 -0
- build/lib/catocli/parsers/query_accountSnapshot/__init__.py +16 -0
- build/lib/catocli/parsers/query_admin/__init__.py +16 -0
- build/lib/catocli/parsers/query_admins/__init__.py +16 -0
- build/lib/catocli/parsers/query_appStats/__init__.py +16 -0
- build/lib/catocli/parsers/query_appStatsTimeSeries/__init__.py +16 -0
- build/lib/catocli/parsers/query_auditFeed/__init__.py +16 -0
- build/lib/catocli/parsers/query_catalogs/__init__.py +16 -0
- build/lib/catocli/parsers/query_container/__init__.py +16 -0
- build/lib/catocli/parsers/query_devices/__init__.py +16 -0
- build/lib/catocli/parsers/query_entityLookup/__init__.py +16 -0
- build/lib/catocli/parsers/query_events/__init__.py +16 -0
- build/lib/catocli/parsers/query_eventsFeed/__init__.py +16 -0
- build/lib/catocli/parsers/query_eventsTimeSeries/__init__.py +16 -0
- build/lib/catocli/parsers/query_hardware/__init__.py +16 -0
- build/lib/catocli/parsers/query_hardwareManagement/__init__.py +16 -0
- build/lib/catocli/parsers/query_licensing/__init__.py +16 -0
- build/lib/catocli/parsers/query_policy/__init__.py +161 -0
- build/lib/catocli/parsers/query_sandbox/__init__.py +16 -0
- build/lib/catocli/parsers/query_site/__init__.py +100 -0
- build/lib/catocli/parsers/query_siteLocation/__init__.py +13 -0
- build/lib/catocli/parsers/query_subDomains/__init__.py +16 -0
- build/lib/catocli/parsers/query_xdr/__init__.py +35 -0
- build/lib/catocli/parsers/raw/__init__.py +12 -0
- build/lib/graphql_client/__init__.py +11 -0
- build/lib/graphql_client/api/__init__.py +3 -0
- build/lib/graphql_client/api/call_api.py +84 -0
- build/lib/graphql_client/api_client.py +192 -0
- build/lib/graphql_client/api_client_types.py +409 -0
- build/lib/graphql_client/configuration.py +232 -0
- build/lib/graphql_client/models/__init__.py +13 -0
- build/lib/graphql_client/models/no_schema.py +71 -0
- build/lib/schema/catolib.py +1141 -0
- build/lib/schema/importSchema.py +60 -0
- build/lib/schema/remove_policyid.py +89 -0
- build/lib/schema/remove_policyid_mutations.py +89 -0
- build/lib/scripts/catolib.py +62 -0
- build/lib/scripts/export_if_rules_to_json.py +188 -0
- build/lib/scripts/export_wf_rules_to_json.py +111 -0
- build/lib/scripts/import_wf_rules_to_tfstate.py +331 -0
- build/lib/vendor/certifi/__init__.py +4 -0
- build/lib/vendor/certifi/__main__.py +12 -0
- build/lib/vendor/certifi/core.py +114 -0
- build/lib/vendor/certifi/py.typed +0 -0
- build/lib/vendor/six.py +998 -0
- build/lib/vendor/urllib3/__init__.py +211 -0
- build/lib/vendor/urllib3/_base_connection.py +172 -0
- build/lib/vendor/urllib3/_collections.py +483 -0
- build/lib/vendor/urllib3/_request_methods.py +278 -0
- build/lib/vendor/urllib3/_version.py +16 -0
- build/lib/vendor/urllib3/connection.py +1033 -0
- build/lib/vendor/urllib3/connectionpool.py +1182 -0
- build/lib/vendor/urllib3/contrib/__init__.py +0 -0
- build/lib/vendor/urllib3/contrib/emscripten/__init__.py +18 -0
- build/lib/vendor/urllib3/contrib/emscripten/connection.py +254 -0
- build/lib/vendor/urllib3/contrib/emscripten/fetch.py +418 -0
- build/lib/vendor/urllib3/contrib/emscripten/request.py +22 -0
- build/lib/vendor/urllib3/contrib/emscripten/response.py +285 -0
- build/lib/vendor/urllib3/contrib/pyopenssl.py +552 -0
- build/lib/vendor/urllib3/contrib/socks.py +228 -0
- build/lib/vendor/urllib3/exceptions.py +321 -0
- build/lib/vendor/urllib3/fields.py +341 -0
- build/lib/vendor/urllib3/filepost.py +89 -0
- build/lib/vendor/urllib3/http2/__init__.py +53 -0
- build/lib/vendor/urllib3/http2/connection.py +356 -0
- build/lib/vendor/urllib3/http2/probe.py +87 -0
- build/lib/vendor/urllib3/poolmanager.py +637 -0
- build/lib/vendor/urllib3/py.typed +2 -0
- build/lib/vendor/urllib3/response.py +1265 -0
- build/lib/vendor/urllib3/util/__init__.py +42 -0
- build/lib/vendor/urllib3/util/connection.py +137 -0
- build/lib/vendor/urllib3/util/proxy.py +43 -0
- build/lib/vendor/urllib3/util/request.py +256 -0
- build/lib/vendor/urllib3/util/response.py +101 -0
- build/lib/vendor/urllib3/util/retry.py +533 -0
- build/lib/vendor/urllib3/util/ssl_.py +513 -0
- build/lib/vendor/urllib3/util/ssl_match_hostname.py +159 -0
- build/lib/vendor/urllib3/util/ssltransport.py +276 -0
- build/lib/vendor/urllib3/util/timeout.py +275 -0
- build/lib/vendor/urllib3/util/url.py +471 -0
- build/lib/vendor/urllib3/util/util.py +42 -0
- build/lib/vendor/urllib3/util/wait.py +124 -0
- catocli/Utils/clidriver.py +1 -4
- catocli/__init__.py +1 -1
- catocli/parsers/custom/export_sites/export_sites.py +2 -2
- catocli/parsers/mutation_container/__init__.py +116 -0
- catocli/parsers/mutation_container_fqdn/README.md +7 -0
- catocli/parsers/mutation_container_fqdn_addValues/README.md +17 -0
- catocli/parsers/mutation_container_fqdn_createFromFile/README.md +17 -0
- catocli/parsers/mutation_container_fqdn_removeValues/README.md +17 -0
- catocli/parsers/mutation_container_fqdn_updateFromFile/README.md +17 -0
- catocli/parsers/mutation_container_ipAddressRange/README.md +7 -0
- catocli/parsers/mutation_container_ipAddressRange_addValues/README.md +17 -0
- catocli/parsers/mutation_container_ipAddressRange_createFromFile/README.md +17 -0
- catocli/parsers/mutation_container_ipAddressRange_removeValues/README.md +17 -0
- catocli/parsers/mutation_container_ipAddressRange_updateFromFile/README.md +17 -0
- catocli/parsers/mutation_policy_internetFirewall_addRule/README.md +1 -1
- catocli/parsers/mutation_policy_internetFirewall_updateRule/README.md +1 -1
- catocli/parsers/mutation_policy_wanFirewall_addRule/README.md +1 -1
- catocli/parsers/mutation_policy_wanFirewall_updateRule/README.md +1 -1
- catocli/parsers/parserApiClient.py +25 -11
- catocli/parsers/query_policy/README.md +0 -17
- catocli/parsers/query_policy/__init__.py +153 -8
- catocli/parsers/query_policy_appTenantRestriction/README.md +7 -0
- catocli/parsers/query_policy_appTenantRestriction_policy/README.md +17 -0
- catocli/parsers/query_policy_dynamicIpAllocation/README.md +7 -0
- catocli/parsers/query_policy_dynamicIpAllocation_policy/README.md +17 -0
- catocli/parsers/query_policy_internetFirewall/README.md +7 -0
- catocli/parsers/query_policy_internetFirewall_policy/README.md +17 -0
- catocli/parsers/query_policy_remotePortFwd/README.md +7 -0
- catocli/parsers/query_policy_remotePortFwd_policy/README.md +17 -0
- catocli/parsers/query_policy_socketLan/README.md +7 -0
- catocli/parsers/query_policy_socketLan_policy/README.md +17 -0
- catocli/parsers/query_policy_terminalServer/README.md +7 -0
- catocli/parsers/query_policy_terminalServer_policy/README.md +17 -0
- catocli/parsers/query_policy_wanFirewall/README.md +7 -0
- catocli/parsers/query_policy_wanFirewall_policy/README.md +17 -0
- catocli/parsers/query_policy_wanNetwork/README.md +7 -0
- catocli/parsers/query_policy_wanNetwork_policy/README.md +17 -0
- catocli/parsers/query_site/README.md +0 -16
- catocli/parsers/query_site/__init__.py +92 -8
- catocli/parsers/query_site_availableVersionList/README.md +17 -0
- catocli/parsers/query_site_bgpPeer/README.md +17 -0
- catocli/parsers/query_site_bgpPeerList/README.md +17 -0
- catocli/parsers/query_site_cloudInterconnectConnectionConnectivity/README.md +17 -0
- catocli/parsers/query_site_cloudInterconnectPhysicalConnection/README.md +17 -0
- catocli/parsers/query_site_cloudInterconnectPhysicalConnectionId/README.md +17 -0
- catocli/parsers/query_site_siteBgpStatus/README.md +17 -0
- catocli/parsers/raw/README.md +0 -14
- catocli/parsers/raw/__init__.py +0 -2
- {catocli-2.0.4.dist-info → catocli-2.0.5.dist-info}/METADATA +1 -1
- {catocli-2.0.4.dist-info → catocli-2.0.5.dist-info}/RECORD +290 -120
- {catocli-2.0.4.dist-info → catocli-2.0.5.dist-info}/top_level.txt +1 -0
- graphql_client/api/call_api.py +4 -3
- models/mutation.container.fqdn.addValues.json +866 -0
- models/mutation.container.fqdn.createFromFile.json +819 -0
- models/mutation.container.fqdn.removeValues.json +866 -0
- models/mutation.container.fqdn.updateFromFile.json +1045 -0
- models/mutation.container.ipAddressRange.addValues.json +1020 -0
- models/mutation.container.ipAddressRange.createFromFile.json +819 -0
- models/mutation.container.ipAddressRange.removeValues.json +1020 -0
- models/mutation.container.ipAddressRange.updateFromFile.json +1045 -0
- models/mutation.policy.appTenantRestriction.addRule.json +8 -8
- models/mutation.policy.appTenantRestriction.addSection.json +1 -1
- models/mutation.policy.appTenantRestriction.createPolicyRevision.json +2 -2
- models/mutation.policy.appTenantRestriction.discardPolicyRevision.json +2 -2
- models/mutation.policy.appTenantRestriction.moveRule.json +2 -2
- models/mutation.policy.appTenantRestriction.moveSection.json +1 -1
- models/mutation.policy.appTenantRestriction.publishPolicyRevision.json +2 -2
- models/mutation.policy.appTenantRestriction.removeRule.json +2 -2
- models/mutation.policy.appTenantRestriction.removeSection.json +1 -1
- models/mutation.policy.appTenantRestriction.updatePolicy.json +2 -2
- models/mutation.policy.appTenantRestriction.updateRule.json +8 -8
- models/mutation.policy.appTenantRestriction.updateSection.json +1 -1
- models/mutation.policy.dynamicIpAllocation.addRule.json +1 -1
- models/mutation.policy.dynamicIpAllocation.addSection.json +1 -1
- models/mutation.policy.dynamicIpAllocation.createPolicyRevision.json +1 -1
- models/mutation.policy.dynamicIpAllocation.discardPolicyRevision.json +1 -1
- models/mutation.policy.dynamicIpAllocation.moveRule.json +1 -1
- models/mutation.policy.dynamicIpAllocation.moveSection.json +1 -1
- models/mutation.policy.dynamicIpAllocation.publishPolicyRevision.json +1 -1
- models/mutation.policy.dynamicIpAllocation.removeRule.json +1 -1
- models/mutation.policy.dynamicIpAllocation.removeSection.json +1 -1
- models/mutation.policy.dynamicIpAllocation.updatePolicy.json +1 -1
- models/mutation.policy.dynamicIpAllocation.updateRule.json +1 -1
- models/mutation.policy.dynamicIpAllocation.updateSection.json +1 -1
- models/mutation.policy.internetFirewall.addRule.json +502 -55
- models/mutation.policy.internetFirewall.addSection.json +1 -1
- models/mutation.policy.internetFirewall.createPolicyRevision.json +127 -10
- models/mutation.policy.internetFirewall.discardPolicyRevision.json +127 -10
- models/mutation.policy.internetFirewall.moveRule.json +127 -10
- models/mutation.policy.internetFirewall.moveSection.json +1 -1
- models/mutation.policy.internetFirewall.publishPolicyRevision.json +127 -10
- models/mutation.policy.internetFirewall.removeRule.json +127 -10
- models/mutation.policy.internetFirewall.removeSection.json +1 -1
- models/mutation.policy.internetFirewall.updatePolicy.json +127 -10
- models/mutation.policy.internetFirewall.updateRule.json +493 -55
- models/mutation.policy.internetFirewall.updateSection.json +1 -1
- models/mutation.policy.remotePortFwd.addRule.json +5 -5
- models/mutation.policy.remotePortFwd.addSection.json +1 -1
- models/mutation.policy.remotePortFwd.createPolicyRevision.json +2 -2
- models/mutation.policy.remotePortFwd.discardPolicyRevision.json +2 -2
- models/mutation.policy.remotePortFwd.moveRule.json +2 -2
- models/mutation.policy.remotePortFwd.moveSection.json +1 -1
- models/mutation.policy.remotePortFwd.publishPolicyRevision.json +2 -2
- models/mutation.policy.remotePortFwd.removeRule.json +2 -2
- models/mutation.policy.remotePortFwd.removeSection.json +1 -1
- models/mutation.policy.remotePortFwd.updatePolicy.json +2 -2
- models/mutation.policy.remotePortFwd.updateRule.json +5 -5
- models/mutation.policy.remotePortFwd.updateSection.json +1 -1
- models/mutation.policy.socketLan.addRule.json +16 -16
- models/mutation.policy.socketLan.addSection.json +1 -1
- models/mutation.policy.socketLan.createPolicyRevision.json +4 -4
- models/mutation.policy.socketLan.discardPolicyRevision.json +4 -4
- models/mutation.policy.socketLan.moveRule.json +4 -4
- models/mutation.policy.socketLan.moveSection.json +1 -1
- models/mutation.policy.socketLan.publishPolicyRevision.json +4 -4
- models/mutation.policy.socketLan.removeRule.json +4 -4
- models/mutation.policy.socketLan.removeSection.json +1 -1
- models/mutation.policy.socketLan.updatePolicy.json +4 -4
- models/mutation.policy.socketLan.updateRule.json +16 -16
- models/mutation.policy.socketLan.updateSection.json +1 -1
- models/mutation.policy.terminalServer.addRule.json +1 -1
- models/mutation.policy.terminalServer.addSection.json +1 -1
- models/mutation.policy.terminalServer.createPolicyRevision.json +1 -1
- models/mutation.policy.terminalServer.discardPolicyRevision.json +1 -1
- models/mutation.policy.terminalServer.moveRule.json +1 -1
- models/mutation.policy.terminalServer.moveSection.json +1 -1
- models/mutation.policy.terminalServer.publishPolicyRevision.json +1 -1
- models/mutation.policy.terminalServer.removeRule.json +1 -1
- models/mutation.policy.terminalServer.removeSection.json +1 -1
- models/mutation.policy.terminalServer.updatePolicy.json +1 -1
- models/mutation.policy.terminalServer.updateRule.json +1 -1
- models/mutation.policy.terminalServer.updateSection.json +1 -1
- models/mutation.policy.wanFirewall.addRule.json +500 -53
- models/mutation.policy.wanFirewall.addSection.json +1 -1
- models/mutation.policy.wanFirewall.createPolicyRevision.json +128 -11
- models/mutation.policy.wanFirewall.discardPolicyRevision.json +128 -11
- models/mutation.policy.wanFirewall.moveRule.json +128 -11
- models/mutation.policy.wanFirewall.moveSection.json +1 -1
- models/mutation.policy.wanFirewall.publishPolicyRevision.json +128 -11
- models/mutation.policy.wanFirewall.removeRule.json +128 -11
- models/mutation.policy.wanFirewall.removeSection.json +1 -1
- models/mutation.policy.wanFirewall.updatePolicy.json +128 -11
- models/mutation.policy.wanFirewall.updateRule.json +491 -53
- models/mutation.policy.wanFirewall.updateSection.json +1 -1
- models/mutation.policy.wanNetwork.addRule.json +13 -13
- models/mutation.policy.wanNetwork.addSection.json +1 -1
- models/mutation.policy.wanNetwork.createPolicyRevision.json +1 -1
- models/mutation.policy.wanNetwork.discardPolicyRevision.json +1 -1
- models/mutation.policy.wanNetwork.moveRule.json +1 -1
- models/mutation.policy.wanNetwork.moveSection.json +1 -1
- models/mutation.policy.wanNetwork.publishPolicyRevision.json +1 -1
- models/mutation.policy.wanNetwork.removeRule.json +1 -1
- models/mutation.policy.wanNetwork.removeSection.json +1 -1
- models/mutation.policy.wanNetwork.updatePolicy.json +1 -1
- models/mutation.policy.wanNetwork.updateRule.json +13 -13
- models/mutation.policy.wanNetwork.updateSection.json +1 -1
- models/query.policy.appTenantRestriction.policy.json +3086 -0
- models/query.policy.dynamicIpAllocation.policy.json +1934 -0
- models/query.policy.internetFirewall.policy.json +7833 -0
- models/query.policy.json +233 -0
- models/query.policy.remotePortFwd.policy.json +2387 -0
- models/query.policy.socketLan.policy.json +7140 -0
- models/query.policy.terminalServer.policy.json +1632 -0
- models/query.policy.wanFirewall.policy.json +9212 -0
- models/query.policy.wanNetwork.policy.json +8010 -0
- models/query.site.availableVersionList.json +365 -0
- models/query.site.bgpPeer.json +1917 -0
- models/query.site.bgpPeerList.json +2076 -0
- models/query.site.cloudInterconnectConnectionConnectivity.json +298 -0
- models/query.site.cloudInterconnectPhysicalConnection.json +728 -0
- models/query.site.cloudInterconnectPhysicalConnectionId.json +660 -0
- models/query.site.siteBgpStatus.json +869 -0
- schema/catolib.py +13 -6
- schema/remove_policyid.py +89 -0
- schema/remove_policyid_mutations.py +89 -0
- {catocli-2.0.4.dist-info → catocli-2.0.5.dist-info}/LICENSE +0 -0
- {catocli-2.0.4.dist-info → catocli-2.0.5.dist-info}/WHEEL +0 -0
- {catocli-2.0.4.dist-info → catocli-2.0.5.dist-info}/entry_points.txt +0 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
from __future__ import absolute_import
|
|
4
|
+
|
|
5
|
+
# # import api into package
|
|
6
|
+
from graphql_client.api.call_api import CallApi
|
|
7
|
+
|
|
8
|
+
# import ApiClient
|
|
9
|
+
from graphql_client.api_client_types import ApiClient
|
|
10
|
+
from graphql_client.configuration import Configuration
|
|
11
|
+
from graphql_client.models.no_schema import NoSchema
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
from __future__ import absolute_import
|
|
4
|
+
import re
|
|
5
|
+
import json
|
|
6
|
+
|
|
7
|
+
# python 2 and python 3 compatibility library
|
|
8
|
+
import sys
|
|
9
|
+
sys.path.insert(0, 'vendor')
|
|
10
|
+
import six
|
|
11
|
+
from graphql_client.api_client_types import ApiClient
|
|
12
|
+
|
|
13
|
+
class CallApi(object):
|
|
14
|
+
def __init__(self, api_client=None):
|
|
15
|
+
if api_client is None:
|
|
16
|
+
api_client = ApiClient()
|
|
17
|
+
self.api_client = api_client
|
|
18
|
+
|
|
19
|
+
def call_api(self, body, args, **kwargs): # noqa: E501
|
|
20
|
+
(data) = self.call_api_with_http_info(body, args, **kwargs) # noqa: E501
|
|
21
|
+
return data
|
|
22
|
+
|
|
23
|
+
def call_api_with_http_info(self, body, args, **kwargs): # noqa: E501
|
|
24
|
+
all_params = ['body', 'sync_type'] # noqa: E501
|
|
25
|
+
all_params.append('async_req')
|
|
26
|
+
if args.get("v")==True:
|
|
27
|
+
all_params.append('_return_http_data_only')
|
|
28
|
+
all_params.append('_preload_content')
|
|
29
|
+
all_params.append('_request_timeout')
|
|
30
|
+
|
|
31
|
+
params = locals()
|
|
32
|
+
for key, val in six.iteritems(params['kwargs']):
|
|
33
|
+
if key not in all_params:
|
|
34
|
+
raise TypeError(
|
|
35
|
+
"Got an unexpected keyword argument '%s'"
|
|
36
|
+
" to method create_asset4" % key
|
|
37
|
+
)
|
|
38
|
+
params[key] = val
|
|
39
|
+
del params['kwargs']
|
|
40
|
+
|
|
41
|
+
if ('body' not in params or params['body'] is None):
|
|
42
|
+
raise ValueError("Missing the required parameter `body` when calling `create_asset4`")
|
|
43
|
+
|
|
44
|
+
collection_formats = {}
|
|
45
|
+
|
|
46
|
+
header_params = {}
|
|
47
|
+
|
|
48
|
+
form_params = []
|
|
49
|
+
local_var_files = {}
|
|
50
|
+
|
|
51
|
+
body_params = None
|
|
52
|
+
if 'body' in params:
|
|
53
|
+
body_params = params['body']
|
|
54
|
+
header_params['Accept'] = self.api_client.select_header_accept(['application/json'])
|
|
55
|
+
header_params['Content-Type'] = self.api_client.select_header_content_type(['application/json'])
|
|
56
|
+
# Only add x-api-key if not using custom headers
|
|
57
|
+
using_custom_headers = hasattr(self.api_client.configuration, 'custom_headers') and self.api_client.configuration.custom_headers
|
|
58
|
+
if not using_custom_headers and 'x-api-key' in self.api_client.configuration.api_key:
|
|
59
|
+
header_params['x-api-key'] = self.api_client.configuration.api_key['x-api-key']
|
|
60
|
+
header_params['User-Agent'] = "Cato-CLI-v"+self.api_client.configuration.version
|
|
61
|
+
|
|
62
|
+
# Add custom headers from configuration
|
|
63
|
+
if using_custom_headers:
|
|
64
|
+
header_params.update(self.api_client.configuration.custom_headers)
|
|
65
|
+
|
|
66
|
+
if args.get("v")==True:
|
|
67
|
+
print("Host: ",self.api_client.configuration.host)
|
|
68
|
+
# Create a copy of header_params with masked API key for verbose output
|
|
69
|
+
masked_headers = header_params.copy()
|
|
70
|
+
if 'x-api-key' in masked_headers:
|
|
71
|
+
masked_headers['x-api-key'] = '***MASKED***'
|
|
72
|
+
print("Request Headers:",json.dumps(masked_headers,indent=4,sort_keys=True))
|
|
73
|
+
print("Request Data:",json.dumps(body_params,indent=4,sort_keys=True),"\n\n")
|
|
74
|
+
|
|
75
|
+
return self.api_client.call_api(
|
|
76
|
+
header_params,
|
|
77
|
+
body=body_params,
|
|
78
|
+
files=local_var_files,
|
|
79
|
+
response_type="NoSchema", # noqa: E501
|
|
80
|
+
async_req=params.get('async_req'),
|
|
81
|
+
_return_http_data_only=params.get('_return_http_data_only'),
|
|
82
|
+
_preload_content=params.get('_preload_content', True),
|
|
83
|
+
_request_timeout=params.get('_request_timeout'),
|
|
84
|
+
collection_formats=collection_formats)
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
from __future__ import absolute_import
|
|
4
|
+
|
|
5
|
+
import io
|
|
6
|
+
import json
|
|
7
|
+
import logging
|
|
8
|
+
import re
|
|
9
|
+
import ssl
|
|
10
|
+
|
|
11
|
+
# python 2 and python 3 compatibility library
|
|
12
|
+
import sys
|
|
13
|
+
sys.path.insert(0, 'vendor')
|
|
14
|
+
import certifi
|
|
15
|
+
import six
|
|
16
|
+
from six.moves.urllib.parse import urlencode
|
|
17
|
+
|
|
18
|
+
try:
|
|
19
|
+
import urllib3
|
|
20
|
+
except ImportError:
|
|
21
|
+
raise ImportError('GraphQL python client requires urllib3.')
|
|
22
|
+
|
|
23
|
+
logger = logging.getLogger(__name__)
|
|
24
|
+
|
|
25
|
+
class QUERYResponse(io.IOBase):
|
|
26
|
+
|
|
27
|
+
def __init__(self, resp):
|
|
28
|
+
self.urllib3_response = resp
|
|
29
|
+
self.status = resp.status
|
|
30
|
+
self.reason = resp.reason
|
|
31
|
+
self.data = resp.data
|
|
32
|
+
|
|
33
|
+
def getheaders(self):
|
|
34
|
+
"""Returns a dictionary of the response headers."""
|
|
35
|
+
return self.urllib3_response.getheaders()
|
|
36
|
+
|
|
37
|
+
def getheader(self, name, default=None):
|
|
38
|
+
"""Returns a given response header."""
|
|
39
|
+
return self.urllib3_response.getheader(name, default)
|
|
40
|
+
|
|
41
|
+
class QUERYClientObject(object):
|
|
42
|
+
|
|
43
|
+
def __init__(self, configuration, pools_size=4, maxsize=None):
|
|
44
|
+
# urllib3.PoolManager will pass all kw parameters to connectionpool
|
|
45
|
+
# https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/poolmanager.py#L75 # noqa: E501
|
|
46
|
+
# https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/connectionpool.py#L680 # noqa: E501
|
|
47
|
+
# maxsize is the number of requests to host that are allowed in parallel # noqa: E501
|
|
48
|
+
# Custom SSL certificates and client certificates: http://urllib3.readthedocs.io/en/latest/advanced-usage.html # noqa: E501
|
|
49
|
+
|
|
50
|
+
# cert_reqs
|
|
51
|
+
if configuration.verify_ssl:
|
|
52
|
+
cert_reqs = ssl.CERT_REQUIRED
|
|
53
|
+
else:
|
|
54
|
+
cert_reqs = ssl.CERT_NONE
|
|
55
|
+
|
|
56
|
+
# ca_certs
|
|
57
|
+
if configuration.ssl_ca_cert:
|
|
58
|
+
ca_certs = configuration.ssl_ca_cert
|
|
59
|
+
else:
|
|
60
|
+
# if not set certificate file, use Mozilla's root certificates.
|
|
61
|
+
ca_certs = certifi.where()
|
|
62
|
+
|
|
63
|
+
addition_pool_args = {}
|
|
64
|
+
if configuration.assert_hostname is not None:
|
|
65
|
+
addition_pool_args['assert_hostname'] = configuration.assert_hostname # noqa: E501
|
|
66
|
+
|
|
67
|
+
if maxsize is None:
|
|
68
|
+
if configuration.connection_pool_maxsize is not None:
|
|
69
|
+
maxsize = configuration.connection_pool_maxsize
|
|
70
|
+
else:
|
|
71
|
+
maxsize = 4
|
|
72
|
+
|
|
73
|
+
# https pool manager
|
|
74
|
+
if configuration.proxy:
|
|
75
|
+
self.pool_manager = urllib3.ProxyManager(
|
|
76
|
+
num_pools=pools_size,
|
|
77
|
+
maxsize=maxsize,
|
|
78
|
+
cert_reqs=cert_reqs,
|
|
79
|
+
ca_certs=ca_certs,
|
|
80
|
+
cert_file=configuration.cert_file,
|
|
81
|
+
key_file=configuration.key_file,
|
|
82
|
+
proxy_url=configuration.proxy,
|
|
83
|
+
**addition_pool_args
|
|
84
|
+
)
|
|
85
|
+
else:
|
|
86
|
+
self.pool_manager = urllib3.PoolManager(
|
|
87
|
+
num_pools=pools_size,
|
|
88
|
+
maxsize=maxsize,
|
|
89
|
+
cert_reqs=cert_reqs,
|
|
90
|
+
ca_certs=ca_certs,
|
|
91
|
+
cert_file=configuration.cert_file,
|
|
92
|
+
key_file=configuration.key_file,
|
|
93
|
+
**addition_pool_args
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
def request(self, method, url, headers=None,
|
|
97
|
+
body=None, _preload_content=True,
|
|
98
|
+
_request_timeout=None):
|
|
99
|
+
"""Perform requests.
|
|
100
|
+
:param headers: http request headers
|
|
101
|
+
:param body: request json body, for `application/json`
|
|
102
|
+
:param _preload_content: if False, the urllib3.HTTPResponse object will
|
|
103
|
+
be returned without reading/decoding response
|
|
104
|
+
data. Default is True.
|
|
105
|
+
:param _request_timeout: timeout setting for this request. If one
|
|
106
|
+
number provided, it will be total request
|
|
107
|
+
timeout. It can also be a pair (tuple) of
|
|
108
|
+
(connection, read) timeouts.
|
|
109
|
+
"""
|
|
110
|
+
method = method.upper()
|
|
111
|
+
assert method in ['POST']
|
|
112
|
+
headers = headers or {}
|
|
113
|
+
|
|
114
|
+
timeout = None
|
|
115
|
+
if _request_timeout:
|
|
116
|
+
if isinstance(_request_timeout, (int, ) if six.PY3 else (int, long)): # noqa: E501,F821
|
|
117
|
+
timeout = urllib3.Timeout(total=_request_timeout)
|
|
118
|
+
elif (isinstance(_request_timeout, tuple) and
|
|
119
|
+
len(_request_timeout) == 2):
|
|
120
|
+
timeout = urllib3.Timeout(
|
|
121
|
+
connect=_request_timeout[0], read=_request_timeout[1])
|
|
122
|
+
|
|
123
|
+
if 'Content-Type' not in headers:
|
|
124
|
+
headers['Content-Type'] = 'application/json'
|
|
125
|
+
|
|
126
|
+
try:
|
|
127
|
+
if re.search('json', headers['Content-Type'], re.IGNORECASE):
|
|
128
|
+
try:
|
|
129
|
+
r = self.pool_manager.request( method=method, url=url,
|
|
130
|
+
body=json.dumps(body),
|
|
131
|
+
preload_content=_preload_content,
|
|
132
|
+
timeout=timeout,
|
|
133
|
+
headers=headers)
|
|
134
|
+
except Exception as e:
|
|
135
|
+
# remove the restriction for raw
|
|
136
|
+
print("ERROR: ",e)
|
|
137
|
+
exit()
|
|
138
|
+
|
|
139
|
+
else:
|
|
140
|
+
# Cannot generate the request from given parameters
|
|
141
|
+
msg = """Cannot prepare a request message for provided
|
|
142
|
+
arguments. Please check that your arguments match
|
|
143
|
+
declared content type."""
|
|
144
|
+
raise ApiException(status=0, reason=msg)
|
|
145
|
+
|
|
146
|
+
except urllib3.exceptions.SSLError as e:
|
|
147
|
+
msg = "{0}\n{1}".format(type(e).__name__, str(e))
|
|
148
|
+
raise ApiException(status=0, reason=msg)
|
|
149
|
+
|
|
150
|
+
if _preload_content:
|
|
151
|
+
r = QUERYResponse(r)
|
|
152
|
+
|
|
153
|
+
# log response body
|
|
154
|
+
logger.debug("response body: %s", r.data)
|
|
155
|
+
|
|
156
|
+
if not 200 <= r.status <= 299:
|
|
157
|
+
raise ApiException(http_resp=r)
|
|
158
|
+
|
|
159
|
+
return r
|
|
160
|
+
|
|
161
|
+
def POST(self, url, headers=None, body=None, _preload_content=True, _request_timeout=None):
|
|
162
|
+
return self.request("POST", url, headers=headers,
|
|
163
|
+
_preload_content=_preload_content,
|
|
164
|
+
_request_timeout=_request_timeout,
|
|
165
|
+
body=body)
|
|
166
|
+
|
|
167
|
+
class ApiException(Exception):
|
|
168
|
+
|
|
169
|
+
def __init__(self, status=None, reason=None, http_resp=None):
|
|
170
|
+
if http_resp:
|
|
171
|
+
self.status = http_resp.status
|
|
172
|
+
self.reason = http_resp.reason
|
|
173
|
+
self.body = http_resp.data
|
|
174
|
+
self.headers = http_resp.getheaders()
|
|
175
|
+
else:
|
|
176
|
+
self.status = status
|
|
177
|
+
self.reason = reason
|
|
178
|
+
self.body = None
|
|
179
|
+
self.headers = None
|
|
180
|
+
|
|
181
|
+
def __str__(self):
|
|
182
|
+
"""Custom error messages for exception"""
|
|
183
|
+
if self.body:
|
|
184
|
+
# error_message += "HTTP response body:\n{}".format(self.body.decode('utf8'))
|
|
185
|
+
return self.body.decode('utf8')
|
|
186
|
+
else:
|
|
187
|
+
error_message = "({0})\n"\
|
|
188
|
+
"Reason: {1}\n".format(self.status, self.reason)
|
|
189
|
+
if self.headers:
|
|
190
|
+
error_message += "HTTP response headers: {0}\n".format(
|
|
191
|
+
self.headers)
|
|
192
|
+
|
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
from __future__ import absolute_import
|
|
4
|
+
|
|
5
|
+
import datetime
|
|
6
|
+
import json
|
|
7
|
+
import mimetypes
|
|
8
|
+
from multiprocessing.pool import ThreadPool
|
|
9
|
+
import os
|
|
10
|
+
import re
|
|
11
|
+
import tempfile
|
|
12
|
+
|
|
13
|
+
from graphql_client.configuration import Configuration
|
|
14
|
+
import graphql_client.models
|
|
15
|
+
from graphql_client import api_client
|
|
16
|
+
|
|
17
|
+
# python 2 and python 3 compatibility library
|
|
18
|
+
import sys
|
|
19
|
+
sys.path.insert(0, 'vendor')
|
|
20
|
+
import six
|
|
21
|
+
|
|
22
|
+
class ApiClient(object):
|
|
23
|
+
PRIMITIVE_TYPES = (float, bool, bytes, six.text_type) + six.integer_types
|
|
24
|
+
NATIVE_TYPES_MAPPING = {
|
|
25
|
+
'int': int,
|
|
26
|
+
'long': int if six.PY3 else long,
|
|
27
|
+
'float': float,
|
|
28
|
+
'str': str,
|
|
29
|
+
'bool': bool,
|
|
30
|
+
'date': datetime.date,
|
|
31
|
+
'datetime': datetime.datetime,
|
|
32
|
+
'object': object,
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
def __init__(self, configuration=None, header_name=None, header_value=None,
|
|
36
|
+
cookie=None):
|
|
37
|
+
if configuration is None:
|
|
38
|
+
configuration = Configuration()
|
|
39
|
+
self.configuration = configuration
|
|
40
|
+
|
|
41
|
+
self.pool = ThreadPool()
|
|
42
|
+
self.rest_client = api_client.QUERYClientObject(configuration)
|
|
43
|
+
self.default_headers = {}
|
|
44
|
+
if header_name is not None:
|
|
45
|
+
self.default_headers[header_name] = header_value
|
|
46
|
+
self.cookie = cookie
|
|
47
|
+
self.user_agent = "Cato-CLI-v"+self.configuration.version
|
|
48
|
+
|
|
49
|
+
def __del__(self):
|
|
50
|
+
self.pool.close()
|
|
51
|
+
self.pool.join()
|
|
52
|
+
|
|
53
|
+
@property
|
|
54
|
+
def user_agent(self):
|
|
55
|
+
"""User agent for this API client"""
|
|
56
|
+
return self.default_headers['User-Agent']
|
|
57
|
+
|
|
58
|
+
@user_agent.setter
|
|
59
|
+
def user_agent(self, value):
|
|
60
|
+
self.default_headers['User-Agent'] = value
|
|
61
|
+
|
|
62
|
+
def set_default_header(self, header_name, header_value):
|
|
63
|
+
self.default_headers[header_name] = header_value
|
|
64
|
+
|
|
65
|
+
def __call_api(
|
|
66
|
+
self, header_params=None, body=None,
|
|
67
|
+
files=None, response_type=None,
|
|
68
|
+
_return_http_data_only=None, collection_formats=None,
|
|
69
|
+
_preload_content=True, _request_timeout=None):
|
|
70
|
+
|
|
71
|
+
config = self.configuration
|
|
72
|
+
|
|
73
|
+
# header parameters
|
|
74
|
+
header_params = header_params or {}
|
|
75
|
+
header_params.update(self.default_headers)
|
|
76
|
+
if self.cookie:
|
|
77
|
+
header_params['Cookie'] = self.cookie
|
|
78
|
+
if header_params:
|
|
79
|
+
header_params = self.sanitize_for_serialization(header_params)
|
|
80
|
+
header_params = dict(self.parameters_to_tuples(header_params,
|
|
81
|
+
collection_formats))
|
|
82
|
+
|
|
83
|
+
# body
|
|
84
|
+
if body:
|
|
85
|
+
body = self.sanitize_for_serialization(body)
|
|
86
|
+
|
|
87
|
+
# request url
|
|
88
|
+
url = self.configuration.host
|
|
89
|
+
|
|
90
|
+
# perform request and return response
|
|
91
|
+
response_data = self.request(
|
|
92
|
+
url, headers=header_params, body=body,
|
|
93
|
+
_preload_content=_preload_content,
|
|
94
|
+
_request_timeout=_request_timeout)
|
|
95
|
+
|
|
96
|
+
self.last_response = response_data
|
|
97
|
+
|
|
98
|
+
return_data = response_data
|
|
99
|
+
if _preload_content:
|
|
100
|
+
# deserialize response data
|
|
101
|
+
if response_type:
|
|
102
|
+
return_data = self.deserialize(response_data, response_type)
|
|
103
|
+
else:
|
|
104
|
+
return_data = None
|
|
105
|
+
|
|
106
|
+
# Temporarily commented out to allow custom error handling
|
|
107
|
+
# if "errors" in return_data:
|
|
108
|
+
# print(json.dumps(return_data))
|
|
109
|
+
# exit(1)
|
|
110
|
+
|
|
111
|
+
if _return_http_data_only:
|
|
112
|
+
return (return_data)
|
|
113
|
+
else:
|
|
114
|
+
return (return_data, response_data.status,
|
|
115
|
+
response_data.getheaders())
|
|
116
|
+
|
|
117
|
+
def sanitize_for_serialization(self, obj):
|
|
118
|
+
"""Builds a JSON POST object.
|
|
119
|
+
If obj is None, return None.
|
|
120
|
+
If obj is str, int, long, float, bool, return directly.
|
|
121
|
+
If obj is datetime.datetime, datetime.date
|
|
122
|
+
convert to string in iso8601 format.
|
|
123
|
+
If obj is list, sanitize each element in the list.
|
|
124
|
+
If obj is dict, return the dict.
|
|
125
|
+
:param obj: The data to serialize.
|
|
126
|
+
:return: The serialized form of data.
|
|
127
|
+
"""
|
|
128
|
+
if obj is None:
|
|
129
|
+
return None
|
|
130
|
+
elif isinstance(obj, self.PRIMITIVE_TYPES):
|
|
131
|
+
return obj
|
|
132
|
+
elif isinstance(obj, list):
|
|
133
|
+
return [self.sanitize_for_serialization(sub_obj)
|
|
134
|
+
for sub_obj in obj]
|
|
135
|
+
elif isinstance(obj, tuple):
|
|
136
|
+
return tuple(self.sanitize_for_serialization(sub_obj)
|
|
137
|
+
for sub_obj in obj)
|
|
138
|
+
elif isinstance(obj, (datetime.datetime, datetime.date)):
|
|
139
|
+
return obj.isoformat()
|
|
140
|
+
|
|
141
|
+
if isinstance(obj, dict):
|
|
142
|
+
obj_dict = obj
|
|
143
|
+
else:
|
|
144
|
+
obj_dict = {obj.attribute_map[attr]: getattr(obj, attr)
|
|
145
|
+
for attr, _ in six.iteritems(obj.swagger_types)
|
|
146
|
+
if getattr(obj, attr) is not None}
|
|
147
|
+
|
|
148
|
+
return {key: self.sanitize_for_serialization(val)
|
|
149
|
+
for key, val in six.iteritems(obj_dict)}
|
|
150
|
+
|
|
151
|
+
def deserialize(self, response, response_type):
|
|
152
|
+
# handle file downloading
|
|
153
|
+
# save response body into a tmp file and return the instance
|
|
154
|
+
if response_type == "file":
|
|
155
|
+
return self.__deserialize_file(response)
|
|
156
|
+
|
|
157
|
+
# fetch data from response object
|
|
158
|
+
try:
|
|
159
|
+
data = json.loads(response.data)
|
|
160
|
+
except ValueError:
|
|
161
|
+
data = response.data
|
|
162
|
+
|
|
163
|
+
return self.__deserialize(data, response_type)
|
|
164
|
+
|
|
165
|
+
def __deserialize(self, data, klass):
|
|
166
|
+
if data is None:
|
|
167
|
+
return None
|
|
168
|
+
|
|
169
|
+
if type(klass) == str:
|
|
170
|
+
if klass.startswith('list['):
|
|
171
|
+
sub_kls = re.match(r'list\[(.*)\]', klass).group(1)
|
|
172
|
+
return [self.__deserialize(sub_data, sub_kls)
|
|
173
|
+
for sub_data in data]
|
|
174
|
+
|
|
175
|
+
if klass.startswith('dict('):
|
|
176
|
+
sub_kls = re.match(r'dict\(([^,]*), (.*)\)', klass).group(2)
|
|
177
|
+
return {k: self.__deserialize(v, sub_kls)
|
|
178
|
+
for k, v in six.iteritems(data)}
|
|
179
|
+
|
|
180
|
+
# convert str to class
|
|
181
|
+
if klass in self.NATIVE_TYPES_MAPPING:
|
|
182
|
+
klass = self.NATIVE_TYPES_MAPPING[klass]
|
|
183
|
+
else:
|
|
184
|
+
klass = getattr(graphql_client.models, klass)
|
|
185
|
+
|
|
186
|
+
if klass in self.PRIMITIVE_TYPES:
|
|
187
|
+
return self.__deserialize_primitive(data, klass)
|
|
188
|
+
elif klass == object:
|
|
189
|
+
return self.__deserialize_object(data)
|
|
190
|
+
elif klass == datetime.date:
|
|
191
|
+
return self.__deserialize_date(data)
|
|
192
|
+
elif klass == datetime.datetime:
|
|
193
|
+
return self.__deserialize_datatime(data)
|
|
194
|
+
else:
|
|
195
|
+
return self.__deserialize_model(data, klass)
|
|
196
|
+
|
|
197
|
+
def call_api(self, header_params=None, body=None, files=None,
|
|
198
|
+
response_type=None, async_req=None,
|
|
199
|
+
_return_http_data_only=None, collection_formats=None,
|
|
200
|
+
_preload_content=True, _request_timeout=None):
|
|
201
|
+
|
|
202
|
+
if not async_req:
|
|
203
|
+
return self.__call_api( header_params, body, files,
|
|
204
|
+
response_type, _return_http_data_only, collection_formats,
|
|
205
|
+
_preload_content, _request_timeout)
|
|
206
|
+
else:
|
|
207
|
+
thread = self.pool.apply_async(self.__call_api, ( header_params,
|
|
208
|
+
body, files, response_type,
|
|
209
|
+
_return_http_data_only,
|
|
210
|
+
collection_formats,
|
|
211
|
+
_preload_content, _request_timeout))
|
|
212
|
+
return thread
|
|
213
|
+
|
|
214
|
+
def request(self, url, headers=None,
|
|
215
|
+
body=None, _preload_content=True,
|
|
216
|
+
_request_timeout=None):
|
|
217
|
+
|
|
218
|
+
return self.rest_client.POST(url, headers=headers,
|
|
219
|
+
_preload_content=_preload_content,
|
|
220
|
+
_request_timeout=_request_timeout,
|
|
221
|
+
body=body)
|
|
222
|
+
|
|
223
|
+
def parameters_to_tuples(self, params, collection_formats):
|
|
224
|
+
"""Get parameters as list of tuples, formatting collections.
|
|
225
|
+
|
|
226
|
+
:param params: Parameters as dict or list of two-tuples
|
|
227
|
+
:param dict collection_formats: Parameter collection formats
|
|
228
|
+
:return: Parameters as list of tuples, collections formatted
|
|
229
|
+
"""
|
|
230
|
+
new_params = []
|
|
231
|
+
if collection_formats is None:
|
|
232
|
+
collection_formats = {}
|
|
233
|
+
for k, v in six.iteritems(params) if isinstance(params, dict) else params: # noqa: E501
|
|
234
|
+
if k in collection_formats:
|
|
235
|
+
collection_format = collection_formats[k]
|
|
236
|
+
if collection_format == 'multi':
|
|
237
|
+
new_params.extend((k, value) for value in v)
|
|
238
|
+
else:
|
|
239
|
+
if collection_format == 'ssv':
|
|
240
|
+
delimiter = ' '
|
|
241
|
+
elif collection_format == 'tsv':
|
|
242
|
+
delimiter = '\t'
|
|
243
|
+
elif collection_format == 'pipes':
|
|
244
|
+
delimiter = '|'
|
|
245
|
+
else: # csv is the default
|
|
246
|
+
delimiter = ','
|
|
247
|
+
new_params.append(
|
|
248
|
+
(k, delimiter.join(str(value) for value in v)))
|
|
249
|
+
else:
|
|
250
|
+
new_params.append((k, v))
|
|
251
|
+
return new_params
|
|
252
|
+
|
|
253
|
+
def select_header_accept(self, accepts):
|
|
254
|
+
"""Returns `Accept` based on an array of accepts provided.
|
|
255
|
+
|
|
256
|
+
:param accepts: List of headers.
|
|
257
|
+
:return: Accept (e.g. application/json).
|
|
258
|
+
"""
|
|
259
|
+
if not accepts:
|
|
260
|
+
return
|
|
261
|
+
|
|
262
|
+
accepts = [x.lower() for x in accepts]
|
|
263
|
+
|
|
264
|
+
if 'application/json' in accepts:
|
|
265
|
+
return 'application/json'
|
|
266
|
+
else:
|
|
267
|
+
return ', '.join(accepts)
|
|
268
|
+
|
|
269
|
+
def select_header_content_type(self, content_types):
|
|
270
|
+
"""Returns `Content-Type` based on an array of content_types provided.
|
|
271
|
+
|
|
272
|
+
:param content_types: List of content-types.
|
|
273
|
+
:return: Content-Type (e.g. application/json).
|
|
274
|
+
"""
|
|
275
|
+
if not content_types:
|
|
276
|
+
return 'application/json'
|
|
277
|
+
|
|
278
|
+
content_types = [x.lower() for x in content_types]
|
|
279
|
+
|
|
280
|
+
if 'application/json' in content_types or '*/*' in content_types:
|
|
281
|
+
return 'application/json'
|
|
282
|
+
else:
|
|
283
|
+
return content_types[0]
|
|
284
|
+
|
|
285
|
+
def __deserialize_file(self, response):
|
|
286
|
+
"""Deserializes body to file
|
|
287
|
+
|
|
288
|
+
Saves response body into a file in a temporary folder,
|
|
289
|
+
using the filename from the `Content-Disposition` header if provided.
|
|
290
|
+
|
|
291
|
+
:param response: RESTResponse.
|
|
292
|
+
:return: file path.
|
|
293
|
+
"""
|
|
294
|
+
fd, path = tempfile.mkstemp(dir=self.configuration.temp_folder_path)
|
|
295
|
+
os.close(fd)
|
|
296
|
+
os.remove(path)
|
|
297
|
+
|
|
298
|
+
content_disposition = response.getheader("Content-Disposition")
|
|
299
|
+
if content_disposition:
|
|
300
|
+
filename = re.search(r'filename=[\'"]?([^\'"\s]+)[\'"]?',
|
|
301
|
+
content_disposition).group(1)
|
|
302
|
+
path = os.path.join(os.path.dirname(path), filename)
|
|
303
|
+
response_data = response.data
|
|
304
|
+
with open(path, "wb") as f:
|
|
305
|
+
if isinstance(response_data, str):
|
|
306
|
+
# change str to bytes so we can write it
|
|
307
|
+
response_data = response_data.encode('utf-8')
|
|
308
|
+
f.write(response_data)
|
|
309
|
+
else:
|
|
310
|
+
f.write(response_data)
|
|
311
|
+
return path
|
|
312
|
+
|
|
313
|
+
def __deserialize_primitive(self, data, klass):
|
|
314
|
+
"""Deserializes string to primitive type.
|
|
315
|
+
|
|
316
|
+
:param data: str.
|
|
317
|
+
:param klass: class literal.
|
|
318
|
+
|
|
319
|
+
:return: int, long, float, str, bool.
|
|
320
|
+
"""
|
|
321
|
+
try:
|
|
322
|
+
return klass(data)
|
|
323
|
+
except UnicodeEncodeError:
|
|
324
|
+
return six.text_type(data)
|
|
325
|
+
except TypeError:
|
|
326
|
+
return data
|
|
327
|
+
|
|
328
|
+
def __deserialize_object(self, value):
|
|
329
|
+
"""Return a original value.
|
|
330
|
+
|
|
331
|
+
:return: object.
|
|
332
|
+
"""
|
|
333
|
+
return value
|
|
334
|
+
|
|
335
|
+
def __deserialize_date(self, string):
|
|
336
|
+
"""Deserializes string to date.
|
|
337
|
+
|
|
338
|
+
:param string: str.
|
|
339
|
+
:return: date.
|
|
340
|
+
"""
|
|
341
|
+
try:
|
|
342
|
+
from dateutil.parser import parse
|
|
343
|
+
return parse(string).date()
|
|
344
|
+
except ImportError:
|
|
345
|
+
return string
|
|
346
|
+
except ValueError:
|
|
347
|
+
raise apiclient.ApiException(
|
|
348
|
+
status=0,
|
|
349
|
+
reason="Failed to parse `{0}` as date object".format(string)
|
|
350
|
+
)
|
|
351
|
+
|
|
352
|
+
def __deserialize_datatime(self, string):
|
|
353
|
+
"""Deserializes string to datetime.
|
|
354
|
+
|
|
355
|
+
The string should be in iso8601 datetime format.
|
|
356
|
+
|
|
357
|
+
:param string: str.
|
|
358
|
+
:return: datetime.
|
|
359
|
+
"""
|
|
360
|
+
try:
|
|
361
|
+
from dateutil.parser import parse
|
|
362
|
+
return parse(string)
|
|
363
|
+
except ImportError:
|
|
364
|
+
return string
|
|
365
|
+
except ValueError:
|
|
366
|
+
raise apiclient.ApiException(
|
|
367
|
+
status=0,
|
|
368
|
+
reason=(
|
|
369
|
+
"Failed to parse `{0}` as datetime object"
|
|
370
|
+
.format(string)
|
|
371
|
+
)
|
|
372
|
+
)
|
|
373
|
+
|
|
374
|
+
def __hasattr(self, object, name):
|
|
375
|
+
return name in object.__class__.__dict__
|
|
376
|
+
|
|
377
|
+
def __deserialize_model(self, data, klass):
|
|
378
|
+
"""Deserializes list or dict to model.
|
|
379
|
+
|
|
380
|
+
:param data: dict, list.
|
|
381
|
+
:param klass: class literal.
|
|
382
|
+
:return: model object.
|
|
383
|
+
"""
|
|
384
|
+
|
|
385
|
+
if not klass.swagger_types and not self.__hasattr(klass, 'get_real_child_model'):
|
|
386
|
+
return data
|
|
387
|
+
|
|
388
|
+
kwargs = {}
|
|
389
|
+
if klass.swagger_types is not None:
|
|
390
|
+
for attr, attr_type in six.iteritems(klass.swagger_types):
|
|
391
|
+
if (data is not None and
|
|
392
|
+
klass.attribute_map[attr] in data and
|
|
393
|
+
isinstance(data, (list, dict))):
|
|
394
|
+
value = data[klass.attribute_map[attr]]
|
|
395
|
+
kwargs[attr] = self.__deserialize(value, attr_type)
|
|
396
|
+
|
|
397
|
+
instance = klass(**kwargs)
|
|
398
|
+
|
|
399
|
+
if (isinstance(instance, dict) and
|
|
400
|
+
klass.swagger_types is not None and
|
|
401
|
+
isinstance(data, dict)):
|
|
402
|
+
for key, value in data.items():
|
|
403
|
+
if key not in klass.swagger_types:
|
|
404
|
+
instance[key] = value
|
|
405
|
+
if self.__hasattr(instance, 'get_real_child_model'):
|
|
406
|
+
klass_name = instance.get_real_child_model(data)
|
|
407
|
+
if klass_name:
|
|
408
|
+
instance = self.__deserialize(data, klass_name)
|
|
409
|
+
return instance
|