Add sendgrid username/password authentication #1297
This change fixes an issue where the Azure PaaS deployments were unable
The issue was caused by the fact that the Sendgrid API assumes
Note that the Sendgrid API has a limit on 100 API keys so we always
Another nice property of this change is that it's now possible to
The text was updated successfully, but these errors were encountered:
This change fixes an issue where the Azure PaaS deployments were unable to send mail via Sendgrid. The issue was caused by the fact that the Sendgrid API assumes authentication via an API key, but in the ARM template we only have access to the Sendgrid account admin username and password. Due to the limitations of the ARM template format, it's difficult to automatically generate the API key outside of the OKpy application during the deployment: we'd have to spin up an Azure Container Instances deployment, generate the key in the container, upload it to a storage like Key Vault and then access the key from the OKpy application. Reading configuration from a storage like Key Vault instead of environment variables would be a non-trivial change to OKpy so this commit implements a more pragmatic work-around: generate a new API key on the fly at runtime given the Sendgrid admin credentials. The key is cached for the lifetime of the server so this shouldn't add overhead past the first email sent. Note that the Sendgrid API has a limit on 100 API keys so we always ensure to auto-create at most one API key for OKpy and delete any old copies of the key before creating a new one (this would happen when the OKpy server is restarted since any auto-created API key only is persisted in the server memory). Another nice property of this change is that it's now possible to authenticate to Sendgrid in OKpy in the same way as we do in AutoPY.