From d372454eeda99ef70831f6eccbe1a803ae305804 Mon Sep 17 00:00:00 2001 From: Martin Kudlej Date: Fri, 28 Jan 2022 14:11:00 +0100 Subject: [PATCH] rebase with master change import of `Retry` to `from urllib3.util import Retry` because of newer verion of requests and its dependecies --- .gitignore | 1 + threescale_api/auth.py | 11 ++-- threescale_api/defaults.py | 8 +-- threescale_api/errors.py | 4 +- threescale_api/resources.py | 106 ++++++++++++++++++------------------ 5 files changed, 65 insertions(+), 65 deletions(-) diff --git a/.gitignore b/.gitignore index ffcda3b..11fe40c 100644 --- a/.gitignore +++ b/.gitignore @@ -32,6 +32,7 @@ share/python-wheels/ .installed.cfg *.egg MANIFEST +Pipfile.lock # PyInstaller # Usually these files are written by a python script from a template diff --git a/threescale_api/auth.py b/threescale_api/auth.py index a802cc0..5b98cae 100644 --- a/threescale_api/auth.py +++ b/threescale_api/auth.py @@ -19,8 +19,7 @@ def __call__(self, request): credentials = self.credentials if self.location == "authorization": - credentials = credentials.values() - auth = requests.auth.HTTPBasicAuth(*credentials) + auth = requests.auth.HTTPBasicAuth(credentials["username"], credentials["password"]) return auth(request) if self.location == "headers": @@ -37,7 +36,7 @@ class UserKeyAuth(BaseClientAuth): """Provides user_key authentication for api client calls""" def __init__(self, app, location=None): - BaseClientAuth.__init__(self, app, location) + super(UserKeyAuth, self).__init__(app, location) self.credentials = { self.app.service.proxy.list()["auth_user_key"]: self.app["user_key"] } @@ -46,14 +45,14 @@ def __call__(self, request): if self.location == "authorization": auth = requests.auth.HTTPBasicAuth(next(iter(self.credentials.values())), "") return auth(request) - return BaseClientAuth.__call__(self, request) + return super().__call__(request) class AppIdKeyAuth(BaseClientAuth): """Provides app_id/app_key pair based authentication for api client calls""" def __init__(self, app, location=None): - BaseClientAuth.__init__(self, app, location) + super(AppIdKeyAuth, self).__init__(app, location) proxy = self.app.service.proxy.list() self.credentials = { proxy["auth_app_id"]: self.app["application_id"], @@ -61,4 +60,4 @@ def __init__(self, app, location=None): } def __call__(self, request): - return BaseClientAuth.__call__(self, request) + return super().__call__(request) diff --git a/threescale_api/defaults.py b/threescale_api/defaults.py index bbbf0d1..55ec01b 100644 --- a/threescale_api/defaults.py +++ b/threescale_api/defaults.py @@ -261,7 +261,7 @@ def __make_instance(self, extracted: dict, klass): class DefaultResource(collections.abc.MutableMapping): def __init__(self, client: DefaultClient = None, entity_id: int = None, entity_name: str = None, - entity: dict = None, **kwargs): + entity: dict = None): """Create instance of the resource Args: client: Client instance of the resource @@ -281,7 +281,7 @@ def threescale_client(self) -> 'ThreeScaleClient': @property def parent(self) -> 'DefaultResource': return self.client.parent - + @parent.setter def parent(self, parent): self.client.parent = parent @@ -416,7 +416,7 @@ def get_default(self, **kwargs) -> Optional['DefaultResource']: class DefaultPlanResource(DefaultResource): def __init__(self, entity_name='system_name', **kwargs): - DefaultResource.__init__(self, entity_name=entity_name, **kwargs) + super().__init__(entity_name=entity_name, **kwargs) def set_default(self, **kwargs) -> 'DefaultStateResource': """Set the plan default @@ -462,7 +462,7 @@ def set_state(self, state: str, **kwargs) -> 'DefaultStateResource': class DefaultUserResource(DefaultStateResource): def __init__(self, entity_name='username', **kwargs): - DefaultStateResource.__init__(self, entity_name=entity_name, **kwargs) + super().__init__(entity_name=entity_name, **kwargs) def suspend(self, **kwargs) -> 'DefaultUserResource': """Suspends the user diff --git a/threescale_api/errors.py b/threescale_api/errors.py index dbadc72..ccde43d 100644 --- a/threescale_api/errors.py +++ b/threescale_api/errors.py @@ -1,7 +1,7 @@ class ThreeScaleApiError(Exception): def __init__(self, message, *args): self.message = message - Exception.__init__(self, message, *args) + super(ThreeScaleApiError, self).__init__(message, *args) class ApiClientError(ThreeScaleApiError): @@ -13,4 +13,4 @@ def __init__(self, code, reason, body, message: str = None): msg = f"Response({self.code} {reason}): {body}" if message: msg += f"; {message}" - ThreeScaleApiError.__init__(self, msg) + super(ApiClientError, self).__init__(msg) diff --git a/threescale_api/resources.py b/threescale_api/resources.py index 15c7fed..4408968 100644 --- a/threescale_api/resources.py +++ b/threescale_api/resources.py @@ -14,7 +14,7 @@ class Services(DefaultClient): def __init__(self, *args, entity_name='service', entity_collection='services', **kwargs): - DefaultClient.__init__(self, *args, entity_name=entity_name, + super().__init__(*args, entity_name=entity_name, entity_collection=entity_collection, **kwargs) @property @@ -25,7 +25,7 @@ def url(self) -> str: class MappingRules(DefaultClient): def __init__(self, *args, entity_name='mapping_rule', entity_collection='mapping_rules', **kwargs): - DefaultClient.__init__(self, *args, entity_name=entity_name, + super().__init__(*args, entity_name=entity_name, entity_collection=entity_collection, **kwargs) @property @@ -35,7 +35,7 @@ def url(self) -> str: class Metrics(DefaultClient): def __init__(self, *args, entity_name='metric', entity_collection='metrics', **kwargs): - DefaultClient.__init__(self, *args, entity_name=entity_name, + super().__init__(*args, entity_name=entity_name, entity_collection=entity_collection, **kwargs) @property @@ -46,7 +46,7 @@ def url(self) -> str: class Limits(DefaultClient): def __init__(self, *args, entity_name='limit', entity_collection='limits', metric, **kwargs): - DefaultClient.__init__(self, *args, entity_name=entity_name, + super().__init__(*args, entity_name=entity_name, entity_collection=entity_collection, **kwargs) self._metric = metric @@ -77,7 +77,7 @@ def list_per_app_plan(self, **kwargs): class PricingRules(DefaultClient): def __init__(self, *args, entity_name='pricing_rule', entity_collection='pricing_rules', metric: 'Metric' = None, **kwargs): - DefaultClient.__init__(self, *args, entity_name=entity_name, + super().__init__(*args, entity_name=entity_name, entity_collection=entity_collection, **kwargs) self._metric = metric @@ -100,7 +100,7 @@ def url(self) -> str: class Methods(DefaultClient): def __init__(self, *args, entity_name='method', entity_collection='methods', **kwargs): - DefaultClient.__init__(self, *args, entity_name=entity_name, + super().__init__(*args, entity_name=entity_name, entity_collection=entity_collection, **kwargs) @property @@ -110,7 +110,7 @@ def url(self) -> str: class ApplicationPlans(DefaultPlanClient): def __init__(self, *args, entity_name='application_plan', entity_collection='plans', **kwargs): - DefaultClient.__init__(self, *args, entity_name=entity_name, + super().__init__(*args, entity_name=entity_name, entity_collection=entity_collection, **kwargs) @property @@ -124,7 +124,7 @@ def plans_url(self) -> str: class ApplicationPlanFeatures(DefaultClient): def __init__(self, *args, entity_name='feature', entity_collection='features', **kwargs): - DefaultClient.__init__(self, *args, entity_name=entity_name, + super().__init__(*args, entity_name=entity_name, entity_collection=entity_collection, **kwargs) @property @@ -134,7 +134,7 @@ def url(self) -> str: class AccountUsers(DefaultStateClient): def __init__(self, *args, entity_name='user', entity_collection='users', **kwargs): - DefaultClient.__init__(self, *args, entity_name=entity_name, + super().__init__(*args, entity_name=entity_name, entity_collection=entity_collection, **kwargs) @property @@ -144,7 +144,7 @@ def url(self) -> str: class AccountPlans(DefaultPlanClient): def __init__(self, *args, entity_name='account_plan', entity_collection='plans', **kwargs): - DefaultPlanClient.__init__(self, *args, entity_name=entity_name, + super().__init__(*args, entity_name=entity_name, entity_collection=entity_collection, **kwargs) @property @@ -154,7 +154,7 @@ def url(self) -> str: class Accounts(DefaultStateClient): def __init__(self, *args, entity_name='account', entity_collection='accounts', **kwargs): - DefaultStateClient.__init__(self, *args, entity_name=entity_name, + super().__init__(*args, entity_name=entity_name, entity_collection=entity_collection, **kwargs) @property @@ -244,7 +244,7 @@ def pending(self, entity_id, **kwargs) -> 'Account': class Applications(DefaultStateClient): def __init__(self, *args, entity_name='application', entity_collection='applications', **kwargs): - DefaultStateClient.__init__(self, *args, entity_name=entity_name, + super().__init__(*args, entity_name=entity_name, entity_collection=entity_collection, **kwargs) @property @@ -286,7 +286,7 @@ def resume(self, entity_id: int, **kwargs): class DevPortalAuthProviders(DefaultClient): def __init__(self, *args, entity_name='authentication_provider', entity_collection='authentication_providers', **kwargs): - DefaultClient.__init__(self, *args, entity_name=entity_name, + super().__init__(*args, entity_name=entity_name, entity_collection=entity_collection, **kwargs) @property @@ -297,7 +297,7 @@ def url(self) -> str: class ApplicationReferrerFilters(DefaultClient): def __init__(self, *args, entity_name='application', entity_collection='applications', **kwargs): - DefaultClient.__init__(self, *args, entity_name=entity_name, + super().__init__(*args, entity_name=entity_name, entity_collection=entity_collection, **kwargs) @property @@ -308,7 +308,7 @@ def url(self) -> str: class ApplicationKeys(DefaultClient): def __init__(self, *args, entity_name='application', entity_collection='applications', **kwargs): - DefaultClient.__init__(self, *args, entity_name=entity_name, + super().__init__(*args, entity_name=entity_name, entity_collection=entity_collection, **kwargs) @property @@ -318,7 +318,7 @@ def url(self) -> str: class Providers(DefaultClient): def __init__(self, *args, entity_name='user', entity_collection='users', **kwargs): - DefaultClient.__init__(self, *args, entity_name=entity_name, + super().__init__(*args, entity_name=entity_name, entity_collection=entity_collection, **kwargs) @property @@ -346,7 +346,7 @@ def url(self) -> str: class ActiveDocs(DefaultClient): def __init__(self, *args, entity_name='api_doc', entity_collection='api_docs', **kwargs): - DefaultClient.__init__(self, *args, entity_name=entity_name, + super().__init__(*args, entity_name=entity_name, entity_collection=entity_collection, **kwargs) @property @@ -385,7 +385,7 @@ def list_by_backend(self, backend: Union['Backend', int], **kwargs): class Tenants(DefaultClient): def __init__(self, *args, entity_name='tenant', entity_collection='tenants', **kwargs): - DefaultClient.__init__(self, *args, entity_name=entity_name, + super().__init__(*args, entity_name=entity_name, entity_collection=entity_collection, **kwargs) def read(self, id, **kwargs): @@ -433,7 +433,7 @@ def trigger_billing_account(self, tenant: Union['Tenant', int], account: Union[' class Proxies(DefaultClient): def __init__(self, *args, entity_name='proxy', **kwargs): - DefaultClient.__init__(self, *args, entity_name=entity_name, **kwargs) + super().__init__(*args, entity_name=entity_name, **kwargs) @property def url(self) -> str: @@ -458,7 +458,7 @@ def mapping_rules(self) -> 'MappingRules': class ProxyConfigs(DefaultClient): def __init__(self, *args, entity_name='proxy_config', entity_collection='configs', env: str = None, **kwargs): - DefaultClient.__init__(self, *args, entity_name=entity_name, + super().__init__(*args, entity_name=entity_name, entity_collection=entity_collection, **kwargs) self._env = env @@ -483,7 +483,7 @@ def list(self, **kwargs): if "env" in kwargs: self._env = kwargs["env"] del (kwargs["env"]) - return DefaultClient.list(self, **kwargs) + return super().list(**kwargs) def promote(self, version: int = 1, from_env: str = 'sandbox', to_env: str = 'production', **kwargs) -> 'Proxy': @@ -514,7 +514,7 @@ def version(self, version: int = 1, env: str = "sandbox") -> 'ProxyConfig': class SettingsClient(DefaultClient): def __init__(self, *args, entity_name='settings', **kwargs): - DefaultClient.__init__(self, *args, entity_name=entity_name, **kwargs) + super().__init__(*args, entity_name=entity_name, **kwargs) @property def url(self) -> str: @@ -524,7 +524,7 @@ def url(self) -> str: class AdminPortalAuthProviders(DefaultClient): def __init__(self, *args, entity_name='authentication_provider', entity_collection='authentication_providers', **kwargs): - DefaultClient.__init__(self, *args, entity_name=entity_name, + super().__init__(*args, entity_name=entity_name, entity_collection=entity_collection, **kwargs) @property @@ -534,7 +534,7 @@ def url(self) -> str: class UserPermissionsClient(DefaultClient): def __init__(self, *args, entity_name='permissions', **kwargs): - DefaultClient.__init__(self, *args, entity_name=entity_name, **kwargs) + super().__init__(*args, entity_name=entity_name, **kwargs) @property def url(self) -> str: @@ -543,7 +543,7 @@ def url(self) -> str: class Policies(DefaultClient): def __init__(self, *args, entity_name='policy', entity_collection='policies', **kwargs): - DefaultClient.__init__(self, *args, entity_name=entity_name, + super().__init__(*args, entity_name=entity_name, entity_collection=entity_collection, **kwargs) @property @@ -579,7 +579,7 @@ def read(self, params: dict = None, **kwargs) -> dict: class Backends(DefaultClient): def __init__(self, *args, entity_name='backend_api', entity_collection='backend_apis', **kwargs): - DefaultClient.__init__(self, *args, entity_name=entity_name, + super().__init__(*args, entity_name=entity_name, entity_collection=entity_collection, **kwargs) @property @@ -587,11 +587,11 @@ def url(self) -> str: return self.threescale_client.admin_api_url + '/backend_apis' def list(self, **kwargs): - return list(DefaultClient.list(self, **kwargs)) + return list(super().list(**kwargs)) def _list(self, **kwargs): if "page" in kwargs.get("params", {}): - return DefaultClient._list(self, **kwargs) + return super()._list(**kwargs) pagenum = 1 @@ -602,14 +602,14 @@ def _list(self, **kwargs): kwargs["params"]["page"] = pagenum kwargs["params"]["per_page"] = 500 - page = DefaultClient._list(self, **kwargs) + page = super()._list(**kwargs) while len(page): for i in page: yield i pagenum += 1 kwargs["params"]["page"] = pagenum - page = DefaultClient._list(self, **kwargs) + page = super()._list(**kwargs) def __iter__(self): return self._list() @@ -617,21 +617,21 @@ def __iter__(self): class BackendMetrics(Metrics): def __init__(self, *args, entity_name='metric', entity_collection='metrics', **kwargs): - Metrics.__init__(self, *args, entity_name=entity_name, + super().__init__(*args, entity_name=entity_name, entity_collection=entity_collection, **kwargs) class BackendMappingRules(MappingRules): def __init__(self, *args, entity_name='mapping_rule', entity_collection='mapping_rules', **kwargs): - MappingRules.__init__(self, *args, entity_name=entity_name, + super().__init__(*args, entity_name=entity_name, entity_collection=entity_collection, **kwargs) class BackendUsages(Services): def __init__(self, *args, entity_name='backend_usage', entity_collection='backend_usages', **kwargs): - Services.__init__(self, *args, entity_name=entity_name, + super().__init__(*args, entity_name=entity_name, entity_collection=entity_collection, **kwargs) @property @@ -641,7 +641,7 @@ def url(self) -> str: class PoliciesRegistry(DefaultClient): def __init__(self, *args, entity_name='policy', entity_collection='policies', **kwargs): - DefaultClient.__init__(self, *args, entity_name=entity_name, + super().__init__(*args, entity_name=entity_name, entity_collection=entity_collection, **kwargs) @property @@ -742,7 +742,7 @@ class Webhooks(DefaultClient): """ def __init__(self, *args, entity_name='webhook', entity_collection='webhooks', **kwargs): - DefaultClient.__init__(self, *args, entity_name=entity_name, + super().__init__(*args, entity_name=entity_name, entity_collection=entity_collection, **kwargs) @property @@ -904,7 +904,7 @@ def url(self) -> str: class ApplicationPlan(DefaultPlanResource): def __init__(self, entity_name='system_name', **kwargs): - DefaultPlanResource.__init__(self, entity_name=entity_name, **kwargs) + super().__init__(entity_name=entity_name, **kwargs) @property def plans_url(self) -> str: @@ -923,7 +923,7 @@ def pricing_rules(self, metric: 'Metric' = None) -> 'PricingRules': class Method(DefaultResource): def __init__(self, entity_name='system_name', **kwargs): - DefaultResource.__init__(self, entity_name=entity_name, **kwargs) + super().__init__(entity_name=entity_name, **kwargs) @property def metric(self) -> 'Metric': @@ -936,7 +936,7 @@ def service(self) -> 'Service': class Metric(DefaultResource): def __init__(self, entity_name='system_name', **kwargs): - DefaultResource.__init__(self, entity_name=entity_name, **kwargs) + super().__init__(entity_name=entity_name, **kwargs) @property def service(self) -> 'Service': @@ -975,19 +975,19 @@ def __getitem__(self, key): if "proxy_configs" in self.entity: return self.entity["proxy_configs"][key] else: - return DefaultResource.__getitem__(self, key) + return super().__getitem__(key) # Same problem as in __getitem__. def __len__(self): if "proxy_configs" in self.entity: return len(self.entity["proxy_configs"]) else: - return DefaultResource.__len__(self) + return super().__len__() class Policy(DefaultResource): def __init__(self, entity_name='system_name', **kwargs): - DefaultResource.__init__(self, entity_name=entity_name, **kwargs) + super().__init__(entity_name=entity_name, **kwargs) @property def proxy(self) -> 'Proxy': @@ -1036,7 +1036,7 @@ class Service(DefaultResource): AUTH_OIDC = "oidc" def __init__(self, entity_name='system_name', **kwargs): - DefaultResource.__init__(self, entity_name=entity_name, **kwargs) + super().__init__(entity_name=entity_name, **kwargs) @property def app_plans(self) -> ApplicationPlans: @@ -1082,12 +1082,12 @@ def list(self, **kwargs) -> List['DefaultResource']: class ActiveDoc(DefaultResource): def __init__(self, entity_name='system_name', **kwargs): - DefaultResource.__init__(self, entity_name=entity_name, **kwargs) + super().__init__(entity_name=entity_name, **kwargs) class Provider(DefaultResource): def __init__(self, entity_name='org_name', **kwargs): - DefaultResource.__init__(self, entity_name=entity_name, **kwargs) + super().__init__(entity_name=entity_name, **kwargs) class AccessToken(DefaultResource): @@ -1142,8 +1142,8 @@ def trigger_billing_account(self, account: Union['Account', int], date: str) -> class Application(DefaultResource): - def __init__(self, entity_name='system_name', **kwargs): - DefaultResource.__init__(self, entity_name=entity_name, **kwargs) + def __init__(self, entity_name='name', **kwargs): + super().__init__(entity_name=entity_name, **kwargs) self._auth_objects = { Service.AUTH_USER_KEY: auth.UserKeyAuth, Service.AUTH_APP_ID_KEY: auth.AppIdKeyAuth @@ -1241,7 +1241,7 @@ def test_request(self, relpath=None, verify: bool = None): class Account(DefaultResource): def __init__(self, entity_name='org_name', **kwargs): - DefaultResource.__init__(self, entity_name=entity_name, **kwargs) + super().__init__(entity_name=entity_name, **kwargs) @property def applications(self) -> Applications: @@ -1258,7 +1258,7 @@ class UserPermissions(DefaultResource): class AccountUser(DefaultUserResource): def __init__(self, entity_name='username', **kwargs): - DefaultUserResource.__init__(self, entity_name=entity_name, **kwargs) + super().__init__(entity_name=entity_name, **kwargs) @property def account(self) -> 'Account': @@ -1271,7 +1271,7 @@ def permissions(self) -> 'UserPermissionsClient': class AccountPlan(DefaultResource): def __init__(self, entity_name='system_name', **kwargs): - DefaultResource.__init__(self, entity_name=entity_name, **kwargs) + super().__init__(entity_name=entity_name, **kwargs) class Limit(DefaultResource): @@ -1288,7 +1288,7 @@ def app_plan(self) -> ApplicationPlan: class Backend(DefaultResource): def __init__(self, entity_name='system_name', **kwargs): - DefaultResource.__init__(self, entity_name=entity_name, **kwargs) + super().__init__(entity_name=entity_name, **kwargs) @property def metrics(self) -> 'BackendMetrics': @@ -1305,17 +1305,17 @@ def usages(self) -> 'BackendUsages': class BackendMetric(Metric): def __init__(self, entity_name='system_name', **kwargs): - Metric.__init__(self, entity_name=entity_name, **kwargs) + super().__init__(entity_name=entity_name, **kwargs) class BackendMappingRule(MappingRule): def __init__(self, **kwargs): - MappingRule.__init__(self, **kwargs) + super().__init__(**kwargs) class BackendUsage(DefaultResource): def __init__(self, entity_name='', **kwargs): - DefaultResource.__init__(self, entity_name=entity_name, **kwargs) + super().__init__(entity_name=entity_name, **kwargs) @property def backend(self) -> 'Backend':