Auth microservice from Ruby Microservices course
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
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
$ bundle install
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
$ 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"
$ bin/rspec
- Use a timestamp for the new migration filename:
$ date -u +%Y%m%d%H%M%S
- After adding additional migration files, you can run the migrations:
$ rake dev_up
$ rake test_up
$ rake prod_up
- 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
- Roll back database migration all the way down:
$ rake dev_down
$ rake test_down
$ rake prod_down
- Feed the database with initial data:
$ rake dev_seed
$ rake test_seed
$ rake prod_seed
- The list of all tasks is called by the command:
$ bin/rake --tasks
- 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
- it.Architect https://github.com/rubygitflow
- Inspired by Jeremy Evans and Evgeniy Fateev