Compare commits
51 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
8ef25a0720 |
|||
|
dfce12b156 |
|||
|
1992280022 |
|||
|
98cdbaef90 |
|||
|
3de726658f |
|||
|
fa9f3c490f |
|||
|
e16d9ed188 |
|||
|
5eddb8cec5 |
|||
|
7f5a418f28 |
|||
|
e80bf3abc3 |
|||
|
ce6b78d13e |
|||
|
66471df024 |
|||
|
feb4e93f03 |
|||
|
3f0a638266 |
|||
|
205902205f |
|||
| de845830ef | |||
|
b0c6a8e0f9 |
|||
|
31da556505 |
|||
| 83d99310a6 | |||
|
cee580b473 |
|||
| 55deef8987 | |||
|
68c216c48a |
|||
| 51de27f294 | |||
|
d31f7d4e0a |
|||
|
1f9d3847e0 |
|||
| 6e8f65223c | |||
|
0ad1626bdb |
|||
|
41563e9256 |
|||
|
821fc8c3d9 |
|||
| 3f3fe2ecac | |||
|
2cc564c420 |
|||
| 5d0c415ac6 | |||
|
2ee18b5d93 |
|||
|
8f3d9da55e |
|||
|
a2288ec90a |
|||
|
0695062ad7 |
|||
|
82a057f131 |
|||
|
b7e44e85af |
|||
|
8861c369cc |
|||
| ba64038d70 | |||
|
f75519fa91 |
|||
| f65131cce4 | |||
|
c38375eb2b |
|||
|
ee4e2e3e31 |
|||
| da4f296b5e | |||
|
fc3ef55c80 |
|||
|
6675a35088 |
|||
| c30cdc7bfa | |||
|
8483d7631a |
|||
|
5cd2f11306 |
|||
| 6a9c1f2ae3 |
24 changed files with 841 additions and 69 deletions
75
.forgejo/workflows/release.yml
Normal file
75
.forgejo/workflows/release.yml
Normal 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
|
||||
70
.forgejo/workflows/test.yml
Normal file
70
.forgejo/workflows/test.yml
Normal 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
|
||||
|
|
@ -29,8 +29,9 @@ lint:
|
|||
image: golangci/golangci-lint:$GOLANGCI_LINT_VERSION
|
||||
stage: check
|
||||
before_script: []
|
||||
services: []
|
||||
script:
|
||||
- golangci-lint run --issues-exit-code 1 --print-issued-lines=false --out-format code-climate:gl-code-quality-report.json,line-number
|
||||
- golangci-lint run --issues-exit-code 0 --out-format code-climate | tee gl-code-quality-report.json
|
||||
artifacts:
|
||||
reports:
|
||||
codequality: gl-code-quality-report.json
|
||||
|
|
@ -70,6 +71,8 @@ integration_test:
|
|||
- 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
|
||||
needs:
|
||||
- build
|
||||
|
||||
|
|
@ -92,11 +95,10 @@ release-latest:
|
|||
- build
|
||||
- integration_test
|
||||
|
||||
release-front:
|
||||
release:
|
||||
stage: release
|
||||
image: docker:23.0.3-cli
|
||||
variables:
|
||||
IMAGE_TYPE: front
|
||||
DOCKER_TLS_VERIFY: 1
|
||||
DOCKER_CERT_PATH: /certs/client
|
||||
script:
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
FROM golang:1.21-alpine AS develop
|
||||
FROM golang:1.24-alpine AS develop
|
||||
|
||||
# Changement du répertoire de travail
|
||||
WORKDIR /
|
||||
|
||||
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 && \
|
||||
tar xzvf minicurl_linux_amd64.tar.gz
|
||||
curl -OJ https://git.g3e.fr/api/packages/H6N/generic/minicurl/1.1.0/minicurl-linux-amd64 && \
|
||||
mv minicurl-linux-amd64 minicurl && \
|
||||
chmod +x ./minicurl
|
||||
|
||||
# Changement du répertoire de travail
|
||||
WORKDIR /app
|
||||
|
|
|
|||
|
|
@ -8,13 +8,19 @@ Has this project is in H6N global project his requirement will first meet H6N ne
|
|||
|
||||
## Version
|
||||
|
||||
v1.0.0: Helixire
|
||||
v1.2.0: Helium
|
||||
|
||||
## Developpement
|
||||
|
||||
- Golang
|
||||
- Docker
|
||||
|
||||
### generate swagger
|
||||
|
||||
```bash
|
||||
swag init --parseInternal --generalInfo ./cmd/main.go --output ./cmd/docs/
|
||||
```
|
||||
|
||||
### with docker compose
|
||||
|
||||
```bash
|
||||
|
|
|
|||
146
cmd/docs/docs.go
Normal file
146
cmd/docs/docs.go
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
// Package docs Code generated by swaggo/swag. DO NOT EDIT
|
||||
package docs
|
||||
|
||||
import "github.com/swaggo/swag"
|
||||
|
||||
const docTemplate = `{
|
||||
"schemes": {{ marshal .Schemes }},
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"description": "{{escape .Description}}",
|
||||
"title": "{{.Title}}",
|
||||
"termsOfService": "http://swagger.io/terms/",
|
||||
"contact": {
|
||||
"name": "API Support",
|
||||
"url": "http://www.swagger.io/support",
|
||||
"email": "support@swagger.io"
|
||||
},
|
||||
"license": {
|
||||
"name": "Apache 2.0",
|
||||
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
|
||||
},
|
||||
"version": "{{.Version}}"
|
||||
},
|
||||
"host": "{{.Host}}",
|
||||
"basePath": "{{.BasePath}}",
|
||||
"paths": {
|
||||
"/": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"description": "Cette route de verifier que le token est toujours valide",
|
||||
"tags": [
|
||||
"auth"
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"post": {
|
||||
"description": "Cette route permet d'obtenir un token user",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"auth"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"description": "request body",
|
||||
"name": "request",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/logins.RequestLogin"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/logins.ResponseLogin"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"delete": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"description": "Cette route permet de revoker sont token",
|
||||
"tags": [
|
||||
"auth"
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"logins.RequestLogin": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"password": {
|
||||
"type": "string"
|
||||
},
|
||||
"username": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"logins.ResponseLogin": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"publickey": {
|
||||
"type": "string"
|
||||
},
|
||||
"token": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"securityDefinitions": {
|
||||
"ApiKeyAuth": {
|
||||
"description": "Enter the token with the ` + "`" + `Bearer: ` + "`" + ` prefix, e.g. \"Bearer abcde12345\".",
|
||||
"type": "apiKey",
|
||||
"name": "Authorization",
|
||||
"in": "header"
|
||||
}
|
||||
}
|
||||
}`
|
||||
|
||||
// SwaggerInfo holds exported Swagger Info so clients can modify it
|
||||
var SwaggerInfo = &swag.Spec{
|
||||
Version: "1.0",
|
||||
Host: "",
|
||||
BasePath: "",
|
||||
Schemes: []string{},
|
||||
Title: "Users",
|
||||
Description: "",
|
||||
InfoInstanceName: "swagger",
|
||||
SwaggerTemplate: docTemplate,
|
||||
LeftDelim: "{{",
|
||||
RightDelim: "}}",
|
||||
}
|
||||
|
||||
func init() {
|
||||
swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo)
|
||||
}
|
||||
119
cmd/docs/swagger.json
Normal file
119
cmd/docs/swagger.json
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
{
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"title": "Users",
|
||||
"termsOfService": "http://swagger.io/terms/",
|
||||
"contact": {
|
||||
"name": "API Support",
|
||||
"url": "http://www.swagger.io/support",
|
||||
"email": "support@swagger.io"
|
||||
},
|
||||
"license": {
|
||||
"name": "Apache 2.0",
|
||||
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
|
||||
},
|
||||
"version": "1.0"
|
||||
},
|
||||
"paths": {
|
||||
"/": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"description": "Cette route de verifier que le token est toujours valide",
|
||||
"tags": [
|
||||
"auth"
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"post": {
|
||||
"description": "Cette route permet d'obtenir un token user",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"auth"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"description": "request body",
|
||||
"name": "request",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/logins.RequestLogin"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/logins.ResponseLogin"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"delete": {
|
||||
"security": [
|
||||
{
|
||||
"ApiKeyAuth": []
|
||||
}
|
||||
],
|
||||
"description": "Cette route permet de revoker sont token",
|
||||
"tags": [
|
||||
"auth"
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"logins.RequestLogin": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"password": {
|
||||
"type": "string"
|
||||
},
|
||||
"username": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"logins.ResponseLogin": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"publickey": {
|
||||
"type": "string"
|
||||
},
|
||||
"token": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"securityDefinitions": {
|
||||
"ApiKeyAuth": {
|
||||
"description": "Enter the token with the `Bearer: ` prefix, e.g. \"Bearer abcde12345\".",
|
||||
"type": "apiKey",
|
||||
"name": "Authorization",
|
||||
"in": "header"
|
||||
}
|
||||
}
|
||||
}
|
||||
75
cmd/docs/swagger.yaml
Normal file
75
cmd/docs/swagger.yaml
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
definitions:
|
||||
logins.RequestLogin:
|
||||
properties:
|
||||
password:
|
||||
type: string
|
||||
username:
|
||||
type: string
|
||||
type: object
|
||||
logins.ResponseLogin:
|
||||
properties:
|
||||
publickey:
|
||||
type: string
|
||||
token:
|
||||
type: string
|
||||
type: object
|
||||
info:
|
||||
contact:
|
||||
email: support@swagger.io
|
||||
name: API Support
|
||||
url: http://www.swagger.io/support
|
||||
license:
|
||||
name: Apache 2.0
|
||||
url: http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
termsOfService: http://swagger.io/terms/
|
||||
title: Users
|
||||
version: "1.0"
|
||||
paths:
|
||||
/:
|
||||
delete:
|
||||
description: Cette route permet de revoker sont token
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
type: string
|
||||
security:
|
||||
- ApiKeyAuth: []
|
||||
tags:
|
||||
- auth
|
||||
get:
|
||||
description: Cette route de verifier que le token est toujours valide
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
type: string
|
||||
security:
|
||||
- ApiKeyAuth: []
|
||||
tags:
|
||||
- auth
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: Cette route permet d'obtenir un token user
|
||||
parameters:
|
||||
- description: request body
|
||||
in: body
|
||||
name: request
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/logins.RequestLogin'
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/logins.ResponseLogin'
|
||||
tags:
|
||||
- auth
|
||||
securityDefinitions:
|
||||
ApiKeyAuth:
|
||||
description: 'Enter the token with the `Bearer: ` prefix, e.g. "Bearer abcde12345".'
|
||||
in: header
|
||||
name: Authorization
|
||||
type: apiKey
|
||||
swagger: "2.0"
|
||||
13
cmd/login.go
13
cmd/login.go
|
|
@ -5,15 +5,24 @@ import (
|
|||
|
||||
"github.com/labstack/echo/v4"
|
||||
logins "gitlab.g3e.fr/h6n/users/internal"
|
||||
login_lib "gitlab.g3e.fr/h6n/users/lib/login"
|
||||
)
|
||||
|
||||
// Login
|
||||
// @Tags auth
|
||||
// @Description Cette route permet d'obtenir un token user
|
||||
// @Accept json
|
||||
// @Product json
|
||||
// @Router / [post]
|
||||
// @Param request body logins.RequestLogin true "request body"
|
||||
// @Success 200 {object} logins.ResponseLogin
|
||||
func login(c echo.Context) error {
|
||||
var request logins.RequestLogin
|
||||
var request login_lib.RequestLogin
|
||||
if err := c.Bind(&request); err != nil {
|
||||
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")
|
||||
} else {
|
||||
return c.JSON(http.StatusOK, response)
|
||||
|
|
|
|||
56
cmd/main.go
56
cmd/main.go
|
|
@ -6,33 +6,46 @@ import (
|
|||
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/labstack/echo/v4/middleware"
|
||||
echoSwagger "github.com/swaggo/echo-swagger"
|
||||
logins "gitlab.g3e.fr/h6n/users/internal"
|
||||
"gitlab.g3e.fr/h6n/users/lib"
|
||||
|
||||
"database/sql"
|
||||
"gitlab.g3e.fr/h6n/users/lib/health"
|
||||
"gorm.io/gorm"
|
||||
|
||||
_ "github.com/lib/pq"
|
||||
_ "gitlab.g3e.fr/h6n/users/cmd/docs"
|
||||
)
|
||||
|
||||
var db *sql.DB = nil
|
||||
var dbGor *gorm.DB = nil
|
||||
|
||||
// Logout
|
||||
// @Tags auth
|
||||
// @Description Cette route permet de revoker sont token
|
||||
// @Product json
|
||||
// @Router / [delete]
|
||||
// @Success 200 {object} string
|
||||
// @Security ApiKeyAuth
|
||||
func logout(c echo.Context) error {
|
||||
return c.NoContent(http.StatusNoContent)
|
||||
}
|
||||
|
||||
// Logout
|
||||
// @Tags auth
|
||||
// @Description Cette route de verifier que le token est toujours valide
|
||||
// @Product json
|
||||
// @Router / [get]
|
||||
// @Success 200 {object} string
|
||||
// @Security ApiKeyAuth
|
||||
func isLoggedIn(c echo.Context) error {
|
||||
return c.NoContent(http.StatusNoContent)
|
||||
}
|
||||
|
||||
func health(c echo.Context) error {
|
||||
return c.NoContent(http.StatusOK)
|
||||
}
|
||||
|
||||
func init_database() {
|
||||
var err error
|
||||
|
||||
connStr := "postgres://acc:totor@postgres:5432/accounts?sslmode=disable"
|
||||
|
||||
db, err = sql.Open("postgres", connStr)
|
||||
dbGor, err = logins.Init_database(connStr)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
|
@ -42,19 +55,31 @@ func skip_auth(c echo.Context) bool {
|
|||
if c.Request().Method == "POST" && c.Path() == "/" {
|
||||
return true
|
||||
}
|
||||
if c.Request().Method == "GET" && c.Path() == "/health" {
|
||||
if len(c.Path()) > 9 && c.Path()[:9] == "/swagger/" {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
return health.IsHealth(c)
|
||||
}
|
||||
|
||||
func skip_log(c echo.Context) bool {
|
||||
if c.Request().Method == "GET" && c.Path() == "/health" {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
return health.IsHealth(c)
|
||||
}
|
||||
|
||||
// @title Users
|
||||
// @version 1.0
|
||||
// @termsOfService http://swagger.io/terms/
|
||||
|
||||
// @contact.name API Support
|
||||
// @contact.url http://www.swagger.io/support
|
||||
// @contact.email support@swagger.io
|
||||
|
||||
// @license.name Apache 2.0
|
||||
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
|
||||
// @securityDefinitions.apikey ApiKeyAuth
|
||||
// @in header
|
||||
// @name Authorization
|
||||
// @description Enter the token with the `Bearer: ` prefix, e.g. "Bearer abcde12345".
|
||||
func main() {
|
||||
init_database()
|
||||
if err := lib.InitLoginBiscuit(); err != nil {
|
||||
|
|
@ -75,7 +100,8 @@ func main() {
|
|||
e.GET("/", isLoggedIn)
|
||||
e.POST("/", login)
|
||||
e.DELETE("/", logout)
|
||||
e.GET("/health", health)
|
||||
e.GET("/health", health.Health)
|
||||
e.GET("/swagger/*", echoSwagger.WrapHandler)
|
||||
|
||||
// Start server
|
||||
e.Logger.Fatal(e.Start(":1222"))
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
10
docs/release.md
Normal file
10
docs/release.md
Normal 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)
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
# Helixire v1.0.0
|
||||
# Helixire v1.0.1
|
||||
|
||||
## Release feature
|
||||
|
||||
- ...
|
||||
- ...
|
||||
- import login from accounts
|
||||
- add personnal healthcheck
|
||||
|
|
|
|||
6
docs/release/v1.1.0_fer.md
Normal file
6
docs/release/v1.1.0_fer.md
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
# Fer v1.1.0
|
||||
|
||||
## Release feature
|
||||
|
||||
- add swagger api
|
||||
- add code quality test
|
||||
9
docs/release/v1.2.0_helium.md
Normal file
9
docs/release/v1.2.0_helium.md
Normal 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
|
||||
34
go.mod
34
go.mod
|
|
@ -3,20 +3,48 @@ module gitlab.g3e.fr/h6n/users
|
|||
go 1.21.0
|
||||
|
||||
require (
|
||||
github.com/KyleBanks/depth v1.2.1 // indirect
|
||||
github.com/PuerkitoBio/purell v1.2.1 // indirect
|
||||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
|
||||
github.com/alecthomas/participle/v2 v2.0.0 // indirect
|
||||
github.com/biscuit-auth/biscuit-go/v2 v2.2.0 // indirect
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d // indirect
|
||||
github.com/ghodss/yaml v1.0.0 // indirect
|
||||
github.com/go-openapi/jsonpointer v0.21.0 // indirect
|
||||
github.com/go-openapi/jsonreference v0.21.0 // indirect
|
||||
github.com/go-openapi/spec v0.21.0 // indirect
|
||||
github.com/go-openapi/swag v0.23.0 // 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/labstack/echo/v4 v4.11.4 // indirect
|
||||
github.com/labstack/gommon v0.4.2 // indirect
|
||||
github.com/lib/pq v1.10.9 // indirect
|
||||
github.com/mailru/easyjson v0.7.7 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/russross/blackfriday/v2 v2.0.1 // indirect
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
|
||||
github.com/swaggo/echo-swagger v1.4.1 // indirect
|
||||
github.com/swaggo/files/v2 v2.0.0 // indirect
|
||||
github.com/swaggo/swag v1.16.3 // indirect
|
||||
github.com/urfave/cli/v2 v2.3.0 // indirect
|
||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||
github.com/valyala/fasttemplate v1.2.2 // indirect
|
||||
golang.org/x/crypto v0.17.0 // indirect
|
||||
golang.org/x/net v0.19.0 // indirect
|
||||
golang.org/x/sys v0.15.0 // indirect
|
||||
golang.org/x/crypto v0.21.0 // indirect
|
||||
golang.org/x/net v0.22.0 // indirect
|
||||
golang.org/x/sys v0.18.0 // indirect
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
golang.org/x/time v0.5.0 // indirect
|
||||
golang.org/x/tools v0.19.0 // indirect
|
||||
google.golang.org/protobuf v1.31.0 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // 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
|
||||
)
|
||||
|
|
|
|||
108
go.sum
108
go.sum
|
|
@ -1,39 +1,147 @@
|
|||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc=
|
||||
github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE=
|
||||
github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tNFfI=
|
||||
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
|
||||
github.com/PuerkitoBio/purell v1.2.1 h1:QsZ4TjvwiMpat6gBCBxEQI0rcS9ehtkKtSpiUnd9N28=
|
||||
github.com/PuerkitoBio/purell v1.2.1/go.mod h1:ZwHcC/82TOaovDi//J/804umJFFmbOHPngi8iYYv/Eo=
|
||||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M=
|
||||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
|
||||
github.com/alecthomas/participle/v2 v2.0.0 h1:Fgrq+MbuSsJwIkw3fEj9h75vDP0Er5JzepJ0/HNHv0g=
|
||||
github.com/alecthomas/participle/v2 v2.0.0/go.mod h1:rAKZdJldHu8084ojcWevWAL8KmEU+AT+Olodb+WoN2Y=
|
||||
github.com/biscuit-auth/biscuit-go/v2 v2.2.0 h1:1zBfZ0ZCbxJbhtAhou6Fa07lBlJ+wcphBEPV/sENBvY=
|
||||
github.com/biscuit-auth/biscuit-go/v2 v2.2.0/go.mod h1:c7AsMdr816vPd/4Psb3z6Xv2EKciKxSEayI8ueBaJio=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
|
||||
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
|
||||
github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
|
||||
github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUeOFYEICuY=
|
||||
github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
|
||||
github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ=
|
||||
github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY=
|
||||
github.com/go-openapi/jsonreference v0.19.6 h1:UBIxjkht+AWIgYzCDSv2GN+E/togfwXUJFRTWhl2Jjs=
|
||||
github.com/go-openapi/jsonreference v0.19.6/go.mod h1:diGHMEHg2IqXZGKxqyvWdfWU/aim5Dprw5bqpKkTvns=
|
||||
github.com/go-openapi/jsonreference v0.21.0 h1:Rs+Y7hSXT83Jacb7kFyjn4ijOuVGSvOdF2+tg1TRrwQ=
|
||||
github.com/go-openapi/jsonreference v0.21.0/go.mod h1:LmZmgsrTkVg9LG4EaHeY8cBDslNPMo06cago5JNLkm4=
|
||||
github.com/go-openapi/spec v0.20.4 h1:O8hJrt0UMnhHcluhIdUgCLRWyM2x7QkBXRvOs7m+O1M=
|
||||
github.com/go-openapi/spec v0.20.4/go.mod h1:faYFR1CvsJZ0mNsmsphTMSoRrNV3TEDoAM7FOEWeq8I=
|
||||
github.com/go-openapi/spec v0.21.0 h1:LTVzPc3p/RzRnkQqLRndbAzjY0d0BCL72A6j3CdL9ZY=
|
||||
github.com/go-openapi/spec v0.21.0/go.mod h1:78u6VdPw81XU44qEWGhtr982gJ5BWg2c0I5XwVMotYk=
|
||||
github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
|
||||
github.com/go-openapi/swag v0.19.15 h1:D2NRCBzS9/pEY3gP9Nl8aDqGUcPFrwG2p+CNFrLyrCM=
|
||||
github.com/go-openapi/swag v0.19.15/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ=
|
||||
github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE=
|
||||
github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ=
|
||||
github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
|
||||
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/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/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/labstack/echo/v4 v4.11.4 h1:vDZmA+qNeh1pd/cCkEicDMrjtrnMGQ1QFI9gWN1zGq8=
|
||||
github.com/labstack/echo/v4 v4.11.4/go.mod h1:noh7EvLwqDsmh/X/HWKPUl1AjzJrhyptRyEbQJfxen8=
|
||||
github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0=
|
||||
github.com/labstack/gommon v0.4.2/go.mod h1:QlUFxVM+SNXhDL/Z7YhocGIBYOiwB0mXm1+1bAPHPyU=
|
||||
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
|
||||
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
||||
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
||||
github.com/mailru/easyjson v0.7.6 h1:8yTIVnZgCoiM1TgqoeTl+LfU5Jg6/xL3QhGQnimLYnA=
|
||||
github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
|
||||
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
|
||||
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
|
||||
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||
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.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/go.mod h1:C8bSi+9yH2FLZsnhqMZLIZddpUxZdBYuNHbtaS1Hljc=
|
||||
github.com/swaggo/files/v2 v2.0.0 h1:hmAt8Dkynw7Ssz46F6pn8ok6YmGZqHSVLZ+HQM7i0kw=
|
||||
github.com/swaggo/files/v2 v2.0.0/go.mod h1:24kk2Y9NYEJ5lHuCra6iVwkMjIekMCaFq/0JQj66kyM=
|
||||
github.com/swaggo/swag v1.16.3 h1:PnCYjPCah8FK4I26l2F/KQ4yz3sILcVUN3cTlBFA9Pg=
|
||||
github.com/swaggo/swag v1.16.3/go.mod h1:DImHIuOFXKpMFAQjcC7FG4m3Dg4+QuUgUzJmKjI/gRk=
|
||||
github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M=
|
||||
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
|
||||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||
github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=
|
||||
github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
|
||||
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
|
||||
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
|
||||
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
|
||||
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
|
||||
golang.org/x/net v0.0.0-20210421230115-4e50805a0758/go.mod h1:72T/g9IO56b78aLF+1Kcs5dz7/ng1VjMUvfKvpfy+jM=
|
||||
golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c=
|
||||
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
|
||||
golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc=
|
||||
golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210420072515-93ed5bcd2bfe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
|
||||
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
|
||||
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
|
||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
|
||||
golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.7.0 h1:W4OVu8VVOaIO0yzWMNdepAulS7YfoS3Zabrm8DOXXU4=
|
||||
golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s=
|
||||
golang.org/x/tools v0.19.0 h1:tfGCXNR1OsFG+sVdLAitlpjAvD/I6dHDKnYrpEZUHkw=
|
||||
golang.org/x/tools v0.19.0/go.mod h1:qoJWxmGSIBmAeriMx19ogtrEPrGtDbPK634QFIcLAhc=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
|
||||
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/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/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/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package logins
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
|
|
@ -10,7 +9,9 @@ import (
|
|||
"github.com/biscuit-auth/biscuit-go/v2"
|
||||
"github.com/biscuit-auth/biscuit-go/v2/parser"
|
||||
"gitlab.g3e.fr/h6n/users/lib"
|
||||
login_lib "gitlab.g3e.fr/h6n/users/lib/login"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func CheckPasswordHash(password, hash string) bool {
|
||||
|
|
@ -18,20 +19,14 @@ func CheckPasswordHash(password, hash string) bool {
|
|||
return err == nil
|
||||
}
|
||||
|
||||
func CreateLogin(db *sql.DB, request RequestLogin) (ResponseLogin, error) {
|
||||
type (
|
||||
User struct {
|
||||
Username string
|
||||
EncryptedPassword string
|
||||
}
|
||||
)
|
||||
var user User
|
||||
var response ResponseLogin
|
||||
func CreateLogin(db *gorm.DB, request login_lib.RequestLogin) (login_lib.ResponseLogin, error) {
|
||||
var response login_lib.ResponseLogin
|
||||
|
||||
if err := db.QueryRow("SELECT username, password FROM users WHERE email = $1", request.Username).Scan(&user.Username, &user.EncryptedPassword); err != nil {
|
||||
return response, err
|
||||
var user = Users{Email: request.Username}
|
||||
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
|
||||
}
|
||||
now := time.Now()
|
||||
|
|
|
|||
50
internal/databases.go
Normal file
50
internal/databases.go
Normal 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
10
lib/health/isHealth.go
Normal 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
11
lib/health/status.go
Normal 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)
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@ package lib
|
|||
import (
|
||||
"crypto/ed25519"
|
||||
"crypto/rand"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"time"
|
||||
|
|
@ -22,7 +23,12 @@ func InitLoginBiscuit() error {
|
|||
if file, err := os.Create(filePrivateKey); err != nil {
|
||||
return err
|
||||
} 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 {
|
||||
return err
|
||||
|
|
@ -34,7 +40,12 @@ func InitLoginBiscuit() error {
|
|||
if file, err := os.Create(filePublicKey); err != nil {
|
||||
return err
|
||||
} 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 {
|
||||
return err
|
||||
|
|
@ -47,7 +58,12 @@ func InitLoginBiscuit() error {
|
|||
if file, err := os.Open(filePrivateKey); err != nil {
|
||||
return err
|
||||
} 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)
|
||||
if err != nil {
|
||||
|
|
@ -57,7 +73,12 @@ func InitLoginBiscuit() error {
|
|||
if file, err := os.Open(filePublicKey); err != nil {
|
||||
return err
|
||||
} 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)
|
||||
if err != nil {
|
||||
|
|
@ -86,7 +107,12 @@ func InitGlobalBiscuit() error {
|
|||
if file, err := os.Open(filePrivateKey); err != nil {
|
||||
return err
|
||||
} 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)
|
||||
if err != nil {
|
||||
|
|
@ -96,7 +122,12 @@ func InitGlobalBiscuit() error {
|
|||
if file, err := os.Open(filePublicKey); err != nil {
|
||||
return err
|
||||
} 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)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
package logins
|
||||
package login_lib
|
||||
|
||||
type (
|
||||
// RequestLogin model info
|
||||
RequestLogin struct {
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
// ResponseLogin model info
|
||||
ResponseLogin struct {
|
||||
Token string `json:"token"`
|
||||
PublicKey string `json:"publickey"`
|
||||
|
|
@ -1,20 +1,9 @@
|
|||
#!/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 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:
|
||||
postgres:
|
||||
image: postgres:15.2-alpine3.17
|
||||
|
|
@ -29,7 +18,7 @@ services:
|
|||
timeout: 5s
|
||||
retries: 5
|
||||
users:
|
||||
image: $IMAGE_TYPE
|
||||
image: users-release
|
||||
volumes:
|
||||
- ./docker/keys:/keys
|
||||
depends_on:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue