From 5eac0275411082cc90f2ac5923b95a78712005ac Mon Sep 17 00:00:00 2001 From: Denis Arh Date: Mon, 30 Dec 2019 17:14:56 +0100 Subject: [PATCH] Cleanup options, remove obsolete, rename jwt to auth --- compose/app.go | 3 +-- compose/service/service.go | 1 - corteza/corteza.go | 2 +- messaging/app.go | 3 +-- messaging/service/service.go | 3 +-- pkg/app/options.go | 4 ++-- pkg/app/options/corredor.go | 4 ++++ pkg/app/options/jwt.go | 12 ++++++++---- system/app.go | 3 +-- system/service/service.go | 1 - tests/helpers/app.go | 4 ++-- 11 files changed, 21 insertions(+), 19 deletions(-) diff --git a/compose/app.go b/compose/app.go index 95695af3c..2a51bfeb8 100644 --- a/compose/app.go +++ b/compose/app.go @@ -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 { diff --git a/compose/service/service.go b/compose/service/service.go index 6e444a4f9..586c7ca7e 100644 --- a/compose/service/service.go +++ b/compose/service/service.go @@ -27,7 +27,6 @@ type ( Config struct { Storage options.StorageOpt - Corredor options.CorredorOpt GRPCClientSystem options.GRPCServerOpt } diff --git a/corteza/corteza.go b/corteza/corteza.go index d8602dc46..3b0bfce9d 100644 --- a/corteza/corteza.go +++ b/corteza/corteza.go @@ -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( diff --git a/messaging/app.go b/messaging/app.go index c585eb8c6..1f81ef36b 100644 --- a/messaging/app.go +++ b/messaging/app.go @@ -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 { diff --git a/messaging/service/service.go b/messaging/service/service.go index 055447339..08a5913ca 100644 --- a/messaging/service/service.go +++ b/messaging/service/service.go @@ -29,8 +29,7 @@ type ( } Config struct { - Storage options.StorageOpt - Corredor options.CorredorOpt + Storage options.StorageOpt } ) diff --git a/pkg/app/options.go b/pkg/app/options.go index b80e7a50a..b0da004a1 100644 --- a/pkg/app/options.go +++ b/pkg/app/options.go @@ -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), diff --git a/pkg/app/options/corredor.go b/pkg/app/options/corredor.go index 788bb14aa..1a4aa0bf8 100644 --- a/pkg/app/options/corredor.go +++ b/pkg/app/options/corredor.go @@ -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, diff --git a/pkg/app/options/jwt.go b/pkg/app/options/jwt.go index 3fdaab6ef..51c311180 100644 --- a/pkg/app/options/jwt.go +++ b/pkg/app/options/jwt.go @@ -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)) } diff --git a/system/app.go b/system/app.go index 75a9bda6c..94e775a42 100644 --- a/system/app.go +++ b/system/app.go @@ -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 { diff --git a/system/service/service.go b/system/service/service.go index 1209d9dbd..f871895e9 100644 --- a/system/service/service.go +++ b/system/service/service.go @@ -26,7 +26,6 @@ type ( Config struct { Storage options.StorageOpt - Corredor options.CorredorOpt GRPCClientSystem options.GRPCServerOpt } diff --git a/tests/helpers/app.go b/tests/helpers/app.go index 4d12161c4..603128570 100644 --- a/tests/helpers/app.go +++ b/tests/helpers/app.go @@ -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()