This project is a service that will notify publishers about the metrics of their snaps. A cron job that polls the store for stats about each snap, combines this with Marketo user data, generates an email and posts the email to Marketo to send to the relevant user.
All the code here is to create a valid CronJob for Kubernetes; the logic of this service is possible with surl.
This cronjob has stored the session macaroons as secrets on k8s, and if you need to renew the session, we are using the web team account.
To generate a fresh macaroon use:
snapcraft export-login --acls package_upload --expires="2022-01-01T00:00:00" webteam-session.txtIn snapcraft 7+ the output is a base64 encoded string that you can extract the parts:
cat webteam-session.txt | base64 -dThis will return a JSON blob. You need the r key for the root and d key for the discharge. They then both need base64 encoding.
cat webteam-session.txt | base64 -d | jq -r .v.r | base64 -w 0cat webteam-session.txt | base64 -d | jq -r .v.d | base64 -w 0The maximum amount of time for a valid session is one year
Extract the macaroon and discharge from the generated file and update the secrets on Kubernetes.
kubectl edit secret snapcraft-monthly-stats-email --namespace production-
You will need to create a
.env.localfile in the root of the project with the following secrets:WEBTEAM_ACCOUNT_EMAIL WEBTEAM_ROOT_MACAROON WEBTEAM_DISCHARGE_MACAROON MARKETO_REST_DOMAIN MARKETO_CLIENT_ID MARKETO_SECRET SENTRY_DSN (Optional) -
Build the Docker image:
docker build . --tag snapcraft-monthly-stats -
Run the Docker image:
docker run -ti --env-file .env.local snapcraft-monthly-stats