2019-05-13 01:27:26 +02:00
|
|
|
package serv
|
|
|
|
|
2019-06-04 16:54:51 +02:00
|
|
|
import (
|
2019-06-14 06:32:15 +02:00
|
|
|
"strings"
|
|
|
|
|
2019-06-04 16:54:51 +02:00
|
|
|
"github.com/gobuffalo/flect"
|
|
|
|
)
|
|
|
|
|
2019-05-13 01:27:26 +02:00
|
|
|
type config struct {
|
2019-09-08 20:56:32 +02:00
|
|
|
AppName string `mapstructure:"app_name"`
|
|
|
|
Env string
|
|
|
|
HostPort string `mapstructure:"host_port"`
|
|
|
|
Host string
|
|
|
|
Port string
|
|
|
|
WebUI bool `mapstructure:"web_ui"`
|
|
|
|
LogLevel string `mapstructure:"log_level"`
|
|
|
|
EnableTracing bool `mapstructure:"enable_tracing"`
|
|
|
|
UseAllowList bool `mapstructure:"use_allow_list"`
|
|
|
|
WatchAndReload bool `mapstructure:"reload_on_config_change"`
|
|
|
|
AuthFailBlock string `mapstructure:"auth_fail_block"`
|
2019-09-20 06:19:11 +02:00
|
|
|
SeedFile string `mapstructure:"seed_file"`
|
2019-09-26 06:35:31 +02:00
|
|
|
MigrationsPath string `mapstructure:"migrations_path"`
|
|
|
|
|
|
|
|
Inflections map[string]string
|
2019-05-13 01:27:26 +02:00
|
|
|
|
|
|
|
Auth struct {
|
|
|
|
Type string
|
|
|
|
Cookie string
|
|
|
|
Header string
|
|
|
|
|
|
|
|
Rails struct {
|
|
|
|
Version string
|
|
|
|
SecretKeyBase string `mapstructure:"secret_key_base"`
|
|
|
|
URL string
|
|
|
|
Password string
|
|
|
|
MaxIdle int `mapstructure:"max_idle"`
|
|
|
|
MaxActive int `mapstructure:"max_active"`
|
|
|
|
Salt string
|
|
|
|
SignSalt string `mapstructure:"sign_salt"`
|
|
|
|
AuthSalt string `mapstructure:"auth_salt"`
|
|
|
|
}
|
|
|
|
|
|
|
|
JWT struct {
|
|
|
|
Provider string
|
|
|
|
Secret string
|
|
|
|
PubKeyFile string `mapstructure:"public_key_file"`
|
|
|
|
PubKeyType string `mapstructure:"public_key_type"`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DB struct {
|
|
|
|
Type string
|
|
|
|
Host string
|
2019-09-26 06:35:31 +02:00
|
|
|
Port uint16
|
2019-05-13 01:27:26 +02:00
|
|
|
DBName string
|
|
|
|
User string
|
|
|
|
Password string
|
|
|
|
Schema string
|
2019-09-26 06:35:31 +02:00
|
|
|
PoolSize int32 `mapstructure:"pool_size"`
|
2019-05-13 01:27:26 +02:00
|
|
|
MaxRetries int `mapstructure:"max_retries"`
|
|
|
|
LogLevel string `mapstructure:"log_level"`
|
|
|
|
|
2019-07-29 07:13:33 +02:00
|
|
|
vars map[string][]byte `mapstructure:"variables"`
|
2019-05-13 01:27:26 +02:00
|
|
|
|
|
|
|
Defaults struct {
|
|
|
|
Filter []string
|
2019-09-08 07:54:38 +02:00
|
|
|
Blocklist []string
|
2019-05-13 01:27:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Tables []configTable
|
|
|
|
} `mapstructure:"database"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type configTable struct {
|
|
|
|
Name string
|
|
|
|
Filter []string
|
|
|
|
Table string
|
2019-09-08 07:54:38 +02:00
|
|
|
Blocklist []string
|
2019-05-13 01:27:26 +02:00
|
|
|
Remotes []configRemote
|
|
|
|
}
|
|
|
|
|
|
|
|
type configRemote struct {
|
|
|
|
Name string
|
|
|
|
ID string
|
|
|
|
Path string
|
|
|
|
URL string
|
2019-06-06 14:57:00 +02:00
|
|
|
Debug bool
|
2019-05-13 01:27:26 +02:00
|
|
|
PassHeaders []string `mapstructure:"pass_headers"`
|
|
|
|
SetHeaders []struct {
|
|
|
|
Name string
|
|
|
|
Value string
|
|
|
|
} `mapstructure:"set_headers"`
|
|
|
|
}
|
|
|
|
|
2019-07-29 07:13:33 +02:00
|
|
|
func (c *config) getVariables() map[string]string {
|
|
|
|
vars := make(map[string]string, len(c.DB.vars))
|
|
|
|
|
|
|
|
for k, v := range c.DB.vars {
|
|
|
|
isVar := false
|
|
|
|
|
|
|
|
for i := range v {
|
|
|
|
if v[i] == '$' {
|
|
|
|
isVar = true
|
|
|
|
} else if v[i] == ' ' {
|
|
|
|
isVar = false
|
|
|
|
} else if isVar && v[i] >= 'a' && v[i] <= 'z' {
|
|
|
|
v[i] = 'A' + (v[i] - 'a')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
vars[k] = string(v)
|
|
|
|
}
|
|
|
|
return vars
|
|
|
|
}
|
|
|
|
|
2019-06-14 06:32:15 +02:00
|
|
|
func (c *config) getAliasMap() map[string][]string {
|
|
|
|
m := make(map[string][]string, len(c.DB.Tables))
|
2019-05-13 01:27:26 +02:00
|
|
|
|
|
|
|
for i := range c.DB.Tables {
|
|
|
|
t := c.DB.Tables[i]
|
|
|
|
|
|
|
|
if len(t.Table) == 0 {
|
|
|
|
continue
|
|
|
|
}
|
2019-06-14 06:32:15 +02:00
|
|
|
|
|
|
|
k := strings.ToLower(t.Table)
|
|
|
|
m[k] = append(m[k], strings.ToLower(t.Name))
|
2019-05-13 01:27:26 +02:00
|
|
|
}
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *config) getFilterMap() map[string][]string {
|
|
|
|
m := make(map[string][]string, len(c.DB.Tables))
|
|
|
|
|
|
|
|
for i := range c.DB.Tables {
|
|
|
|
t := c.DB.Tables[i]
|
|
|
|
|
|
|
|
if len(t.Filter) == 0 {
|
|
|
|
continue
|
|
|
|
}
|
2019-06-14 06:32:15 +02:00
|
|
|
singular := flect.Singularize(t.Name)
|
|
|
|
plural := flect.Pluralize(t.Name)
|
2019-05-13 01:27:26 +02:00
|
|
|
|
|
|
|
if t.Filter[0] == "none" {
|
2019-06-14 06:32:15 +02:00
|
|
|
m[singular] = []string{}
|
|
|
|
m[plural] = []string{}
|
|
|
|
|
2019-05-13 01:27:26 +02:00
|
|
|
} else {
|
2019-06-14 06:32:15 +02:00
|
|
|
m[singular] = t.Filter
|
|
|
|
m[plural] = t.Filter
|
2019-05-13 01:27:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return m
|
|
|
|
}
|