Skip to content

rubygitflow/auth_microservice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Auth Microservice

Auth microservice from Ruby Microservices course

Download this app from the repository

It's set up so you can clone this repository and base your application on it:

$ git clone git@github.com:rubygitflow/auth_microservice.git app_auth && cd app_auth && rm -r -f .git/

Initialize and configure a new Git repository (you need to have a personal access token):

$ git init
$ git config --global user.name # get USER_NAME from your own Git repository
$ git config --global user.name USER_NAME # set USER_NAME from your own Git repository if the "global user.name" is empty
$ git config --global user.email USER_EMAIL # set USER_EMAIL from your own Git repository if the "global user.name" is empty
# create the new repository
$ curl \
  -X POST \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: Bearer <YOUR-TOKEN>" \
  https://api.github.com/user/repos \
  -d'{"name":"app_auth", "description":"Some information"}'
$ git remote add origin git@github.com:USER_NAME/app_auth.git 
$ git add . && git commit -m 'init project'
$ git push -u origin master

For more details, see the github docs

Database Setup

By default Sequel assumes a PostgreSQL database, with an application specific PostgreSQL database account. You can create this via:

$ createuser -U postgres app_auth
$ createdb -U postgres -O app_auth auth_microservice_production -p 5432 -h 127.0.0.1
$ createdb -U postgres -O app_auth auth_microservice_test -p 5432 -h 127.0.0.1
$ createdb -U postgres -O app_auth auth_microservice_development -p 5432 -h 127.0.0.1

Create password for user account via:

$ sudo su - postgres
$ psql -c "alter user app_auth with password 'mypassword'"

Configure the database connection defined in .env.rb for the ENV parameter ENV['APP_AUTH_DATABASE_URL'] ||= "postgres://user:password@host:port/database_name_environment" like so:

case ENV['RACK_ENV'] ||= 'development'
when 'test'
  ENV['APP_AUTH_DATABASE_URL'] ||= "postgres://app_auth:mypassword@127.0.0.1:5432/auth_microservice_test"
when 'production'
  ENV['APP_AUTH_DATABASE_URL'] ||= "postgres://app_auth:mypassword@127.0.0.1:5432/auth_microservice_production"
else
  ENV['APP_AUTH_DATABASE_URL'] ||= "postgres://app_auth:mypassword@127.0.0.1:5432/auth_microservice_development"
end

According to the Sequel documentation, you can also specify optional parameters Settings.db in config/settings/*.yml and config/*.yml

Environment setup

$ bundle install

Run App

Either set up configuration into config/initializers/config.rb, config/settings/*.yml and config/*.yml before running

$ bin/puma
$ bin/console

or run the application with modified configuration using environment variables

$ RACK_ENV=test ENV__PAGINATION__PAGE_SIZE=100 bin/puma
$ RACK_ENV=test ENV__PAGINATION__PAGE_SIZE=100 bin/console

HTTP-requests to the app

$ curl --url "http://localhost:3000" -v
$ http :3000
$ http -f post ":3000/api/v1/user" "name=bob" "email=bob@example.com" "password=password"
$ http -f post ":3000/api/v1/user_session" "email=bob@example.com" "password=password"
$ http -f post ":3000/api/v1/auth" "Authorization:Bearer some_token_received_in_user_session"

Run tests

$ bin/rspec

Additional tips

  1. Use a timestamp for the new migration filename:
$ date -u +%Y%m%d%H%M%S
  1. After adding additional migration files, you can run the migrations:
$ rake dev_up  
$ rake test_up 
$ rake prod_up 
  1. After modifying the migration file, you can drop down and then back up the migrations with a single command:
$ rake dev_bounce  
$ rake test_bounce 
  1. Roll back database migration all the way down:
$ rake dev_down  
$ rake test_down 
$ rake prod_down 
  1. Feed the database with initial data:
$ rake dev_seed
$ rake test_seed
$ rake prod_seed
  1. The list of all tasks is called by the command:
$ bin/rake --tasks
  1. Making a database's schema dump and other manipulations from the command line interface
$ bin/sequel -d postgres://user:pass@host/database_name
$ bin/sequel -D postgres://user:pass@host/database_name

Author

About

Auth microservice from Ruby Microservices course

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages