Skip to content

Commit

Permalink
Bump dependencies. Lint.
Browse files Browse the repository at this point in the history
  • Loading branch information
costastf committed Mar 3, 2023
1 parent d3d523d commit 34c4914
Show file tree
Hide file tree
Showing 24 changed files with 832 additions and 501 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ jobs:

steps:
- name: Checkout sources
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: 3.7.10
python-version: 3.9.15

- name: Install pipenv
run: pip install pipenv
Expand All @@ -41,12 +41,12 @@ jobs:
name: release
steps:
- name: Checkout sources
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: 3.7.10
python-version: 3.9.15

- name: Install pipenv
run: pip install pipenv
Expand Down
5 changes: 4 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ load-plugins=

[MESSAGES CONTROL]

disable=logging-fstring-interpolation,locally-disabled

[FORMAT]
max-line-length=121
disable=locally-disabled, locally-enabled, logging-format-interpolation, logging-fstring-interpolation

[General]
init-hook='import sys; sys.path.append("awsapilib")'
49 changes: 24 additions & 25 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,30 @@ name = "pypi"

[dev-packages]

flake8 = "==3.8.0"
sphinx = "~=2.1.2"
sphinx-rtd-theme = "~=0.4.3"
prospector = "~=1.3.0"
coverage = "~=4.5.4"
nose = "~=1.3.7"
nose-htmloutput = "~=0.6.0"
tox = "~=3.13.2"
betamax = "~=0.8.1"
betamax-serializers = "~=0.2.1"
semver = "~=2.8.1"
gitwrapperlib = "~=0.10.1"
twine = "~=1.13.0"
coloredlogs = "~=10.0"
emoji = "~=0.5.3"
toml = "~=0.10.0"
boto3-type-annotations-with-docs = "~=0.3"
sphinx = ">=6.0,<7.0"
sphinx-rtd-theme = ">=1.0,<2.0"
prospector = ">=1.8,<2.0"
coverage = ">=7,<8.0"
nose = ">=1.3,<2.0"
nose-htmloutput = ">=0.1,<1.0"
tox = ">=4.0<5.0"
betamax = ">=0.8,<1.0"
betamax-serializers = "~=0.2,<1.0"
semver = ">=2.0,<3.0"
gitwrapperlib = ">=1.0,<2.0"
twine = ">=4.0,<5.0"
coloredlogs = ">=15.0,<16.0"
emoji = ">=2.0,<3.0"
toml = ">=0.1,<1.0"
boto3-type-annotations-with-docs = ">=0.3,<1.0"

[packages]

requests = "~=2.26.0"
boto3 = "~=1.24.52"
beautifulsoup4 = "~=4.10.0"
opnieuw = "~=1.1.0"
boto3-type-annotations = "~=0.3.1"
cachetools = "~=4.2.4"
pyotp = "~=2.6.0"
2captcha-python = "~=1.0.3"
requests = ">=2.26.0,<3.0"
boto3 = ">=1.24.52,<2.0"
beautifulsoup4 = ">=4.10.0,<5.0"
opnieuw = ">=1.1.0,<2.0"
boto3-type-annotations = ">=0.3.1,<1.0"
cachetools = ">=4.2.4,<5.0"
pyotp = ">=2.6.0,<3.0"
2captcha-python = ">=1.0.3,<2.0"
1,160 changes: 742 additions & 418 deletions Pipfile.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion _CI/files/environment_variables.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"PIPENV_VENV_IN_PROJECT": "true",
"PIPENV_DEFAULT_PYTHON_VERSION": "3.7",
"PIPENV_DEFAULT_PYTHON_VERSION": "3.9",
"PYPI_URL": "https://upload.pypi.org/legacy/",
"PROJECT_SLUG": "awsapilib"
}
4 changes: 2 additions & 2 deletions _CI/library/core_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ def bump(segment=None, version_file=None):
try:
with open(version_file) as version:
version_text = version.read().strip()
_ = semver.parse(version_text)
old_version = semver.Version.parse(version_text)
except FileNotFoundError:
LOGGER.error('Could not find .VERSION file')
raise SystemExit(1)
Expand All @@ -511,7 +511,7 @@ def bump(segment=None, version_file=None):
if segment not in ('major', 'minor', 'patch'):
LOGGER.error('Invalid segment "%s" was provided for semantic versioning, exiting...')
raise SystemExit(1)
new_version = getattr(semver, f'bump_{segment}')(version_text)
new_version = getattr(old_version, f'next_{segment}').text
with open(version_file, 'w') as vfile:
vfile.write(new_version)
return new_version
Expand Down
2 changes: 1 addition & 1 deletion _CI/scripts/_initialize_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def initialize_template_environment():
activate_virtual_environment()
from emoji import emojize
LOGGER.info('%s Successfully created virtual environment and loaded it! %s',
emojize(':white_heavy_check_mark:'),
emojize(':check_mark_button:'),
emojize(':thumbs_up:'))
else:
LOGGER.error('Creation of virtual environment failed, cannot continue, '
Expand Down
2 changes: 1 addition & 1 deletion _CI/scripts/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def build():
success = execute_command('pipenv lock')
if success:
LOGGER.info('Successfully created lock file %s %s',
emojize(':white_heavy_check_mark:'),
emojize(':check_mark_button:'),
emojize(':thumbs_up:'))
else:
LOGGER.error('%s Errors creating lock file! %s',
Expand Down
2 changes: 1 addition & 1 deletion _CI/scripts/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def document():
except Exception:
LOGGER.warning('Could not execute UI portion. Maybe running headless?')
LOGGER.info('%s Successfully built documentation %s',
emojize(':white_heavy_check_mark:'),
emojize(':check_mark_button:'),
emojize(':thumbs_up:'))
else:
LOGGER.error('%s Documentation creation errors found! %s',
Expand Down
5 changes: 3 additions & 2 deletions _CI/scripts/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
# this sets up everything and MUST be included before any third party module in every step
import _initialize_template

from pathlib import Path
from bootstrap import bootstrap
from emoji import emojize
from library import execute_command
Expand All @@ -47,11 +48,11 @@ def graph():
'-o png '
'-A '
'-f PUB_ONLY '
'-p graphs {}').format(os.path.join('..', f'{PROJECT_SLUG}'))
f'-p graphs \"{Path("..", PROJECT_SLUG)}\"')
success = execute_command(create_graph_command)
if success:
LOGGER.info('%s Successfully created graph images %s',
emojize(':white_heavy_check_mark:'),
emojize(':check_mark_button:'),
emojize(':thumbs_up:'))
else:
LOGGER.error('%s Errors in creation of graph images found! %s',
Expand Down
4 changes: 2 additions & 2 deletions _CI/scripts/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@

def lint():
bootstrap()
success = execute_command('prospector -DFM')
success = execute_command('prospector -DFM --no-autodetect')
if success:
LOGGER.info('%s No linting errors found! %s',
emojize(':white_heavy_check_mark:'),
emojize(':check_mark_button:'),
emojize(':thumbs_up:'))
else:
LOGGER.error('%s Linting errors found! %s',
Expand Down
2 changes: 1 addition & 1 deletion _CI/scripts/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def check_branch():
def push(current_version):
git = Git()
git.commit('Updated history file with changelog', 'HISTORY.rst')
git.commit('Set version to {}'.format(current_version), '.VERSION')
git.commit(f'Set version to {current_version}', '.VERSION')
git.add_tag(current_version)
git.push()
git.push('origin', current_version)
Expand Down
2 changes: 1 addition & 1 deletion _CI/scripts/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test():
LOGGER.warning('Could not execute UI portion. Maybe running headless?')
if success:
LOGGER.info('%s No testing errors found! %s',
emojize(':white_heavy_check_mark:'),
emojize(':check_mark_button:'),
emojize(':thumbs_up:'))
else:
LOGGER.error('%s Testing errors found! %s',
Expand Down
2 changes: 1 addition & 1 deletion _CI/scripts/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def upload():
success = execute_command(upload_command)
if success:
LOGGER.info('%s Successfully uploaded artifact! %s',
emojize(':white_heavy_check_mark:'),
emojize(':check_mark_button:'),
emojize(':thumbs_up:'))
else:
LOGGER.error('%s Errors found in uploading artifact! %s',
Expand Down
4 changes: 2 additions & 2 deletions awsapilib/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@
)

try:
with open(VERSION_FILE_PATH) as f:
with open(VERSION_FILE_PATH, encoding='utf-8') as f:
__version__ = f.read()
except IOError:
with open(LOCAL_VERSION_FILE_PATH) as f:
with open(LOCAL_VERSION_FILE_PATH, encoding='utf-8') as f:
__version__ = f.read()
21 changes: 11 additions & 10 deletions awsapilib/authentication/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def regional_console(self):
return f'{self.region}.console.{self.root}'


@dataclass # pylint: disable=too-many-instance-attributes
@dataclass
class Urls:
"""Dataclass holding the urls required for authenticating."""

Expand Down Expand Up @@ -191,7 +191,7 @@ def global_iam_home(self):
return f'{self.scheme}us-east-1.console.{self.root_domain}/iam/home'


class LoggerMixin: # pylint: disable=too-few-public-methods
class LoggerMixin:
"""Logger."""

@property
Expand All @@ -205,7 +205,7 @@ def logger(self):
return logging.getLogger(f'{LOGGER_BASENAME}.{self.__class__.__name__}')


class BaseAuthenticator(LoggerMixin): # pylint: disable=too-few-public-methods
class BaseAuthenticator(LoggerMixin):
"""Interfaces with aws authentication mechanisms, providing pre signed urls, or authenticated sessions."""

def __init__(self, region=None):
Expand Down Expand Up @@ -265,7 +265,8 @@ def _get_response(self, url, params=None, extra_cookies=None, headers=None):
arguments = {'url': url,
'headers': headers,
'cookies': self._cookies_to_dict(cookies),
'allow_redirects': False}
'allow_redirects': False,
'timeout': 5}
if params:
arguments.update({'params': params})
self.logger.debug('Getting url :%s with arguments : %s', url, arguments)
Expand All @@ -276,10 +277,10 @@ def _get_response(self, url, params=None, extra_cookies=None, headers=None):
error_title = error_response.title.string.strip()
err_msg = error_response.find('div', {'id': 'content'}).find('p').string
except AttributeError:
raise ValueError('Response received: %s' % response.text)
raise ValueError(f'Response received: {response.text}') from None
if all([response.status_code == 400, error_title == 'Credentials expired']):
raise ExpiredCredentials(response.status_code, err_msg)
raise ValueError('Response received: %s' % response.text)
raise ValueError(f'Response received: {response.text}') from None
self._debug_response(response, cookies)
self._session.cookies.update(response.cookies)
return response
Expand Down Expand Up @@ -323,7 +324,7 @@ def _get_session_from_console(self,
csrf_token = soup.find(csrf_token_data.entity_type,
csrf_token_data.attributes).attrs.get(csrf_token_data.attribute_value)
except AttributeError:
raise ValueError('Response received: %s' % console_page_response.text)
raise ValueError(f'Response received: {console_page_response.text}') from None
if not csrf_token:
raise NoSigninTokenReceived('Unable to retrieve csrf token.')
session = requests.Session()
Expand All @@ -337,7 +338,7 @@ def _get_session_from_console(self,
return session


class Authenticator(BaseAuthenticator): # pylint: disable=too-many-instance-attributes
class Authenticator(BaseAuthenticator):
"""Interfaces with aws authentication mechanisms, providing pre signed urls, or authenticated sessions."""

def __init__(self, arn, session_duration=3600, region=None):
Expand All @@ -362,7 +363,7 @@ def _get_assumed_role(self, arn):
RoleSessionName="AssumeRoleSession",
DurationSeconds=self.session_duration)
except botocore.exceptions.ParamValidationError as error:
raise ValueError('The arn you provided is incorrect: {}'.format(error)) from None
raise ValueError(f'The arn you provided is incorrect: {error}') from None
except (botocore.exceptions.NoCredentialsError, botocore.exceptions.ClientError) as error:
raise InvalidCredentials(error) from None

Expand Down Expand Up @@ -405,7 +406,7 @@ def _get_signin_token(self): # we can pass a duration here.
params = {'Action': 'getSigninToken',
# 'SessionDuration': str(duration),
'Session': json.dumps(self.session_credentials)}
response = requests.get(self.urls.federation, params=params)
response = requests.get(self.urls.federation, params=params, timeout=5)
if all([response.status_code == 401, response.text == 'Token Expired']):
try:
self._assumed_role = self._get_assumed_role(self.arn)
Expand Down
7 changes: 4 additions & 3 deletions awsapilib/authentication/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,18 @@ def __init__(self, har_file):
@staticmethod
def _parse(har_file):
try:
data = json.load(open(har_file, 'r'))
with open(har_file, 'r', encoding='utf-8') as ifile:
data = json.load(ifile)
except Exception:
raise ValueError(f'Could not read or parse file: {har_file}')
raise ValueError(f'Could not read or parse file: {har_file}') from None
return data

def _get_service_calls(self, service):
calls = [entry for entry in self.data['log']['entries']
if any(['aws.amazon.com/oauth' in entry['request']['url'],
all([f'aws.amazon.com/{service}' in entry['request']['url'],
f'aws.amazon.com/{service}/api' not in entry['request']['url']])])]
return [] if not any([True for entry in calls if service in entry["request"]["url"]]) else calls
return [] if not any(True for entry in calls if service in entry["request"]["url"]) else calls

@staticmethod
def _get_text_from_calls(calls):
Expand Down
4 changes: 2 additions & 2 deletions awsapilib/captcha/captcha.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def solve(self, url):
guess (str): The guess of the user for the captcha.
"""
response = requests.get(url)
response = requests.get(url, timeout=5)
if not response.ok:
raise CaptchaError(response.text)
image = base64.b64encode(response.content).decode()
Expand Down Expand Up @@ -158,7 +158,7 @@ def solve(self, url):
'lang': 'en'}
try:
self.logger.debug(f'Trying to get captcha image from url : {url}')
response = requests.get(url)
response = requests.get(url, timeout=5)
image = base64.b64encode(response.content).decode("utf-8")
self.logger.debug('Waiting for the solved captcha from 2captcha service.')
result = self.solver.normal(image, **captcha_parameters)
Expand Down
8 changes: 4 additions & 4 deletions awsapilib/console/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ def _get_captcha_info(response):
captcha_obfuscation_token = properties.get('captchaObfuscationToken')
return Captcha(url, captcha_token, captcha_obfuscation_token)
except ValueError:
raise InvalidAuthentication(response.text)
raise InvalidAuthentication(response.text) from None

@staticmethod
def _get_oidc_info(referer):
Expand Down Expand Up @@ -590,7 +590,7 @@ def request_password_reset(self, email):
try:
self._resolve_account_type(email)
except UnableToResolveAccount:
raise UnableToRequestResetPassword(f'Could not resolve account type for email: {email}')
raise UnableToRequestResetPassword(f'Could not resolve account type for email: {email}') from None
parameters = {'action': 'captcha',
'forgotpassword': True,
'csrf': self.session.cookies.get('aws-signin-csrf', path='/signin')}
Expand Down Expand Up @@ -719,8 +719,8 @@ def _update_account(self, payload):
mfa_serial=self.mfa_serial)
response = session.get(update_url)
if not response.ok:
ServerError(f'Unsuccessful response received: {response.text} '
f'with status code: {response.status_code}')
raise ServerError(f'Unsuccessful response received: {response.text} '
f'with status code: {response.status_code}')
headers = {'X-Requested-With': 'XMLHttpRequest'}
payload_ = {'redirect_uri': f'{Urls.billing_home}#/account',
'csrf': response.cookies.get('aws-signin-csrf', path='/updateaccount')}
Expand Down
Loading

0 comments on commit 34c4914

Please sign in to comment.