Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SDK-2687] Implement automatic rate-limit handling #285

Merged
merged 6 commits into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 31 additions & 26 deletions auth0/v3/management/auth0.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,36 @@ class Auth0(object):
domain (str): Your Auth0 domain, e.g: 'username.auth0.com'

token (str): Management API v2 Token

rest_options (RestClientOptions): Pass an instance of
RestClientOptions to configure additional RestClient
options, such as rate-limit retries.
(defaults to None)
"""

def __init__(self, domain, token):
self.blacklists = Blacklists(domain, token)
self.client_grants = ClientGrants(domain, token)
self.clients = Clients(domain, token)
self.connections = Connections(domain, token)
self.custom_domains = CustomDomains(domain, token)
self.device_credentials = DeviceCredentials(domain, token)
self.email_templates = EmailTemplates(domain, token)
self.emails = Emails(domain, token)
self.grants = Grants(domain, token)
self.guardian = Guardian(domain, token)
self.hooks = Hooks(domain, token)
self.jobs = Jobs(domain, token)
self.log_streams = LogStreams(domain, token)
self.logs = Logs(domain, token)
self.organizations = Organizations(domain, token)
self.resource_servers = ResourceServers(domain, token)
self.roles = Roles(domain, token)
self.rules_configs = RulesConfigs(domain, token)
self.rules = Rules(domain, token)
self.stats = Stats(domain, token)
self.tenants = Tenants(domain, token)
self.tickets = Tickets(domain, token)
self.user_blocks = UserBlocks(domain, token)
self.users_by_email = UsersByEmail(domain, token)
self.users = Users(domain, token)
def __init__(self, domain, token, rest_options=None):
self.blacklists = Blacklists(domain=domain, token=token, rest_options=rest_options)
self.client_grants = ClientGrants(domain=domain, token=token, rest_options=rest_options)
self.clients = Clients(domain=domain, token=token, rest_options=rest_options)
self.connections = Connections(domain=domain, token=token, rest_options=rest_options)
self.custom_domains = CustomDomains(domain=domain, token=token, rest_options=rest_options)
self.device_credentials = DeviceCredentials(domain=domain, token=token, rest_options=rest_options)
self.email_templates = EmailTemplates(domain=domain, token=token, rest_options=rest_options)
self.emails = Emails(domain=domain, token=token, rest_options=rest_options)
self.grants = Grants(domain=domain, token=token, rest_options=rest_options)
self.guardian = Guardian(domain=domain, token=token, rest_options=rest_options)
self.hooks = Hooks(domain=domain, token=token, rest_options=rest_options)
self.jobs = Jobs(domain=domain, token=token, rest_options=rest_options)
self.log_streams = LogStreams(domain=domain, token=token, rest_options=rest_options)
self.logs = Logs(domain=domain, token=token, rest_options=rest_options)
self.organizations = Organizations(domain=domain, token=token, rest_options=rest_options)
self.resource_servers = ResourceServers(domain=domain, token=token, rest_options=rest_options)
self.roles = Roles(domain=domain, token=token, rest_options=rest_options)
self.rules_configs = RulesConfigs(domain=domain, token=token, rest_options=rest_options)
self.rules = Rules(domain=domain, token=token, rest_options=rest_options)
self.stats = Stats(domain=domain, token=token, rest_options=rest_options)
self.tenants = Tenants(domain=domain, token=token, rest_options=rest_options)
self.tickets = Tickets(domain=domain, token=token, rest_options=rest_options)
self.user_blocks = UserBlocks(domain=domain, token=token, rest_options=rest_options)
self.users_by_email = UsersByEmail(domain=domain, token=token, rest_options=rest_options)
self.users = Users(domain=domain, token=token, rest_options=rest_options)
9 changes: 7 additions & 2 deletions auth0/v3/management/blacklists.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@ class Blacklists(object):
connect and read timeout. Pass a tuple to specify
both values separately or a float to set both to it.
(defaults to 5.0 for both)

rest_options (RestClientOptions): Pass an instance of
RestClientOptions to configure additional RestClient
options, such as rate-limit retries.
(defaults to None)
"""

def __init__(self, domain, token, telemetry=True, timeout=5.0, protocol="https"):
def __init__(self, domain, token, telemetry=True, timeout=5.0, protocol="https", rest_options=None):
self.url = '{}://{}/api/v2/blacklists/tokens'.format(protocol, domain)
self.client = RestClient(jwt=token, telemetry=telemetry, timeout=timeout)
self.client = RestClient(jwt=token, telemetry=telemetry, timeout=timeout, options=rest_options)

def get(self, aud=None):
"""Retrieves the jti and aud of all tokens in the blacklist.
Expand Down
9 changes: 7 additions & 2 deletions auth0/v3/management/client_grants.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ class ClientGrants(object):
connect and read timeout. Pass a tuple to specify
both values separately or a float to set both to it.
(defaults to 5.0 for both)

rest_options (RestClientOptions): Pass an instance of
RestClientOptions to configure additional RestClient
options, such as rate-limit retries.
(defaults to None)
"""

def __init__(self, domain, token, telemetry=True, timeout=5.0, protocol="https"):
def __init__(self, domain, token, telemetry=True, timeout=5.0, protocol="https", rest_options=None):
self.domain = domain
self.protocol = protocol
self.client = RestClient(jwt=token, telemetry=telemetry, timeout=timeout)
self.client = RestClient(jwt=token, telemetry=telemetry, timeout=timeout, options=rest_options)

def _url(self, id=None):
url = '{}://{}/api/v2/client-grants'.format(self.protocol, self.domain)
Expand Down
9 changes: 7 additions & 2 deletions auth0/v3/management/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ class Clients(object):
connect and read timeout. Pass a tuple to specify
both values separately or a float to set both to it.
(defaults to 5.0 for both)

rest_options (RestClientOptions): Pass an instance of
RestClientOptions to configure additional RestClient
options, such as rate-limit retries.
(defaults to None)
"""

def __init__(self, domain, token, telemetry=True, timeout=5.0, protocol="https"):
def __init__(self, domain, token, telemetry=True, timeout=5.0, protocol="https", rest_options=None):
self.domain = domain
self.protocol = protocol
self.client = RestClient(jwt=token, telemetry=telemetry, timeout=timeout)
self.client = RestClient(jwt=token, telemetry=telemetry, timeout=timeout, options=rest_options)

def _url(self, id=None):
url = '{}://{}/api/v2/clients'.format(self.protocol, self.domain)
Expand Down
9 changes: 7 additions & 2 deletions auth0/v3/management/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ class Connections(object):
connect and read timeout. Pass a tuple to specify
both values separately or a float to set both to it.
(defaults to 5.0 for both)

rest_options (RestClientOptions): Pass an instance of
RestClientOptions to configure additional RestClient
options, such as rate-limit retries.
(defaults to None)
"""

def __init__(self, domain, token, telemetry=True, timeout=5.0, protocol="https"):
def __init__(self, domain, token, telemetry=True, timeout=5.0, protocol="https", rest_options=None):
self.domain = domain
self.protocol = protocol
self.client = RestClient(jwt=token, telemetry=telemetry, timeout=timeout)
self.client = RestClient(jwt=token, telemetry=telemetry, timeout=timeout, options=rest_options)

def _url(self, id=None):
url = '{}://{}/api/v2/connections'.format(self.protocol, self.domain)
Expand Down
9 changes: 7 additions & 2 deletions auth0/v3/management/custom_domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ class CustomDomains(object):
connect and read timeout. Pass a tuple to specify
both values separately or a float to set both to it.
(defaults to 5.0 for both)

rest_options (RestClientOptions): Pass an instance of
RestClientOptions to configure additional RestClient
options, such as rate-limit retries.
(defaults to None)
"""

def __init__(self, domain, token, telemetry=True, timeout=5.0, protocol="https"):
def __init__(self, domain, token, telemetry=True, timeout=5.0, protocol="https", rest_options=None):
self.domain = domain
self.protocol = protocol
self.client = RestClient(jwt=token, telemetry=telemetry, timeout=timeout)
self.client = RestClient(jwt=token, telemetry=telemetry, timeout=timeout, options=rest_options)

def _url(self, id=None):
url = '{}://{}/api/v2/custom-domains'.format(self.protocol, self.domain)
Expand Down
9 changes: 7 additions & 2 deletions auth0/v3/management/device_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ class DeviceCredentials(object):
connect and read timeout. Pass a tuple to specify
both values separately or a float to set both to it.
(defaults to 5.0 for both)

rest_options (RestClientOptions): Pass an instance of
RestClientOptions to configure additional RestClient
options, such as rate-limit retries.
(defaults to None)
"""

def __init__(self, domain, token, telemetry=True, timeout=5.0, protocol="https"):
def __init__(self, domain, token, telemetry=True, timeout=5.0, protocol="https", rest_options=None):
self.domain = domain
self.protocol = protocol
self.client = RestClient(jwt=token, telemetry=telemetry, timeout=timeout)
self.client = RestClient(jwt=token, telemetry=telemetry, timeout=timeout, options=rest_options)

def _url(self, id=None):
url = '{}://{}/api/v2/device-credentials'.format(self.protocol, self.domain)
Expand Down
9 changes: 7 additions & 2 deletions auth0/v3/management/email_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ class EmailTemplates(object):
connect and read timeout. Pass a tuple to specify
both values separately or a float to set both to it.
(defaults to 5.0 for both)

rest_options (RestClientOptions): Pass an instance of
RestClientOptions to configure additional RestClient
options, such as rate-limit retries.
(defaults to None)
"""

def __init__(self, domain, token, telemetry=True, timeout=5.0, protocol="https"):
def __init__(self, domain, token, telemetry=True, timeout=5.0, protocol="https", rest_options=None):
self.domain = domain
self.protocol = protocol
self.client = RestClient(jwt=token, telemetry=telemetry, timeout=timeout)
self.client = RestClient(jwt=token, telemetry=telemetry, timeout=timeout, options=rest_options)

def _url(self, id=None):
url = '{}://{}/api/v2/email-templates'.format(self.protocol, self.domain)
Expand Down
9 changes: 7 additions & 2 deletions auth0/v3/management/emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ class Emails(object):
connect and read timeout. Pass a tuple to specify
both values separately or a float to set both to it.
(defaults to 5.0 for both)

rest_options (RestClientOptions): Pass an instance of
RestClientOptions to configure additional RestClient
options, such as rate-limit retries.
(defaults to None)
"""

def __init__(self, domain, token, telemetry=True, timeout=5.0, protocol="https"):
def __init__(self, domain, token, telemetry=True, timeout=5.0, protocol="https", rest_options=None):
self.domain = domain
self.protocol = protocol
self.client = RestClient(jwt=token, telemetry=telemetry, timeout=timeout)
self.client = RestClient(jwt=token, telemetry=telemetry, timeout=timeout, options=rest_options)

def _url(self, id=None):
url = '{}://{}/api/v2/emails/provider'.format(self.protocol, self.domain)
Expand Down
11 changes: 8 additions & 3 deletions auth0/v3/management/grants.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ class Grants(object):
connect and read timeout. Pass a tuple to specify
both values separately or a float to set both to it.
(defaults to 5.0 for both)

rest_options (RestClientOptions): Pass an instance of
RestClientOptions to configure additional RestClient
options, such as rate-limit retries.
(defaults to None)
"""

def __init__(self, domain, token, telemetry=True, timeout=5.0, protocol="https"):
def __init__(self, domain, token, telemetry=True, timeout=5.0, protocol="https", rest_options=None):
self.domain = domain
self.protocol = protocol
self.client = RestClient(jwt=token, telemetry=telemetry, timeout=timeout)
self.client = RestClient(jwt=token, telemetry=telemetry, timeout=timeout, options=rest_options)

def _url(self, id=None):
url = '{}://{}/api/v2/grants'.format(self.protocol, self.domain)
Expand All @@ -45,7 +50,7 @@ def all(self, page=None, per_page=None, include_totals=False, extra_params=None)
extra_params (dictionary, optional): The extra parameters to add to
the request. The page, per_page, and include_totals values
specified as parameters take precedence over the ones defined here.

See: https://auth0.com/docs/api/management/v2#!/Grants/get_grants
"""
params = extra_params or {}
Expand Down
11 changes: 8 additions & 3 deletions auth0/v3/management/guardian.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ class Guardian(object):
connect and read timeout. Pass a tuple to specify
both values separately or a float to set both to it.
(defaults to 5.0 for both)

rest_options (RestClientOptions): Pass an instance of
RestClientOptions to configure additional RestClient
options, such as rate-limit retries.
(defaults to None)
"""

def __init__(self, domain, token, telemetry=True, timeout=5.0, protocol="https"):
def __init__(self, domain, token, telemetry=True, timeout=5.0, protocol="https", rest_options=None):
self.domain = domain
self.protocol = protocol
self.client = RestClient(jwt=token, telemetry=telemetry, timeout=timeout)
self.client = RestClient(jwt=token, telemetry=telemetry, timeout=timeout, options=rest_options)

def _url(self, id=None):
url = '{}://{}/api/v2/guardian'.format(self.protocol, self.domain)
Expand All @@ -33,7 +38,7 @@ def all_factors(self):
"""Retrieves all factors. Useful to check factor enablement and
trial status.

See: https://auth0.com/docs/api/management/v2#!/Guardian/get_factors
See: https://auth0.com/docs/api/management/v2#!/Guardian/get_factors
"""

return self.client.get(self._url('factors'))
Expand Down
9 changes: 7 additions & 2 deletions auth0/v3/management/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@ class Hooks(object):
connect and read timeout. Pass a tuple to specify
both values separately or a float to set both to it.
(defaults to 5.0 for both)

rest_options (RestClientOptions): Pass an instance of
RestClientOptions to configure additional RestClient
options, such as rate-limit retries.
(defaults to None)
"""

def __init__(self, domain, token, telemetry=True, timeout=5.0, protocol="https"):
def __init__(self, domain, token, telemetry=True, timeout=5.0, protocol="https", rest_options=None):
self.domain = domain
self.protocol = protocol
self.client = RestClient(jwt=token, telemetry=telemetry, timeout=timeout)
self.client = RestClient(jwt=token, telemetry=telemetry, timeout=timeout, options=rest_options)

def _url(self, id=None):
url = "{}://{}/api/v2/hooks".format(self.protocol, self.domain)
Expand Down
13 changes: 9 additions & 4 deletions auth0/v3/management/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@ class Jobs(object):
connect and read timeout. Pass a tuple to specify
both values separately or a float to set both to it.
(defaults to 5.0 for both)

rest_options (RestClientOptions): Pass an instance of
RestClientOptions to configure additional RestClient
options, such as rate-limit retries.
(defaults to None)
"""

def __init__(self, domain, token, telemetry=True, timeout=5.0, protocol="https"):
def __init__(self, domain, token, telemetry=True, timeout=5.0, protocol="https", rest_options=None):
self.domain = domain
self.protocol = protocol
self.client = RestClient(jwt=token, telemetry=telemetry, timeout=timeout)
self.client = RestClient(jwt=token, telemetry=telemetry, timeout=timeout, options=rest_options)

def _url(self, path=None):
url = '{}://{}/api/v2/jobs'.format(self.protocol, self.domain)
Expand Down Expand Up @@ -57,10 +62,10 @@ def get_results(self, job_id):
Args:
job_id (str): The id of the job.

Deprecation:
Deprecation:
The /jobs/{id}/results endpoint was removed from the Management API.
You can obtain the Job results by querying a Job by ID.

See: https://auth0.com/docs/api/management/v2#!/Jobs/get_jobs_by_id
"""
warnings.warn("/jobs/{id}/results is no longer available. The get(id) function will be called instead.", DeprecationWarning)
Expand Down
9 changes: 7 additions & 2 deletions auth0/v3/management/log_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ class LogStreams(object):
connect and read timeout. Pass a tuple to specify
both values separately or a float to set both to it.
(defaults to 5.0 for both)

rest_options (RestClientOptions): Pass an instance of
RestClientOptions to configure additional RestClient
options, such as rate-limit retries.
(defaults to None)
"""

def __init__(self, domain, token, telemetry=True, timeout=5.0, protocol="https"):
def __init__(self, domain, token, telemetry=True, timeout=5.0, protocol="https", rest_options=None):
self.domain = domain
self.protocol = protocol
self.client = RestClient(jwt=token, telemetry=telemetry, timeout=timeout)
self.client = RestClient(jwt=token, telemetry=telemetry, timeout=timeout, options=rest_options)

def _url(self, id=None):
url = '{}://{}/api/v2/log-streams'.format(self.protocol, self.domain)
Expand Down
9 changes: 7 additions & 2 deletions auth0/v3/management/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ class Logs(object):
connect and read timeout. Pass a tuple to specify
both values separately or a float to set both to it.
(defaults to 5.0 for both)

rest_options (RestClientOptions): Pass an instance of
RestClientOptions to configure additional RestClient
options, such as rate-limit retries.
(defaults to None)
"""

def __init__(self, domain, token, telemetry=True, timeout=5.0, protocol="https"):
def __init__(self, domain, token, telemetry=True, timeout=5.0, protocol="https", rest_options=None):
self.domain = domain
self.protocol = protocol
self.client = RestClient(jwt=token, telemetry=telemetry, timeout=timeout)
self.client = RestClient(jwt=token, telemetry=telemetry, timeout=timeout, options=rest_options)

def _url(self, id=None):
url = '{}://{}/api/v2/logs'.format(self.protocol, self.domain)
Expand Down
9 changes: 7 additions & 2 deletions auth0/v3/management/organizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ class Organizations(object):
connect and read timeout. Pass a tuple to specify
both values separately or a float to set both to it.
(defaults to 5.0 for both)

rest_options (RestClientOptions): Pass an instance of
RestClientOptions to configure additional RestClient
options, such as rate-limit retries.
(defaults to None)
"""

def __init__(self, domain, token, telemetry=True, timeout=5.0, protocol="https"):
def __init__(self, domain, token, telemetry=True, timeout=5.0, protocol="https", rest_options=None):
self.domain = domain
self.protocol = protocol
self.client = RestClient(jwt=token, telemetry=telemetry, timeout=timeout)
self.client = RestClient(jwt=token, telemetry=telemetry, timeout=timeout, options=rest_options)

def _url(self, *args):
url = '{}://{}/api/v2/organizations'.format(self.protocol, self.domain)
Expand Down
Loading