nix(loadtest): remove useless try/except blocks
Rethrowing the same error, but without stacktrace is not really useful, but only makes the code (and debugging!) harder than it should be.
This commit is contained in:
@@ -37,22 +37,14 @@ def main():
|
||||
jwks.add(hs)
|
||||
jwks.add(rsa)
|
||||
|
||||
try:
|
||||
# Technically, this exports the private keys, because HS does not have the concept
|
||||
# of a public key. This is not a problem for tests, though, PostgREST can verify
|
||||
# tokens with the private key just as well.
|
||||
args.jwks_path.write_text(jwks.export())
|
||||
print(f"Created JWKSet on {args.jwks_path}")
|
||||
except OSError as e:
|
||||
print(f"Error writing to {args.jwks_path}:{e}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
# Technically, this exports the private keys, because HS does not have the concept
|
||||
# of a public key. This is not a problem for tests, though, PostgREST can verify
|
||||
# tokens with the private key just as well.
|
||||
args.jwks_path.write_text(jwks.export())
|
||||
print(f"Created JWKSet on {args.jwks_path}")
|
||||
|
||||
try:
|
||||
args.private_key_path.write_text(rsa.export_private())
|
||||
print(f"Created private key on {args.private_key_path}")
|
||||
except OSError as e:
|
||||
print(f"Error writing to {args.private_key_path}:{e}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
args.private_key_path.write_text(rsa.export_private())
|
||||
print(f"Created private key on {args.private_key_path}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
# from an array
|
||||
import time
|
||||
import argparse
|
||||
import sys
|
||||
import random
|
||||
import jwcrypto.jwt as jwt
|
||||
from typing import Optional
|
||||
@@ -91,22 +90,8 @@ def main():
|
||||
nsamples = 500 # per algorithm
|
||||
ntargets = 100000
|
||||
|
||||
try:
|
||||
private_key_data = args.private_key_path.read_text()
|
||||
except OSError as e:
|
||||
err = (
|
||||
f"Error reading RSA private key from {args.private_key_path}: "
|
||||
f"{e}. Generate RSA materials first with gen_rsa_materials.py."
|
||||
)
|
||||
print(err, file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
rsa_private_key = jwt.JWK.from_json(private_key_data)
|
||||
except Exception as exc: # broad exception to capture parsing errors
|
||||
err = f"Error loading RSA private key from {args.private_key_path}: " f"{exc}"
|
||||
print(err, file=sys.stderr)
|
||||
sys.exit(1)
|
||||
private_key_data = args.private_key_path.read_text()
|
||||
rsa_private_key = jwt.JWK.from_json(private_key_data)
|
||||
|
||||
print(f"Generating {ntargets} targets...")
|
||||
|
||||
@@ -140,12 +125,8 @@ def main():
|
||||
target = random.choice(hs_targets if i % 2 == 0 else rsa_targets)
|
||||
lines.extend(target)
|
||||
|
||||
try:
|
||||
with open(targets_path, "w") as f:
|
||||
f.write("\n".join(lines))
|
||||
except IOError as e:
|
||||
print(f"Error writing to {targets_path}: {e}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
with open(targets_path, "w") as f:
|
||||
f.write("\n".join(lines))
|
||||
|
||||
print(f"Created {ntargets} targets", end=" ")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user