From c02576c794e140062384840aa3d8ba7e528eed2c Mon Sep 17 00:00:00 2001 From: Frederik Ring Date: Fri, 19 Jul 2019 21:02:12 +0200 Subject: [PATCH] fix use before definition --- accounts/lambdas/authorizer.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/accounts/lambdas/authorizer.py b/accounts/lambdas/authorizer.py index d8d5c2f..ddb510d 100644 --- a/accounts/lambdas/authorizer.py +++ b/accounts/lambdas/authorizer.py @@ -11,6 +11,16 @@ boto_client = session.client( service_name="secretsmanager", region_name=environ.get("AWS_REGION") ) + +def get_secret(boto_client, secret_name): + ssm_response = boto_client.get_secret_value( + SecretId="{}/accounts/{}".format(environ.get("STAGE"), secret_name) + ) + if "SecretString" in ssm_response: + return ssm_response["SecretString"] + return base64.b64decode(ssm_response["SecretBinary"]) + + basic_auth_user = get_secret(boto_client, "basicAuthUser") hashed_basic_auth_password = get_secret(boto_client, "hashedBasicAuthPassword") @@ -49,15 +59,6 @@ def build_response(api_arn, allow): } -def get_secret(secret_name): - ssm_response = boto_client.get_secret_value( - SecretId="{}/accounts/{}".format(environ.get("STAGE"), secret_name) - ) - if "SecretString" in ssm_response: - return ssm_response["SecretString"] - return base64.b64decode(ssm_response["SecretBinary"]) - - def handler(event, context): api_arn = build_api_arn(event["methodArn"])