I'm new to python and I am sure there's a better way to do this. For my specific issue I have stored an API key. I've given the user means to send an argument with a new API key if needed. Otherwise the argument is set as False
. So if the user sends an API key, I first want to find out if it's different from the one I already have. And if it is different I then want to update it in my secret manager.
There's one addtl layer of possible complication. It's a header in a webhook.
So I'm writing an if
function but it feels very inelegant. This is what I currently have written. I'm also using Flask, hence request
.
This is my code:
if request.headers['x-api-key'] and request.headers['x-api-key'] not in stored_api_key:
# do something
Would love to know how I should be writing this. Thank you.