feat(conf)!: allow multiple keys to be used for different endpoints
This commit is contained in:
parent
8e5a90ec1f
commit
ab5927bfa4
2 changed files with 5 additions and 5 deletions
|
@ -45,10 +45,10 @@ parser.add_argument(
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-k",
|
"-k",
|
||||||
"--api-key",
|
"--api-keys",
|
||||||
help="shared secret to use this service. Required. Environment variable: `API_KEY`",
|
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
|
if "API_KEY" in os.environ
|
||||||
else {"required": True}
|
else {"required": True}
|
||||||
),
|
),
|
||||||
|
@ -63,5 +63,5 @@ SERVER_ADDRESS = (args.host, args.port)
|
||||||
MATRIX_URL = args.matrix_url
|
MATRIX_URL = args.matrix_url
|
||||||
MATRIX_ID = args.matrix_id
|
MATRIX_ID = args.matrix_id
|
||||||
MATRIX_PW = args.matrix_pw
|
MATRIX_PW = args.matrix_pw
|
||||||
API_KEY = args.api_key
|
API_KEYS = args.api_keys.split(",")
|
||||||
VERBOSE = args.verbose
|
VERBOSE = args.verbose
|
||||||
|
|
|
@ -69,7 +69,7 @@ async def matrix_webhook(request):
|
||||||
HTTPStatus.BAD_REQUEST, f"Missing {', '.join(missing)}"
|
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")
|
return utils.create_json_response(HTTPStatus.UNAUTHORIZED, "Invalid API key")
|
||||||
|
|
||||||
if "formatted_body" in data:
|
if "formatted_body" in data:
|
||||||
|
|
Loading…
Reference in a new issue