8000 Uptake of review comments · twilio/twilio-python@b973065 · GitHub
[go: up one dir, main page]

Skip to content

Commit b973065

Browse files
committed
Uptake of review comments
1 parent 2959689 commit b973065

File tree

10 files changed

+19
-34
lines changed

10 files changed

+19
-34
lines changed
File renamed without changes.

twilio/authStrategy/authStrategy.py renamed to twilio/auth_strategy/auth_strategy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from twilio.authStrategy.authType import AuthType
1+
from twilio.auth_strategy.auth_type import AuthType
22
from enum import Enum
33
from abc import abstractmethod
44

twilio/authStrategy/authType.py renamed to twilio/auth_strategy/auth_type.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from enum import Enum
22

33
class AuthType(Enum):
4-
TOKEN = 'token'
4+
ORGS_TOKEN = 'orgs_stoken'
55
NO_AUTH = 'noauth'
66
BASIC = 'basic'
77
API_KEY = 'api_key'

twilio/authStrategy/tokenAuthStrategy.py renamed to twilio/auth_strategy/token_auth_strategy.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
import jwt
22
import threading
3+
import logging
34
from datetime import datetime, timedelta
45

5-
from twilio.authStrategy.authType import AuthType
6-
from twilio.authStrategy.authStrategy import AuthStrategy
6+
from twilio.auth_strategy.auth_type import AuthType
7+
from twilio.auth_strategy.auth_strategy import AuthStrategy
78
from twilio.http.token_manager import TokenManager
89

910

1011
class TokenAuthStrategy(AuthStrategy):
1112
def __init__(self, token_manager: TokenManager):
12-
super().__init__(AuthType.TOKEN)
13+
super().__init__(AuthType.ORGS_TOKEN)
1314
self.token_manager = token_manager
1415
self.token = None
1516
self.lock = threading.Lock()
17+
logging.basicConfig(level=logging.INFO)
18+
self.logger = logging.getLogger(__name__)
1619

1720
def get_auth_string(self) -> str:
1821
if self.token is None:
@@ -23,7 +26,7 @@ def requires_authentication(self) -> bool:
2326
return True
2427

2528
def fetch_token(self):
26-
print(f'token is fetch_token {self.token}')
29+
self.logger.info("New token fetched for accessing organization API")
2730
if self.token is None or self.token == "" or self.is_token_expired(self.token):
2831
with self.lock:
2932
if self.token is None or self.token == "" or self.is_token_expired(self.token):

twilio/base/client_base.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
from twilio.http import HttpClient
88
from twilio.http.http_client import TwilioHttpClient
99
from twilio.http.response import Response
10-
from twilio.authStrategy.authType import AuthType
11-
from twilio.credential.credentialProvider import CredentialProvider
10+
from twilio.auth_strategy.auth_type import AuthType
11+
from twilio.credential.credential_provider import CredentialProvider
1212

1313

1414
class ClientBase(object):
@@ -93,7 +93,6 @@ def request(
9393

9494
##If credential provider is provided by user, get the associated auth strategy
9595
##Using the auth strategy, fetch the auth string and set it to authorization header
96-
auth_strategy = None ##Initialization
9796
if self.credential_provider:
9897
auth_strategy = self.credential_provider.to_auth_strategy()
9998
headers["Authorization"] = auth_strategy.get_auth_string()
@@ -151,15 +150,14 @@ async def request_async(
151150

152151
##If credential provider is provided by user, get the associated auth strategy
153152
##Using the auth strategy, fetch the auth string and set it to authorization header
154-
auth_strategy = None ##Initialization
155153
if self.credential_provider:
156154
auth_strategy = self.credential_provider.to_auth_strategy()
157-
if auth_strategy.auth_type == AuthType.TOKEN:
158-
auth_strategy.fetch_token()
159-
headers["Authorization"] = auth_strategy.get_auth_string()
155+
headers["Authorization"] = auth_strategy.get_auth_string()
160156
else:
161157
auth = self.get_auth(auth)
162158

159+
uri = self.get_hostname(uri)
160+
163161
return await self.http_client.request(
164162
method,
165163
uri,

twilio/credential/credentialProvider.py renamed to twilio/credential/credential_provider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from twilio.authStrat F438 egy.authType import AuthType
1+
from twilio.auth_strategy.auth_type import AuthType
22

33
class CredentialProvider:
44
def __init__(self, auth_type: AuthType):

twilio/credential/orgsCredentialProvider.py renamed to twilio/credential/orgs_credential_provider.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
from twilio.http.orgs_token_manager import OrgTokenManager
44
from twilio.base.exceptions import TwilioException
5-
from twilio.credential.credentialProvider import CredentialProvider
6-
from twilio.authStrategy.authType import AuthType
7-
from twilio.authStrategy.tokenAuthStrategy import TokenAuthStrategy
5+
from twilio.credential.credential_provider import CredentialProvider
6+
from twilio.auth_strategy.auth_type import AuthType
7+
from twilio.auth_strategy.token_auth_strategy import TokenAuthStrategy
88

99

1010
class OrgsCredentialProvider(CredentialProvider):

twilio/http/token_manager_initializer.py

Lines changed: 0 additions & 16 deletions
This file was deleted.

twilio/rest/preview_iam/organizations/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def __init__(self, domain: Domain):
3535
@property
3636
def accounts(self) -> AccountList:
3737
if self._accounts is None:
38-
self._accounts = AccountList(self)
38+
self._accounts = AccountList(self, "OR64adedc0f4dc99b9113305f725677b47")
3939
return self._accounts
4040

4141

0 commit comments

Comments
 (0)
0