Skip to content

Commit c5f92c1

Browse files
authored
Revert "DRIVERS-3019 Add ruff linter and apply fixes" (#539)
1 parent e08d9ad commit c5f92c1

37 files changed

+241
-255
lines changed

.evergreen/auth_aws/aws_tester.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1+
#!/usr/bin/env python3
12
"""
23
Script for testing MONGDOB-AWS authentication.
34
"""
45
import argparse
5-
import json
66
import os
7-
import subprocess
7+
import json
88
import sys
9+
import subprocess
910
from functools import partial
10-
from urllib.parse import quote_plus
1111

1212
from pymongo import MongoClient
1313
from pymongo.errors import OperationFailure
14+
from urllib.parse import quote_plus
1415

1516
HERE = os.path.abspath(os.path.dirname(__file__))
1617

@@ -19,10 +20,10 @@ def join(*parts):
1920

2021

2122
sys.path.insert(0, join(HERE, 'lib'))
22-
from aws_assign_instance_profile import _assign_instance_policy
23+
from util import get_key as _get_key
2324
from aws_assume_role import _assume_role
2425
from aws_assume_web_role import _assume_role_with_web_identity
25-
from util import get_key as _get_key
26+
from aws_assign_instance_profile import _assign_instance_policy
2627

2728
ASSUMED_ROLE = "arn:aws:sts::557821124784:assumed-role/authtest_user_assume_role/*"
2829
ASSUMED_WEB_ROLE = "arn:aws:sts::857654397073:assumed-role/webIdentityTestRole/*"
@@ -43,7 +44,7 @@ def join(*parts):
4344
def run(args, env):
4445
"""Run a python command in a subprocess."""
4546
env.update(os.environ.copy())
46-
return subprocess.run([sys.executable, *args], env=env, check=False).returncode
47+
return subprocess.run([sys.executable] + args, env=env).returncode
4748

4849

4950
def create_user(user, kwargs):

.evergreen/auth_aws/lib/aws_assign_instance_profile.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1+
#!/usr/bin/env python3
12
"""
23
Script for assign an instance policy to the current machine.
34
"""
45

56
import argparse
6-
import json
7+
import urllib.request
78
import logging
9+
import json
810
import os
911
import sys
1012
import time
11-
import urllib.request
1213
from functools import partial
1314

1415
import boto3
1516
import botocore
17+
1618
from util import get_key as _get_key
1719

1820
sys.path.insert(1, os.path.join(sys.path[0], '..'))
@@ -39,7 +41,7 @@ def _has_instance_profile():
3941
try:
4042
url = base_url + iam_role
4143
print("Reading: " + url)
42-
urllib.request.urlopen(url)
44+
req = urllib.request.urlopen(url)
4345
print("Assigned " + iam_role)
4446
except urllib.error.HTTPError as e:
4547
print(e)

.evergreen/auth_aws/lib/aws_assume_role.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
#!/usr/bin/env python3
12
"""
23
Script for assuming an aws role.
34
"""
45

56
import argparse
6-
import logging
77
import uuid
8+
import logging
89

910
import boto3
1011

.evergreen/auth_aws/lib/aws_assume_web_role.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
#!/usr/bin/env python3
12
"""
23
Script for assuming an aws role using AssumeRoleWithWebIdentity.
34
"""
45

56
import argparse
6-
import logging
77
import os
88
import uuid
9+
import logging
910

1011
import boto3
1112

.evergreen/auth_aws/lib/aws_handle_oidc_creds.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env python3
12
"""
23
Script for handling OIDC credentials.
34
"""
@@ -14,6 +15,7 @@
1415
from pyop.userinfo import Userinfo
1516

1617

18+
1719
class CustomSubjectIdentifierFactory(HashBasedSubjectIdentifierFactory):
1820
"""
1921
Implements a hash based algorithm for creating a pairwise subject identifier.
@@ -31,7 +33,7 @@ def create_pairwise_identifier(self, user_id, sector_identifier):
3133

3234

3335
def get_default_config():
34-
return {
36+
config = {
3537
"issuer": os.getenv('IDP_ISSUER', ''),
3638
"jwks_uri": os.getenv('IDP_JWKS_URI', ''),
3739
'rsa_key': os.getenv('IDP_RSA_KEY', ''),
@@ -40,6 +42,7 @@ def get_default_config():
4042
'username': os.getenv("IDP_USERNAME", 'test_user'),
4143
'token_file': os.getenv('AWS_WEB_IDENTITY_TOKEN_FILE')
4244
}
45+
return config
4346

4447

4548
def get_provider(config=None, expires=None):

.evergreen/auth_aws/lib/aws_unassign_instance_profile.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
#!/usr/bin/env python3
12
"""
23
Script for unassigning an instance policy from the current machine.
34
"""
45

56
import argparse
7+
import urllib.error
8+
import urllib.request
69
import logging
710
import sys
811
import time
9-
import urllib.error
10-
import urllib.request
1112

1213
import boto3
1314
import botocore
@@ -31,7 +32,7 @@ def _has_instance_profile():
3132
try:
3233
url = base_url + iam_role
3334
print("Reading: " + url)
34-
urllib.request.urlopen(url)
35+
req = urllib.request.urlopen(url)
3536
except urllib.error.HTTPError as e:
3637
print(e)
3738
if e.code == 404:

.evergreen/auth_aws/lib/container_tester.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env python3
12
"""
23
Script for testing mongodb in containers.
34
@@ -40,7 +41,7 @@
4041

4142
def _run_process(params, cwd=None):
4243
LOGGER.info("RUNNING COMMAND: %s", params)
43-
ret = subprocess.run(params, cwd=cwd, check=False)
44+
ret = subprocess.run(params, cwd=cwd)
4445
return ret.returncode
4546

4647
def _userandhostandport(endpoint):
@@ -136,7 +137,7 @@ def remote_ps_container(cluster):
136137
assert private_ip_address
137138

138139
eni = ec2_client.describe_network_interfaces(NetworkInterfaceIds=enis)
139-
public_ip = next(iter(n["Association"]["PublicIp"] for n in eni["NetworkInterfaces"]))
140+
public_ip = [n["Association"]["PublicIp"] for n in eni["NetworkInterfaces"]][0]
140141

141142
for container in task['containers']:
142143
taskArn = container['taskArn']
@@ -145,7 +146,7 @@ def remote_ps_container(cluster):
145146
task_id = task_id + "/" + name
146147
lastStatus = container['lastStatus']
147148

148-
print(f"{task_id:<43}{lastStatus:<9}{public_ip:<25}{private_ip_address:<25}{taskDefinition_short:<16}")
149+
print("{:<43}{:<9}{:<25}{:<25}{:<16}".format(task_id, lastStatus, public_ip, private_ip_address, taskDefinition_short ))
149150

150151
def _remote_create_container_args(args):
151152
remote_create_container(args.cluster, args.task_definition, args.service, args.subnets, args.security_group)
@@ -246,7 +247,7 @@ def remote_get_public_endpoint_str(cluster, service_name):
246247
assert enis
247248

248249
eni = ec2_client.describe_network_interfaces(NetworkInterfaceIds=enis)
249-
public_ip = next(iter(n["Association"]["PublicIp"] for n in eni["NetworkInterfaces"]))
250+
public_ip = [n["Association"]["PublicIp"] for n in eni["NetworkInterfaces"]][0]
250251
break
251252

252253
return f"root@{public_ip}:22"

.evergreen/auth_aws/lib/util.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
def get_key(key: str, uppercase: bool) -> str:
22
if uppercase:
33
return key.upper()
4-
return key
4+
else:
5+
return key

.evergreen/auth_oidc/azure/handle_secrets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
import os
33
from base64 import b64decode
44

5-
from azure.identity import DefaultAzureCredential
65
from azure.keyvault.secrets import SecretClient
6+
from azure.identity import DefaultAzureCredential
77

88

99
def main():

.evergreen/auth_oidc/azure/remote-scripts/test.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import json
2-
import os
3-
from urllib.request import Request, urlopen
4-
51
from pymongo import MongoClient
2+
import os
3+
import json
4+
from urllib.request import urlopen, Request
65
from pymongo.auth_oidc import OIDCCallback, OIDCCallbackContext, OIDCCallbackResult
76

87
app_id = os.environ['AZUREOIDC_APPID']
@@ -23,16 +22,16 @@ def fetch(self, context: OIDCCallbackContext) -> OIDCCallbackResult:
2322
body = response.read().decode('utf8')
2423
except Exception as e:
2524
msg = "Failed to acquire IMDS access token: %s" % e
26-
raise ValueError(msg) from e
25+
raise ValueError(msg)
2726

2827
if status != 200:
2928
print(body)
3029
msg = "Failed to acquire IMDS access token."
3130
raise ValueError(msg)
3231
try:
3332
data = json.loads(body)
34-
except Exception as e:
35-
raise ValueError("Azure IMDS response must be in JSON format.") from e
33+
except Exception:
34+
raise ValueError("Azure IMDS response must be in JSON format.")
3635

3736
for key in ["access_token", "expires_in"]:
3837
if not data.get(key):

0 commit comments

Comments
 (0)