3
0

Cleanup options, remove obsolete, rename jwt to auth

This commit is contained in:
Denis Arh
2019-12-30 17:14:56 +01:00
parent 8a1d808466
commit 5eac027541
11 changed files with 21 additions and 19 deletions
+1 -2
View File
@@ -56,8 +56,7 @@ func (app *App) Upgrade(ctx context.Context) (err error) {
func (app *App) Initialize(ctx context.Context) (err error) {
// Connects to all services it needs to
err = service.Initialize(ctx, app.Log, service.Config{
Storage: app.Opts.Storage,
Corredor: app.Opts.Corredor,
Storage: app.Opts.Storage,
})
if err != nil {
-1
View File
@@ -27,7 +27,6 @@ type (
Config struct {
Storage options.StorageOpt
Corredor options.CorredorOpt
GRPCClientSystem options.GRPCServerOpt
}
+1 -1
View File
@@ -43,7 +43,7 @@ func (app *App) Setup(log *zap.Logger, opts *app.Options) (err error) {
// that might occur inside auth, mail setup...
defer sentry.Recover()
auth.SetupDefault(opts.JWT.Secret, int(opts.JWT.Expiry/time.Minute))
auth.SetupDefault(opts.Auth.Secret, int(opts.Auth.Expiry/time.Minute))
mail.SetupDialer(opts.SMTP.Host, opts.SMTP.Port, opts.SMTP.User, opts.SMTP.Pass, opts.SMTP.From)
http.SetupDefaults(
+1 -2
View File
@@ -63,8 +63,7 @@ func (app *App) Upgrade(ctx context.Context) (err error) {
func (app *App) Initialize(ctx context.Context) (err error) {
// Connects to all services it needs to
err = service.Initialize(ctx, app.Log, service.Config{
Storage: app.Opts.Storage,
Corredor: app.Opts.Corredor,
Storage: app.Opts.Storage,
})
if err != nil {
+1 -2
View File
@@ -29,8 +29,7 @@ type (
}
Config struct {
Storage options.StorageOpt
Corredor options.CorredorOpt
Storage options.StorageOpt
}
)
+2 -2
View File
@@ -7,7 +7,7 @@ import (
type (
Options struct {
SMTP options.SMTPOpt
JWT options.JWTOpt
Auth options.AuthOpt
HTTPClient options.HTTPClientOpt
DB options.DBOpt
Upgrade options.UpgradeOpt
@@ -30,8 +30,8 @@ func NewOptions(prefix ...string) *Options {
}
return &Options{
Auth: *options.Auth(),
SMTP: *options.SMTP(p),
JWT: *options.JWT(p),
HTTPClient: *options.HttpClient(p),
DB: *options.DB(p),
Upgrade: *options.Upgrade(p),
+4
View File
@@ -17,12 +17,16 @@ type (
MaxBackoffDelay time.Duration `env:"CORREDOR_MAX_BACKOFF_DELAY"`
DefaultExecTimeout time.Duration `env:"CORREDOR_DEFAULT_EXEC_TIMEOUT"`
// Allow scripts to have runner explicitly defined
RunAsEnabled bool `env:"CORREDOR_RUN_AS_ENABLED"`
}
)
func Corredor(pfix string) (o *CorredorOpt) {
o = &CorredorOpt{
Enabled: true,
RunAsEnabled: true,
Addr: "corredor:80",
MaxBackoffDelay: time.Minute,
DefaultExecTimeout: time.Minute,
+8 -4
View File
@@ -7,20 +7,24 @@ import (
)
type (
JWTOpt struct {
AuthOpt struct {
Secret string `env:"AUTH_JWT_SECRET"`
Expiry time.Duration `env:"AUTH_JWT_EXPIRY"`
}
)
func JWT(pfix string) (o *JWTOpt) {
o = &JWTOpt{
func Auth() (o *AuthOpt) {
o = &AuthOpt{
Expiry: time.Hour * 24 * 30,
}
fill(o, pfix)
fill(o, "")
// Setting JWT secret to random string to prevent security accidents...
//
// @todo check if this is a monolith system
// on microservice setup we can not afford to autogenerate secret:
// each subsystem will get it's own
if o.Secret == "" {
o.Secret = string(rand.Bytes(32))
}
+1 -2
View File
@@ -59,8 +59,7 @@ func (app *App) Upgrade(ctx context.Context) (err error) {
func (app *App) Initialize(ctx context.Context) (err error) {
// Connects to all services it needs to
err = service.Initialize(ctx, app.Log, service.Config{
Storage: app.Opts.Storage,
Corredor: app.Opts.Corredor,
Storage: app.Opts.Storage,
})
if err != nil {
-1
View File
@@ -26,7 +26,6 @@ type (
Config struct {
Storage options.StorageOpt
Corredor options.CorredorOpt
GRPCClientSystem options.GRPCServerOpt
}
+2 -2
View File
@@ -28,8 +28,8 @@ func NewIntegrationTestApp(service string, parts ...app.Runnable) app.Runnable {
opt.Upgrade.Always = true
// Create a new JWT secret (to prevent any security weirdness)
opt.JWT.Secret = string(rand.Bytes(32))
opt.JWT.Expiry = time.Minute
opt.Auth.Secret = string(rand.Bytes(32))
opt.Auth.Expiry = time.Minute
logger.DefaultLevel.SetLevel(zap.DebugLevel)
log := logger.MakeDebugLogger()