Skip to content

canonical/snapcraft-monthly-stats-email

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

snapcraft.io Snapcraft Monthly Stats

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.

Regenerate credentials

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.txt

Snapcraft 7+

In snapcraft 7+ the output is a base64 encoded string that you can extract the parts:

cat webteam-session.txt | base64 -d

This 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.

Root

cat webteam-session.txt | base64 -d | jq -r .v.r | base64 -w 0

Discharge

cat webteam-session.txt | base64 -d | jq -r .v.d | base64 -w 0

The 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

Run the project

  1. You will need to create a .env.local file 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)
    
  2. Build the Docker image: docker build . --tag snapcraft-monthly-stats

  3. Run the Docker image: docker run -ti --env-file .env.local snapcraft-monthly-stats