Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update main #15

Merged
merged 143 commits into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
143 commits
Select commit Hold shift + click to select a range
e83b37e
feat: add User model
Nitiwat-owen Dec 22, 2023
95e1ef6
feat: init user repository
Nitiwat-owen Dec 22, 2023
6770195
feat: implement user repository
Nitiwat-owen Dec 22, 2023
4f3449d
chore: ignore memory file
Nitiwat-owen Dec 22, 2023
30b2765
feat: update userRepositoryImpl struct
Nitiwat-owen Dec 22, 2023
c0ded54
feat: update user package
Nitiwat-owen Dec 22, 2023
3bb9b18
feat: init auth service
Nitiwat-owen Dec 22, 2023
ead6995
feat: init jwt service
Nitiwat-owen Dec 22, 2023
5427a6e
feat: init token service
Nitiwat-owen Dec 22, 2023
af7a559
fix: user repository unit test
Nitiwat-owen Dec 23, 2023
f45109e
feat: create ci workflow
Nitiwat-owen Dec 23, 2023
416c36f
fix: import package
Nitiwat-owen Dec 23, 2023
2c0b40e
feat: create Dockerfile
Nitiwat-owen Dec 23, 2023
0bf1c35
fix: import package
Nitiwat-owen Dec 23, 2023
4299dbf
fix: ci workflow
Nitiwat-owen Dec 23, 2023
afa13e4
fix: port
Nitiwat-owen Dec 23, 2023
093f8dd
Merge pull request #1 from isd-sgcu/feature/ci-workflow
Nitiwat-owen Dec 23, 2023
e5774af
feat: create jwtStrategyMock
Nitiwat-owen Dec 23, 2023
ff0b335
feat: create JwtUtil
Nitiwat-owen Dec 23, 2023
d47814f
feat: implement SignAuth method
Nitiwat-owen Dec 23, 2023
f7bf3b2
feat: implement VerifyAuth method
Nitiwat-owen Dec 23, 2023
1ffaa55
feat: implement GetConfig method
Nitiwat-owen Dec 23, 2023
0939b62
chore: chore
Nitiwat-owen Dec 23, 2023
797d48b
feat: add jwt.strategy_test.go
Nitiwat-owen Dec 23, 2023
511d129
feat: add role parameter in SignAuth method
Nitiwat-owen Dec 23, 2023
fe45113
feat: update CreateCredential Signature
Nitiwat-owen Dec 23, 2023
443eb0e
fix: SignAuth signature
Nitiwat-owen Dec 23, 2023
7f7df92
fix: CreateCredential signature
Nitiwat-owen Dec 23, 2023
5e812cd
Merge pull request #2 from isd-sgcu/feature/jwt-service
bookpanda Dec 23, 2023
477cf1e
feat: create jwtServiceMock
Nitiwat-owen Dec 23, 2023
8348d08
feat: create uuid util
Nitiwat-owen Dec 23, 2023
1f4b686
feat: add CreateRefreshToken method and uuidUtil
Nitiwat-owen Dec 23, 2023
2c641be
feat: add unit test for token service
Nitiwat-owen Dec 23, 2023
fca3075
feat: update jwtServiceMock
Nitiwat-owen Dec 23, 2023
15d663c
feat: implement token service
Nitiwat-owen Dec 23, 2023
18371f8
chore: chore
Nitiwat-owen Dec 23, 2023
4de393e
fix: unit test
Nitiwat-owen Dec 23, 2023
e458120
fix: unit test
Nitiwat-owen Dec 23, 2023
6c92397
Merge pull request #3 from isd-sgcu/feature/token-service
Nitiwat-owen Dec 23, 2023
774068e
feat: draft auth service
Nitiwat-owen Dec 24, 2023
2790874
feat: create BcryptUtil
Nitiwat-owen Dec 24, 2023
4d961ff
chore: remove config from struct
Nitiwat-owen Dec 24, 2023
8ecc0ee
feat: mock user repo
bookpanda Dec 24, 2023
389e803
chore: rename jwt service mock package
Nitiwat-owen Dec 24, 2023
5684879
feat: create UserRepositoryMock
Nitiwat-owen Dec 24, 2023
a1877a2
feat: create TokenServiceMock
Nitiwat-owen Dec 24, 2023
9cf68f5
feat: create BcryptUtilMock
Nitiwat-owen Dec 24, 2023
0e0cd4a
chore: chore
Nitiwat-owen Dec 24, 2023
605f25b
feat: user service
bookpanda Dec 24, 2023
7c9b5db
fix: update user model
Nitiwat-owen Dec 24, 2023
5b8d7c1
fix: add more repo mock methods
bookpanda Dec 24, 2023
b85ae9c
feat: user service tests
bookpanda Dec 24, 2023
19643fd
feat: add postgresql container for testing
Nitiwat-owen Dec 24, 2023
647e49c
chore: update workflow
Nitiwat-owen Dec 24, 2023
3e8f10b
Merge branch 'fix/userrepo-unittest' into feature/signup
Nitiwat-owen Dec 24, 2023
be1e1c3
chore: set TranslateError be true
Nitiwat-owen Dec 24, 2023
910485c
Merge branch 'fix/userrepo-unittest' into feature/signup
Nitiwat-owen Dec 24, 2023
ffd8619
fix: user repository mock
Nitiwat-owen Dec 24, 2023
54f7d4d
feat: implement signup method
Nitiwat-owen Dec 24, 2023
a482e29
refactor: apply error message constant
Nitiwat-owen Dec 24, 2023
41bf9b7
chore: add AutoMigrate
Nitiwat-owen Dec 24, 2023
20bd425
feat: add FindByEmail method in user repository
Nitiwat-owen Dec 24, 2023
e4a75c6
feat: implement unit test for signIn method
Nitiwat-owen Dec 24, 2023
71c5e97
feat: implement signIn method
Nitiwat-owen Dec 24, 2023
7c4c47d
fix: typo
Nitiwat-owen Dec 24, 2023
e75a341
Merge pull request #5 from isd-sgcu/fix/userrepo-unittest
bookpanda Dec 24, 2023
be4436f
Merge branch 'dev' into feature/signup
Nitiwat-owen Dec 24, 2023
e6559a7
Merge pull request #6 from isd-sgcu/feature/signup
bookpanda Dec 24, 2023
02bb870
Merge branch 'dev' into feature/signin
Nitiwat-owen Dec 24, 2023
bd9b138
Merge pull request #7 from isd-sgcu/feature/signin
bookpanda Dec 25, 2023
370b353
feat: add redis connection
Nitiwat-owen Dec 27, 2023
d3ff7b8
Merge branch 'dev' into feature/user-service
bookpanda Dec 27, 2023
b0f8d2a
feat: create cache repository
Nitiwat-owen Dec 28, 2023
2b2b6d4
chorefeat: update go-proto version
Nitiwat-owen Dec 28, 2023
cf5464f
chore: add cacheRepo in auth service
Nitiwat-owen Dec 28, 2023
8ee9132
chore: add gomock dependency
Nitiwat-owen Dec 28, 2023
41fcfed
feat: generate cache repository mock
Nitiwat-owen Dec 28, 2023
00d4c44
fix: update unit test
Nitiwat-owen Dec 28, 2023
51f0ee0
feat: update cache repository interface
Nitiwat-owen Dec 28, 2023
1ea770e
feat: remove refresh token on user model
Nitiwat-owen Dec 28, 2023
98cd678
feat: create AuthSession model
Nitiwat-owen Dec 28, 2023
5cf7fea
feat: create auth repository
Nitiwat-owen Dec 28, 2023
7a3a119
feat: generate auth repository mock
Nitiwat-owen Dec 28, 2023
83b8829
feat: update auth service struct
Nitiwat-owen Dec 28, 2023
ec5fe45
chore: rename package import
Nitiwat-owen Dec 28, 2023
d347be0
feat: add accessToken and refreshToken cache in token service
Nitiwat-owen Dec 28, 2023
d8bea18
feat: update SignAuth method
Nitiwat-owen Dec 28, 2023
14680d7
feat: update CreateCredential method
Nitiwat-owen Dec 28, 2023
97512be
feat: register user service
bookpanda Dec 28, 2023
0184576
feat: update signin
Nitiwat-owen Dec 28, 2023
bdf2352
fix: use authSessionId as key in cache
Nitiwat-owen Dec 28, 2023
cb89520
chore: rename file
Nitiwat-owen Dec 28, 2023
cb95af8
chore: autoMigrate AuthSession
Nitiwat-owen Dec 28, 2023
009c24a
feat: test cache repository
Nitiwat-owen Dec 28, 2023
64c1e99
fix: AuthSession model
Nitiwat-owen Dec 28, 2023
313f2c9
fix: use new user repo mock
bookpanda Dec 28, 2023
5d2f708
fix: field name
Nitiwat-owen Dec 28, 2023
42e6222
Merge pull request #9 from isd-sgcu/JOH-26/fix-signin
Nitiwat-owen Dec 28, 2023
63b5a2a
feat: implement unit test for signout
Nitiwat-owen Dec 28, 2023
3a495fe
feat: implement sign out
Nitiwat-owen Dec 28, 2023
d08aaba
feat: update UserCredential dto
Nitiwat-owen Dec 28, 2023
dd0ba63
feat: update token validate logic
Nitiwat-owen Dec 28, 2023
96a9d11
Merge branch 'dev' into feature/user-service
bookpanda Dec 28, 2023
d49cada
fix: register user service
bookpanda Dec 28, 2023
db1afbd
fix: change app port + db name
bookpanda Dec 28, 2023
4c91059
feat: update proto
bookpanda Dec 28, 2023
6c5a413
fix: auth signup -> signUp (grpc test)
bookpanda Dec 28, 2023
583ccbc
feat: update cache repository
Nitiwat-owen Dec 28, 2023
192599b
feat: implement RemoveTokenCache method
Nitiwat-owen Dec 28, 2023
ce783fb
fix: sign out
Nitiwat-owen Dec 28, 2023
5f931df
feat: implement signout
Nitiwat-owen Dec 29, 2023
b8e5a6b
fix: type
Nitiwat-owen Dec 29, 2023
7a926f9
fix: user srv dont return password, hash password
bookpanda Dec 29, 2023
3d3d875
fix: add bcrypt to pkg user srv
bookpanda Dec 29, 2023
084b48f
fix: user srv text add brcypt, hashed pw
bookpanda Dec 29, 2023
7ceeb7d
Merge pull request #8 from isd-sgcu/JOH-26/sign-out
Nitiwat-owen Dec 30, 2023
2b26540
fix: handle update user not found
Nitiwat-owen Dec 30, 2023
30df31f
fix: user service error types
bookpanda Dec 30, 2023
367aaa4
fix: user srv tests
bookpanda Dec 30, 2023
dbd6fa1
fix: user srv tests name
bookpanda Dec 30, 2023
23c69ce
fix: user srv err message
bookpanda Dec 30, 2023
fd556fa
Merge pull request #10 from isd-sgcu/fix/update-user
Nitiwat-owen Dec 31, 2023
606d179
Merge pull request #4 from isd-sgcu/feature/user-service
bookpanda Dec 31, 2023
ae5d9c5
refactor: project structure
Nitiwat-owen Jan 1, 2024
fb92560
fix: package
Nitiwat-owen Jan 1, 2024
5cf4446
fix: ci
Nitiwat-owen Jan 1, 2024
36eaeca
fix: remove loop dependencies
Nitiwat-owen Jan 1, 2024
e9e9c30
fix: fix
Nitiwat-owen Jan 1, 2024
2fc36fe
fix: repository unit test
Nitiwat-owen Jan 1, 2024
fbf16df
fix: import package name
Nitiwat-owen Jan 1, 2024
16fbfbf
Merge pull request #11 from isd-sgcu/refactor/project-structure
Nitiwat-owen Jan 1, 2024
3e8dec3
feat: implement validate service
Nitiwat-owen Jan 2, 2024
32f4d5f
Merge pull request #12 from isd-sgcu/JOH-26/validate
Nitiwat-owen Jan 2, 2024
9afe9ae
feat: implement FindRefreshTokenCache in token service
Nitiwat-owen Jan 2, 2024
44b804b
feat: implement RefreshToken service
Nitiwat-owen Jan 2, 2024
b1258d1
feat: separate RemoveToken method
Nitiwat-owen Jan 2, 2024
12e82d8
feat: update auth service
Nitiwat-owen Jan 2, 2024
026adc0
Merge pull request #13 from isd-sgcu/JOH-26/refresh-token
Nitiwat-owen Jan 3, 2024
719585d
feat: update readme
bookpanda Jan 4, 2024
132a49b
feat: add build package workflow
bookpanda Jan 4, 2024
24b7293
fix: build package add platform
bookpanda Jan 6, 2024
77b8309
fix: readme
bookpanda Jan 6, 2024
dda5c66
Merge pull request #14 from isd-sgcu/JOH-37/publish
bookpanda Jan 6, 2024
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
79 changes: 79 additions & 0 deletions .github/workflows/build-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: "Build and Deploy"

on:
push:
branches:
- main
- beta
- dev

env:
IMAGE_NAME: ghcr.io/${{ github.repository }}
IMAGE_TAG: ${{ github.sha }}

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.21
check-latest: true

- name: Download dependencies
run: go mod download

- name: Start Test Database Container
run: docker-compose -f docker-compose-unittest.yaml up -d

- name: Vet
run: |
go vet ./...

- name: Test
run: |
go test -v -coverpkg ./internal/... -coverprofile coverage.out -covermode count ./internal/...
go tool cover -func="./coverage.out"

build:
name: Build
runs-on: ubuntu-latest

permissions:
contents: read
packages: write

outputs:
BRANCH: ${{ steps.branch.outputs.BRANCH }}

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Set branch
id: branch
run: |
echo "BRANCH=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT

- name: Log in to the Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and Push Docker Image
uses: docker/build-push-action@v2
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }},${{ env.IMAGE_NAME }}:latest
cache-from: type=registry,ref=${{ env.IMAGE_NAME }}:buildcache
cache-to: type=registry,ref=${{ env.IMAGE_NAME }}:buildcache,mode=max
35 changes: 35 additions & 0 deletions .github/workflows/run-unit-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: "Pull request: Run unit test"

on:
pull_request:
branches:
- main
- beta
- dev

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.21
check-latest: true

- name: Download dependencies
run: go mod download

- name: Start Test Database Container
run: docker-compose -f docker-compose-unittest.yaml up -d

- name: Vet
run: |
go vet ./...

- name: Test
run: |
go test -v -coverpkg ./internal/... -coverprofile coverage.out -covermode count ./internal/...
go tool cover -func="./coverage.out"
28 changes: 28 additions & 0 deletions .github/workflows/test-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: "Pull request: Build test"

on:
pull_request:
branches:
- main
- beta
- dev

jobs:
docker-build:
name: "Docker build and create an image"
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Build Docker image
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
push: false
tags: test
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ volumes
coverage.out
coverage.html

.DS_store
.DS_store

internal/repository/user/memory:
49 changes: 49 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Base Image
FROM golang:1.21.4-alpine3.18 as base

# Working directory
WORKDIR /app

# Copy go.mod and go.sum files
COPY go.mod go.sum ./

# Download dependencies
RUN go mod download

# Copy the source code
COPY . .

# Build the application
RUN go build -o server ./cmd/main.go

# Copy config files
COPY ./config ./config

# Adding the grpc_health_probe
RUN GRPC_HEALTH_PROBE_VERSION=v0.3.1 && \
wget -qO/bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64 && \
chmod +x /bin/grpc_health_probe

# Create master image
FROM alpine AS master

# Working directory
WORKDIR /app

# Copy grpc_heath_prob
COPY --from=base /bin/grpc_health_probe ./

# Copy execute file
COPY --from=base /app/server ./

# Copy config files
COPY --from=base /app/config ./config

# Set ENV to production
ENV GO_ENV production

# Expose port 3002
EXPOSE 3002

# Run the application
CMD ["./server"]
15 changes: 14 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
server:
go run ./src/.
go run ./cmd/.

mock-gen:
mockgen -source ./pkg/repository/cache/cache.repository.go -destination ./mocks/repository/cache/cache.mock.go
mockgen -source ./pkg/repository/auth/auth.repository.go -destination ./mocks/repository/auth/auth.mock.go

test:
go vet ./...
go test -v -coverpkg ./internal/... -coverprofile coverage.out -covermode count ./internal/...
go tool cover -func=coverage.out
go tool cover -html=coverage.out -o coverage.html

proto:
go get github.com/isd-sgcu/johnjud-go-proto@latest
26 changes: 21 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
# Johnjud-auth

Johnjud-auth is a user authentication and authorization service for the Johnjud project.

### What is Johnjud?
Johnjud is a pet adoption web application of the [CUVET For Animal Welfare Club](https://www.facebook.com/CUVETforAnimalWelfareClub)

## Stacks
- golang
- gRPC
- postgresql
- redis

## Getting Start
## Getting Started
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

### Prerequisites
- golang 1.19 or [later](https://go.dev)
- golang 1.21 or [later](https://go.dev)
- docker
- makefile

Expand All @@ -18,9 +24,19 @@ These instructions will get you a copy of the project up and running on your loc
2. Import project
3. Copy `config.example.yaml` in `config` and paste it in the same location then remove `.example` from its name.
4. Download dependencies by `go mod download`
### Testing
1. Run ` go test -v -coverpkg ./src/internal/... -coverprofile coverage.out -covermode count ./src/internal/...` or `make test`

### Running
1. Run `docker-compose up -d`
2. Run `go run ./src/.` or `make server`
2. Run `go run ./cmd/.` or `make server`

### Testing
1. Run `go test -v -coverpkg ./internal/... -coverprofile coverage.out -covermode count ./internal/...` or `make test`

## Other microservices/repositories of Johnjud
- [Johnjud-gateway](https://github.com/isd-sgcu/johnjud-gateway): Routing and request handling
- [Johnjud-auth](https://github.com/isd-sgcu/johnjud-auth): Authentication and authorization
- [Johnjud-backend](https://github.com/isd-sgcu/johnjud-backend): Main business logic
- [Johnjud-file](https://github.com/isd-sgcu/johnjud-file): File management service
- [Johnjud-proto](https://github.com/isd-sgcu/johnjud-proto): Protobuf files generator
- [Johnjud-go-proto](https://github.com/isd-sgcu/johnjud-go-proto): Generated protobuf files for golang
- [Johnjud-frontend](https://github.com/isd-sgcu/johnjud-frontend): Frontend web application
18 changes: 17 additions & 1 deletion src/config/config.go → cfgldr/config.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package config
package cfgldr

import (
"github.com/pkg/errors"
Expand All @@ -20,9 +20,25 @@ type App struct {
Secret string `mapstructure:"secret"`
}

type Jwt struct {
Secret string `mapstructure:"secret"`
ExpiresIn int `mapstructure:"expires_in"`
RefreshTokenTTL int `mapstructure:"refresh_token_ttl"`
Issuer string `mapstructure:"issuer"`
}

type Redis struct {
Host string `mapstructure:"host"`
Port int `mapstructure:"port"`
Password string `mapstructure:"password"`
Dbnum int `mapstructure:"dbnum"`
}

type Config struct {
App App `mapstructure:"app"`
Database Database `mapstructure:"database"`
Jwt Jwt `mapstructure:"jwt"`
Redis Redis `mapstructure:"redis"`
}

func LoadConfig() (config *Config, err error) {
Expand Down
Loading
Loading