An HTTP endpoint for polling Mailchimp subscriber numbers for an LaMetric Time device. Designed to run on Azure Functions uusing a Custom Request Handler which receives HTTP requests and responds like a web app.
get_subscribers: returns the latest stats from Mailchimp in JSON format as an LaMetric indicator app.
Uses Rocket so requires Rust nightly. Set up a nightly override on the directory once cloned:
rustup override set nightlySet environment variables (see below) with the relevant config then run:
cargo runto start the web server. Issue requests to the endpoints e.g.:
curl -v http://localhost:3000/api/get_subscriberscargo testRequirements:
# Create the local.settings.json file which will set the environment variables
# Only required on a fresh clone when the file doesn't exist
func azure functionapp fetch-app-settings lamsubs
func startcurl -v http://localhost:7071/api/get_subscribersLAMSUBS_MAILCHIMP_APIKEY: Mailchimp API key.LAMSUBS_MAILCHIMP_LIST_ID: Mailchimp list ID string.LAMSUBS_PRODUCTION: Set to any value when running in production.
Create a new tag with the name format release-vx.y.z where x.y.z is a semantic versioning formatted version string e.g. release-v0.1.4
Azure
uses
the x86_64-unknown-linux-musl platform. Builds are done through a dedicated
Docker container that has various C
libraries built against musl.
Azure resources defined in main.bicep.
Requirements:
- Docker e.g.
sudo pacman install docker - Bicep
- Azure CLI
- Azure Functions Core Tools
docker pull clux/muslrust
docker run -v $PWD:/volume --rm -t clux/muslrust cargo build --release
mkdir bin # host.json configured to expect binary here
cp target/x86_64-unknown-linux-musl/release/lamsubs bin/
bicep build ./main.bicep # generates main.json
az login
az deployment group create -f ./main.json -g lamsubs
func azure functionapp publish lamsubsUses Azure ARM and Login GitHub actions to deploy.
AZURE_CREDENTIALS created as per the service principal
instructions.
az ad sp create-for-rbac --name "lamsubs - GitHub" --sdk-auth --role contributor \
--scopes /subscriptions/SUBSCRIPTIONID/resourceGroups/lamsubs