Code Monkey home page Code Monkey logo

sso's Introduction

logo



License Go Report Card Go Reference Build Status

Features

The template for this project was taken from the project of Nikolay Tuzov. This project is developed as a grps microservice for authentication, authorization and permissions.

The project used:

  • Standard CRUD operations of a database table
  • JWT-based authentication
  • Environment dependent application configuration management
  • Structured logging with contextual information
  • Error handling with proper error response generation
  • Database migration
  • Data validation
  • Containerizing an application in Docker

The kit uses the following Go packages:


scheme of user interaction, SSO and URL-shortener
scheme

Note

This project is a microservice that works in conjunction with other microservice. For example you can use url-shortener
URL-shortener PROTO


Getting Started

If this is your first time encountering Go, please follow the instructions to install Go on your computer. The project requires Go 1.21 or above.

Docker is also needed if you want to try the kit without setting up your own database server. The project requires Docker 17.05 or higher for the multi-stage build support.

Also for simple run commands i use Taskfile.

After installing Go, Docker and TaskFile, run the following commands to start experiencing:

## RUN SSO
# download the project
git clone [https://github.com/neepooha/url_shortener.git](https://github.com/neepooha/sso)
cd sso

# create config.env with that text:
$ nano config.env {
CONFIG_PATH=./config/local.yaml
POSTGRES_DB=url
POSTGRES_USER=myuser
POSTGRES_PASSWORD=mypass
}

# start a PostgreSQL database server in a Docker container
task db-start

# run the SSO server
go run ./cmd/sso

Also, you can start project in dev mode. For that you need rename in config.env "CONFIG_PATH=./config/local.yaml" to "CONFIG_PATH=./config/dev.yaml" in both projects and run following commads:

# run the SSO server
cd sso/
docker compose up --build

SSO-grpc Server running at http://localhost:44044. The server provides the following endpoints:

auth

  • Regiter: register new user in db
  • Login: log in to the application
  • GETUserID: get user ID by name

permissions

  • SetAdmin: set exists user to admin in your app. You need be creator of app
  • DelAdmin: delete exists user from admin in your app. You need be creator of app
  • IsAdmin: is the user an admin by userID
  • IsCreator: is the user a creator by userID

apps

  • SetApp: set new app in db. You will be creator of the app
  • DelApp: delete exists apps. You need be creator of app
  • UpdApp: update app name and secret
  • GetAppID: get app id by app name

Project Layout

Project has the following project layout:

sso/
├── cmd/                       start of applications of the project
├── config/                    configuration files for different environments
├── deployment/                configuration for create daemon in linux
├── internal/                  private application and library code
│   ├── app/                   application assembly
│   ├── config/                configuration library
│   ├── domain/                models of apps and users
│   ├── grpc/                  grpc handlers
│   │   ├── apps/              handlers of apps
│   │   ├── auth/              handlers of auth
│   │   └── permissions/       handlers of permissions
│   ├── lib/                   additional functions for logging, error handling, migration
│   ├── services/              logics of handlers
│   │   ├── apps/              handlers of apps
│   │   ├── auth/              handlers of auth
│   │   └── permissions/       handlers of permissions
│   └── storage/               storage library
├── migrations/                migrations
└── config.env                 config for sercret variables

The top level directories cmd, internal, lib are commonly found in other popular Go projects, as explained in Standard Go Project Layout.

Within each feature package, code are organized in layers (grpc server, service, db), following the dependency guidelines as described in the clean architecture.

Updating Database Schema

for simple migration you can use the following commands

# For up migrations
task up

# For drop migrations
task drop

# Revert the last database migration.
tasl rollback

Managing Configurations

The application configuration is represented in internal/config/config.go. When the application starts, it loads the configuration from a configuration environment as well as environment variables. The path to the configuration environment should be in the project root folder.

The config directory contains the configuration files named after different environments. For example, config/local.yml corresponds to the local development environment and is used when running the application via go run ./cmd/url-shortener

You can keep secrets in local/dev confing, but do not keep secrets in the prud and in the configuration environment. For set secret variable user github secrets and deploy.yaml.

sso's People

Contributors

neepooha avatar

Watchers

 avatar

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.