Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .env_example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
POSTGRES_USER=user
POSTGRES_PASSWORD=password
POSTGRES_DB=test
DB_ADDR=postgres://user:password@db:5432/test?sslmode=disable
JWT_SECRET=secret
21 changes: 21 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: build.yml
on:
pull_request:
branches: [main]
push:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Build docker-compose
run: |
mv .env_example .env
docker compose build

- name: Run docker-compose
run : |
docker compose up -d
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
.idea
config/auth/
config/api-gateway/
.env
18 changes: 16 additions & 2 deletions cmd/auth-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ func LoadConfig() (*auth.Config, error) {
return nil, err
}

expanded := os.ExpandEnv(string(doc))

var config auth.Config
err = toml.Unmarshal(doc, &config)
err = toml.Unmarshal([]byte(expanded), &config)

if err != nil {
return nil, err
Expand All @@ -51,10 +53,22 @@ func main() {

defer db.Close()

accessTTL, err := time.ParseDuration(config.JWT.AccessTokenTTL)

if err != nil {
log.Fatalf("Error to parser access token ttl: %v", err.Error())
}

refreshTTL, err := time.ParseDuration(config.JWT.RefreshTokenTTL)

if err != nil {
log.Fatalf("Error to parser refresh token ttl: %v", err.Error())
}

userRepo := storage.NewUserRepository(db)
tokenRepo := storage.NewRefreshTokenRepository(db)
hasher := infrastructure.NewBcryptHasher(bcrypt.DefaultCost)
jwtService := infrastructure.NewJWTService(config.JWT.Secret, 15*time.Minute, 20*time.Hour)
jwtService := infrastructure.NewJWTService(config.JWT.Secret, accessTTL, refreshTTL)

authService := service.NewAuthService(hasher, tokenRepo, userRepo, jwtService)

Expand Down
Empty file added config/api-gateway/config.toml
Empty file.
7 changes: 7 additions & 0 deletions config/auth/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[database]
addr = "${DB_ADDR}"

[jwt]
secret = "${JWT_SECRET}"
access_token_ttl = "15m"
refresh_token_ttl = "20h"
1 change: 0 additions & 1 deletion config/server/config.toml

This file was deleted.

9 changes: 6 additions & 3 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@ services:
dockerfile: docker/auth-service/Dockerfile
ports:
- "8081:8081"
environment:
JWT_SECRET: ${JWT_SECRET}
DB_ADDR: ${DB_ADDR}
depends_on:
- db

db:
image: postgres:17
restart: always
environment:
POSTGRES_USER: user
POSTGRES_PASSWORD: password
POSTGRES_DB: test
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
ports:
- "5432:5432"
volumes:
Expand Down
5 changes: 3 additions & 2 deletions internal/auth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ type Config struct {
type DatabaseConfig struct {
Addr string `toml:"addr"`
}

type JWTConfig struct {
Secret string `toml:"secret"`
Secret string `toml:"secret"`
AccessTokenTTL string `toml:"access_token_ttl"`
RefreshTokenTTL string `toml:"refresh_token_ttl"`
}
Loading