feat(proxy): Add reverse proxy feature
This commit is contained in:
@@ -1,11 +1,73 @@
|
||||
package config
|
||||
|
||||
type Config interface {
|
||||
type BaseConfiguration interface {
|
||||
GetConfiguration() *Configuration
|
||||
GetGatewayConfiguration() *GatewayConfiguration
|
||||
GetFeatures() []string
|
||||
GetRoutes() []RouteConfiguration
|
||||
GetApis() []ApiConfiguration
|
||||
GetHost() string
|
||||
GetPort() int
|
||||
}
|
||||
|
||||
type Configuration struct {
|
||||
Gateway Gateway `yaml:"gateway"`
|
||||
Hosts []Host `yaml:"hosts"`
|
||||
Targets []Target `yaml:"targets"`
|
||||
Apis []Api `yaml:"apis"`
|
||||
Routes []Route `yaml:"routes"`
|
||||
}
|
||||
|
||||
type Gateway struct {
|
||||
Host string `yaml:"host"`
|
||||
Port int `yaml:"port"`
|
||||
Features []string `yaml:"features"`
|
||||
}
|
||||
|
||||
type Host struct {
|
||||
ID string `yaml:"id"`
|
||||
Name string `yaml:"name"`
|
||||
Domain string `yaml:"domain"`
|
||||
Secure bool `yaml:"secure"`
|
||||
}
|
||||
|
||||
type Target struct {
|
||||
ID string `yaml:"id"`
|
||||
Name string `yaml:"name"`
|
||||
URL string `yaml:"url"`
|
||||
}
|
||||
|
||||
type Api struct {
|
||||
ID string `yaml:"id"`
|
||||
Host string `yaml:"host"`
|
||||
Target string `yaml:"target"`
|
||||
}
|
||||
|
||||
type Route struct {
|
||||
ID string `yaml:"id"`
|
||||
Api string `yaml:"api"`
|
||||
Path string `yaml:"path"`
|
||||
StripPrefix StripPrefix `yaml:"strip_prefix"`
|
||||
Security Security `yaml:"security"`
|
||||
}
|
||||
|
||||
type StripPrefix struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
Prefix string `yaml:"prefix"`
|
||||
}
|
||||
|
||||
type Security struct {
|
||||
Auth Auth `yaml:"auth"`
|
||||
WAF WAF `yaml:"waf"`
|
||||
}
|
||||
|
||||
type Auth struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
Type string `yaml:"type"`
|
||||
Header string `yaml:"header"`
|
||||
Path AuthPath `yaml:"path"`
|
||||
}
|
||||
|
||||
type AuthPath struct {
|
||||
Include []string `yaml:"include"`
|
||||
Exclude []string `yaml:"exclude"`
|
||||
}
|
||||
|
||||
type WAF struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
Methods []string `yaml:"methods"`
|
||||
}
|
||||
|
||||
34
app/config/database.go
Normal file
34
app/config/database.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package config
|
||||
|
||||
import "git.secnex.io/secnex/api-gateway/utils"
|
||||
|
||||
type Database struct {
|
||||
Host string
|
||||
Port int
|
||||
User string
|
||||
Password string
|
||||
Database string
|
||||
SSLMode string
|
||||
}
|
||||
|
||||
func NewDatabaseConfiguration(host string, port int, user string, password string, database string, sslmode string) Database {
|
||||
return Database{
|
||||
Host: host,
|
||||
Port: port,
|
||||
User: user,
|
||||
Password: password,
|
||||
Database: database,
|
||||
SSLMode: sslmode,
|
||||
}
|
||||
}
|
||||
|
||||
func NewDatabaseConfigurationFromEnv() Database {
|
||||
return NewDatabaseConfiguration(
|
||||
utils.GetEnv("DATABASE_HOST", "localhost"),
|
||||
utils.GetEnvInt("DATABASE_PORT", 5432),
|
||||
utils.GetEnv("DATABASE_USER", "postgres"),
|
||||
utils.GetEnv("DATABASE_PASSWORD", "postgres"),
|
||||
utils.GetEnv("DATABASE_NAME", "secnex"),
|
||||
utils.GetEnv("DATABASE_SSLMODE", "disable"),
|
||||
)
|
||||
}
|
||||
@@ -6,20 +6,20 @@ import (
|
||||
"go.yaml.in/yaml/v3"
|
||||
)
|
||||
|
||||
type FileConfig struct {
|
||||
type File struct {
|
||||
filePath string
|
||||
config *Configuration
|
||||
}
|
||||
|
||||
func NewFileConfig(filePath string) (*FileConfig, error) {
|
||||
c := &FileConfig{filePath: filePath, config: &Configuration{}}
|
||||
func NewFile(filePath string) (*File, error) {
|
||||
c := &File{filePath: filePath, config: &Configuration{}}
|
||||
if err := c.loadConfig(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return c, nil
|
||||
}
|
||||
|
||||
func (c *FileConfig) loadConfig() error {
|
||||
func (c *File) loadConfig() error {
|
||||
data, err := os.ReadFile(c.filePath)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -27,34 +27,6 @@ func (c *FileConfig) loadConfig() error {
|
||||
return yaml.Unmarshal(data, c.config)
|
||||
}
|
||||
|
||||
func (c *FileConfig) GetConfiguration() *Configuration {
|
||||
func (c *File) GetConfiguration() *Configuration {
|
||||
return c.config
|
||||
}
|
||||
|
||||
func (c *FileConfig) GetGatewayConfiguration() *GatewayConfiguration {
|
||||
return &c.config.Gateway
|
||||
}
|
||||
|
||||
func (c *FileConfig) GetRoutes() []RouteConfiguration {
|
||||
return c.config.Routes
|
||||
}
|
||||
|
||||
func (c *FileConfig) GetProxies() []ProxyConfiguration {
|
||||
return c.config.Proxies
|
||||
}
|
||||
|
||||
func (c *FileConfig) GetHost() string {
|
||||
return c.config.Gateway.Host
|
||||
}
|
||||
|
||||
func (c *FileConfig) GetPort() int {
|
||||
return c.config.Gateway.Port
|
||||
}
|
||||
|
||||
func (c *FileConfig) GetApis() []ApiConfiguration {
|
||||
return c.config.Apis
|
||||
}
|
||||
|
||||
func (c *FileConfig) GetFeatures() []string {
|
||||
return c.config.Gateway.Features
|
||||
}
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
package config
|
||||
|
||||
type Configuration struct {
|
||||
Gateway GatewayConfiguration `yaml:"gateway"`
|
||||
Apis []ApiConfiguration `yaml:"apis"`
|
||||
Routes []RouteConfiguration `yaml:"routes"`
|
||||
Proxies []ProxyConfiguration `yaml:"proxies"`
|
||||
}
|
||||
|
||||
type GatewayConfiguration struct {
|
||||
Host string `yaml:"host"`
|
||||
Port int `yaml:"port"`
|
||||
Features []string `yaml:"features"`
|
||||
}
|
||||
|
||||
type RouteConfiguration struct {
|
||||
ID string `yaml:"id"`
|
||||
Path string `yaml:"path"`
|
||||
StripPrefix struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
Prefix string `yaml:"prefix"`
|
||||
} `yaml:"strip_prefix"`
|
||||
Security SecurityConfiguration `yaml:"security"`
|
||||
}
|
||||
|
||||
type SecurityConfiguration struct {
|
||||
Auth AuthConfiguration `yaml:"auth"`
|
||||
WAF WAFConfiguration `yaml:"waf"`
|
||||
}
|
||||
|
||||
type WAFConfiguration struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
Methods []string `yaml:"methods"`
|
||||
}
|
||||
|
||||
type AuthConfiguration struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
Type string `yaml:"type"`
|
||||
Header string `yaml:"header"`
|
||||
Path AuthPathConfiguration `yaml:"path"`
|
||||
}
|
||||
|
||||
type AuthPathConfiguration struct {
|
||||
Include []string `yaml:"include"`
|
||||
Exclude []string `yaml:"exclude"`
|
||||
}
|
||||
|
||||
type ProxyConfiguration struct {
|
||||
ID string `yaml:"id"`
|
||||
Host string `yaml:"host"`
|
||||
Target string `yaml:"target"`
|
||||
}
|
||||
|
||||
type ApiConfiguration struct {
|
||||
ID string `yaml:"id"`
|
||||
Target string `yaml:"target"`
|
||||
}
|
||||
Reference in New Issue
Block a user