feat(conf)!: allow multiple keys to be used for different endpoints

This commit is contained in:
Alex Kelly 2021-11-04 13:26:54 -04:00
parent 8e5a90ec1f
commit ab5927bfa4
2 changed files with 5 additions and 5 deletions

View file

@ -45,10 +45,10 @@ parser.add_argument(
)
parser.add_argument(
"-k",
"--api-key",
help="shared secret to use this service. Required. Environment variable: `API_KEY`",
"--api-keys",
help="comma separated list of shared secrets to use this service. Required. Environment variable: `API_KEYS`",
**(
{"default": os.environ["API_KEY"]}
{"default": os.environ["API_KEYS"]}
if "API_KEY" in os.environ
else {"required": True}
),
@ -63,5 +63,5 @@ SERVER_ADDRESS = (args.host, args.port)
MATRIX_URL = args.matrix_url
MATRIX_ID = args.matrix_id
MATRIX_PW = args.matrix_pw
API_KEY = args.api_key
API_KEYS = args.api_keys.split(",")
VERBOSE = args.verbose

View file

@ -69,7 +69,7 @@ async def matrix_webhook(request):
HTTPStatus.BAD_REQUEST, f"Missing {', '.join(missing)}"
)
if data["key"] != conf.API_KEY:
if data["key"] not in conf.API_KEYS:
return utils.create_json_response(HTTPStatus.UNAUTHORIZED, "Invalid API key")
if "formatted_body" in data: