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(hs)
|
||||||
jwks.add(rsa)
|
jwks.add(rsa)
|
||||||
|
|
||||||
try:
|
# Technically, this exports the private keys, because HS does not have the concept
|
||||||
# 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
|
||||||
# of a public key. This is not a problem for tests, though, PostgREST can verify
|
# tokens with the private key just as well.
|
||||||
# tokens with the private key just as well.
|
args.jwks_path.write_text(jwks.export())
|
||||||
args.jwks_path.write_text(jwks.export())
|
print(f"Created JWKSet on {args.jwks_path}")
|
||||||
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)
|
|
||||||
|
|
||||||
try:
|
args.private_key_path.write_text(rsa.export_private())
|
||||||
args.private_key_path.write_text(rsa.export_private())
|
print(f"Created private key on {args.private_key_path}")
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -12,7 +12,6 @@
|
|||||||
# from an array
|
# from an array
|
||||||
import time
|
import time
|
||||||
import argparse
|
import argparse
|
||||||
import sys
|
|
||||||
import random
|
import random
|
||||||
import jwcrypto.jwt as jwt
|
import jwcrypto.jwt as jwt
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
@@ -91,22 +90,8 @@ def main():
|
|||||||
nsamples = 500 # per algorithm
|
nsamples = 500 # per algorithm
|
||||||
ntargets = 100000
|
ntargets = 100000
|
||||||
|
|
||||||
try:
|
private_key_data = args.private_key_path.read_text()
|
||||||
private_key_data = args.private_key_path.read_text()
|
rsa_private_key = jwt.JWK.from_json(private_key_data)
|
||||||
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)
|
|
||||||
|
|
||||||
print(f"Generating {ntargets} targets...")
|
print(f"Generating {ntargets} targets...")
|
||||||
|
|
||||||
@@ -140,12 +125,8 @@ def main():
|
|||||||
target = random.choice(hs_targets if i % 2 == 0 else rsa_targets)
|
target = random.choice(hs_targets if i % 2 == 0 else rsa_targets)
|
||||||
lines.extend(target)
|
lines.extend(target)
|
||||||
|
|
||||||
try:
|
with open(targets_path, "w") as f:
|
||||||
with open(targets_path, "w") as f:
|
f.write("\n".join(lines))
|
||||||
f.write("\n".join(lines))
|
|
||||||
except IOError as e:
|
|
||||||
print(f"Error writing to {targets_path}: {e}", file=sys.stderr)
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
print(f"Created {ntargets} targets", end=" ")
|
print(f"Created {ntargets} targets", end=" ")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user