diff --git a/.gitignore b/.gitignore index fff9a08..dc18857 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ __pycache__ *.swp *.egg-info .env +.envrc /.vscode /docs/build /build diff --git a/coto/clients/account.py b/coto/clients/account.py index e937f19..f80008c 100644 --- a/coto/clients/account.py +++ b/coto/clients/account.py @@ -4,6 +4,10 @@ import json from . import BaseClient +import os + +ACCOUNT_CONSOLE_URL = os.environ.get('ACCOUNT_CONSOLE_URL', 'https://console.aws.amazon.com/console/') +ACCOUNT_SIGNIN_URL = os.environ.get('ACCOUNT_SIGNIN_URL', 'https://signin.aws.amazon.com/updateaccount') class ReauthException(Exception): pass @@ -27,7 +31,7 @@ class Client(BaseClient): * :py:meth:`update_account_email` * :py:meth:`update_account_password` """ - _REDIRECT_URL = "https://console.aws.amazon.com/console/home?state=hashArgs%23&isauthcode=true" + _REDIRECT_URL = ACCOUNT_CONSOLE_URL + "home?state=hashArgs%23&isauthcode=true" def __init__(self, session): super().__init__(session) @@ -41,7 +45,7 @@ def _csrf_token(self): def _get_tokens(self): r = self.session()._get( - 'https://signin.aws.amazon.com/updateaccount?redirect_uri=https%3A%2F%2Fconsole.aws.amazon.com%2Fbilling%2Fhome%23%2Faccount' + ACCOUNT_SIGNIN_URL + '?redirect_uri=https%3A%2F%2Fconsole.aws.amazon.com%2Fbilling%2Fhome%23%2Faccount' ) if r.status_code != 200: @@ -77,7 +81,7 @@ def _action(self, action, data=None): data['csrf'] = self._csrf_token() r = self.session()._post( - 'https://signin.aws.amazon.com/updateaccount', + ACCOUNT_SIGNIN_URL, data=data, ) diff --git a/coto/clients/billing.py b/coto/clients/billing.py index cd745d5..3bbd622 100644 --- a/coto/clients/billing.py +++ b/coto/clients/billing.py @@ -1,6 +1,11 @@ import json from . import BaseClient +import os + +BILLING_CONSOLE_URL = os.environ.get('BILLING_CONSOLE_URL', 'https://console.aws.amazon.com/billing/') +BILLING_REGION = os.environ.get('BILLING_REGION', 'eu-central-1') + class Client(BaseClient): """ @@ -41,7 +46,7 @@ def _xsrf_token(self): def _get_xsrf_token(self): r = self.session()._get( - 'https://console.aws.amazon.com/billing/home?region=eu-central-1&state=hashArgs%23' + BILLING_CONSOLE_URL + 'home?region=' + BILLING_REGION + '&state=hashArgs%23' ) if r.status_code != 200: @@ -51,7 +56,7 @@ def _get_xsrf_token(self): def _get(self, api): r = self.session()._get( - "https://console.aws.amazon.com/billing/rest/v1.0/{0}?state=hashArgs%23". + BILLING_CONSOLE_URL + "rest/v1.0/{0}?state=hashArgs%23". format(api), headers={'x-awsbc-xsrf-token': self._xsrf_token()}) @@ -63,7 +68,7 @@ def _get(self, api): def _put(self, api, data=None): if data is None: r = self.session()._put( - "https://console.aws.amazon.com/billing/rest/v1.0/{0}?state=hashArgs%23". + BILLING_CONSOLE_URL + "rest/v1.0/{0}?state=hashArgs%23". format(api), headers={ 'x-awsbc-xsrf-token': self._xsrf_token(), @@ -71,7 +76,7 @@ def _put(self, api, data=None): }) else: r = self.session()._put( - "https://console.aws.amazon.com/billing/rest/v1.0/{0}?state=hashArgs%23". + BILLING_CONSOLE_URL + "rest/v1.0/{0}?state=hashArgs%23". format(api), headers={ 'x-awsbc-xsrf-token': self._xsrf_token(), diff --git a/coto/clients/federation.py b/coto/clients/federation.py index a2a8684..f40f265 100644 --- a/coto/clients/federation.py +++ b/coto/clients/federation.py @@ -3,6 +3,11 @@ import requests from . import BaseClient +import os + +FEDERATION_SIGNIN_URL = os.environ.get('FEDERATION_SIGNIN_URL', 'https://signin.aws.amazon.com/federation') +FEDERATION_DESTINATION = os.environ.get('FEDERATION_DESTINATION', 'https://console.aws.amazon.com/') + class Client(BaseClient): REQUIRES_AUTHENTICATION = False @@ -87,11 +92,11 @@ def get_signin_url(self, boto3_session): Returns: bool: Signin succeeded. """ - url = furl('https://signin.aws.amazon.com/federation') + url = furl(FEDERATION_SIGNIN_URL) url.args['Action'] = "login" url.args['Issuer'] = None - url.args['Destination'] = "https://console.aws.amazon.com/" + url.args['Destination'] = FEDERATION_DESTINATION url.args['SigninToken'] = self.get_signin_token(boto3_session) return url.url @@ -119,7 +124,7 @@ def get_signin_token(self, boto3_session): """ credentials = boto3_session.get_credentials() - url = "https://signin.aws.amazon.com/federation" + url = FEDERATION_SIGNIN_URL response = self.session()._get( url, params={ diff --git a/coto/clients/iam.py b/coto/clients/iam.py index 1cabb47..c914e9c 100644 --- a/coto/clients/iam.py +++ b/coto/clients/iam.py @@ -4,6 +4,9 @@ import json from . import BaseClient +import os + +IAM_ENDPOINT_URL = os.environ.get('IAM_ENDPOINT_URL', 'https://console.aws.amazon.com/iam/') class Client(BaseClient): """ @@ -40,7 +43,7 @@ def __init__(self, session): self.__xsrf_token = None def _url(self, api): - return "https://console.aws.amazon.com/iam/{0}".format(api) + return IAM_ENDPOINT_URL + "{0}".format(api) def _xsrf_token(self): if self.__xsrf_token is None: @@ -50,12 +53,12 @@ def _xsrf_token(self): def _get_xsrf_token(self): r = self.session()._get( - 'https://console.aws.amazon.com/iam/home?&state=hashArgs%23') + IAM_ENDPOINT_URL + 'home?&state=hashArgs%23') if r.status_code != 200: raise Exception("failed get token") - r = self.session()._get('https://console.aws.amazon.com/iam/home?') + r = self.session()._get(IAM_ENDPOINT_URL + 'home?') if r.status_code != 200: raise Exception("failed get token") diff --git a/coto/clients/mfa.py b/coto/clients/mfa.py index 465f0b4..fb231ac 100644 --- a/coto/clients/mfa.py +++ b/coto/clients/mfa.py @@ -3,10 +3,14 @@ import json from . import BaseClient +import os + +MFA_CONSOLE_URL = os.environ.get('MFA_CONSOLE_URL', 'https://console.aws.amazon.com/console/') +MFA_SIGNIN_URL = os.environ.get('MFA_SIGNIN_URL', 'https://signin.aws.amazon.com/mfa') class Client(BaseClient): REQUIRES_AUTHENTICATION = False - _REDIRECT_URL = "https://console.aws.amazon.com/console/home?state=hashArgs%23&isauthcode=true" + _REDIRECT_URL = MFA_CONSOLE_URL + "home?state=hashArgs%23&isauthcode=true" def __init__(self, session): super().__init__(session) @@ -14,7 +18,7 @@ def __init__(self, session): def get_mfa_status(self, email): r = self.session()._post( - "https://signin.aws.amazon.com/mfa", + MFA_SIGNIN_URL, data={ 'email': email, '_redirect_url': self._REDIRECT_URL, diff --git a/coto/clients/resetpassword.py b/coto/clients/resetpassword.py index cbe85b3..b62d3ac 100644 --- a/coto/clients/resetpassword.py +++ b/coto/clients/resetpassword.py @@ -4,10 +4,15 @@ import json from . import BaseClient +import os + +RESET_PASSWORD_CONSOLE_URL = os.environ.get('RESET_PASSWORD_CONSOLE_URL', 'https://console.aws.amazon.com/console/') +RESET_PASSWORD_SIGNIN_URL = os.environ.get('RESET_PASSWORD_SIGNIN_URL', 'https://signin.aws.amazon.com/resetpassword') +RESET_PASSWORD_AWS_SIGNIN_URL = os.environ.get('RESET_PASSWORD_SIGNIN_URL', 'https://signin.aws.amazon.com/') class Client(BaseClient): REQUIRES_AUTHENTICATION = False - _REDIRECT_URL = "https://console.aws.amazon.com/console/home?state=hashArgs%23&isauthcode=true" + _REDIRECT_URL = RESET_PASSWORD_CONSOLE_URL + "home?state=hashArgs%23&isauthcode=true" def __init__(self, session): super().__init__(session) @@ -21,7 +26,7 @@ def _csrf_token(self): def _get_tokens(self): r = self.session()._get( - 'https://signin.aws.amazon.com/resetpassword' + RESET_PASSWORD_SIGNIN_URL ) if r.status_code != 200: @@ -56,7 +61,7 @@ def _action(self, action, data=None, api="signin"): data['csrf'] = self._csrf_token() r = self.session()._post( - "https://signin.aws.amazon.com/{0}".format(api), + RESET_PASSWORD_AWS_SIGNIN_URL + "{0}".format(api), data=data, ) diff --git a/coto/clients/support.py b/coto/clients/support.py index 58458e6..a4533b1 100644 --- a/coto/clients/support.py +++ b/coto/clients/support.py @@ -4,6 +4,10 @@ import json from . import BaseClient +import os + +SUPPORT_URL = os.environ.get('SUPPORT_URL', 'https://console.aws.amazon.com/support/') +SUPPORT_REGION = os.environ.get('SUPPORT_REGION', 'eu-central-1') class ReauthException(Exception): pass @@ -30,7 +34,7 @@ def __init__(self, session): self.__xsrf_token = None def _url(self, api): - return "https://console.aws.amazon.com/support/plans/service/{0}?state=hashArgs%23".format(api) + return SUPPORT_URL + "plans/service/{0}?state=hashArgs%23".format(api) def _xsrf_token(self): if self.__xsrf_token is None: @@ -40,7 +44,7 @@ def _xsrf_token(self): def _get_xsrf_token(self): r = self.session()._get( - 'https://console.aws.amazon.com/support/plans/home?region=eu-central-1&state=hashArgs%23' + SUPPORT_URL + 'plans/home?region=' + SUPPORT_REGION + '&state=hashArgs%23' ) if r.status_code != 200: diff --git a/setup.py b/setup.py index 247ef68..4ee6ff6 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ author = "Sentia MPC B.V.", author_email = "info@sentia.com", license = "Apache", - version = "0.2.4", + version = "0.2.5", packages = find_packages(), install_requires = [ 'requests',