fix: end of line char
This commit is contained in:
128
.gitignore
vendored
128
.gitignore
vendored
@@ -1,65 +1,65 @@
|
|||||||
# Binaries for programs and plugins
|
# Binaries for programs and plugins
|
||||||
*.exe
|
*.exe
|
||||||
*.exec
|
*.exec
|
||||||
*.exe~
|
*.exe~
|
||||||
*.dll
|
*.dll
|
||||||
*.so
|
*.so
|
||||||
*.dylib
|
*.dylib
|
||||||
*.test
|
*.test
|
||||||
|
|
||||||
# Build output (common names)
|
# Build output (common names)
|
||||||
/bin/
|
/bin/
|
||||||
/dist/
|
/dist/
|
||||||
/build/
|
/build/
|
||||||
*.out
|
*.out
|
||||||
coverage.out
|
coverage.out
|
||||||
|
|
||||||
# Go tooling
|
# Go tooling
|
||||||
go.work
|
go.work
|
||||||
# Uncomment if you don't commit vendored deps
|
# Uncomment if you don't commit vendored deps
|
||||||
# vendor/
|
# vendor/
|
||||||
|
|
||||||
# Dependency manager files (optional)
|
# Dependency manager files (optional)
|
||||||
Gopkg.lock
|
Gopkg.lock
|
||||||
glide.lock
|
glide.lock
|
||||||
|
|
||||||
# Generated code
|
# Generated code
|
||||||
gen/
|
gen/
|
||||||
generated/
|
generated/
|
||||||
|
|
||||||
# Environment / secrets
|
# Environment / secrets
|
||||||
.env
|
.env
|
||||||
.env.*
|
.env.*
|
||||||
*.key
|
*.key
|
||||||
*.pem
|
*.pem
|
||||||
|
|
||||||
# Logs
|
# Logs
|
||||||
*.log
|
*.log
|
||||||
|
|
||||||
# Editor directories and files
|
# Editor directories and files
|
||||||
.idea/
|
.idea/
|
||||||
# .vscode/
|
# .vscode/
|
||||||
*.iml
|
*.iml
|
||||||
*.sublime-project
|
*.sublime-project
|
||||||
*.sublime-workspace
|
*.sublime-workspace
|
||||||
|
|
||||||
# Swap/backup files
|
# Swap/backup files
|
||||||
*~
|
*~
|
||||||
*.swp
|
*.swp
|
||||||
*.swo
|
*.swo
|
||||||
.#*
|
.#*
|
||||||
|
|
||||||
# macOS / Windows
|
# macOS / Windows
|
||||||
.DS_Store
|
.DS_Store
|
||||||
Thumbs.db
|
Thumbs.db
|
||||||
|
|
||||||
# Container / OS artifacts
|
# Container / OS artifacts
|
||||||
docker-compose.override.yml
|
docker-compose.override.yml
|
||||||
|
|
||||||
# CI artifacts
|
# CI artifacts
|
||||||
coverage/
|
coverage/
|
||||||
reports/
|
reports/
|
||||||
|
|
||||||
# Misc
|
# Misc
|
||||||
node_modules/
|
node_modules/
|
||||||
deprecated/
|
deprecated/
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
PHONY: gen_openapi_models
|
PHONY: gen_openapi_models
|
||||||
gen_openapi_models: openapi/cfg.yaml openapi/openapi.yaml
|
gen_openapi_models: openapi/cfg.yaml openapi/openapi.yaml
|
||||||
oapi-codegen.exe -config .\openapi\cfg.yaml .\openapi\openapi.yaml
|
oapi-codegen.exe -config .\openapi\cfg.yaml .\openapi\openapi.yaml
|
||||||
|
|||||||
@@ -1,24 +1,29 @@
|
|||||||
# ETA API v2
|
# ETA API v2
|
||||||
|
|
||||||
This is the second generation of the ETA API developed on GoLang using OpenAPI to auto document and generate api endpoints.
|
This is the second generation of the ETA API developed on GoLang using OpenAPI to auto document and generate api endpoints.
|
||||||
|
|
||||||
# OpenApi Generator
|
# OpenApi Generator
|
||||||
|
|
||||||
With the following command the generator tool can be installed
|
With the following command the generator tool can be installed
|
||||||
|
|
||||||
```.{sh}
|
```.{sh}
|
||||||
go install github.com/deepmap/oapi-codegen/cmd/oapi-codegen@latest
|
go install github.com/deepmap/oapi-codegen/cmd/oapi-codegen@latest
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Deployment
|
# Deployment
|
||||||
|
|
||||||
The details on how to deploy are described here
|
The details on how to deploy are described here
|
||||||
|
|
||||||
## DOTENV
|
## DOTENV
|
||||||
|
|
||||||
```{.sh}
|
```{.sh}
|
||||||
SQL_DSN="{USER}:{PASS}@tcp({HOST}:{PORT})/{DB}?charset=utf8mb4&parseTime=true&loc=Local"
|
SQL_DSN="{USER}:{PASS}@tcp({HOST}:{PORT})/{DB}?charset=utf8mb4&parseTime=true&loc=Local"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
# GPU information
|
||||||
|
|
||||||
|
https://en.wikipedia.org/wiki/Graphics_processing_unit ->
|
||||||
|
https://en.wikipedia.org/wiki/Shader -> https://en.wikipedia.org/wiki/RenderMan_Interface_Specification
|
||||||
@@ -1,42 +1,42 @@
|
|||||||
package database
|
package database
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
"gorm.io/driver/mysql"
|
"gorm.io/driver/mysql"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
var shared_db_connection *gorm.DB
|
var shared_db_connection *gorm.DB
|
||||||
|
|
||||||
func initDB() *gorm.DB {
|
func initDB() *gorm.DB {
|
||||||
// load .env into environment (so viper can read them)
|
// load .env into environment (so viper can read them)
|
||||||
if err := godotenv.Load(); err != nil {
|
if err := godotenv.Load(); err != nil {
|
||||||
log.Println(".env not found or could not be loaded; proceeding with existing environment variables")
|
log.Println(".env not found or could not be loaded; proceeding with existing environment variables")
|
||||||
}
|
}
|
||||||
|
|
||||||
viper.AutomaticEnv() // read from environment
|
viper.AutomaticEnv() // read from environment
|
||||||
|
|
||||||
sql_dsn := viper.GetString("SQL_DSN")
|
sql_dsn := viper.GetString("SQL_DSN")
|
||||||
|
|
||||||
if sql_dsn == "" {
|
if sql_dsn == "" {
|
||||||
log.Fatal("SQL_DSN must be set in .env or environment")
|
log.Fatal("SQL_DSN must be set in .env or environment")
|
||||||
}
|
}
|
||||||
|
|
||||||
db, err := gorm.Open(mysql.Open(sql_dsn), &gorm.Config{})
|
db, err := gorm.Open(mysql.Open(sql_dsn), &gorm.Config{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("failed to connect to MySQL Server: %v", err)
|
log.Fatalf("failed to connect to MySQL Server: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Println("connected to MySQL Server")
|
log.Println("connected to MySQL Server")
|
||||||
return db
|
return db
|
||||||
}
|
}
|
||||||
|
|
||||||
func Init() *gorm.DB {
|
func Init() *gorm.DB {
|
||||||
if shared_db_connection == nil {
|
if shared_db_connection == nil {
|
||||||
shared_db_connection = initDB()
|
shared_db_connection = initDB()
|
||||||
}
|
}
|
||||||
return shared_db_connection
|
return shared_db_connection
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,124 +1,124 @@
|
|||||||
/**
|
/**
|
||||||
* @file schema.rbac.go
|
* @file schema.rbac.go
|
||||||
* @brief RBAC schema models for GORM
|
* @brief RBAC schema models for GORM
|
||||||
*
|
*
|
||||||
* This file defines the base database models used by the RBAC
|
* This file defines the base database models used by the RBAC
|
||||||
* (Role-Based Access Control) system. Models map to the following
|
* (Role-Based Access Control) system. Models map to the following
|
||||||
* tables: user_types, users, auth_identities, auth_credentials,
|
* tables: user_types, users, auth_identities, auth_credentials,
|
||||||
* roles, permissions, role_permissions and user_roles.
|
* roles, permissions, role_permissions and user_roles.
|
||||||
*
|
*
|
||||||
* The structs include GORM tags for column names and relationships:
|
* The structs include GORM tags for column names and relationships:
|
||||||
* - UserType: types of users.
|
* - UserType: types of users.
|
||||||
* - User: main user record; links to UserType, AuthIdentity and UserRole.
|
* - User: main user record; links to UserType, AuthIdentity and UserRole.
|
||||||
* - AuthIdentity: external identity providers; links to AuthCredential.
|
* - AuthIdentity: external identity providers; links to AuthCredential.
|
||||||
* - AuthCredential: stored credentials for an identity.
|
* - AuthCredential: stored credentials for an identity.
|
||||||
* - Role: role definitions and their permissions and assigned users.
|
* - Role: role definitions and their permissions and assigned users.
|
||||||
* - Permission: permission definitions.
|
* - Permission: permission definitions.
|
||||||
* - RolePermission: join table between Role and Permission.
|
* - RolePermission: join table between Role and Permission.
|
||||||
* - UserRole: join table between User and Role with optional expiration.
|
* - UserRole: join table between User and Role with optional expiration.
|
||||||
*
|
*
|
||||||
* These models are intended for use with GORM to perform ORM operations
|
* These models are intended for use with GORM to perform ORM operations
|
||||||
* against the RBAC schema.
|
* against the RBAC schema.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package rbac
|
package rbac
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UserType struct {
|
type UserType struct {
|
||||||
ID uint `gorm:"primaryKey;column:id"`
|
ID uint `gorm:"primaryKey;column:id"`
|
||||||
Name string `gorm:"type:text;column:name"`
|
Name string `gorm:"type:text;column:name"`
|
||||||
Description *string `gorm:"type:text;column:description"`
|
Description *string `gorm:"type:text;column:description"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (UserType) TableName() string { return "user_types" }
|
func (UserType) TableName() string { return "user_types" }
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
ID uint `gorm:"primaryKey;column:id"`
|
ID uint `gorm:"primaryKey;column:id"`
|
||||||
UserTypeID uint `gorm:"column:user_type"`
|
UserTypeID uint `gorm:"column:user_type"`
|
||||||
Name string `gorm:"type:text;column:name"`
|
Name string `gorm:"type:text;column:name"`
|
||||||
LastName string `gorm:"type:text;column:last_name"`
|
LastName string `gorm:"type:text;column:last_name"`
|
||||||
CreatedAt time.Time `gorm:"column:created_at;autoCreateTime"`
|
CreatedAt time.Time `gorm:"column:created_at;autoCreateTime"`
|
||||||
UpdatedAt time.Time `gorm:"column:updated_at;autoUpdateTime"`
|
UpdatedAt time.Time `gorm:"column:updated_at;autoUpdateTime"`
|
||||||
|
|
||||||
UserType UserType `gorm:"foreignKey:UserTypeID;references:ID"`
|
UserType UserType `gorm:"foreignKey:UserTypeID;references:ID"`
|
||||||
AuthIdentities []AuthIdentity `gorm:"foreignKey:UserID;references:ID"`
|
AuthIdentities []AuthIdentity `gorm:"foreignKey:UserID;references:ID"`
|
||||||
UserRoles []UserRole `gorm:"foreignKey:UserID;references:ID"`
|
UserRoles []UserRole `gorm:"foreignKey:UserID;references:ID"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (User) TableName() string { return "users" }
|
func (User) TableName() string { return "users" }
|
||||||
|
|
||||||
type AuthIdentity struct {
|
type AuthIdentity struct {
|
||||||
ID uint `gorm:"primaryKey;column:id"`
|
ID uint `gorm:"primaryKey;column:id"`
|
||||||
UserID uint `gorm:"column:user_id"`
|
UserID uint `gorm:"column:user_id"`
|
||||||
Provider string `gorm:"type:text;column:provider"`
|
Provider string `gorm:"type:text;column:provider"`
|
||||||
Identifier string `gorm:"type:text;column:identifier"`
|
Identifier string `gorm:"type:text;column:identifier"`
|
||||||
IsPrimary bool `gorm:"column:is_primary"`
|
IsPrimary bool `gorm:"column:is_primary"`
|
||||||
IsVerified bool `gorm:"column:is_verified"`
|
IsVerified bool `gorm:"column:is_verified"`
|
||||||
CreatedAt time.Time `gorm:"column:created_at;autoCreateTime"`
|
CreatedAt time.Time `gorm:"column:created_at;autoCreateTime"`
|
||||||
UpdatedAt time.Time `gorm:"column:updated_at;autoUpdateTime"`
|
UpdatedAt time.Time `gorm:"column:updated_at;autoUpdateTime"`
|
||||||
|
|
||||||
User User `gorm:"foreignKey:UserID;references:ID"`
|
User User `gorm:"foreignKey:UserID;references:ID"`
|
||||||
Credentials []AuthCredential `gorm:"foreignKey:IdentityID;references:ID"`
|
Credentials []AuthCredential `gorm:"foreignKey:IdentityID;references:ID"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (AuthIdentity) TableName() string { return "auth_identities" }
|
func (AuthIdentity) TableName() string { return "auth_identities" }
|
||||||
|
|
||||||
type AuthCredential struct {
|
type AuthCredential struct {
|
||||||
ID uint `gorm:"primaryKey;column:id"`
|
ID uint `gorm:"primaryKey;column:id"`
|
||||||
IdentityID uint `gorm:"column:identity_id"`
|
IdentityID uint `gorm:"column:identity_id"`
|
||||||
Password string `gorm:"type:text;column:password"`
|
Password string `gorm:"type:text;column:password"`
|
||||||
CreatedAt time.Time `gorm:"column:created_at;autoCreateTime"`
|
CreatedAt time.Time `gorm:"column:created_at;autoCreateTime"`
|
||||||
UpdatedAt time.Time `gorm:"column:updated_at;autoUpdateTime"`
|
UpdatedAt time.Time `gorm:"column:updated_at;autoUpdateTime"`
|
||||||
|
|
||||||
Identity AuthIdentity `gorm:"foreignKey:IdentityID;references:ID"`
|
Identity AuthIdentity `gorm:"foreignKey:IdentityID;references:ID"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (AuthCredential) TableName() string { return "auth_credentials" }
|
func (AuthCredential) TableName() string { return "auth_credentials" }
|
||||||
|
|
||||||
type Role struct {
|
type Role struct {
|
||||||
ID uint `gorm:"primaryKey;column:id"`
|
ID uint `gorm:"primaryKey;column:id"`
|
||||||
Name string `gorm:"type:text;column:name"`
|
Name string `gorm:"type:text;column:name"`
|
||||||
Description *string `gorm:"type:text;column:description"`
|
Description *string `gorm:"type:text;column:description"`
|
||||||
CreatedAt time.Time `gorm:"column:created_at;autoCreateTime"`
|
CreatedAt time.Time `gorm:"column:created_at;autoCreateTime"`
|
||||||
UpdatedAt time.Time `gorm:"column:updated_at;autoUpdateTime"`
|
UpdatedAt time.Time `gorm:"column:updated_at;autoUpdateTime"`
|
||||||
RolePermissions []RolePermission `gorm:"foreignKey:RoleID;references:ID"`
|
RolePermissions []RolePermission `gorm:"foreignKey:RoleID;references:ID"`
|
||||||
UserRoles []UserRole `gorm:"foreignKey:RoleID;references:ID"`
|
UserRoles []UserRole `gorm:"foreignKey:RoleID;references:ID"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Role) TableName() string { return "roles" }
|
func (Role) TableName() string { return "roles" }
|
||||||
|
|
||||||
type Permission struct {
|
type Permission struct {
|
||||||
ID uint `gorm:"primaryKey;column:id"`
|
ID uint `gorm:"primaryKey;column:id"`
|
||||||
Name string `gorm:"type:text;column:name"`
|
Name string `gorm:"type:text;column:name"`
|
||||||
Description *string `gorm:"type:text;column:description"`
|
Description *string `gorm:"type:text;column:description"`
|
||||||
RolePermissions []RolePermission `gorm:"foreignKey:PermissionID;references:ID"`
|
RolePermissions []RolePermission `gorm:"foreignKey:PermissionID;references:ID"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Permission) TableName() string { return "permissions" }
|
func (Permission) TableName() string { return "permissions" }
|
||||||
|
|
||||||
type RolePermission struct {
|
type RolePermission struct {
|
||||||
ID uint `gorm:"primaryKey;column:id"`
|
ID uint `gorm:"primaryKey;column:id"`
|
||||||
RoleID uint `gorm:"column:role_id"`
|
RoleID uint `gorm:"column:role_id"`
|
||||||
PermissionID uint `gorm:"column:permission_id"`
|
PermissionID uint `gorm:"column:permission_id"`
|
||||||
|
|
||||||
Role Role `gorm:"foreignKey:RoleID;references:ID"`
|
Role Role `gorm:"foreignKey:RoleID;references:ID"`
|
||||||
Permission Permission `gorm:"foreignKey:PermissionID;references:ID"`
|
Permission Permission `gorm:"foreignKey:PermissionID;references:ID"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (RolePermission) TableName() string { return "role_permissions" }
|
func (RolePermission) TableName() string { return "role_permissions" }
|
||||||
|
|
||||||
type UserRole struct {
|
type UserRole struct {
|
||||||
ID uint `gorm:"primaryKey;column:id"`
|
ID uint `gorm:"primaryKey;column:id"`
|
||||||
UserID uint `gorm:"column:user_id"`
|
UserID uint `gorm:"column:user_id"`
|
||||||
RoleID uint `gorm:"column:role_id"`
|
RoleID uint `gorm:"column:role_id"`
|
||||||
CreatedAt time.Time `gorm:"column:created_at;autoCreateTime"`
|
CreatedAt time.Time `gorm:"column:created_at;autoCreateTime"`
|
||||||
ExpiresAt *time.Time `gorm:"column:expires_at"`
|
ExpiresAt *time.Time `gorm:"column:expires_at"`
|
||||||
|
|
||||||
User User `gorm:"foreignKey:UserID;references:ID"`
|
User User `gorm:"foreignKey:UserID;references:ID"`
|
||||||
Role Role `gorm:"foreignKey:RoleID;references:ID"`
|
Role Role `gorm:"foreignKey:RoleID;references:ID"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (UserRole) TableName() string { return "user_roles" }
|
func (UserRole) TableName() string { return "user_roles" }
|
||||||
|
|||||||
@@ -1,52 +1,52 @@
|
|||||||
package auth
|
package auth
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"cloud.etaviaporte.com/api/libs/openapi"
|
"cloud.etaviaporte.com/api/libs/openapi"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Handler struct{}
|
type Handler struct{}
|
||||||
|
|
||||||
// GetAuthMe implements openapi.ServerInterface.
|
// GetAuthMe implements openapi.ServerInterface.
|
||||||
func (handler Handler) GetAuthMe(c *fiber.Ctx) error {
|
func (handler Handler) GetAuthMe(c *fiber.Ctx) error {
|
||||||
err_code := fiber.StatusInternalServerError
|
err_code := fiber.StatusInternalServerError
|
||||||
code := "Something went wrong!"
|
code := "Something went wrong!"
|
||||||
message := "This endpoint is not yet implemented"
|
message := "This endpoint is not yet implemented"
|
||||||
return c.Status(err_code).JSON(openapi.Error{
|
return c.Status(err_code).JSON(openapi.Error{
|
||||||
Code: &code,
|
Code: &code,
|
||||||
Message: &message,
|
Message: &message,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// PostAuthLogin implements openapi.ServerInterface.
|
// PostAuthLogin implements openapi.ServerInterface.
|
||||||
func (handler Handler) PostAuthLogin(c *fiber.Ctx) error {
|
func (handler Handler) PostAuthLogin(c *fiber.Ctx) error {
|
||||||
err_code := fiber.StatusInternalServerError
|
err_code := fiber.StatusInternalServerError
|
||||||
code := "Something went wrong!"
|
code := "Something went wrong!"
|
||||||
message := "This endpoint is not yet implemented"
|
message := "This endpoint is not yet implemented"
|
||||||
return c.Status(err_code).JSON(openapi.Error{
|
return c.Status(err_code).JSON(openapi.Error{
|
||||||
Code: &code,
|
Code: &code,
|
||||||
Message: &message,
|
Message: &message,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// PostAuthLogout implements openapi.ServerInterface.
|
// PostAuthLogout implements openapi.ServerInterface.
|
||||||
func (handler Handler) PostAuthLogout(c *fiber.Ctx) error {
|
func (handler Handler) PostAuthLogout(c *fiber.Ctx) error {
|
||||||
err_code := fiber.StatusInternalServerError
|
err_code := fiber.StatusInternalServerError
|
||||||
code := "Something went wrong!"
|
code := "Something went wrong!"
|
||||||
message := "This endpoint is not yet implemented"
|
message := "This endpoint is not yet implemented"
|
||||||
return c.Status(err_code).JSON(openapi.Error{
|
return c.Status(err_code).JSON(openapi.Error{
|
||||||
Code: &code,
|
Code: &code,
|
||||||
Message: &message,
|
Message: &message,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// PostAuthRefresh implements openapi.ServerInterface.
|
// PostAuthRefresh implements openapi.ServerInterface.
|
||||||
func (handler Handler) PostAuthRefresh(c *fiber.Ctx) error {
|
func (handler Handler) PostAuthRefresh(c *fiber.Ctx) error {
|
||||||
err_code := fiber.StatusInternalServerError
|
err_code := fiber.StatusInternalServerError
|
||||||
code := "Something went wrong!"
|
code := "Something went wrong!"
|
||||||
message := "This endpoint is not yet implemented"
|
message := "This endpoint is not yet implemented"
|
||||||
return c.Status(err_code).JSON(openapi.Error{
|
return c.Status(err_code).JSON(openapi.Error{
|
||||||
Code: &code,
|
Code: &code,
|
||||||
Message: &message,
|
Message: &message,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
82
app/main.go
82
app/main.go
@@ -1,41 +1,41 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"github.com/gofiber/fiber/v2/middleware/cors"
|
"github.com/gofiber/fiber/v2/middleware/cors"
|
||||||
"github.com/gofiber/fiber/v2/middleware/helmet"
|
"github.com/gofiber/fiber/v2/middleware/helmet"
|
||||||
"github.com/gofiber/fiber/v2/middleware/logger"
|
"github.com/gofiber/fiber/v2/middleware/logger"
|
||||||
|
|
||||||
"cloud.etaviaporte.com/api/libs/services/auth"
|
"cloud.etaviaporte.com/api/libs/services/auth"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
app := fiber.New()
|
app := fiber.New()
|
||||||
|
|
||||||
app.Use(cors.New(cors.Config{
|
app.Use(cors.New(cors.Config{
|
||||||
AllowOrigins: "https://api.etaviaporte.com, http://127.0.0.1, http://localhost",
|
AllowOrigins: "https://api.etaviaporte.com, http://127.0.0.1, http://localhost",
|
||||||
AllowHeaders: "Origin, Content-Type, Accept, Authorization",
|
AllowHeaders: "Origin, Content-Type, Accept, Authorization",
|
||||||
AllowMethods: "GET, POST, HEAD, PUT, DELETE, PATCH",
|
AllowMethods: "GET, POST, HEAD, PUT, DELETE, PATCH",
|
||||||
AllowCredentials: true,
|
AllowCredentials: true,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
app.Use(logger.New(logger.Config{
|
app.Use(logger.New(logger.Config{
|
||||||
Format: "[${ip}]:${port} ${status} - ${method} ${path}\n",
|
Format: "[${ip}]:${port} ${status} - ${method} ${path}\n",
|
||||||
}))
|
}))
|
||||||
|
|
||||||
app.Use(helmet.New())
|
app.Use(helmet.New())
|
||||||
|
|
||||||
app.Get("/", func(c *fiber.Ctx) error {
|
app.Get("/", func(c *fiber.Ctx) error {
|
||||||
return c.SendString("Hello, World!")
|
return c.SendString("Hello, World!")
|
||||||
})
|
})
|
||||||
|
|
||||||
handler := auth.Handler{}
|
handler := auth.Handler{}
|
||||||
// openapi.RegisterHandlers(app, auth.Handler{})
|
// openapi.RegisterHandlers(app, auth.Handler{})
|
||||||
|
|
||||||
app.Post("/auth/login", handler.PostAuthLogin)
|
app.Post("/auth/login", handler.PostAuthLogin)
|
||||||
app.Post("/auth/logout", handler.PostAuthLogout)
|
app.Post("/auth/logout", handler.PostAuthLogout)
|
||||||
app.Get("/auth/me", handler.GetAuthMe)
|
app.Get("/auth/me", handler.GetAuthMe)
|
||||||
app.Post("/auth/refresh", handler.PostAuthRefresh)
|
app.Post("/auth/refresh", handler.PostAuthRefresh)
|
||||||
|
|
||||||
app.Listen(":3000")
|
app.Listen(":3000")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package: openapi
|
package: openapi
|
||||||
output: libs/openapi/generated.go
|
output: libs/openapi/generated.go
|
||||||
generate:
|
generate:
|
||||||
models: true
|
models: true
|
||||||
output-options:
|
output-options:
|
||||||
skip-prune: true
|
skip-prune: true
|
||||||
|
|||||||
@@ -1,182 +1,182 @@
|
|||||||
openapi: 3.0.3
|
openapi: 3.0.3
|
||||||
info:
|
info:
|
||||||
title: Authorization API
|
title: Authorization API
|
||||||
version: "1.0.0"
|
version: "1.0.0"
|
||||||
description: Simple authorization endpoints for login, refresh, logout and getting current user info.
|
description: Simple authorization endpoints for login, refresh, logout and getting current user info.
|
||||||
servers:
|
servers:
|
||||||
- url: http://localhost:8080
|
- url: http://localhost:8080
|
||||||
description: Local development server
|
description: Local development server
|
||||||
|
|
||||||
paths:
|
paths:
|
||||||
/auth/login:
|
/auth/login:
|
||||||
post:
|
post:
|
||||||
summary: Obtain access and refresh tokens
|
summary: Obtain access and refresh tokens
|
||||||
tags:
|
tags:
|
||||||
- Auth
|
- Auth
|
||||||
requestBody:
|
requestBody:
|
||||||
required: true
|
required: true
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/LoginRequest'
|
$ref: '#/components/schemas/LoginRequest'
|
||||||
responses:
|
responses:
|
||||||
'200':
|
'200':
|
||||||
description: Tokens issued
|
description: Tokens issued
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/TokenResponse'
|
$ref: '#/components/schemas/TokenResponse'
|
||||||
'400':
|
'400':
|
||||||
$ref: '#/components/responses/BadRequest'
|
$ref: '#/components/responses/BadRequest'
|
||||||
'401':
|
'401':
|
||||||
$ref: '#/components/responses/Unauthorized'
|
$ref: '#/components/responses/Unauthorized'
|
||||||
|
|
||||||
/auth/refresh:
|
/auth/refresh:
|
||||||
post:
|
post:
|
||||||
summary: Refresh access token using a refresh token
|
summary: Refresh access token using a refresh token
|
||||||
tags:
|
tags:
|
||||||
- Auth
|
- Auth
|
||||||
requestBody:
|
requestBody:
|
||||||
required: true
|
required: true
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/RefreshRequest'
|
$ref: '#/components/schemas/RefreshRequest'
|
||||||
responses:
|
responses:
|
||||||
'200':
|
'200':
|
||||||
description: New tokens
|
description: New tokens
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/TokenResponse'
|
$ref: '#/components/schemas/TokenResponse'
|
||||||
'400':
|
'400':
|
||||||
$ref: '#/components/responses/BadRequest'
|
$ref: '#/components/responses/BadRequest'
|
||||||
'401':
|
'401':
|
||||||
$ref: '#/components/responses/Unauthorized'
|
$ref: '#/components/responses/Unauthorized'
|
||||||
|
|
||||||
/auth/logout:
|
/auth/logout:
|
||||||
post:
|
post:
|
||||||
summary: Revoke refresh token / logout
|
summary: Revoke refresh token / logout
|
||||||
tags:
|
tags:
|
||||||
- Auth
|
- Auth
|
||||||
security:
|
security:
|
||||||
- bearerAuth: []
|
- bearerAuth: []
|
||||||
requestBody:
|
requestBody:
|
||||||
required: true
|
required: true
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/RevokeRequest'
|
$ref: '#/components/schemas/RevokeRequest'
|
||||||
responses:
|
responses:
|
||||||
'204':
|
'204':
|
||||||
description: Successfully logged out (no content)
|
description: Successfully logged out (no content)
|
||||||
'400':
|
'400':
|
||||||
$ref: '#/components/responses/BadRequest'
|
$ref: '#/components/responses/BadRequest'
|
||||||
'401':
|
'401':
|
||||||
$ref: '#/components/responses/Unauthorized'
|
$ref: '#/components/responses/Unauthorized'
|
||||||
|
|
||||||
/auth/me:
|
/auth/me:
|
||||||
get:
|
get:
|
||||||
summary: Get current authenticated user
|
summary: Get current authenticated user
|
||||||
tags:
|
tags:
|
||||||
- Auth
|
- Auth
|
||||||
security:
|
security:
|
||||||
- bearerAuth: []
|
- bearerAuth: []
|
||||||
responses:
|
responses:
|
||||||
'200':
|
'200':
|
||||||
description: Current user profile
|
description: Current user profile
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/UserProfile'
|
$ref: '#/components/schemas/UserProfile'
|
||||||
'401':
|
'401':
|
||||||
$ref: '#/components/responses/Unauthorized'
|
$ref: '#/components/responses/Unauthorized'
|
||||||
|
|
||||||
components:
|
components:
|
||||||
securitySchemes:
|
securitySchemes:
|
||||||
bearerAuth:
|
bearerAuth:
|
||||||
type: http
|
type: http
|
||||||
scheme: bearer
|
scheme: bearer
|
||||||
bearerFormat: JWT
|
bearerFormat: JWT
|
||||||
|
|
||||||
schemas:
|
schemas:
|
||||||
LoginRequest:
|
LoginRequest:
|
||||||
type: object
|
type: object
|
||||||
required:
|
required:
|
||||||
- username
|
- username
|
||||||
- password
|
- password
|
||||||
properties:
|
properties:
|
||||||
username:
|
username:
|
||||||
type: string
|
type: string
|
||||||
example: user@example.com
|
example: user@example.com
|
||||||
password:
|
password:
|
||||||
type: string
|
type: string
|
||||||
format: password
|
format: password
|
||||||
example: secret123
|
example: secret123
|
||||||
|
|
||||||
TokenResponse:
|
TokenResponse:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
accessToken:
|
accessToken:
|
||||||
type: string
|
type: string
|
||||||
example: eyJhbGciOi...
|
example: eyJhbGciOi...
|
||||||
refreshToken:
|
refreshToken:
|
||||||
type: string
|
type: string
|
||||||
example: dummyr3fr3sht0k3n
|
example: dummyr3fr3sht0k3n
|
||||||
expiresIn:
|
expiresIn:
|
||||||
type: integer
|
type: integer
|
||||||
description: Seconds until access token expiration
|
description: Seconds until access token expiration
|
||||||
example: 3600
|
example: 3600
|
||||||
|
|
||||||
RefreshRequest:
|
RefreshRequest:
|
||||||
type: object
|
type: object
|
||||||
required:
|
required:
|
||||||
- refreshToken
|
- refreshToken
|
||||||
properties:
|
properties:
|
||||||
refreshToken:
|
refreshToken:
|
||||||
type: string
|
type: string
|
||||||
|
|
||||||
RevokeRequest:
|
RevokeRequest:
|
||||||
type: object
|
type: object
|
||||||
required:
|
required:
|
||||||
- refreshToken
|
- refreshToken
|
||||||
properties:
|
properties:
|
||||||
refreshToken:
|
refreshToken:
|
||||||
type: string
|
type: string
|
||||||
|
|
||||||
UserProfile:
|
UserProfile:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
id:
|
id:
|
||||||
type: string
|
type: string
|
||||||
example: "123e4567-e89b-12d3-a456-426614174000"
|
example: "123e4567-e89b-12d3-a456-426614174000"
|
||||||
username:
|
username:
|
||||||
type: string
|
type: string
|
||||||
example: user@example.com
|
example: user@example.com
|
||||||
email:
|
email:
|
||||||
type: string
|
type: string
|
||||||
example: user@example.com
|
example: user@example.com
|
||||||
|
|
||||||
Error:
|
Error:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
code:
|
code:
|
||||||
type: string
|
type: string
|
||||||
example: invalid_request
|
example: invalid_request
|
||||||
message:
|
message:
|
||||||
type: string
|
type: string
|
||||||
example: "Detailed error message"
|
example: "Detailed error message"
|
||||||
|
|
||||||
responses:
|
responses:
|
||||||
BadRequest:
|
BadRequest:
|
||||||
description: Invalid request
|
description: Invalid request
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/Error'
|
$ref: '#/components/schemas/Error'
|
||||||
Unauthorized:
|
Unauthorized:
|
||||||
description: Authentication failed or missing credentials
|
description: Authentication failed or missing credentials
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/Error'
|
$ref: '#/components/schemas/Error'
|
||||||
|
|||||||
2
db/.gitignore
vendored
2
db/.gitignore
vendored
@@ -1 +1 @@
|
|||||||
*.bak
|
*.bak
|
||||||
|
|||||||
@@ -1,23 +1,23 @@
|
|||||||
# Original author : https://github.com/yobasystems/alpine-mariadb.git
|
# Original author : https://github.com/yobasystems/alpine-mariadb.git
|
||||||
FROM alpine:latest
|
FROM alpine:latest
|
||||||
|
|
||||||
ARG BUILD_DATE
|
ARG BUILD_DATE
|
||||||
ARG VCS_REF
|
ARG VCS_REF
|
||||||
|
|
||||||
RUN apk add --no-cache mariadb mysql-client mariadb-server-utils pwgen && \
|
RUN apk add --no-cache mariadb mysql-client mariadb-server-utils pwgen && \
|
||||||
rm -f /var/cache/apk/*
|
rm -f /var/cache/apk/*
|
||||||
|
|
||||||
RUN mkdir /schemas
|
RUN mkdir /schemas
|
||||||
COPY schemas /schemas
|
COPY schemas /schemas
|
||||||
|
|
||||||
ADD scripts/run.sh /scripts/run.sh
|
ADD scripts/run.sh /scripts/run.sh
|
||||||
RUN mkdir /docker-entrypoint-initdb.d && \
|
RUN mkdir /docker-entrypoint-initdb.d && \
|
||||||
mkdir /scripts/pre-exec.d && \
|
mkdir /scripts/pre-exec.d && \
|
||||||
mkdir /scripts/pre-init.d && \
|
mkdir /scripts/pre-init.d && \
|
||||||
chmod -R 755 /scripts
|
chmod -R 755 /scripts
|
||||||
|
|
||||||
EXPOSE 3306
|
EXPOSE 3306
|
||||||
|
|
||||||
VOLUME ["/var/lib/mysql"]
|
VOLUME ["/var/lib/mysql"]
|
||||||
|
|
||||||
ENTRYPOINT ["/scripts/run.sh"]
|
ENTRYPOINT ["/scripts/run.sh"]
|
||||||
|
|||||||
Reference in New Issue
Block a user