Code Monkey home page Code Monkey logo

zio-cassandra-finch-http4s-doobie-auth-example's Introduction

the-who

A Scala and ZIO playground which happens to be an auth service.


Run

Finch server and In memory DB

  • ./sbt app/run

Cassandra DB

  • brew cask install java11
  • brew install cassandra (will also install cqlsh)
  • Cassandra doesn't work with java 14 (we are using java 11)
  • Some jvm options doesn't work so we have to edit /usr/local/etc/cassandra/jvm.options
  • Launch with cassandra -f
  • Stop with ctrl c or ps to get the PID and then kill <PID>
  • Default host and port is 127.0.0.1:9042
  • cqlsh will connect there by default
  • CREATE KEYSPACE IF NOT EXISTS thewho_dummy WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };
  • Edit app/Main and build.sbt to use cassandra instead of in memory db

Http4s server

  • Edit app/Main and build.sbt to use http4s instead of finch. See server/http4s/Server

Postgres DB

  • Edit app/Main and build.sbt to use postgres instead of in memory db
  • Add 127.0.0.1 postgres to your /etc/hosts file
  • docker-compose up
  • docker exec -it postgres bash
  • psql -d postgres -U postgres

Endpoints

ENDPOINT METHOD INPUT OUTPUT STATUS CODES
/signup POST Credential TokenResponse 201, 209, 422, 500
/login GET, POST Credential TokenResponse 200, 401 403, 404, 422, 500
/change-password POST CredentialSecretUpdateRequest TokenResponse 200, 401 403, 404, 422, 500
/signout POST Credential empty 204, 401 403, 404, 422, 500
/find-credential-id POST UserCredentialIdRequest UserCredentialIdResponse 200, 401 403, 404, 422, 500
Credential:                    { id: String, secret: String }
CredentialSecretUpdateRequest: { oldCredential: Credential, newSecret: String }
TokenResponse:                 { token: String }
UserCredentialIdRequest:       { token: String }
UserCredentialIdResponse:      { credentialId: String }

Test

Load test (Gatling)

  • ./sbt gatling/gatling:test

Other tests

  • ./sbt test

Troubleshooting

  • To generate key pairs:
openssl genrsa -out private.pem 1024
openssl rsa -in private.pem -pubout -outform PEM -out public_key.pem
openssl pkcs8 -topk8 -inform PEM -in private.pem -out private_key.pem -nocrypt

the las line is needed because of the format java uses.

  • Sending json thru httpie:
echo '{ "id": "Salvador", "secret": "Dalí" }' | http POST http://127.0.0.1:8080/signup -v
echo '{ "oldCredential": { "id": "Salvador", "secret": "Dalí" }, "newSecret": "lanadanisman" }' | http POST http://127.0.0.1:8080/change-password -v  

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.