/lamsubs

LaMetric HTTP endpoint for Mailchimp subscribers.

Primary LanguageRustGNU Affero General Public License v3.0AGPL-3.0

Mailchimp App for LaMetric

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.

Methods

Development

Uses Rocket so requires Rust nightly. Set up a nightly override on the directory once cloned:

rustup override set nightly

Set environment variables (see below) with the relevant config then run:

cargo run

to start the web server. Issue requests to the endpoints e.g.:

curl -v http://localhost:3000/api/get_subscribers

Unit tests

cargo test

Testing with Azure Functions

Requirements:

# 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 start

Trigger HTTP function

curl -v http://localhost:7071/api/get_subscribers

Environment variables

  • LAMSUBS_MAILCHIMP_APIKEY: Mailchimp API key.
  • LAMSUBS_MAILCHIMP_LIST_ID: Mailchimp list ID string.
  • LAMSUBS_PRODUCTION: Set to any value when running in production.

Deployment

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.

Manual

Requirements:

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 lamsubs

Automatic

Uses 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