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

String Formatting Updated #141

Merged
merged 6 commits into from
Nov 7, 2018
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion auth0/v3/authentication/authorize_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ def authorize(self, client_id, audience=None, state=None, redirect_uri=None,
}

return self.get(
'https://%s/authorize' % self.domain,
'https://{}/authorize'.format(self.domain),
params=params)
6 changes: 3 additions & 3 deletions auth0/v3/authentication/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def login(self, client_id, username, password, connection, id_token=None,
"""
warnings.warn("/oauth/ro will be deprecated in future releases", DeprecationWarning)
return self.post(
'https://%s/oauth/ro' % self.domain,
'https://{}/oauth/ro'.format(self.domain),
data={
'client_id': client_id,
'username': username,
Expand All @@ -44,7 +44,7 @@ def signup(self, client_id, email, password, connection):
"""

return self.post(
'https://%s/dbconnections/signup' % self.domain,
'https://{}/dbconnections/signup'.format(self.domain),
data={
'client_id': client_id,
'email': email,
Expand All @@ -59,7 +59,7 @@ def change_password(self, client_id, email, connection, password=None):
"""

return self.post(
'https://%s/dbconnections/change_password' % self.domain,
'https://{}/dbconnections/change_password'.format(self.domain),
data={
'client_id': client_id,
'email': email,
Expand Down
2 changes: 1 addition & 1 deletion auth0/v3/authentication/delegated.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def get_token(self, client_id, target, api_type, grant_type,
'have a value')

return self.post(
'https://%s/delegation' % self.domain,
'https://{}/delegation'.format(self.domain),
headers={'Content-Type': 'application/json'},
data=data
)
4 changes: 2 additions & 2 deletions auth0/v3/authentication/enterprise.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def wsfed_metadata(self):
"""Returns the WS-Federation Metadata.
"""

url = 'https://%s/wsfed/FederationMetadata' \
url = 'https://{}/wsfed/FederationMetadata' \
'/2007-06/FederationMetadata.xml'

return self.get(url=url % self.domain)
return self.get(url=url.format(self.domain))
10 changes: 5 additions & 5 deletions auth0/v3/authentication/get_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def authorization_code(self, client_id, client_secret, code,
"""

return self.post(
'https://%s/oauth/token' % self.domain,
'https://{}/oauth/token'.format(self.domain),
data={
'client_id': client_id,
'client_secret': client_secret,
Expand Down Expand Up @@ -75,7 +75,7 @@ def authorization_code_pkce(self, client_id, code_verifier, code,
"""

return self.post(
'https://%s/oauth/token' % self.domain,
'https://{}/oauth/token'.format(self.domain),
data={
'client_id': client_id,
'code_verifier': code_verifier,
Expand Down Expand Up @@ -110,7 +110,7 @@ def client_credentials(self, client_id, client_secret, audience,
"""

return self.post(
'https://%s/oauth/token' % self.domain,
'https://{}/oauth/token'.format(self.domain),
data={
'client_id': client_id,
'client_secret': client_secret,
Expand Down Expand Up @@ -157,7 +157,7 @@ def login(self, client_id, client_secret, username, password, scope, realm,
"""

return self.post(
'https://%s/oauth/token' % self.domain,
'https://{}/oauth/token'.format(self.domain),
data={
'client_id': client_id,
'username': username,
Expand Down Expand Up @@ -191,7 +191,7 @@ def refresh_token(self, client_id, client_secret, refresh_token, grant_type='ref
"""

return self.post(
'https://%s/oauth/token' % self.domain,
'https://{}/oauth/token'.format(self.domain),
data={
'client_id': client_id,
'client_secret': client_secret,
Expand Down
6 changes: 3 additions & 3 deletions auth0/v3/authentication/passwordless.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def email(self, client_id, email, send='link', auth_params=None):
"""

return self.post(
'https://%s/passwordless/start' % self.domain,
'https://{}/passwordless/start'.format(self.domain),
data={
'client_id': client_id,
'connection': 'email',
Expand All @@ -53,7 +53,7 @@ def sms(self, client_id, phone_number):
"""

return self.post(
'https://%s/passwordless/start' % self.domain,
'https://{}/passwordless/start'.format(self.domain),
data={
'client_id': client_id,
'connection': 'sms',
Expand All @@ -67,7 +67,7 @@ def sms_login(self, client_id, phone_number, code, scope='openid'):
"""

return self.post(
'https://%s/oauth/ro' % self.domain,
'https://{}/oauth/ro'.format(self.domain),
data={
'client_id': client_id,
'connection': 'sms',
Expand Down
2 changes: 1 addition & 1 deletion auth0/v3/authentication/social.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def login(self, client_id, access_token, connection, scope='openid'):
"""

return self.post(
'https://%s/oauth/access_token' % self.domain,
'https://{}/oauth/access_token'.format(self.domain),
data={
'client_id': client_id,
'access_token': access_token,
Expand Down
6 changes: 3 additions & 3 deletions auth0/v3/authentication/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def userinfo(self, access_token):
"""

return self.get(
url='https://%s/userinfo' % self.domain,
headers={'Authorization': 'Bearer %s' % access_token}
url='https://{}/userinfo'.format(self.domain),
headers={'Authorization': 'Bearer {}'.format(access_token)}
)

def tokeninfo(self, jwt):
Expand All @@ -46,7 +46,7 @@ def tokeninfo(self, jwt):
"""
warnings.warn("/tokeninfo will be deprecated in future releases", DeprecationWarning)
return self.post(
url='https://%s/tokeninfo' % self.domain,
url='https://{}/tokeninfo'.format(self.domain),
data={'id_token': jwt},
headers={'Content-Type': 'application/json'}
)
8 changes: 3 additions & 5 deletions auth0/v3/management/blacklists.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


class Blacklists(object):

"""Auth0 blacklists endpoints

Args:
Expand All @@ -15,7 +14,7 @@ class Blacklists(object):
"""

def __init__(self, domain, token, telemetry=True):
self.url = 'https://%s/api/v2/blacklists/tokens' % domain
self.url = 'https://{}/api/v2/blacklists/tokens'.format(domain)
self.client = RestClient(jwt=token, telemetry=telemetry)

def get(self, aud=None):
Expand All @@ -29,9 +28,8 @@ def get(self, aud=None):
See: https://auth0.com/docs/api/management/v2#!/Blacklists/get_tokens
"""

params = {
'aud': aud
}
self.aud_ = {'aud': aud}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of scope, let's leave this out.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code reverted

params = self.aud_

return self.client.get(self.url, params=params)

Expand Down
4 changes: 2 additions & 2 deletions auth0/v3/management/client_grants.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ def __init__(self, domain, token, telemetry=True):
self.client = RestClient(jwt=token, telemetry=telemetry)

def _url(self, id=None):
url = 'https://%s/api/v2/client-grants' % self.domain
url = 'https://{}/api/v2/client-grants'.format(self.domain)
if id is not None:
return url + '/' + id
return '{}/{}'.format(url, id)
return url

def all(self, audience=None, page=None, per_page=None, include_totals=False):
Expand Down
4 changes: 2 additions & 2 deletions auth0/v3/management/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ def __init__(self, domain, token, telemetry=True):
self.client = RestClient(jwt=token, telemetry=telemetry)

def _url(self, id=None):
url = 'https://%s/api/v2/clients' % self.domain
url = 'https://{}/api/v2/clients'.format(self.domain)
if id is not None:
return url + '/' + id
return '{}/{}'.format(url, id)
return url

def all(self, fields=None, include_fields=True, page=None, per_page=None, extra_params=None):
Expand Down
7 changes: 3 additions & 4 deletions auth0/v3/management/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ def __init__(self, domain, token, telemetry=True):
self.client = RestClient(jwt=token, telemetry=telemetry)

def _url(self, id=None):
url = 'https://%s/api/v2/connections' % self.domain
url = 'https://{}/api/v2/connections'.format(self.domain)
if id is not None:
return url + '/' + id
return '{}/{}'.format(url, id)
return url

def all(self, strategy=None, fields=None, include_fields=True, page=None, per_page=None, extra_params=None):
Expand Down Expand Up @@ -138,5 +138,4 @@ def delete_user_by_email(self, id, email):
Returns:
An empty dict.
"""
return self.client.delete(self._url(id) + '/users', params={'email': email})

return self.client.delete('{}/users'.format(self._url(id)), params={'email': email})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is confusing to read ... how about:

return self.client.delete( self._url( '{}/users'.format( id ) ) ...

Copy link
Contributor Author

@vkmrishad vkmrishad Nov 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joshcanhelp
return self.client.delete( self._url( '{}/users'.format( id ) ) ...
Only 'id' is expected in self._url(id) in this method. Above mentioned code passing both id+'/users'.
This will cause problem to

    def _url(self, id=None):
        url = 'https://{}/api/v2/connections'.format(self.domain)
        if id is not None:
            return '{}/{}'.format(url, id)
        return url

For readability we can change this to
return self.client.delete('{_url}/users'.format(_url=self._url(id)), params={'email': email})

or use the same return self.client.delete('{}/users'.format(self._url(id)), params={'email': email}).

or can use return self.client.delete(self._url(id) + '/users', params={'email': email}) without formatting.

Let me know your thought on this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's leave it as it was before:

self._url(id) + '/users'

I don't think the string formatting is adding anything here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, left it as it was before.

4 changes: 2 additions & 2 deletions auth0/v3/management/device_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ def __init__(self, domain, token, telemetry=True):
self.client = RestClient(jwt=token, telemetry=telemetry)

def _url(self, id=None):
url = 'https://%s/api/v2/device-credentials' % self.domain
url = 'https://{}/api/v2/device-credentials'.format(self.domain)
if id is not None:
return url + '/' + id
return '{}/{}'.format(url, id)
return url

def get(self, user_id, client_id, type, fields=None, include_fields=True):
Expand Down
4 changes: 2 additions & 2 deletions auth0/v3/management/email_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ def __init__(self, domain, token, telemetry=True):
self.client = RestClient(jwt=token, telemetry=telemetry)

def _url(self, id=None):
url = 'https://%s/api/v2/email-templates' % self.domain
url = 'https://{}/api/v2/email-templates'.format(self.domain)
if id is not None:
return url + '/' + id
return '{}/{}'.format(url, id)
return url

def create(self, body):
Expand Down
4 changes: 2 additions & 2 deletions auth0/v3/management/emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ def __init__(self, domain, token, telemetry=True):
self.client = RestClient(jwt=token, telemetry=telemetry)

def _url(self, id=None):
url = 'https://%s/api/v2/emails/provider' % self.domain
url = 'https://{}/api/v2/emails/provider'.format(self.domain)
if id is not None:
return url + '/' + id
return '{}/{}'.format(url, id)
return url

def get(self, fields=None, include_fields=True):
Expand Down
10 changes: 5 additions & 5 deletions auth0/v3/management/guardian.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ def __init__(self, domain, token, telemetry=True):
self.client = RestClient(jwt=token, telemetry=telemetry)

def _url(self, id=None):
url = 'https://%s/api/v2/guardian' % self.domain
url = 'https://{}/api/v2/guardian'.format(self.domain)
if id is not None:
return url + '/' + id
return '{}/{}'.format(url, id)
return url

def all_factors(self):
Expand All @@ -42,7 +42,7 @@ def update_factor(self, name, body):
body (dict): Attributes to modify.
See: https://auth0.com/docs/api/management/v2#!/Guardian/put_factors_by_name
"""
url = self._url('factors/%s' % (name))
url = self._url('factors/{}'.format(name))
return self.client.put(url, data=body)

def update_templates(self, body):
Expand Down Expand Up @@ -79,7 +79,7 @@ def get_enrollment(self, id):

See: https://auth0.com/docs/api/management/v2#!/Guardian/get_enrollments_by_id
"""
url = self._url('enrollments/%s' % (id))
url = self._url('enrollments/{}'.format(id))
return self.client.get(url)

def delete_enrollment(self, id):
Expand All @@ -93,7 +93,7 @@ def delete_enrollment(self, id):

See: https://auth0.com/docs/api/management/v2#!/Guardian/delete_enrollments_by_id
"""
url = self._url('enrollments/%s' % (id))
url = self._url('enrollments/{}'.format(id))
return self.client.delete(url)

def create_enrollment_ticket(self, body):
Expand Down
6 changes: 3 additions & 3 deletions auth0/v3/management/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ def __init__(self, domain, token, telemetry=True):
self.client = RestClient(jwt=token, telemetry=telemetry)

def _url(self, path=None):
url = 'https://%s/api/v2/jobs' % self.domain
url = 'https://{}/api/v2/jobs'.format(self.domain)
if path is not None:
return url + '/' + path
return '{}/{}'.format(url, path)
return url

def get(self, id):
Expand All @@ -42,7 +42,7 @@ def get_failed_job(self, id):

See: https://auth0.com/docs/api/management/v2#!/Jobs/get_errors
"""
url = self._url('%s/errors' % (id))
url = self._url('{}/errors'.format(id))
return self.client.get(url)

def export_users(self, body):
Expand Down
4 changes: 2 additions & 2 deletions auth0/v3/management/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ def __init__(self, domain, token, telemetry=True):
self.client = RestClient(jwt=token, telemetry=telemetry)

def _url(self, id=None):
url = 'https://%s/api/v2/logs' % self.domain
url = 'https://{}/api/v2/logs'.format(self.domain)
if id is not None:
return url + '/' + id
return '{}/{}'.format(url, id)
return url

def search(self, page=0, per_page=50, sort=None, q=None,
Expand Down
4 changes: 2 additions & 2 deletions auth0/v3/management/resource_servers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ def __init__(self, domain, token, telemetry=True):
self.client = RestClient(jwt=token, telemetry=telemetry)

def _url(self, id=None):
url = 'https://%s/api/v2/resource-servers' % self.domain
url = 'https://{}/api/v2/resource-servers'.format(self.domain)
if id is not None:
return url + '/' + id
return '{}/{}'.format(url, id)
return url

def create(self, body):
Expand Down
Loading