strautomagically

module
v0.0.0-...-4e5a236 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2024 License: MIT

README ยถ

Strautomagically

Webhook endpoint that runs on Azure Functions to do stuff automagically to my Strava activities as they appear. Inspired by Klimat and Strautomator.

๐Ÿšง WIP ๐Ÿšง

This is very much WIP and it more of a tinker tool to help me learn Go with a purpose. There's no guarantee, yet, that any of the info below is accurate of this even works. As such I've disabled issues and I'm not taking PRs. Feel free to fork and tinker for your own purposes. If I spot a fork and find something I like that you've done, I will pinch it ๐Ÿ˜œ.

Usage

Prerequisites

You will need to create an API application in your settings on Strava and take note of the client ID and secret. If you are running this locally, you will need to set the callback domain to localhost:8080, or your ngrok URL if you want to use ngrok. You will also need a Redis database which is used to store the authentication and refresh tokens. I use a free database from Redis as it's cheaper than Azure ๐Ÿ˜œ. Optional: If you want to add weather information to your entries, you will need to register for a free OpenWeather account and obtain an API key.

Running Locally
  1. Create a .env file and set the following:
    • STRAVA_CLIENT_ID & STRAVA_CLIENT_SECRET to the values from Strava
    • STRAVA_REDIRECT_URI to the callback domain you registered followed by /auth, eg http://localhost:8080/auth
    • STRAVA_CALLBACK_URI to the same domain as you registered followed by /webhook eg http://localhost:8080/webhook
    • STRAVA_VERIFY_TOKEN to any random unique string
    • STATE_TOKEN to any random unique string
    • REDIS_URL to the database URL for your Redis database in the form redis://<username>:<password>@<hostname>/<database>:<port>. If you're using Heroku, you can use the URL Heroku uses.
    • Optional: OWM_API_KEY to the OpenWeather API key.
  2. Copy those same settings to local.settings.json as it makes it easy to set these in the Azure Functions configuration.
  3. Configure your rules in the update.go file. I plan to move this out to a better place in future.
  4. Run: make start and then visit the STRAVA_REDIRECT_URI URL and authorize the application with Strava.
  5. Go for a run.
Deployment
  1. Create the Azure Functions app...
  • in the Azure portal:

    How to set up a custom handler Azure Function

    Start by searching for Function App in the Azure Portal and click Create. The important settings for this are below, other settings you can use default or your own preferences.

    [Basic]

    1. Publish: Code
    2. Runtime stack: Custom Handler
    3. Version: custom

    [Hosting]

    1. Operating System: Linux
    2. Plan type: Consumption (Serverless)

    ... or ...

  • in VSCode

  1. Create an Azure Service Principal for RBAC for the deployment credentials. Follow these instructions.
  2. Add the configuration variables from the .env file above to the Azure function configuration, or if you added them to local.settings.json too, use the VSCode Azure Functions extension to upload them.
  3. Deploy using your preferred method - either manually from the Azure Functions extension in VSCode or using the GitHub workflow by merging a PR into main or pushing directly to main.
  4. Visit the STRAVA_REDIRECT_URI URL and authorize the application with Strava.
  5. Go for a run.

Directories ยถ

Path Synopsis
cmd
internal
cache
Package cache implements a REDIS cache.
Package cache implements a REDIS cache.
calendarevent
Package calendarevent implements methods to get events from ical feeds.
Package calendarevent implements methods to get events from ical feeds.
client
Package client implements a generic REST API client.
Package client implements a generic REST API client.
handlers/auth
Package auth implements the authentication handler.
Package auth implements the authentication handler.
handlers/callback
Package callback implements the callback handler for the Strava webhook subscription.
Package callback implements the callback handler for the Strava webhook subscription.
handlers/update
Package update implements the update handler for Strava activities.
Package update implements the update handler for Strava activities.
strava
Package strava implements methods to update Strava entries in response to receiving webhook events.
Package strava implements methods to update Strava entries in response to receiving webhook events.
weather
Package weather implements methods to gather weather and AQI from OpenWeatherMap and present it in a pretty string.
Package weather implements methods to gather weather and AQI from OpenWeatherMap and present it in a pretty string.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL