Compare commits

...

40 commits

Author SHA1 Message Date
8ef25a0720
Merge pull request '1.3.0: ci: add first forgejo ci #1' (#2) from #1 into main
All checks were successful
Release Workflow / set-release-target (push) Successful in 1s
Release Workflow / build (push) Successful in 2m15s
Reviewed-on: #2
2025-09-27 21:17:41 +00:00
dfce12b156
1.3.0: ci: add release ci
All checks were successful
Release Workflow / set-release-target (push) Successful in 1s
Test Pipeline / lint (pull_request) Successful in 2m32s
Release Workflow / build (push) Successful in 4m28s
Test Pipeline / ci-test (pull_request) Successful in 4m59s
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2025-09-27 22:37:04 +02:00
1992280022
1.3.0: code: fix close issue #1
All checks were successful
Test Pipeline / lint (pull_request) Successful in 2m11s
Test Pipeline / ci-test (pull_request) Successful in 3m41s
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2025-09-26 02:59:06 +02:00
98cdbaef90
1.3.0: ci: update lint params #1
All checks were successful
Test Pipeline / lint (pull_request) Successful in 2m26s
Test Pipeline / ci-test (pull_request) Successful in 3m52s
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2025-09-26 02:47:14 +02:00
3de726658f
1.3.0: go: add return check
Some checks failed
Test Pipeline / lint (pull_request) Failing after 40s
Test Pipeline / ci-test (pull_request) Successful in 4m32s
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2025-09-26 02:37:24 +02:00
fa9f3c490f
1.3.0: docker: update golang version
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2025-09-26 02:36:44 +02:00
e16d9ed188
1.3.0: ci: update with lint params
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2025-09-26 02:36:21 +02:00
5eddb8cec5
1.3.0: ci: add golang to forgejo
Some checks failed
Test Pipeline / lint (pull_request) Failing after 2m30s
Test Pipeline / ci-test (pull_request) Successful in 5m42s
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2025-09-26 02:22:09 +02:00
7f5a418f28
1.3.0: docker: mise au propre
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2025-09-26 02:21:47 +02:00
e80bf3abc3
1.3.0: ci: rollback change image #1
Some checks failed
Test Pipeline / lint (pull_request) Failing after 2m26s
Test Pipeline / ci-test (pull_request) Failing after 2m59s
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2025-09-26 02:13:19 +02:00
ce6b78d13e
1.3.0: ci: change to alpine image
Some checks failed
Test Pipeline / ci-test (pull_request) Failing after 38s
Test Pipeline / lint (pull_request) Failing after 1m24s
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2025-09-26 02:08:36 +02:00
66471df024
1.3.0: docker: update url link #1
Some checks failed
Test Pipeline / lint (pull_request) Failing after 2m23s
Test Pipeline / ci-test (pull_request) Failing after 2m44s
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2025-09-25 23:29:46 +02:00
feb4e93f03
1.3.0: ci: add container gestion #1
Some checks failed
Test Pipeline / ci-test (pull_request) Failing after 59s
Test Pipeline / lint (pull_request) Failing after 1m41s
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2025-09-25 23:24:14 +02:00
3f0a638266
1.3.0: ci: add test for the code #1
Some checks failed
Test Pipeline / ci-test (pull_request) Failing after 20s
Test Pipeline / lint (pull_request) Failing after 1m36s
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2025-09-25 23:21:10 +02:00
205902205f
1.3.0: ci: add first forgejo ci #1
Some checks failed
/ lint (pull_request) Failing after 1m21s
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2025-09-24 22:58:46 +02:00
de845830ef Merge branch '5-issue' into 'main'
Move struct to lib

Closes #5

See merge request h6n/users!14
2024-04-08 12:01:14 +00:00
b0c6a8e0f9
v1.3.0: back: use lib for the request data
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2024-04-08 13:56:25 +02:00
31da556505
v1.3.0: lib: add login struct in lib
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2024-04-08 13:55:22 +02:00
83d99310a6 Merge branch 'release-v1.2.0' into 'main'
release-v1.2.0

See merge request h6n/users!13
2024-04-01 19:34:44 +00:00
cee580b473
release-v1.2.0
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2024-04-01 21:30:58 +02:00
55deef8987 Merge branch '6-issue' into 'main'
Resolve "Define in README naming policy"

Closes #6

See merge request h6n/users!12
2024-04-01 19:26:21 +00:00
68c216c48a
v1.2.0: doc: add release list and naming policy
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2024-04-01 21:25:08 +02:00
51de27f294 Merge branch '9-issue' into 'main'
Resolve "add health path in lib"

Closes #9

See merge request h6n/users!11
2024-04-01 17:53:34 +00:00
d31f7d4e0a
v1.2.0: back: use health lib path
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2024-04-01 19:49:33 +02:00
1f9d3847e0
v1.2.0: lib: add health path
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2024-04-01 19:49:02 +02:00
6e8f65223c Merge branch '10-issue' into 'main'
add health skip function in lib

Closes #10

See merge request h6n/users!10
2024-04-01 17:35:08 +00:00
0ad1626bdb
v1.2.0: back: use health skip from lib
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2024-04-01 19:31:01 +02:00
41563e9256
v1.2.0: back: rename health path
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2024-04-01 19:30:18 +02:00
821fc8c3d9
v1.2.0: lib: add health lib
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2024-04-01 19:29:29 +02:00
3f3fe2ecac Merge branch '7-issue' into 'main'
Resolve "fix name in release"

Closes #7

See merge request h6n/users!9
2024-04-01 15:32:35 +00:00
2cc564c420
v1.2.0: ci: rename job
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2024-04-01 17:26:59 +02:00
5d0c415ac6 Merge branch '8-issue' into 'main'
Change database construct

Closes #8

See merge request h6n/users!8
2024-03-30 23:15:47 +00:00
2ee18b5d93
v1.2.0: back: remove all db intel
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2024-03-31 00:09:20 +01:00
8f3d9da55e
v1.2.0: back: use gorm in login
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2024-03-31 00:06:53 +01:00
a2288ec90a
v1.2.0: back: use gorm in code
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2024-03-31 00:06:52 +01:00
0695062ad7
v1.2.0: take var and return gorm.db
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2024-03-31 00:06:52 +01:00
82a057f131
v1.2.0: back: add DropUnusedColumns
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2024-03-31 00:06:51 +01:00
b7e44e85af
v1.2.0: remove test from gorm
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2024-03-31 00:06:50 +01:00
8861c369cc
v1.2.0: back: first use of gorm for the database
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2024-03-30 11:07:41 +01:00
ba64038d70 Merge branch 'release-v1.1.0' into 'main'
release-v1.1.0

See merge request h6n/users!7
2024-03-20 19:52:17 +00:00
19 changed files with 322 additions and 63 deletions

View file

@ -0,0 +1,75 @@
name: Release Workflow
on:
push:
tags:
- '*'
branches:
- main
jobs:
set-release-target:
runs-on: docker
outputs:
release_cible: ${{ steps.setvar.outputs.release_cible }}
steps:
- name: Déterminer la release cible
id: setvar
run: |
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
TAG="${GITHUB_REF#refs/tags/}"
echo "release_cible=$TAG" >> $GITHUB_OUTPUT
elif [[ "${GITHUB_REF}" == "refs/heads/main" ]]; then
echo "release_cible=latest" >> $GITHUB_OUTPUT
else
echo "release_cible=unknown" >> $GITHUB_OUTPUT
fi
- name: Afficher la variable
run: echo "Release cible = ${{ steps.setvar.outputs.release_cible }}"
build:
runs-on: raw
container:
options: --privileged -v /var/run/docker.sock:/var/run/docker.sock
needs: set-release-target
steps:
- name: Check out repository
uses: actions/checkout@v3
- name: Install docker-cli
run: |
apt-get update
apt-get install -y ca-certificates curl
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
chmod a+r /etc/apt/keyrings/docker.asc
# Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
tee /etc/apt/sources.list.d/docker.list > /dev/null
apt-get update
apt-get install -y docker-ce-cli
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login docker registry
uses: docker/login-action@v2
with:
username: ${{ forge.ACTOR }}
password: ${{ secrets.PACKAGE }}
registry: ${{ forge.SERVER_URL }}
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: git.g3e.fr/h6n/users:${{ needs.set-release-target.outputs.release_cible }}
target: release

View file

@ -0,0 +1,70 @@
name: Test Pipeline
on:
pull_request:
types: [opened, synchronize]
jobs:
lint:
runs-on: raw
steps:
- name: Check out repository
uses: actions/checkout@v3
- name: Setup golang
uses: actions/setup-go@v5
with:
go-version: "1.21"
- name: golangci-lint
uses: https://github.com/golangci/golangci-lint-action@v8
with:
version: v2.1
args: --issues-exit-code 0
ci-test:
runs-on: raw
container:
options: --privileged -v /var/run/docker.sock:/var/run/docker.sock
steps:
- name: Check out repository
uses: actions/checkout@v3
- name: Install docker-cli
run: |
apt-get update
apt-get install -y ca-certificates curl
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
chmod a+r /etc/apt/keyrings/docker.asc
# Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
tee /etc/apt/sources.list.d/docker.list > /dev/null
apt-get update
apt-get install -y docker-ce-cli
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Setup golang
uses: actions/setup-go@v5
with:
go-version: "1.24"
- name: Build image
run: |
docker build --pull -t users-release --target release .
- name: Run Test
run: |
bash -ex ./scripts/prepar_test.sh
. ./config/test.src
go test -v ./cmd/
go install gotest.tools/gotestsum@latest
gotestsum --junitfile report.xml --format testname

View file

@ -95,7 +95,7 @@ release-latest:
- build - build
- integration_test - integration_test
release-front: release:
stage: release stage: release
image: docker:23.0.3-cli image: docker:23.0.3-cli
variables: variables:

View file

@ -1,11 +1,12 @@
FROM golang:1.21-alpine AS develop FROM golang:1.24-alpine AS develop
# Changement du répertoire de travail # Changement du répertoire de travail
WORKDIR / WORKDIR /
RUN apk update && apk add --no-cache curl tar && \ RUN apk update && apk add --no-cache curl tar && \
curl -O https://gitlab.g3e.fr/api/v4/projects/34/packages/generic/minicurl/v1.0.0/minicurl_linux_amd64.tar.gz && \ curl -OJ https://git.g3e.fr/api/packages/H6N/generic/minicurl/1.1.0/minicurl-linux-amd64 && \
tar xzvf minicurl_linux_amd64.tar.gz mv minicurl-linux-amd64 minicurl && \
chmod +x ./minicurl
# Changement du répertoire de travail # Changement du répertoire de travail
WORKDIR /app WORKDIR /app

View file

@ -8,7 +8,7 @@ Has this project is in H6N global project his requirement will first meet H6N ne
## Version ## Version
v1.1.0: Fer v1.2.0: Helium
## Developpement ## Developpement

View file

@ -5,6 +5,7 @@ import (
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
logins "gitlab.g3e.fr/h6n/users/internal" logins "gitlab.g3e.fr/h6n/users/internal"
login_lib "gitlab.g3e.fr/h6n/users/lib/login"
) )
// Login // Login
@ -16,12 +17,12 @@ import (
// @Param request body logins.RequestLogin true "request body" // @Param request body logins.RequestLogin true "request body"
// @Success 200 {object} logins.ResponseLogin // @Success 200 {object} logins.ResponseLogin
func login(c echo.Context) error { func login(c echo.Context) error {
var request logins.RequestLogin var request login_lib.RequestLogin
if err := c.Bind(&request); err != nil { if err := c.Bind(&request); err != nil {
return c.JSON(http.StatusBadRequest, err) return c.JSON(http.StatusBadRequest, err)
} }
if response, err := logins.CreateLogin(db, request); err != nil { if response, err := logins.CreateLogin(dbGor, request); err != nil {
return c.JSON(http.StatusBadRequest, "Not a valide user username or password") return c.JSON(http.StatusBadRequest, "Not a valide user username or password")
} else { } else {
return c.JSON(http.StatusOK, response) return c.JSON(http.StatusOK, response)

View file

@ -7,15 +7,16 @@ import (
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware" "github.com/labstack/echo/v4/middleware"
echoSwagger "github.com/swaggo/echo-swagger" echoSwagger "github.com/swaggo/echo-swagger"
logins "gitlab.g3e.fr/h6n/users/internal"
"gitlab.g3e.fr/h6n/users/lib" "gitlab.g3e.fr/h6n/users/lib"
"gitlab.g3e.fr/h6n/users/lib/health"
"database/sql" "gorm.io/gorm"
_ "github.com/lib/pq" _ "github.com/lib/pq"
_ "gitlab.g3e.fr/h6n/users/cmd/docs" _ "gitlab.g3e.fr/h6n/users/cmd/docs"
) )
var db *sql.DB = nil var dbGor *gorm.DB = nil
// Logout // Logout
// @Tags auth // @Tags auth
@ -39,16 +40,12 @@ func isLoggedIn(c echo.Context) error {
return c.NoContent(http.StatusNoContent) return c.NoContent(http.StatusNoContent)
} }
func health(c echo.Context) error {
return c.NoContent(http.StatusOK)
}
func init_database() { func init_database() {
var err error var err error
connStr := "postgres://acc:totor@postgres:5432/accounts?sslmode=disable" connStr := "postgres://acc:totor@postgres:5432/accounts?sslmode=disable"
db, err = sql.Open("postgres", connStr) dbGor, err = logins.Init_database(connStr)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }
@ -58,20 +55,14 @@ func skip_auth(c echo.Context) bool {
if c.Request().Method == "POST" && c.Path() == "/" { if c.Request().Method == "POST" && c.Path() == "/" {
return true return true
} }
if c.Request().Method == "GET" && c.Path() == "/health" {
return true
}
if len(c.Path()) > 9 && c.Path()[:9] == "/swagger/" { if len(c.Path()) > 9 && c.Path()[:9] == "/swagger/" {
return true return true
} }
return false return health.IsHealth(c)
} }
func skip_log(c echo.Context) bool { func skip_log(c echo.Context) bool {
if c.Request().Method == "GET" && c.Path() == "/health" { return health.IsHealth(c)
return true
}
return false
} }
// @title Users // @title Users
@ -109,7 +100,7 @@ func main() {
e.GET("/", isLoggedIn) e.GET("/", isLoggedIn)
e.POST("/", login) e.POST("/", login)
e.DELETE("/", logout) e.DELETE("/", logout)
e.GET("/health", health) e.GET("/health", health.Health)
e.GET("/swagger/*", echoSwagger.WrapHandler) e.GET("/swagger/*", echoSwagger.WrapHandler)
// Start server // Start server

View file

@ -1,7 +1 @@
CREATE TABLE users (
username TEXT PRIMARY KEY,
email TEXT UNIQUE NOT NULL,
password TEXT NOT NULL
);
INSERT INTO users(username, email, password) VALUES('0000000023', 'root@root.fr', '$2a$14$FU8FKR7pUq4akLThraD9kOu0zY0BuUFASo0xakgWEWbYF2gz20DuG'); INSERT INTO users(username, email, password) VALUES('0000000023', 'root@root.fr', '$2a$14$FU8FKR7pUq4akLThraD9kOu0zY0BuUFASo0xakgWEWbYF2gz20DuG');

10
docs/release.md Normal file
View file

@ -0,0 +1,10 @@
# Release
## Naming policy
The naming policy is based on the [periodique table](https://fr.wikipedia.org/wiki/Tableau_p%C3%A9riodique_des_%C3%A9l%C3%A9ments#/media/Fichier:Tableau_p%C3%A9riodique_des_%C3%A9l%C3%A9ments.svg) for this project.
## Release list
- [v1.0.0 Helixire](./release/v1.0.0_damian.md)
- [v1.1.0 Fer](./release/v1.1.0_fer.md)

View file

@ -0,0 +1,9 @@
# Helium v1.2.0
## Release feature
- Add naming policy
- Add health skip in lib
- Add health path in lib
- Fix ci name for release job
- Change database usage, use Gorm

7
go.mod
View file

@ -15,6 +15,11 @@ require (
github.com/go-openapi/spec v0.21.0 // indirect github.com/go-openapi/spec v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect github.com/go-openapi/swag v0.23.0 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/pgx/v5 v5.4.3 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/josharian/intern v1.0.0 // indirect github.com/josharian/intern v1.0.0 // indirect
github.com/labstack/echo/v4 v4.11.4 // indirect github.com/labstack/echo/v4 v4.11.4 // indirect
github.com/labstack/gommon v0.4.2 // indirect github.com/labstack/gommon v0.4.2 // indirect
@ -39,5 +44,7 @@ require (
google.golang.org/protobuf v1.31.0 // indirect google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/driver/postgres v1.5.7 // indirect
gorm.io/gorm v1.25.9 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect sigs.k8s.io/yaml v1.3.0 // indirect
) )

15
go.sum
View file

@ -40,6 +40,16 @@ github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keL
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I= github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk=
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
github.com/jackc/pgx/v5 v5.4.3 h1:cxFyXhxlvAifxnkKKdlxv8XqUf59tDlYjnV5YYfsJJY=
github.com/jackc/pgx/v5 v5.4.3/go.mod h1:Ig06C2Vu0t5qXC60W8sqIthScaEnFvojjj9dSljmHRA=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
@ -72,6 +82,7 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeV
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/swaggo/echo-swagger v1.4.1 h1:Yf0uPaJWp1uRtDloZALyLnvdBeoEL5Kc7DtnjzO/TUk= github.com/swaggo/echo-swagger v1.4.1 h1:Yf0uPaJWp1uRtDloZALyLnvdBeoEL5Kc7DtnjzO/TUk=
github.com/swaggo/echo-swagger v1.4.1/go.mod h1:C8bSi+9yH2FLZsnhqMZLIZddpUxZdBYuNHbtaS1Hljc= github.com/swaggo/echo-swagger v1.4.1/go.mod h1:C8bSi+9yH2FLZsnhqMZLIZddpUxZdBYuNHbtaS1Hljc=
github.com/swaggo/files/v2 v2.0.0 h1:hmAt8Dkynw7Ssz46F6pn8ok6YmGZqHSVLZ+HQM7i0kw= github.com/swaggo/files/v2 v2.0.0 h1:hmAt8Dkynw7Ssz46F6pn8ok6YmGZqHSVLZ+HQM7i0kw=
@ -128,5 +139,9 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/driver/postgres v1.5.7 h1:8ptbNJTDbEmhdr62uReG5BGkdQyeasu/FZHxI0IMGnM=
gorm.io/driver/postgres v1.5.7/go.mod h1:3e019WlBaYI5o5LIdNV+LyxCMNtLOQETBXL2h4chKpA=
gorm.io/gorm v1.25.9 h1:wct0gxZIELDk8+ZqF/MVnHLkA1rvYlBWUMv2EdsK1g8=
gorm.io/gorm v1.25.9/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo= sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8= sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=

View file

@ -1,7 +1,6 @@
package logins package logins
import ( import (
"database/sql"
"encoding/base64" "encoding/base64"
"encoding/hex" "encoding/hex"
"errors" "errors"
@ -10,7 +9,9 @@ import (
"github.com/biscuit-auth/biscuit-go/v2" "github.com/biscuit-auth/biscuit-go/v2"
"github.com/biscuit-auth/biscuit-go/v2/parser" "github.com/biscuit-auth/biscuit-go/v2/parser"
"gitlab.g3e.fr/h6n/users/lib" "gitlab.g3e.fr/h6n/users/lib"
login_lib "gitlab.g3e.fr/h6n/users/lib/login"
"golang.org/x/crypto/bcrypt" "golang.org/x/crypto/bcrypt"
"gorm.io/gorm"
) )
func CheckPasswordHash(password, hash string) bool { func CheckPasswordHash(password, hash string) bool {
@ -18,20 +19,14 @@ func CheckPasswordHash(password, hash string) bool {
return err == nil return err == nil
} }
func CreateLogin(db *sql.DB, request RequestLogin) (ResponseLogin, error) { func CreateLogin(db *gorm.DB, request login_lib.RequestLogin) (login_lib.ResponseLogin, error) {
type ( var response login_lib.ResponseLogin
User struct {
Username string
EncryptedPassword string
}
)
var user User
var response ResponseLogin
if err := db.QueryRow("SELECT username, password FROM users WHERE email = $1", request.Username).Scan(&user.Username, &user.EncryptedPassword); err != nil { var user = Users{Email: request.Username}
return response, err if err := db.First(&user); err.Error != nil {
return response, err.Error
} }
if !CheckPasswordHash(request.Password, user.EncryptedPassword) { if !CheckPasswordHash(request.Password, user.Password) {
return response, errors.ErrUnsupported return response, errors.ErrUnsupported
} }
now := time.Now() now := time.Now()

50
internal/databases.go Normal file
View file

@ -0,0 +1,50 @@
package logins
import (
"gorm.io/driver/postgres"
"gorm.io/gorm"
)
type Users struct {
Username string `gorm:"primaryKey"`
Email string `gorm:"unique:users_email_key"`
Password string `gorm:""`
}
func DropUnusedColumns(DB *gorm.DB, values ...interface{}) {
for _, dst := range values {
stmt := &gorm.Statement{DB: DB}
if stmt.Parse(dst) != nil {
return
}
fields := stmt.Schema.Fields
columns, _ := DB.Debug().Migrator().ColumnTypes(dst)
for i := range columns {
found := false
for j := range fields {
if columns[i].Name() == fields[j].DBName {
found = true
break
}
}
if !found {
if DB.Migrator().DropColumn(dst, columns[i].Name()) != nil {
return
}
}
}
}
}
func Init_database(dsn string) (*gorm.DB, error) {
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
if err != nil {
return db, err
}
_ = db.AutoMigrate(&Users{})
DropUnusedColumns(db, &Users{})
return db, nil
}

10
lib/health/isHealth.go Normal file
View file

@ -0,0 +1,10 @@
package health
import "github.com/labstack/echo/v4"
func IsHealth(c echo.Context) bool {
if c.Request().Method == "GET" && c.Path() == "/health" {
return true
}
return false
}

11
lib/health/status.go Normal file
View file

@ -0,0 +1,11 @@
package health
import (
"net/http"
"github.com/labstack/echo/v4"
)
func Health(c echo.Context) error {
return c.NoContent(http.StatusOK)
}

View file

@ -3,6 +3,7 @@ package lib
import ( import (
"crypto/ed25519" "crypto/ed25519"
"crypto/rand" "crypto/rand"
"fmt"
"io" "io"
"os" "os"
"time" "time"
@ -22,7 +23,12 @@ func InitLoginBiscuit() error {
if file, err := os.Create(filePrivateKey); err != nil { if file, err := os.Create(filePrivateKey); err != nil {
return err return err
} else { } else {
defer file.Close() defer func() {
if cerr := file.Close(); cerr != nil {
// ici tu peux logger ou faire quelque chose
fmt.Printf("Erreur à la fermeture: %v\n", cerr)
}
}()
if _, err = io.WriteString(file, string(PrivateKey)); err != nil { if _, err = io.WriteString(file, string(PrivateKey)); err != nil {
return err return err
@ -34,7 +40,12 @@ func InitLoginBiscuit() error {
if file, err := os.Create(filePublicKey); err != nil { if file, err := os.Create(filePublicKey); err != nil {
return err return err
} else { } else {
defer file.Close() defer func() {
if cerr := file.Close(); cerr != nil {
// ici tu peux logger ou faire quelque chose
fmt.Printf("Erreur à la fermeture: %v\n", cerr)
}
}()
if _, err = io.WriteString(file, string(PublicKey)); err != nil { if _, err = io.WriteString(file, string(PublicKey)); err != nil {
return err return err
@ -47,7 +58,12 @@ func InitLoginBiscuit() error {
if file, err := os.Open(filePrivateKey); err != nil { if file, err := os.Open(filePrivateKey); err != nil {
return err return err
} else { } else {
defer file.Close() defer func() {
if cerr := file.Close(); cerr != nil {
// ici tu peux logger ou faire quelque chose
fmt.Printf("Erreur à la fermeture: %v\n", cerr)
}
}()
PrivateKey, err = io.ReadAll(file) PrivateKey, err = io.ReadAll(file)
if err != nil { if err != nil {
@ -57,7 +73,12 @@ func InitLoginBiscuit() error {
if file, err := os.Open(filePublicKey); err != nil { if file, err := os.Open(filePublicKey); err != nil {
return err return err
} else { } else {
defer file.Close() defer func() {
if cerr := file.Close(); cerr != nil {
// ici tu peux logger ou faire quelque chose
fmt.Printf("Erreur à la fermeture: %v\n", cerr)
}
}()
PublicKey, err = io.ReadAll(file) PublicKey, err = io.ReadAll(file)
if err != nil { if err != nil {
@ -86,7 +107,12 @@ func InitGlobalBiscuit() error {
if file, err := os.Open(filePrivateKey); err != nil { if file, err := os.Open(filePrivateKey); err != nil {
return err return err
} else { } else {
defer file.Close() defer func() {
if cerr := file.Close(); cerr != nil {
// ici tu peux logger ou faire quelque chose
fmt.Printf("Erreur à la fermeture: %v\n", cerr)
}
}()
PrivateKey, err = io.ReadAll(file) PrivateKey, err = io.ReadAll(file)
if err != nil { if err != nil {
@ -96,7 +122,12 @@ func InitGlobalBiscuit() error {
if file, err := os.Open(filePublicKey); err != nil { if file, err := os.Open(filePublicKey); err != nil {
return err return err
} else { } else {
defer file.Close() defer func() {
if cerr := file.Close(); cerr != nil {
// ici tu peux logger ou faire quelque chose
fmt.Printf("Erreur à la fermeture: %v\n", cerr)
}
}()
PublicKey, err = io.ReadAll(file) PublicKey, err = io.ReadAll(file)
if err != nil { if err != nil {

View file

@ -1,4 +1,4 @@
package logins package login_lib
type ( type (
// RequestLogin model info // RequestLogin model info

View file

@ -1,20 +1,9 @@
#!/bin/bash #!/bin/bash
cat <<ENDFILE >> /etc/apk/repositories
http://ftp.halifax.rwth-aachen.de/alpine/v3.16/main
http://ftp.halifax.rwth-aachen.de/alpine/v3.16/community
ENDFILE
apk update
apk add docker docker-cli-compose
docker version docker version
docker compose version docker compose version
docker load --input "$IMAGE_TYPE-$IMAGE_VERSION-release.tar.gz"
docker tag $CI_REGISTRY_IMAGE:$IMAGE_VERSION-release $IMAGE_TYPE:latest
cat <<ENDFILE > docker-compose.yml
version: '3.1'
cat <<ENDFILE > compose.yml
services: services:
postgres: postgres:
image: postgres:15.2-alpine3.17 image: postgres:15.2-alpine3.17
@ -29,7 +18,7 @@ services:
timeout: 5s timeout: 5s
retries: 5 retries: 5
users: users:
image: $IMAGE_TYPE image: users-release
volumes: volumes:
- ./docker/keys:/keys - ./docker/keys:/keys
depends_on: depends_on: