diff --git a/.evergreen/auth_aws/lib/aws_assign_instance_profile.py b/.evergreen/auth_aws/lib/aws_assign_instance_profile.py index 189c824b..305b9588 100644 --- a/.evergreen/auth_aws/lib/aws_assign_instance_profile.py +++ b/.evergreen/auth_aws/lib/aws_assign_instance_profile.py @@ -1,20 +1,18 @@ -#!/usr/bin/env python3 """ Script for assign an instance policy to the current machine. """ import argparse -import urllib.request -import logging import json +import logging import os import sys import time +import urllib.request from functools import partial import boto3 import botocore - from util import get_key as _get_key sys.path.insert(1, os.path.join(sys.path[0], '..')) @@ -41,7 +39,7 @@ def _has_instance_profile(): try: url = base_url + iam_role print("Reading: " + url) - req = urllib.request.urlopen(url) + urllib.request.urlopen(url) print("Assigned " + iam_role) except urllib.error.HTTPError as e: print(e) diff --git a/.evergreen/auth_aws/lib/aws_assume_role.py b/.evergreen/auth_aws/lib/aws_assume_role.py index 7a230338..422eb20b 100644 --- a/.evergreen/auth_aws/lib/aws_assume_role.py +++ b/.evergreen/auth_aws/lib/aws_assume_role.py @@ -1,11 +1,10 @@ -#!/usr/bin/env python3 """ Script for assuming an aws role. """ import argparse -import uuid import logging +import uuid import boto3 diff --git a/.evergreen/auth_aws/lib/aws_assume_web_role.py b/.evergreen/auth_aws/lib/aws_assume_web_role.py index de0a9c63..9e79a1fd 100644 --- a/.evergreen/auth_aws/lib/aws_assume_web_role.py +++ b/.evergreen/auth_aws/lib/aws_assume_web_role.py @@ -1,12 +1,11 @@ -#!/usr/bin/env python3 """ Script for assuming an aws role using AssumeRoleWithWebIdentity. """ import argparse +import logging import os import uuid -import logging import boto3 diff --git a/.evergreen/auth_aws/lib/aws_handle_oidc_creds.py b/.evergreen/auth_aws/lib/aws_handle_oidc_creds.py index bf277db6..d719f63b 100644 --- a/.evergreen/auth_aws/lib/aws_handle_oidc_creds.py +++ b/.evergreen/auth_aws/lib/aws_handle_oidc_creds.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python3 """ Script for handling OIDC credentials. """ @@ -15,7 +14,6 @@ from pyop.userinfo import Userinfo - class CustomSubjectIdentifierFactory(HashBasedSubjectIdentifierFactory): """ Implements a hash based algorithm for creating a pairwise subject identifier. @@ -33,7 +31,7 @@ def create_pairwise_identifier(self, user_id, sector_identifier): def get_default_config(): - config = { + return { "issuer": os.getenv('IDP_ISSUER', ''), "jwks_uri": os.getenv('IDP_JWKS_URI', ''), 'rsa_key': os.getenv('IDP_RSA_KEY', ''), @@ -42,7 +40,6 @@ def get_default_config(): 'username': os.getenv("IDP_USERNAME", 'test_user'), 'token_file': os.getenv('AWS_WEB_IDENTITY_TOKEN_FILE') } - return config def get_provider(config=None, expires=None): diff --git a/.evergreen/auth_aws/lib/aws_unassign_instance_profile.py b/.evergreen/auth_aws/lib/aws_unassign_instance_profile.py index 02899e8f..c299bd10 100644 --- a/.evergreen/auth_aws/lib/aws_unassign_instance_profile.py +++ b/.evergreen/auth_aws/lib/aws_unassign_instance_profile.py @@ -1,14 +1,13 @@ -#!/usr/bin/env python3 """ Script for unassigning an instance policy from the current machine. """ import argparse -import urllib.error -import urllib.request import logging import sys import time +import urllib.error +import urllib.request import boto3 import botocore @@ -32,7 +31,7 @@ def _has_instance_profile(): try: url = base_url + iam_role print("Reading: " + url) - req = urllib.request.urlopen(url) + urllib.request.urlopen(url) except urllib.error.HTTPError as e: print(e) if e.code == 404: diff --git a/.evergreen/auth_aws/lib/container_tester.py b/.evergreen/auth_aws/lib/container_tester.py index ad259e94..7500fc0e 100644 --- a/.evergreen/auth_aws/lib/container_tester.py +++ b/.evergreen/auth_aws/lib/container_tester.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python3 """ Script for testing mongodb in containers. @@ -41,7 +40,7 @@ def _run_process(params, cwd=None): LOGGER.info("RUNNING COMMAND: %s", params) - ret = subprocess.run(params, cwd=cwd) + ret = subprocess.run(params, cwd=cwd, check=False) return ret.returncode def _userandhostandport(endpoint): @@ -137,7 +136,7 @@ def remote_ps_container(cluster): assert private_ip_address eni = ec2_client.describe_network_interfaces(NetworkInterfaceIds=enis) - public_ip = [n["Association"]["PublicIp"] for n in eni["NetworkInterfaces"]][0] + public_ip = next(iter(n["Association"]["PublicIp"] for n in eni["NetworkInterfaces"])) for container in task['containers']: taskArn = container['taskArn'] @@ -146,7 +145,7 @@ def remote_ps_container(cluster): task_id = task_id + "/" + name lastStatus = container['lastStatus'] - print("{:<43}{:<9}{:<25}{:<25}{:<16}".format(task_id, lastStatus, public_ip, private_ip_address, taskDefinition_short )) + print(f"{task_id:<43}{lastStatus:<9}{public_ip:<25}{private_ip_address:<25}{taskDefinition_short:<16}") def _remote_create_container_args(args): remote_create_container(args.cluster, args.task_definition, args.service, args.subnets, args.security_group) @@ -247,7 +246,7 @@ def remote_get_public_endpoint_str(cluster, service_name): assert enis eni = ec2_client.describe_network_interfaces(NetworkInterfaceIds=enis) - public_ip = [n["Association"]["PublicIp"] for n in eni["NetworkInterfaces"]][0] + public_ip = next(iter(n["Association"]["PublicIp"] for n in eni["NetworkInterfaces"])) break return f"root@{public_ip}:22" diff --git a/.evergreen/auth_aws/lib/util.py b/.evergreen/auth_aws/lib/util.py index 72c75616..2bbaf2e6 100644 --- a/.evergreen/auth_aws/lib/util.py +++ b/.evergreen/auth_aws/lib/util.py @@ -1,5 +1,4 @@ def get_key(key: str, uppercase: bool) -> str: if uppercase: return key.upper() - else: - return key + return key