Giter VIP home page Giter VIP logo

relationships-googlecal-ktor's Introduction

One on one tracker

This is the Heroku/Kotlin rewrite of my prior Docker/Java one-on-one app report.

The production version of this app is hosted at https://s6-1on1s.herokuapp.com/ and https://riot-1on1s.herokuapp.com/. The OAuth account is configured to only allow singularity6.com and riotgames.com email addresses as it requires access to calendar and directory information.

The app is functional and has some improvements over the original app, aside from also, actually working. The remaining work and some ideas is in the TODO file and in the project's Github issue tracker.

Development

System requirements

The versions here specifically work, though newer versions may also.

  • JDK 11
  • Maven 3.6
  • Heroku CLI
  • Probably need a heroku account, but unknown if that's needed for the CLI.
  • Either get Google account secrets from @sergeknystautas or create your own Google developer account for a web client and OAuth.
  • IntelliJ IDEA (recommended)

Run it locally

Make sure you've got the above requirements complete.

Create

relationships/googlecal-ktor/.env

and put the OAuth secrets in there. This would look like OAUTH_CLIENT_ID=<longcharsequence> OAUTH_CLIENT_SECRET=<medcharsequence> OAUTH_PROJECT=<shortcharsequence>

To build and run the service:

mvn clean install && heroku local:start -p 5000

This uses maven to clean previous artifacts and rebuild, then calls the heroku CLI to run the app locally. To see if this works go to:

http://localhost:5000

Deployment

Environments

The app.json adds the metadata and specifies we are using the heroku/java buildpack.

The Procfile defines what Heroku runs.

This app uses the Heroku-20 stack. By default the Java buildpack uses OpenJDK 8 and Maven 3.6.2 in this stack.

Branching strategy

We follow a simple version of git-flow.

We are not using github-flow or the development and release branch strategy yet given the small size of the team.

Email alerts on commits are configured in the github project's notification settings.

CI/CD

We use Heroku for builds. There are two apps for production and staging as described above in the branching strategy.

Heroku uses a github webhook to be alerted when there are changes. It runs the following command:

mvn -DskipTests clean dependency:list install

If this successfully completes, Heroku will shut down the existing dynos and launch one with the new version. This will create a brief downtime for the app. Prebook is not available for the hobby level and we'd have to upgrade to professional to prevent this downtime.

Secrets

Heroku manages secrets as discussed in development above. These are the secrets the app uses that should be configured in a heroku app:

  • OAUTH_CLIENT_ID get this from Google
  • OAUTH_CLIENT_SECRET get this from Google
  • OAUTH_PROJECT get this from Google
  • ENVIRONMENT this prompts HTTPS redirects in production and is sent to Sentry on crash reports. development is the default, also use production for that environment.
  • PAPERTRAIL_API_TOKEN configured automatically by heroku when adding this add-on.
  • SENTRY_DSN configured automatically by heroku when adding this add-on.

Logging

We use the add-on from Papertrail that gives free cloud logging for Heroku deployed environments. This is accessible thru an SSO link per project from the Heroku dashboard.

Alerting

We use alerting in Papertrail to provide business-logic alerts. The one alert in production is based on a saved search for SUCCESSFUL LOGIN log messages which if there are any are emailed nightly to Serge.

Error reporting

We use Sentry's crash reporting to track stack traces in the Kotlin app. If the environment is specified, then an alert along with the user and URI path is sent to Sentry. You can access the Sentry dashboard from an SSO link per project from the Heroku dashboard.

Google APIs

This application heavily on Google APIs. Because this is meant solely for singularity6.com and riotgames.com usage, the application was created in that domain. Its name is One-on-One Project.

We created an OAuth2 web client which needed authorized redirect URLs added for localhost as well as the staging and production hostnames and /login.

The OAuth consent screen does not need verification as we mark this as an internal user type. This allows us to skip the domain verification and page usage agreements. The dashboard shows the APIs this application is approved for.

The dashboard shows the APIs were are using which includes:

  • Google Calendar API
  • People API. This replaces the Contact API that was used by the Java/docker version of this app, so the permissions and call patterns have changed.

Why tech decisions

Why Heroku

Heroku is a low-cost option for hosting hobby projects that provides many critical surrounding features that is more expensive and work with Docker and AWS, including:

  • Easy CI/CD
    • Commits to github's main branch will redeploy the app.
    • Test plans can be included to prevent errant deploys, including alerts in this situation.
    • Support for branching to multiple dev stages.
  • Secrets management to split config, specifically for this the OAuth project secrets, from the codebase.
  • Cloud logging using Papertrail add-on including alerting.
  • Cloud error reporting using Sentry add-on.
  • Easy data layer options such as Redis or MySQL.

All of this for $7/mo.

Why Kotlin

If you fell in love with early Java's simplicity and ease of deployment, then watched Oracle turn it into bloated enterprise-ware, you'll love Kotlin. Other languages do run within the JVM like Groovy or Scala, but they are typically used to solve other types of problems. Kotlin gives the feel of clean, early Java but with 25 years of improved design patterns and simpler language syntax, plus easy access to all existing Java libraries. Key improvements include concurrency, collection operations, error handling, null safety, and booleans.

Why other tech decisions

  • Git because this is a microservice.
  • KTor because it wrapped Netty, gave OAuth options out of the box, gave numerous rendering options, and made it easy to start writing a Kotlin microservice.
  • Maven because I'm old and haven't learned Gradle or other patterns, plus the same heroku app used maven. Pull requests welcome.

relationships-googlecal-ktor's People

Contributors

sergeknystautas avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

relationships-googlecal-ktor's Issues

Must login again every 60 minutes

The current KTOR OAuth2 implementation does not specify the URL parameters that Google wants to provide a refresh token. In OAuth2, in addition to an access token, an authorization provider can supply a refresh token to get a new access token after a certain amount of time has passed.

This is currently blocked by https://youtrack.jetbrains.com/issue/KTOR-2128. When this is fixed, we can incorporate this new version and then we can make changes to our code base to support refreshing the token if it expired. In addition to knowing to refresh if the time has expired, we will likely want to persist the access token and refresh token so restarting the application does not require yet another login.

Docs to get started

There should be instructions for how to set up a new machine, and also a new person to develop locally. This should be comparable to the README in the old version of this service.

Also do more documentation on the code so people can open the KT files and know what's up.

Show relationships by small group encounters

I'm thinking that I don't generally want or desires recurrent 1:1s as a way to refresh social ties, but the idea "you have not been in a meeting with X in Y time" is interesting. I think when there are more than 8 people on VC it's broadcasting.

Can you create additional tabs for building and aging relationships based on meetings with 8 people (or fewer)?

Many meetings show email rather than names

This is a function of the Google calendar API, but often for whatever factors I can't determine, the display_name field is not on the event data, so it falls back to the email address.

We are also getting access to the google people data to show the names in all cases. This would likely be hard to do some caching so we avoid slamming the people API.

Incorporate crash reporting

Right now if someone else uses the website, we have no idea if it crashed for whatever reason. Install Sentry (or whatever library) and confirm error reports go back to there. Create a test page to manually verify crash reports.

Log of who has used the app

Right now I have no idea what users have accessed this. Either send an email each time someone uses it as a super dumb/start, or ideally create a database that stores who has signed in, and when the last time they signed in, and maybe track how many times they've signed in. I guess an authentication log might be better if that's the use case.

Anyway, see who is using it.

Use service accounts for directory & sheets access

Depending on how we are going to get data about Rioters in the future (whether directory or sheets or whatever), it would be nice to use Google's service accounts (https://developers.google.com/identity/protocols/oauth2/service-account) to access this data. The main benefits of this are:

  • The application can download the directory or sheets information on app start-up (if cached in memory) and refreshed whenever necessary.
  • The above means the first user will load their report faster because we do not need to scan and process the Rioter metadata.
  • All users will be able to use the site with providing future scopes, as in, they will just need to provide their calendar data rather than the other major scopes we ask for when you sign in.

Today is not calculated to the right time zone

At 16:57 in California, went to the report and it said:

Prepared Feb 19, 2021 12:56 AM

That's UTC, not California. I should look at the calendar time zone and use that to set the right time zone for "now" so that "today" is correctly defined.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.