From 0d632dfdae59c9aceac6960f8596ce4cdca551de Mon Sep 17 00:00:00 2001 From: Urban Klinc Date: Thu, 26 Nov 2020 10:12:11 +0100 Subject: [PATCH] Add code generated files, removed obsolete files --- pkg/options/DB.gen.go | 35 ++++++++++ pkg/options/DB.go | 12 ++++ pkg/options/HTTPClient.gen.go | 41 ++++++++++++ pkg/options/HTTPServer.gen.go | 72 ++++++++++++++++++++ pkg/options/HTTPServer.go | 12 ++++ pkg/options/README.adoc | 32 +++++++++ pkg/options/SMTP.gen.go | 43 ++++++++++++ pkg/options/actionLog.gen.go | 37 +++++++++++ pkg/options/actionlog.go | 19 ------ pkg/options/auth.gen.go | 40 +++++++++++ pkg/options/auth.go | 12 ++++ pkg/options/corredor.gen.go | 64 ++++++++++++++++++ pkg/options/corredor.go | 52 +-------------- pkg/options/db.go | 26 -------- pkg/options/environment.gen.go | 35 ++++++++++ pkg/options/environment.go | 16 ----- pkg/options/helpers.go | 6 ++ pkg/options/http.go | 74 --------------------- pkg/options/http_client.go | 29 -------- pkg/options/jwt.go | 33 --------- pkg/options/monitor.gen.go | 39 +++++++++++ pkg/options/monitor.go | 20 ------ pkg/options/objectStore.gen.go | 44 ++++++++++++ pkg/options/provision.gen.go | 35 ++++++++++ pkg/options/provision.go | 17 ----- pkg/options/pubsub.go | 41 ------------ pkg/options/sentry.gen.go | 49 ++++++++++++++ pkg/options/sentry.go | 34 ---------- pkg/options/smtp.go | 31 --------- pkg/options/storage.go | 32 --------- pkg/options/upgrade.gen.go | 37 +++++++++++ pkg/options/upgrade.go | 19 ------ pkg/options/{wait_for.go => waitFor.gen.go} | 31 +++++---- pkg/options/waitFor.go | 14 ++++ pkg/options/websocket.gen.go | 43 ++++++++++++ pkg/options/websocket.go | 31 --------- 36 files changed, 722 insertions(+), 485 deletions(-) create mode 100644 pkg/options/DB.gen.go create mode 100644 pkg/options/DB.go create mode 100644 pkg/options/HTTPClient.gen.go create mode 100644 pkg/options/HTTPServer.gen.go create mode 100644 pkg/options/HTTPServer.go create mode 100644 pkg/options/README.adoc create mode 100644 pkg/options/SMTP.gen.go create mode 100644 pkg/options/actionLog.gen.go delete mode 100644 pkg/options/actionlog.go create mode 100644 pkg/options/auth.gen.go create mode 100644 pkg/options/auth.go create mode 100644 pkg/options/corredor.gen.go delete mode 100644 pkg/options/db.go create mode 100644 pkg/options/environment.gen.go delete mode 100644 pkg/options/http.go delete mode 100644 pkg/options/http_client.go delete mode 100644 pkg/options/jwt.go create mode 100644 pkg/options/monitor.gen.go delete mode 100644 pkg/options/monitor.go create mode 100644 pkg/options/objectStore.gen.go create mode 100644 pkg/options/provision.gen.go delete mode 100644 pkg/options/provision.go delete mode 100644 pkg/options/pubsub.go create mode 100644 pkg/options/sentry.gen.go delete mode 100644 pkg/options/sentry.go delete mode 100644 pkg/options/smtp.go delete mode 100644 pkg/options/storage.go create mode 100644 pkg/options/upgrade.gen.go delete mode 100644 pkg/options/upgrade.go rename pkg/options/{wait_for.go => waitFor.gen.go} (54%) create mode 100644 pkg/options/waitFor.go create mode 100644 pkg/options/websocket.gen.go delete mode 100644 pkg/options/websocket.go diff --git a/pkg/options/DB.gen.go b/pkg/options/DB.gen.go new file mode 100644 index 000000000..d0eed20bd --- /dev/null +++ b/pkg/options/DB.gen.go @@ -0,0 +1,35 @@ +package options + +// This file is auto-generated. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// Definitions file that controls how this file is generated: +// pkg/options/DB.yaml + +type ( + DBOpt struct { + DSN string `env:"DB_DSN"` + } +) + +// DB initializes and returns a DBOpt with default values +func DB() (o *DBOpt) { + o = &DBOpt{ + DSN: "sqlite3://file::memory:?cache=shared&mode=memory", + } + + fill(o) + + // Function that allows access to custom logic inside the parent function. + // The custom logic in the other file should be like: + // func (o *DB) Defaults() {...} + func(o interface{}) { + if def, ok := o.(interface{ Defaults() }); ok { + def.Defaults() + } + }(o) + + return +} diff --git a/pkg/options/DB.go b/pkg/options/DB.go new file mode 100644 index 000000000..2bdfb7c03 --- /dev/null +++ b/pkg/options/DB.go @@ -0,0 +1,12 @@ +package options + +import ( + "strings" +) + +func (o *DBOpt) Defaults() { + if o.DSN != "" && !strings.Contains(o.DSN, "://") { + // Make sure DSN is compatible with new requirements + o.DSN = "mysql://" + o.DSN + } +} diff --git a/pkg/options/HTTPClient.gen.go b/pkg/options/HTTPClient.gen.go new file mode 100644 index 000000000..23cbc43fd --- /dev/null +++ b/pkg/options/HTTPClient.gen.go @@ -0,0 +1,41 @@ +package options + +// This file is auto-generated. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// Definitions file that controls how this file is generated: +// pkg/options/HTTPClient.yaml + +import ( + "time" +) + +type ( + HTTPClientOpt struct { + ClientTSLInsecure bool `env:"HTTP_CLIENT_TSL_INSECURE"` + HttpClientTimeout time.Duration `env:"HTTP_CLIENT_TIMEOUT"` + } +) + +// HTTPClient initializes and returns a HTTPClientOpt with default values +func HTTPClient() (o *HTTPClientOpt) { + o = &HTTPClientOpt{ + ClientTSLInsecure: false, + HttpClientTimeout: 30 * time.Second, + } + + fill(o) + + // Function that allows access to custom logic inside the parent function. + // The custom logic in the other file should be like: + // func (o *HTTPClient) Defaults() {...} + func(o interface{}) { + if def, ok := o.(interface{ Defaults() }); ok { + def.Defaults() + } + }(o) + + return +} diff --git a/pkg/options/HTTPServer.gen.go b/pkg/options/HTTPServer.gen.go new file mode 100644 index 000000000..5eb335f94 --- /dev/null +++ b/pkg/options/HTTPServer.gen.go @@ -0,0 +1,72 @@ +package options + +// This file is auto-generated. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// Definitions file that controls how this file is generated: +// pkg/options/HTTPServer.yaml + +import ( + "github.com/cortezaproject/corteza-server/pkg/rand" +) + +type ( + HTTPServerOpt struct { + Addr string `env:"HTTP_ADDR"` + LogRequest bool `env:"HTTP_LOG_REQUEST"` + LogResponse bool `env:"HTTP_LOG_RESPONSE"` + Tracing bool `env:"HTTP_ERROR_TRACING"` + EnableHealthcheckRoute bool `env:"HTTP_ENABLE_HEALTHCHECK_ROUTE"` + EnableVersionRoute bool `env:"HTTP_ENABLE_VERSION_ROUTE"` + EnableDebugRoute bool `env:"HTTP_ENABLE_DEBUG_ROUTE"` + EnableMetrics bool `env:"HTTP_METRICS"` + MetricsServiceLabel string `env:"HTTP_METRICS_NAME"` + MetricsUsername string `env:"HTTP_METRICS_USERNAME"` + MetricsPassword string `env:"HTTP_METRICS_PASSWORD"` + EnablePanicReporting bool `env:"HTTP_REPORT_PANIC"` + ApiEnabled bool `env:"HTTP_API_ENABLED"` + ApiBaseUrl string `env:"HTTP_API_BASE_URL"` + WebappEnabled bool `env:"HTTP_WEBAPP_ENABLED"` + WebappBaseUrl string `env:"HTTP_WEBAPP_BASE_URL"` + WebappBaseDir string `env:"HTTP_WEBAPP_BASE_DIR"` + WebappList string `env:"HTTP_WEBAPP_LIST"` + } +) + +// HTTPServer initializes and returns a HTTPServerOpt with default values +func HTTPServer() (o *HTTPServerOpt) { + o = &HTTPServerOpt{ + Addr: ":80", + LogRequest: false, + LogResponse: false, + Tracing: false, + EnableHealthcheckRoute: true, + EnableVersionRoute: true, + EnableDebugRoute: false, + EnableMetrics: false, + MetricsServiceLabel: "corteza", + MetricsUsername: "metrics", + MetricsPassword: string(rand.Bytes(5)), + EnablePanicReporting: true, + ApiEnabled: true, + WebappEnabled: false, + WebappBaseUrl: "/", + WebappBaseDir: "webapp/public", + WebappList: "admin,auth,messaging,compose", + } + + fill(o) + + // Function that allows access to custom logic inside the parent function. + // The custom logic in the other file should be like: + // func (o *HTTPServer) Defaults() {...} + func(o interface{}) { + if def, ok := o.(interface{ Defaults() }); ok { + def.Defaults() + } + }(o) + + return +} diff --git a/pkg/options/HTTPServer.go b/pkg/options/HTTPServer.go new file mode 100644 index 000000000..ce82aa4f7 --- /dev/null +++ b/pkg/options/HTTPServer.go @@ -0,0 +1,12 @@ +package options + +func (o *HTTPServerOpt) Defaults() { + + if o.WebappEnabled && o.ApiEnabled && o.ApiBaseUrl == "" { + // api base URL is still on root (empty string) + // but webapps are enabled (that means, server also serves static files from WebappBaseDir) + // + // Let's be nice and move API to /api + o.ApiBaseUrl = "/api" + } +} diff --git a/pkg/options/README.adoc b/pkg/options/README.adoc new file mode 100644 index 000000000..581faa056 --- /dev/null +++ b/pkg/options/README.adoc @@ -0,0 +1,32 @@ +# Options YAML integration + +This file is meant to help with the creation of a .YAML file inside options package. + +The name of the .YAML will dedicate the name of the .gen.go file e.g. fileName1.yaml -> fileName1.gen.go, filename2.yaml -> filename2.gen.go + +The contents of the .YAML file should look like this: + + name: + + imports: + + props + - name: ... + type: ... + env: ... + default: ... + + + +**name** +It is the name of the + +name: name of option +imports - the list of needed imports +props: - name -> name of variable +props: - type -> the type of variable if not given it is "string" by +default +props: - env -> environment value that if it is not defined will be auto +generated from "name" and "props: - name" +props: - default -> the default value that is asigned to the "prop" + - strings should be given in double quotations if they are to be qouted diff --git a/pkg/options/SMTP.gen.go b/pkg/options/SMTP.gen.go new file mode 100644 index 000000000..239bc32f1 --- /dev/null +++ b/pkg/options/SMTP.gen.go @@ -0,0 +1,43 @@ +package options + +// This file is auto-generated. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// Definitions file that controls how this file is generated: +// pkg/options/SMTP.yaml + +type ( + SMTPOpt struct { + Host string `env:"SMTP_HOST"` + Port int `env:"SMTP_PORT"` + User string `env:"SMTP_USER"` + Pass string `env:"SMTP_PASS"` + From string `env:"SMTP_FROM"` + TlsInsecure bool `env:"SMTP_TLS_INSECURE"` + TlsServerName string `env:"SMTP_TLS_SERVER_NAME"` + } +) + +// SMTP initializes and returns a SMTPOpt with default values +func SMTP() (o *SMTPOpt) { + o = &SMTPOpt{ + Host: "localhost", + Port: 25, + TlsInsecure: false, + } + + fill(o) + + // Function that allows access to custom logic inside the parent function. + // The custom logic in the other file should be like: + // func (o *SMTP) Defaults() {...} + func(o interface{}) { + if def, ok := o.(interface{ Defaults() }); ok { + def.Defaults() + } + }(o) + + return +} diff --git a/pkg/options/actionLog.gen.go b/pkg/options/actionLog.gen.go new file mode 100644 index 000000000..2e885c120 --- /dev/null +++ b/pkg/options/actionLog.gen.go @@ -0,0 +1,37 @@ +package options + +// This file is auto-generated. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// Definitions file that controls how this file is generated: +// pkg/options/actionLog.yaml + +type ( + ActionLogOpt struct { + Enabled bool `env:"ACTIONLOG_ENABLED"` + Debug bool `env:"ACTIONLOG_DEBUG"` + } +) + +// ActionLog initializes and returns a ActionLogOpt with default values +func ActionLog() (o *ActionLogOpt) { + o = &ActionLogOpt{ + Enabled: true, + Debug: false, + } + + fill(o) + + // Function that allows access to custom logic inside the parent function. + // The custom logic in the other file should be like: + // func (o *ActionLog) Defaults() {...} + func(o interface{}) { + if def, ok := o.(interface{ Defaults() }); ok { + def.Defaults() + } + }(o) + + return +} diff --git a/pkg/options/actionlog.go b/pkg/options/actionlog.go deleted file mode 100644 index 2c9c07af3..000000000 --- a/pkg/options/actionlog.go +++ /dev/null @@ -1,19 +0,0 @@ -package options - -type ( - ActionLogOpt struct { - Enabled bool `env:"ACTIONLOG_ENABLED"` - Debug bool `env:"ACTIONLOG_DEBUG"` - } -) - -func ActionLog() (o *ActionLogOpt) { - o = &ActionLogOpt{ - Enabled: true, - Debug: false, - } - - fill(o) - - return -} diff --git a/pkg/options/auth.gen.go b/pkg/options/auth.gen.go new file mode 100644 index 000000000..f62e3e465 --- /dev/null +++ b/pkg/options/auth.gen.go @@ -0,0 +1,40 @@ +package options + +// This file is auto-generated. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// Definitions file that controls how this file is generated: +// pkg/options/auth.yaml + +import ( + "time" +) + +type ( + AuthOpt struct { + Secret string `env:"AUTH_JWT_SECRET"` + Expiry time.Duration `env:"AUTH_JWT_EXPIRY"` + } +) + +// Auth initializes and returns a AuthOpt with default values +func Auth() (o *AuthOpt) { + o = &AuthOpt{ + Expiry: time.Hour * 24 * 30, + } + + fill(o) + + // Function that allows access to custom logic inside the parent function. + // The custom logic in the other file should be like: + // func (o *Auth) Defaults() {...} + func(o interface{}) { + if def, ok := o.(interface{ Defaults() }); ok { + def.Defaults() + } + }(o) + + return +} diff --git a/pkg/options/auth.go b/pkg/options/auth.go new file mode 100644 index 000000000..07d27f00d --- /dev/null +++ b/pkg/options/auth.go @@ -0,0 +1,12 @@ +package options + +import ( + "github.com/cortezaproject/corteza-server/pkg/rand" +) + +func (o *AuthOpt) Defaults() { + + if o.Secret == "" { + o.Secret = string(rand.Bytes(32)) + } +} diff --git a/pkg/options/corredor.gen.go b/pkg/options/corredor.gen.go new file mode 100644 index 000000000..80b229a64 --- /dev/null +++ b/pkg/options/corredor.gen.go @@ -0,0 +1,64 @@ +package options + +// This file is auto-generated. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// Definitions file that controls how this file is generated: +// pkg/options/corredor.yaml + +import ( + "time" +) + +type ( + CorredorOpt struct { + Enabled bool `env:"CORREDOR_ENABLED"` + Addr string `env:"CORREDOR_ADDR"` + MaxBackoffDelay time.Duration `env:"CORREDOR_MAX_BACKOFF_DELAY"` + MaxReceiveMessageSize int `env:"CORREDOR_MAX_RECEIVE_MESSAGE_SIZE"` + DefaultExecTimeout time.Duration `env:"CORREDOR_DEFAULT_EXEC_TIMEOUT"` + ListTimeout time.Duration `env:"CORREDOR_LIST_TIMEOUT"` + ListRefresh time.Duration `env:"CORREDOR_LIST_REFRESH"` + RunAsEnabled bool `env:"CORREDOR_RUN_AS_ENABLED"` + TlsCertEnabled bool `env:"CORREDOR_CLIENT_CERTIFICATES_ENABLED"` + TlsCertPath string `env:"CORREDOR_CLIENT_CERTIFICATES_PATH"` + TlsCertCA string `env:"CORREDOR_CLIENT_CERTIFICATES_CA"` + TlsCertPrivate string `env:"CORREDOR_CLIENT_CERTIFICATES_PRIVATE"` + TlsCertPublic string `env:"CORREDOR_CLIENT_CERTIFICATES_PUBLIC"` + TlsServerName string `env:"CORREDOR_CLIENT_CERTIFICATES_SERVER_NAME"` + } +) + +// Corredor initializes and returns a CorredorOpt with default values +func Corredor() (o *CorredorOpt) { + o = &CorredorOpt{ + Enabled: true, + Addr: "localhost:50051", + MaxBackoffDelay: time.Minute, + MaxReceiveMessageSize: 2 << 23, + DefaultExecTimeout: time.Minute, + ListTimeout: time.Second * 2, + ListRefresh: time.Second * 5, + RunAsEnabled: true, + TlsCertEnabled: false, + TlsCertPath: "/certs/corredor/client", + TlsCertCA: "ca.crt", + TlsCertPrivate: "private.key", + TlsCertPublic: "public.crt", + } + + fill(o) + + // Function that allows access to custom logic inside the parent function. + // The custom logic in the other file should be like: + // func (o *Corredor) Defaults() {...} + func(o interface{}) { + if def, ok := o.(interface{ Defaults() }); ok { + def.Defaults() + } + }(o) + + return +} diff --git a/pkg/options/corredor.go b/pkg/options/corredor.go index 4d5d7c213..9508ba400 100644 --- a/pkg/options/corredor.go +++ b/pkg/options/corredor.go @@ -2,60 +2,10 @@ package options import ( "path" - "time" ) -type ( - CorredorOpt struct { - Enabled bool `env:"CORREDOR_ENABLED"` - - // Also used by corredor service to configure gRPC server - Addr string `env:"CORREDOR_ADDR"` - - MaxBackoffDelay time.Duration `env:"CORREDOR_MAX_BACKOFF_DELAY"` - - MaxReceiveMessageSize int `env:"CORREDOR_MAX_RECEIVE_MESSAGE_SIZE"` - - DefaultExecTimeout time.Duration `env:"CORREDOR_DEFAULT_EXEC_TIMEOUT"` - - ListTimeout time.Duration `env:"CORREDOR_LIST_TIMEOUT"` - ListRefresh time.Duration `env:"CORREDOR_LIST_REFRESH"` - - // Allow scripts to have runner explicitly defined - RunAsEnabled bool `env:"CORREDOR_RUN_AS_ENABLED"` - - TlsCertEnabled bool `env:"CORREDOR_CLIENT_CERTIFICATES_ENABLED"` - TlsCertPath string `env:"CORREDOR_CLIENT_CERTIFICATES_PATH"` - TlsCertCA string `env:"CORREDOR_CLIENT_CERTIFICATES_CA"` - TlsCertPrivate string `env:"CORREDOR_CLIENT_CERTIFICATES_PRIVATE"` - TlsCertPublic string `env:"CORREDOR_CLIENT_CERTIFICATES_PUBLIC"` - TlsServerName string `env:"CORREDOR_CLIENT_CERTIFICATES_SERVER_NAME"` - } -) - -func Corredor() (o *CorredorOpt) { - o = &CorredorOpt{ - Enabled: true, - RunAsEnabled: true, - Addr: "localhost:50051", - MaxBackoffDelay: time.Minute, - MaxReceiveMessageSize: 2 << 23, // 16MB - DefaultExecTimeout: time.Minute, - ListTimeout: time.Second * 2, - ListRefresh: time.Second * 5, - - TlsCertEnabled: false, - TlsCertPath: "/certs/corredor/client", - TlsCertCA: "ca.crt", - TlsCertPublic: "public.crt", - TlsCertPrivate: "private.key", - } - - fill(o) - +func (o *CorredorOpt) Defaults() { o.TlsCertCA = path.Join(o.TlsCertPath, o.TlsCertCA) o.TlsCertPrivate = path.Join(o.TlsCertPath, o.TlsCertPrivate) o.TlsCertPublic = path.Join(o.TlsCertPath, o.TlsCertPublic) - - return } diff --git a/pkg/options/db.go b/pkg/options/db.go deleted file mode 100644 index 8e34cc10b..000000000 --- a/pkg/options/db.go +++ /dev/null @@ -1,26 +0,0 @@ -package options - -import ( - "strings" -) - -type ( - DBOpt struct { - DSN string `env:"DB_DSN"` - } -) - -func DB(pfix string) (o *DBOpt) { - o = &DBOpt{ - DSN: "sqlite3://file::memory:?cache=shared&mode=memory", - } - - fill(o) - - if o.DSN != "" && !strings.Contains(o.DSN, "://") { - // Make sure DSN is compatible with new requirements - o.DSN = "mysql://" + o.DSN - } - - return -} diff --git a/pkg/options/environment.gen.go b/pkg/options/environment.gen.go new file mode 100644 index 000000000..e5d799b06 --- /dev/null +++ b/pkg/options/environment.gen.go @@ -0,0 +1,35 @@ +package options + +// This file is auto-generated. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// Definitions file that controls how this file is generated: +// pkg/options/environment.yaml + +type ( + EnvironmentOpt struct { + Environment string `env:"ENVIRONMENT"` + } +) + +// Environment initializes and returns a EnvironmentOpt with default values +func Environment() (o *EnvironmentOpt) { + o = &EnvironmentOpt{ + Environment: "production", + } + + fill(o) + + // Function that allows access to custom logic inside the parent function. + // The custom logic in the other file should be like: + // func (o *Environment) Defaults() {...} + func(o interface{}) { + if def, ok := o.(interface{ Defaults() }); ok { + def.Defaults() + } + }(o) + + return +} diff --git a/pkg/options/environment.go b/pkg/options/environment.go index 39bb4d8f0..2b413e6d3 100644 --- a/pkg/options/environment.go +++ b/pkg/options/environment.go @@ -2,22 +2,6 @@ package options import "strings" -type ( - EnvironmentOpt struct { - Environment string `env:"ENVIRONMENT"` - } -) - -func Environment() (o *EnvironmentOpt) { - o = &EnvironmentOpt{ - Environment: "production", - } - - fill(o) - - return -} - func (e EnvironmentOpt) IsDevelopment() bool { return strings.HasPrefix(e.Environment, "dev") } diff --git a/pkg/options/helpers.go b/pkg/options/helpers.go index ae248e3e4..781e0a26a 100644 --- a/pkg/options/helpers.go +++ b/pkg/options/helpers.go @@ -8,6 +8,12 @@ import ( "github.com/spf13/cast" ) +type ( + filler interface { + fill() + } +) + func fill(opt interface{}) { v := reflect.ValueOf(opt) if v.Kind() != reflect.Ptr { diff --git a/pkg/options/http.go b/pkg/options/http.go deleted file mode 100644 index 5027c9c4b..000000000 --- a/pkg/options/http.go +++ /dev/null @@ -1,74 +0,0 @@ -package options - -import ( - "github.com/cortezaproject/corteza-server/pkg/rand" -) - -type ( - HTTPServerOpt struct { - Addr string `env:"HTTP_ADDR"` - LogRequest bool `env:"HTTP_LOG_REQUEST"` - LogResponse bool `env:"HTTP_LOG_RESPONSE"` - Tracing bool `env:"HTTP_ERROR_TRACING"` - - EnableHealthcheckRoute bool `env:"HTTP_ENABLE_HEALTHCHECK_ROUTE"` - EnableVersionRoute bool `env:"HTTP_ENABLE_VERSION_ROUTE"` - EnableDebugRoute bool `env:"HTTP_ENABLE_DEBUG_ROUTE"` - - EnableMetrics bool `env:"HTTP_METRICS"` - MetricsServiceLabel string `env:"HTTP_METRICS_NAME"` - MetricsUsername string `env:"HTTP_METRICS_USERNAME"` - MetricsPassword string `env:"HTTP_METRICS_PASSWORD"` - - EnablePanicReporting bool `env:"HTTP_REPORT_PANIC"` - - ApiEnabled bool `env:"HTTP_API_ENABLED"` - ApiBaseUrl string `env:"HTTP_API_BASE_URL"` - - WebappEnabled bool `env:"HTTP_WEBAPP_ENABLED"` - WebappBaseUrl string `env:"HTTP_WEBAPP_BASE_URL"` - WebappBaseDir string `env:"HTTP_WEBAPP_BASE_DIR"` - WebappList string `env:"HTTP_WEBAPP_LIST"` - } -) - -func HTTP(pfix string) (o *HTTPServerOpt) { - o = &HTTPServerOpt{ - Addr: ":80", - LogRequest: false, - LogResponse: false, - Tracing: false, - EnableHealthcheckRoute: true, - EnableVersionRoute: true, - EnableDebugRoute: false, - EnableMetrics: false, - MetricsServiceLabel: "corteza", - MetricsUsername: "metrics", - - // Reports panics to Sentry through HTTP middleware - EnablePanicReporting: true, - - // Setting metrics password to random string to prevent security accidents... - MetricsPassword: string(rand.Bytes(5)), - - ApiEnabled: true, - ApiBaseUrl: "", - - WebappEnabled: false, - WebappBaseUrl: "/", - WebappBaseDir: "webapp/public", - WebappList: "admin,auth,messaging,compose", - } - - fill(o) - - if o.WebappEnabled && o.ApiEnabled && o.ApiBaseUrl == "" { - // api base URL is still on root (empty string) - // but webapps are enabled (that means, server also serves static files from WebappBaseDir) - // - // Let's be nice and move API to /api - o.ApiBaseUrl = "/api" - } - - return -} diff --git a/pkg/options/http_client.go b/pkg/options/http_client.go deleted file mode 100644 index ce5d2f24f..000000000 --- a/pkg/options/http_client.go +++ /dev/null @@ -1,29 +0,0 @@ -package options - -import ( - "time" -) - -type ( - HTTPClientOpt struct { - ClientTSLInsecure bool `env:"HTTP_CLIENT_TSL_INSECURE"` - HttpClientTimeout time.Duration `env:"HTTP_CLIENT_TIMEOUT"` - } -) - -func HttpClient(pfix string) (o *HTTPClientOpt) { - o = &HTTPClientOpt{ - ClientTSLInsecure: false, - HttpClientTimeout: 30 * time.Second, - } - - fill(o) - - func(o interface{}) { - if def, ok := o.(interface{ Defaults() }); ok { - def.Defaults() - } - }(o) - - return -} diff --git a/pkg/options/jwt.go b/pkg/options/jwt.go deleted file mode 100644 index 6dcf26cf5..000000000 --- a/pkg/options/jwt.go +++ /dev/null @@ -1,33 +0,0 @@ -package options - -import ( - "time" - - "github.com/cortezaproject/corteza-server/pkg/rand" -) - -type ( - AuthOpt struct { - Secret string `env:"AUTH_JWT_SECRET"` - Expiry time.Duration `env:"AUTH_JWT_EXPIRY"` - } -) - -func Auth() (o *AuthOpt) { - o = &AuthOpt{ - Expiry: time.Hour * 24 * 30, - } - - 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)) - } - - return -} diff --git a/pkg/options/monitor.gen.go b/pkg/options/monitor.gen.go new file mode 100644 index 000000000..1de1fa12d --- /dev/null +++ b/pkg/options/monitor.gen.go @@ -0,0 +1,39 @@ +package options + +// This file is auto-generated. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// Definitions file that controls how this file is generated: +// pkg/options/monitor.yaml + +import ( + "time" +) + +type ( + MonitorOpt struct { + Interval time.Duration `env:"MONITOR_INTERVAL"` + } +) + +// Monitor initializes and returns a MonitorOpt with default values +func Monitor() (o *MonitorOpt) { + o = &MonitorOpt{ + Interval: 300 * time.Second, + } + + fill(o) + + // Function that allows access to custom logic inside the parent function. + // The custom logic in the other file should be like: + // func (o *Monitor) Defaults() {...} + func(o interface{}) { + if def, ok := o.(interface{ Defaults() }); ok { + def.Defaults() + } + }(o) + + return +} diff --git a/pkg/options/monitor.go b/pkg/options/monitor.go deleted file mode 100644 index 66a4f4713..000000000 --- a/pkg/options/monitor.go +++ /dev/null @@ -1,20 +0,0 @@ -package options - -import ( - "time" -) - -type ( - MonitorOpt struct { - Interval time.Duration `env:"MONITOR_INTERVAL"` - } -) - -func Monitor(pfix string) (o *MonitorOpt) { - o = &MonitorOpt{ - Interval: 300 * time.Second, - } - fill(o) - - return -} diff --git a/pkg/options/objectStore.gen.go b/pkg/options/objectStore.gen.go new file mode 100644 index 000000000..062d5a52e --- /dev/null +++ b/pkg/options/objectStore.gen.go @@ -0,0 +1,44 @@ +package options + +// This file is auto-generated. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// Definitions file that controls how this file is generated: +// pkg/options/objectStore.yaml + +type ( + ObjectStoreOpt struct { + Path string `env:"STORAGE_PATH"` + MinioEndpoint string `env:"MINIO_ENDPOINT"` + MinioSecure bool `env:"MINIO_SECURE"` + MinioAccessKey string `env:"MINIO_ACCESS_KEY"` + MinioSecretKey string `env:"MINIO_SECRET_KEY"` + MinioSSECKey string `env:"MINIO_SSEC_KEY"` + MinioBucket string `env:"MINIO_BUCKET"` + MinioStrict bool `env:"MINIO_STRICT"` + } +) + +// ObjectStore initializes and returns a ObjectStoreOpt with default values +func ObjectStore() (o *ObjectStoreOpt) { + o = &ObjectStoreOpt{ + Path: "var/store", + MinioSecure: true, + MinioStrict: false, + } + + fill(o) + + // Function that allows access to custom logic inside the parent function. + // The custom logic in the other file should be like: + // func (o *ObjectStore) Defaults() {...} + func(o interface{}) { + if def, ok := o.(interface{ Defaults() }); ok { + def.Defaults() + } + }(o) + + return +} diff --git a/pkg/options/provision.gen.go b/pkg/options/provision.gen.go new file mode 100644 index 000000000..b3d333af6 --- /dev/null +++ b/pkg/options/provision.gen.go @@ -0,0 +1,35 @@ +package options + +// This file is auto-generated. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// Definitions file that controls how this file is generated: +// pkg/options/provision.yaml + +type ( + ProvisionOpt struct { + Always bool `env:"PROVISION_ALWAYS"` + } +) + +// Provision initializes and returns a ProvisionOpt with default values +func Provision() (o *ProvisionOpt) { + o = &ProvisionOpt{ + Always: true, + } + + fill(o) + + // Function that allows access to custom logic inside the parent function. + // The custom logic in the other file should be like: + // func (o *Provision) Defaults() {...} + func(o interface{}) { + if def, ok := o.(interface{ Defaults() }); ok { + def.Defaults() + } + }(o) + + return +} diff --git a/pkg/options/provision.go b/pkg/options/provision.go deleted file mode 100644 index 69cf18f88..000000000 --- a/pkg/options/provision.go +++ /dev/null @@ -1,17 +0,0 @@ -package options - -type ( - ProvisionOpt struct { - Always bool `env:"PROVISION_ALWAYS"` - } -) - -func Provision(pfix string) (o *ProvisionOpt) { - o = &ProvisionOpt{ - Always: true, - } - - fill(o) - - return -} diff --git a/pkg/options/pubsub.go b/pkg/options/pubsub.go deleted file mode 100644 index eab7ac4b4..000000000 --- a/pkg/options/pubsub.go +++ /dev/null @@ -1,41 +0,0 @@ -package options - -import ( - "time" -) - -type ( - PubSubOpt struct { - Mode string `env:"PUBSUB_MODE"` - - // Mode - PollingInterval time.Duration `env:"PUBSUB_POLLING_INTERVAL"` - - // Redis - RedisAddr string `env:"PUBSUB_REDIS_ADDR"` - RedisTimeout time.Duration `env:"PUBSUB_REDIS_TIMEOUT"` - RedisPingTimeout time.Duration `env:"PUBSUB_REDIS_PING_TIMEOUT"` - RedisPingPeriod time.Duration `env:"PUBSUB_REDIS_PING_PERIOD"` - } -) - -func PubSub(pfix string) (o *PubSubOpt) { - const ( - timeout = 15 * time.Second - pingTimeout = 120 * time.Second - pingPeriod = (pingTimeout * 9) / 10 - ) - - o = &PubSubOpt{ - Mode: "poll", - PollingInterval: timeout, - RedisAddr: "redis:6379", - RedisTimeout: timeout, - RedisPingTimeout: pingTimeout, - RedisPingPeriod: pingPeriod, - } - - fill(o) - - return -} diff --git a/pkg/options/sentry.gen.go b/pkg/options/sentry.gen.go new file mode 100644 index 000000000..68f073685 --- /dev/null +++ b/pkg/options/sentry.gen.go @@ -0,0 +1,49 @@ +package options + +// This file is auto-generated. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// Definitions file that controls how this file is generated: +// pkg/options/sentry.yaml + +import ( + "github.com/cortezaproject/corteza-server/pkg/version" +) + +type ( + SentryOpt struct { + DSN string `env:"SENTRY_DSN"` + Debug bool `env:"SENTRY_DEBUG"` + AttachStacktrace bool `env:"SENTRY_ATTACH_STACKTRACE"` + SampleRate float32 `env:"SENTRY_SAMPLE_RATE"` + MaxBreadcrumbs int `env:"SENTRY_MAX_BREADCRUMBS"` + ServerName string `env:"SENTRY_SERVERNAME"` + Release string `env:"SENTRY_RELEASE"` + Dist string `env:"SENTRY_DIST"` + Environment string `env:"SENTRY_ENVIRONMENT"` + } +) + +// Sentry initializes and returns a SentryOpt with default values +func Sentry() (o *SentryOpt) { + o = &SentryOpt{ + AttachStacktrace: true, + MaxBreadcrumbs: 0, + Release: version.Version, + } + + fill(o) + + // Function that allows access to custom logic inside the parent function. + // The custom logic in the other file should be like: + // func (o *Sentry) Defaults() {...} + func(o interface{}) { + if def, ok := o.(interface{ Defaults() }); ok { + def.Defaults() + } + }(o) + + return +} diff --git a/pkg/options/sentry.go b/pkg/options/sentry.go deleted file mode 100644 index 561f088ee..000000000 --- a/pkg/options/sentry.go +++ /dev/null @@ -1,34 +0,0 @@ -package options - -import ( - "github.com/cortezaproject/corteza-server/pkg/version" -) - -type ( - SentryOpt struct { - DSN string `env:"SENTRY_DSN"` - - Debug bool `env:"SENTRY_DEBUG"` - AttachStacktrace bool `env:"SENTRY_ATTACH_STACKTRACE"` - SampleRate float32 `env:"SENTRY_SAMPLE_RATE"` - MaxBreadcrumbs int `env:"SENTRY_MAX_BREADCRUMBS"` - - ServerName string `env:"SENTRY_SERVERNAME"` - Release string `env:"SENTRY_RELEASE"` - Dist string `env:"SENTRY_DIST"` - Environment string `env:"SENTRY_ENVIRONMENT"` - } -) - -func Sentry(pfix string) (o *SentryOpt) { - o = &SentryOpt{ - AttachStacktrace: true, - MaxBreadcrumbs: 0, - - Release: version.Version, - } - - fill(o) - - return -} diff --git a/pkg/options/smtp.go b/pkg/options/smtp.go deleted file mode 100644 index a8cb9e2d9..000000000 --- a/pkg/options/smtp.go +++ /dev/null @@ -1,31 +0,0 @@ -package options - -type ( - SMTPOpt struct { - Host string `env:"SMTP_HOST"` - Port int `env:"SMTP_PORT"` - User string `env:"SMTP_USER"` - Pass string `env:"SMTP_PASS"` - From string `env:"SMTP_FROM"` - - TlsInsecure bool `env:"SMTP_TSL_INSECURE"` - TlsServerName string `env:"SMTP_TSL_SERVER_NAME"` - } -) - -func SMTP(pfix string) (o *SMTPOpt) { - o = &SMTPOpt{ - Host: "localhost", - Port: 25, - User: "", - Pass: "", - From: "", - - TlsInsecure: false, - TlsServerName: "", - } - - fill(o) - - return -} diff --git a/pkg/options/storage.go b/pkg/options/storage.go deleted file mode 100644 index 13131d578..000000000 --- a/pkg/options/storage.go +++ /dev/null @@ -1,32 +0,0 @@ -package options - -type ( - ObjectStoreOpt struct { - Path string `env:"STORAGE_PATH"` - - MinioEndpoint string `env:"MINIO_ENDPOINT"` - MinioSecure bool `env:"MINIO_SECURE"` - MinioAccessKey string `env:"MINIO_ACCESS_KEY"` - MinioSecretKey string `env:"MINIO_SECRET_KEY"` - MinioSSECKey string `env:"MINIO_SSEC_KEY"` - MinioBucket string `env:"MINIO_BUCKET"` - MinioStrict bool `env:"MINIO_STRICT"` - } -) - -func ObjectStore(pfix string) (o *ObjectStoreOpt) { - o = &ObjectStoreOpt{ - Path: "var/store", - - // Make minio secure by default - MinioSecure: true, - - // Run in struct mode: - // - do not create un-existing buckets - MinioStrict: false, - } - - fill(o) - - return -} diff --git a/pkg/options/upgrade.gen.go b/pkg/options/upgrade.gen.go new file mode 100644 index 000000000..80ea30750 --- /dev/null +++ b/pkg/options/upgrade.gen.go @@ -0,0 +1,37 @@ +package options + +// This file is auto-generated. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// Definitions file that controls how this file is generated: +// pkg/options/upgrade.yaml + +type ( + UpgradeOpt struct { + Debug bool `env:"UPGRADE_DEBUG"` + Always bool `env:"UPGRADE_ALWAYS"` + } +) + +// Upgrade initializes and returns a UpgradeOpt with default values +func Upgrade() (o *UpgradeOpt) { + o = &UpgradeOpt{ + Debug: false, + Always: true, + } + + fill(o) + + // Function that allows access to custom logic inside the parent function. + // The custom logic in the other file should be like: + // func (o *Upgrade) Defaults() {...} + func(o interface{}) { + if def, ok := o.(interface{ Defaults() }); ok { + def.Defaults() + } + }(o) + + return +} diff --git a/pkg/options/upgrade.go b/pkg/options/upgrade.go deleted file mode 100644 index 255f18e26..000000000 --- a/pkg/options/upgrade.go +++ /dev/null @@ -1,19 +0,0 @@ -package options - -type ( - UpgradeOpt struct { - Debug bool `env:"UPGRADE_DEBUG"` - Always bool `env:"UPGRADE_ALWAYS"` - } -) - -func Upgrade(pfix string) (o *UpgradeOpt) { - o = &UpgradeOpt{ - Debug: false, - Always: true, - } - - fill(o) - - return -} diff --git a/pkg/options/wait_for.go b/pkg/options/waitFor.gen.go similarity index 54% rename from pkg/options/wait_for.go rename to pkg/options/waitFor.gen.go index f624d09a3..c55bec4a7 100644 --- a/pkg/options/wait_for.go +++ b/pkg/options/waitFor.gen.go @@ -1,7 +1,14 @@ package options +// This file is auto-generated. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// Definitions file that controls how this file is generated: +// pkg/options/waitFor.yaml + import ( - "strings" "time" ) @@ -16,11 +23,11 @@ type ( } ) -func WaitFor(pfix string) (o *WaitForOpt) { +// WaitFor initializes and returns a WaitForOpt with default values +func WaitFor() (o *WaitForOpt) { o = &WaitForOpt{ Delay: 0, StatusPage: true, - Services: "", ServicesTimeout: time.Minute, ServicesProbeTimeout: time.Second * 30, ServicesProbeInterval: time.Second * 5, @@ -28,14 +35,14 @@ func WaitFor(pfix string) (o *WaitForOpt) { fill(o) + // Function that allows access to custom logic inside the parent function. + // The custom logic in the other file should be like: + // func (o *WaitFor) Defaults() {...} + func(o interface{}) { + if def, ok := o.(interface{ Defaults() }); ok { + def.Defaults() + } + }(o) + return } - -// Parses hosts and return slice of strings, one per host -func (o WaitForOpt) GetServices() []string { - if len(o.Services) == 0 { - return []string{} - } - - return strings.Split(o.Services, " ") -} diff --git a/pkg/options/waitFor.go b/pkg/options/waitFor.go new file mode 100644 index 000000000..31f6d3b4b --- /dev/null +++ b/pkg/options/waitFor.go @@ -0,0 +1,14 @@ +package options + +import ( + "strings" +) + +// Parses hosts and return slice of strings, one per host +func (o WaitForOpt) GetServices() []string { + if len(o.Services) == 0 { + return []string{} + } + + return strings.Split(o.Services, " ") +} diff --git a/pkg/options/websocket.gen.go b/pkg/options/websocket.gen.go new file mode 100644 index 000000000..0f52c29c8 --- /dev/null +++ b/pkg/options/websocket.gen.go @@ -0,0 +1,43 @@ +package options + +// This file is auto-generated. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +// Definitions file that controls how this file is generated: +// pkg/options/websocket.yaml + +import ( + "time" +) + +type ( + WebsocketOpt struct { + Timeout time.Duration `env:"WEBSOCKET_TIMEOUT"` + PingTimeout time.Duration `env:"WEBSOCKET_PING_TIMEOUT"` + PingPeriod time.Duration `env:"WEBSOCKET_PING_PERIOD"` + } +) + +// Websocket initializes and returns a WebsocketOpt with default values +func Websocket() (o *WebsocketOpt) { + o = &WebsocketOpt{ + Timeout: 15 * time.Second, + PingTimeout: 120 * time.Second, + PingPeriod: ((120 * time.Second) * 9) / 10, + } + + fill(o) + + // Function that allows access to custom logic inside the parent function. + // The custom logic in the other file should be like: + // func (o *Websocket) Defaults() {...} + func(o interface{}) { + if def, ok := o.(interface{ Defaults() }); ok { + def.Defaults() + } + }(o) + + return +} diff --git a/pkg/options/websocket.go b/pkg/options/websocket.go deleted file mode 100644 index 3c0faf501..000000000 --- a/pkg/options/websocket.go +++ /dev/null @@ -1,31 +0,0 @@ -package options - -import ( - "time" -) - -type ( - WebsocketOpt struct { - Timeout time.Duration `env:"WEBSOCKET_TIMEOUT"` - PingTimeout time.Duration `env:"WEBSOCKET_PING_TIMEOUT"` - PingPeriod time.Duration `env:"WEBSOCKET_PING_PERIOD"` - } -) - -func Websocket(pfix string) (o *WebsocketOpt) { - const ( - timeout = 15 * time.Second - pingTimeout = 120 * time.Second - pingPeriod = (pingTimeout * 9) / 10 - ) - - o = &WebsocketOpt{ - Timeout: timeout, - PingTimeout: pingTimeout, - PingPeriod: pingPeriod, - } - - fill(o) - - return -}