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

feature(domains): all the domains are env variables or defaults. #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ __pycache__
*.swp
*.egg-info
.env
.envrc
/.vscode
/docs/build
/build
Expand Down
10 changes: 7 additions & 3 deletions coto/clients/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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:
Expand Down Expand Up @@ -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,
)

Expand Down
13 changes: 9 additions & 4 deletions coto/clients/billing.py
Original file line number Diff line number Diff line change
@@ -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):
"""
Expand Down Expand Up @@ -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:
Expand All @@ -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()})

Expand All @@ -63,15 +68,15 @@ 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(),
'Content-Type': 'application/json',
})
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(),
Expand Down
11 changes: 8 additions & 3 deletions coto/clients/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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={
Expand Down
9 changes: 6 additions & 3 deletions coto/clients/iam.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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:
Expand All @@ -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")
Expand Down
8 changes: 6 additions & 2 deletions coto/clients/mfa.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@
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)
self._signin = self.session().client('signin_aws')

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,
Expand Down
11 changes: 8 additions & 3 deletions coto/clients/resetpassword.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand Down Expand Up @@ -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,
)

Expand Down
8 changes: 6 additions & 2 deletions coto/clients/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down