From f7a489099824694274027ad6e233b1f30af4109a Mon Sep 17 00:00:00 2001 From: Urban Klinc Date: Thu, 26 Nov 2020 10:03:34 +0100 Subject: [PATCH 1/6] Add .yaml files to be used in code-generation in pkg/options --- pkg/options/DB.yaml | 6 +++ pkg/options/HTTPClient.yaml | 16 +++++++ pkg/options/HTTPServer.yaml | 87 ++++++++++++++++++++++++++++++++++++ pkg/options/SMTP.yaml | 22 +++++++++ pkg/options/actionLog.yaml | 11 +++++ pkg/options/auth.yaml | 15 +++++++ pkg/options/corredor.yaml | 61 +++++++++++++++++++++++++ pkg/options/environment.yaml | 7 +++ pkg/options/monitor.yaml | 10 +++++ pkg/options/objectStore.yaml | 32 +++++++++++++ pkg/options/provision.yaml | 7 +++ pkg/options/sentry.yaml | 32 +++++++++++++ pkg/options/upgrade.yaml | 11 +++++ pkg/options/waitFor.yaml | 34 ++++++++++++++ pkg/options/websocket.yaml | 18 ++++++++ 15 files changed, 369 insertions(+) create mode 100644 pkg/options/DB.yaml create mode 100644 pkg/options/HTTPClient.yaml create mode 100644 pkg/options/HTTPServer.yaml create mode 100644 pkg/options/SMTP.yaml create mode 100644 pkg/options/actionLog.yaml create mode 100644 pkg/options/auth.yaml create mode 100644 pkg/options/corredor.yaml create mode 100644 pkg/options/environment.yaml create mode 100644 pkg/options/monitor.yaml create mode 100644 pkg/options/objectStore.yaml create mode 100644 pkg/options/provision.yaml create mode 100644 pkg/options/sentry.yaml create mode 100644 pkg/options/upgrade.yaml create mode 100644 pkg/options/waitFor.yaml create mode 100644 pkg/options/websocket.yaml diff --git a/pkg/options/DB.yaml b/pkg/options/DB.yaml new file mode 100644 index 000000000..1a1d89883 --- /dev/null +++ b/pkg/options/DB.yaml @@ -0,0 +1,6 @@ + +name: DB + +props: + - name: DSN + default: "sqlite3://file::memory:?cache=shared&mode=memory" \ No newline at end of file diff --git a/pkg/options/HTTPClient.yaml b/pkg/options/HTTPClient.yaml new file mode 100644 index 000000000..2fd538c4b --- /dev/null +++ b/pkg/options/HTTPClient.yaml @@ -0,0 +1,16 @@ + +name: HTTPClient + +imports: + - time + +props: + - name: clientTSLInsecure + type: bool + env: HTTP_CLIENT_TSL_INSECURE + default: false + + - name: httpClientTimeout + type: time.Duration + env: HTTP_CLIENT_TIMEOUT + default: 30 * time.Second \ No newline at end of file diff --git a/pkg/options/HTTPServer.yaml b/pkg/options/HTTPServer.yaml new file mode 100644 index 000000000..09d178abc --- /dev/null +++ b/pkg/options/HTTPServer.yaml @@ -0,0 +1,87 @@ + +name: HTTPServer + +imports: + - github.com/cortezaproject/corteza-server/pkg/rand + +props: + - name: addr + env: HTTP_ADDR + default: ":80" + + - name: logRequest + type: bool + env: HTTP_LOG_REQUEST + default: false + + - name: logResponse + type: bool + env: HTTP_LOG_RESPONSE + default: false + + - name: tracing + type: bool + env: HTTP_ERROR_TRACING + default: false + + - name: enableHealthcheckRoute + type: bool + env: HTTP_ENABLE_HEALTHCHECK_ROUTE + default: true + + - name: enableVersionRoute + type: bool + env: HTTP_ENABLE_VERSION_ROUTE + default: true + + - name: enableDebugRoute + type: bool + env: HTTP_ENABLE_DEBUG_ROUTE + default: false + + - name: enableMetrics + type: bool + env: HTTP_METRICS + default: false + + - name: metricsServiceLabel + env: HTTP_METRICS_NAME + default: "corteza" + + - name: metricsUsername + env: HTTP_METRICS_USERNAME + default: "metrics" + + - name: metricsPassword + env: HTTP_METRICS_PASSWORD + default: string(rand.Bytes(5)) + + - name: enablePanicReporting + type: bool + env: HTTP_REPORT_PANIC + default: true + + - name: apiEnabled + type: bool + env: HTTP_API_ENABLED + default: true + + - name: apiBaseUrl + env: HTTP_API_BASE_URL + + - name: webappEnabled + type: bool + env: HTTP_WEBAPP_ENABLED + default: false + + - name: webappBaseUrl + env: HTTP_WEBAPP_BASE_URL + default: "/" + + - name: webappBaseDir + env: HTTP_WEBAPP_BASE_DIR + default: "webapp/public" + + - name: webappList + env: HTTP_WEBAPP_LIST + default: "admin,auth,messaging,compose" diff --git a/pkg/options/SMTP.yaml b/pkg/options/SMTP.yaml new file mode 100644 index 000000000..068302300 --- /dev/null +++ b/pkg/options/SMTP.yaml @@ -0,0 +1,22 @@ + +name: SMTP + +props: + - name: host + default: "localhost" + + - name: port + type: int + default: 25 + + - name: user + + - name: pass + + - name: from + + - name: tlsInsecure + type: bool + default: false + + - name: tlsServerName diff --git a/pkg/options/actionLog.yaml b/pkg/options/actionLog.yaml new file mode 100644 index 000000000..1a18fd491 --- /dev/null +++ b/pkg/options/actionLog.yaml @@ -0,0 +1,11 @@ + +name: actionLog + +props: + - name: enabled + type: bool + default: true + + - name: debug + type: bool + default: false \ No newline at end of file diff --git a/pkg/options/auth.yaml b/pkg/options/auth.yaml new file mode 100644 index 000000000..428cf6e96 --- /dev/null +++ b/pkg/options/auth.yaml @@ -0,0 +1,15 @@ + +name: auth + +imports: + - time + #- github.com/cortezaproject/corteza-server/pkg/rand + +props: + - name: secret + env: AUTH_JWT_SECRET + + - name: expiry + type: time.Duration + env: AUTH_JWT_EXPIRY + default: time.Hour * 24 * 30 \ No newline at end of file diff --git a/pkg/options/corredor.yaml b/pkg/options/corredor.yaml new file mode 100644 index 000000000..133ed1fa1 --- /dev/null +++ b/pkg/options/corredor.yaml @@ -0,0 +1,61 @@ + +name: corredor + +imports: + - "time" + +props: + - name: enabled + type: bool + default: true + + - name: addr + default: "localhost:50051" + + - name: maxBackoffDelay + type: time.Duration + default: time.Minute + + - name: maxReceiveMessageSize + type: int + default: 2 << 23 + + - name: defaultExecTimeout + type: time.Duration + default: time.Minute + + - name: listTimeout + type: time.Duration + default: time.Second * 2 + + - name: listRefresh + type: time.Duration + default: time.Second * 5 + + - name: runAsEnabled + type: bool + default: true + + - name: tlsCertEnabled + type: bool + env: corredor_client_certificates_enabled + default: false + + - name: tlsCertPath + env: corredor_client_certificates_path + default: "/certs/corredor/client" + + - name: tlsCertCA + env: CORREDOR_CLIENT_CERTIFICATES_CA + default: "ca.crt" + + - name: tlsCertPrivate + env: CORREDOR_CLIENT_CERTIFICATES_PRIVATE + default: "private.key" + + - name: tlsCertPublic + env: CORREDOR_CLIENT_CERTIFICATES_PUBLIC + default: "public.crt" + + - name: tlsServerName + env: CORREDOR_CLIENT_CERTIFICATES_SERVER_NAME \ No newline at end of file diff --git a/pkg/options/environment.yaml b/pkg/options/environment.yaml new file mode 100644 index 000000000..0dc9a84f3 --- /dev/null +++ b/pkg/options/environment.yaml @@ -0,0 +1,7 @@ + +name: environment + +props: + - name: environment + default: "production" + env: ENVIRONMENT diff --git a/pkg/options/monitor.yaml b/pkg/options/monitor.yaml new file mode 100644 index 000000000..93ea38b10 --- /dev/null +++ b/pkg/options/monitor.yaml @@ -0,0 +1,10 @@ + +name: monitor + +imports: + - time + +props: + - name: interval + type: time.Duration + default: 300 * time.Second \ No newline at end of file diff --git a/pkg/options/objectStore.yaml b/pkg/options/objectStore.yaml new file mode 100644 index 000000000..b60bb50cd --- /dev/null +++ b/pkg/options/objectStore.yaml @@ -0,0 +1,32 @@ + +name: objectStore + +props: + - name: path + env: STORAGE_PATH + default: "var/store" + + - name: minioEndpoint + env: MINIO_ENDPOINT + + - name: minioSecure + type: bool + env: MINIO_SECURE + default: true + + - name: minioAccessKey + env: MINIO_ACCESS_KEY + + - name: minioSecretKey + env: MINIO_SECRET_KEY + + - name: minioSSECKey + env: MINIO_SSEC_KEY + + - name: minioBucket + env: MINIO_BUCKET + + - name: minioStrict + type: bool + env: MINIO_STRICT + default: false \ No newline at end of file diff --git a/pkg/options/provision.yaml b/pkg/options/provision.yaml new file mode 100644 index 000000000..e0843676d --- /dev/null +++ b/pkg/options/provision.yaml @@ -0,0 +1,7 @@ + +name: provision + +props: + - name: always + type: bool + default: true \ No newline at end of file diff --git a/pkg/options/sentry.yaml b/pkg/options/sentry.yaml new file mode 100644 index 000000000..0649b5da2 --- /dev/null +++ b/pkg/options/sentry.yaml @@ -0,0 +1,32 @@ + +name: sentry + +imports: + - github.com/cortezaproject/corteza-server/pkg/version + +props: + - name: DSN + + - name: debug + type: bool + + - name: attachStacktrace + type: bool + default: true + + - name: sampleRate + type: float32 + + - name: maxBreadcrumbs + type: int + default: 0 + + - name: serverName + env: SENTRY_SERVERNAME + + - name: release + default: version.Version + + - name: dist + + - name: environment \ No newline at end of file diff --git a/pkg/options/upgrade.yaml b/pkg/options/upgrade.yaml new file mode 100644 index 000000000..9c2eb14d5 --- /dev/null +++ b/pkg/options/upgrade.yaml @@ -0,0 +1,11 @@ + +name: upgrade + +props: + - name: Debug + type: bool + default: false + + - name: Always + type: bool + default: true \ No newline at end of file diff --git a/pkg/options/waitFor.yaml b/pkg/options/waitFor.yaml new file mode 100644 index 000000000..24db6e2ce --- /dev/null +++ b/pkg/options/waitFor.yaml @@ -0,0 +1,34 @@ + +name: waitFor + +imports: + - time + +props: + - name: Delay + type: time.Duration + env: WAIT_FOR + default: 0 + + - name: StatusPage + type: bool + env: WAIT_FOR_STATUS_PAGE + default: true + + - name: Services + env: WAIT_FOR_SERVICES + + - name: ServicesTimeout + type: time.Duration + env: WAIT_FOR_SERVICES_TIMEOUT + default: time.Minute + + - name: ServicesProbeTimeout + type: time.Duration + env: WAIT_FOR_SERVICES_PROBE_TIMEOUT + default: time.Second * 30 + + - name: ServicesProbeInterval + type: time.Duration + env: WAIT_FOR_SERVICES_PROBE_INTERVAL + default: time.Second * 5 \ No newline at end of file diff --git a/pkg/options/websocket.yaml b/pkg/options/websocket.yaml new file mode 100644 index 000000000..475df8d77 --- /dev/null +++ b/pkg/options/websocket.yaml @@ -0,0 +1,18 @@ + +name: websocket + +imports: + - time + +props: + - name: Timeout + type: time.Duration + default: 15 * time.Second + + - name: PingTimeout + type: time.Duration + default: 120 * time.Second + + - name: PingPeriod + type: time.Duration + default: ((120 * time.Second) * 9) / 10 \ No newline at end of file From 0d632dfdae59c9aceac6960f8596ce4cdca551de Mon Sep 17 00:00:00 2001 From: Urban Klinc Date: Thu, 26 Nov 2020 10:12:11 +0100 Subject: [PATCH 2/6] 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 -} From df9ebe54aabecf12651411ce05136bddf372fca5 Mon Sep 17 00:00:00 2001 From: Urban Klinc Date: Thu, 26 Nov 2020 10:17:52 +0100 Subject: [PATCH 3/6] Add codegen template + logic, modifiyed codegen.go to accept new files --- pkg/codegen/assets/options.go.tpl | 48 ++++++++++++ pkg/codegen/codegen.go | 24 +++++- pkg/codegen/options.go | 122 ++++++++++++++++++++++++++++++ 3 files changed, 191 insertions(+), 3 deletions(-) create mode 100644 pkg/codegen/assets/options.go.tpl create mode 100644 pkg/codegen/options.go diff --git a/pkg/codegen/assets/options.go.tpl b/pkg/codegen/assets/options.go.tpl new file mode 100644 index 000000000..44676af26 --- /dev/null +++ b/pkg/codegen/assets/options.go.tpl @@ -0,0 +1,48 @@ +package {{ .Package }} + +// 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: +// {{ .Source }} + +{{ if $.Imports -}} +import ( +{{- range .Imports }} + {{ normalizeImport . }} +{{- end }} +){{ end }} + +type ( + {{ export $.Name }}Opt struct { + {{- range $prop := $.Properties}} + {{ export $prop.Name }} {{ $prop.Type }} `env:"{{ toUpper $prop.Env}}"` + {{- end }} + } +) + +// {{ export $.Name }} initializes and returns a {{ export $.Name }}Opt with default values +func {{ export $.Name }}() (o *{{ export $.Name }}Opt) { + o = &{{ export $.Name }}Opt{ + {{- range $prop := $.Properties }} + {{- if $prop.Default }} + {{ export $prop.Name }}: {{ $prop.Default }}, + {{- end }} + {{- end }} + } + + 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 *{{ export $.Name}}) Defaults() {...} + func(o interface{}) { + if def, ok := o.(interface{ Defaults() }); ok { + def.Defaults() + } + }(o) + + return +} diff --git a/pkg/codegen/codegen.go b/pkg/codegen/codegen.go index cd24af469..5cd7a650c 100644 --- a/pkg/codegen/codegen.go +++ b/pkg/codegen/codegen.go @@ -3,13 +3,14 @@ package codegen import ( "flag" "fmt" - "github.com/Masterminds/sprig" - "github.com/cortezaproject/corteza-server/pkg/cli" - "github.com/fsnotify/fsnotify" "os" "path/filepath" "strings" "text/template" + + "github.com/Masterminds/sprig" + "github.com/cortezaproject/corteza-server/pkg/cli" + "github.com/fsnotify/fsnotify" ) func Proc() { @@ -47,6 +48,10 @@ func Proc() { storeSrc []string storeDefs []*storeDef + optionSrcPath = filepath.Join("pkg", "options", "*.yaml") + optionSrc []string + optionDefs []*optionsDef + tpls *template.Template tplBase = template.New(""). Funcs(map[string]interface{}{ @@ -55,6 +60,7 @@ func Proc() { "unexport": unexport, "toggleExport": toggleExport, "toLower": strings.ToLower, + "toUpper": strings.ToUpper, "cc2underscore": cc2underscore, "normalizeImport": normalizeImport, "comment": func(text string, skip1st bool) string { @@ -123,6 +129,9 @@ func Proc() { storeSrc = glob(storeSrcPath) output("loaded %d store definitions from %s\n", len(storeSrc), storeSrcPath) + optionSrc = glob(optionSrcPath) + output("loaded %d option defenitions from %s\n", len(optionSrc), optionSrcPath) + if watchChanges { if watcher != nil { watcher.Close() @@ -137,6 +146,7 @@ func Proc() { fileList = append(fileList, typeSrc...) fileList = append(fileList, restSrc...) fileList = append(fileList, storeSrc...) + fileList = append(fileList, optionSrc...) for _, d := range fileList { cli.HandleError(watcher.Add(d)) @@ -189,6 +199,14 @@ func Proc() { return } + if optionDefs, err = procOptions(optionSrc...); err == nil { + err = genOptions(tpls, optionDefs...) + } + + if outputErr(err, "fail to process options:\n") { + return + } + }() if !watchChanges { diff --git a/pkg/codegen/options.go b/pkg/codegen/options.go new file mode 100644 index 000000000..f911e66fd --- /dev/null +++ b/pkg/codegen/options.go @@ -0,0 +1,122 @@ +package codegen + +import ( + "fmt" + "io" + "os" + "path" + "strings" + "text/template" + + "gopkg.in/yaml.v3" +) + +type ( + optionsDef struct { + Source string + outputDir string + + Name string + + // List of imports + // Used only by generated file and not pre-generated-user-file + Imports []string `yaml:"imports"` + + Properties optionsPropSet `yaml:"props"` + } + + optionsPropSet []*optionsProp + + optionsProp struct { + Name string + Type string + Env string + Default *optionsPropDefault + } + + optionsPropDefault string +) + +// Processes multiple options defenitions +func procOptions(mm ...string) (dd []*optionsDef, err error) { + var ( + f io.ReadCloser + d *optionsDef + ) + + dd = make([]*optionsDef, 0) + for _, m := range mm { + err = func() error { + if f, err = os.Open(m); err != nil { + return err + } + + defer f.Close() + + d = &optionsDef{} + + if err := yaml.NewDecoder(f).Decode(d); err != nil { + return err + } + + for _, j := range d.Properties { + + if j.Type == "" { + j.Type = "string" + } + + if j.Env == "" { + j.Env = strings.ToUpper(d.Name + "_" + cc2underscore(j.Name)) + } + + } + + d.Source = m + d.outputDir = path.Dir(m) + + dd = append(dd, d) + + return nil + }() + if err != nil { + return nil, fmt.Errorf("could not process %s: %w", m, err) + } + } + return dd, nil +} + +// Custom UnmarshelYAML function for +func (pd *optionsPropDefault) UnmarshalYAML(n *yaml.Node) error { + + val := n.Value + + if n.Style == yaml.DoubleQuotedStyle { + val = "\"" + val + "\"" + } + + *pd = optionsPropDefault(val) + + return nil +} + +// Gets package name from file path +func (o optionsDef) Package() string { + return path.Base(path.Dir(o.Source)) +} + +func genOptions(tpl *template.Template, dd ...*optionsDef) (err error) { + var ( + tplOptionsGen = tpl.Lookup("options.go.tpl") + + dst string + ) + + for _, d := range dd { + dst = path.Join(d.outputDir, path.Base(d.Source)[:strings.LastIndex(path.Base(d.Source), ".")]+".gen.go") + err = goTemplate(dst, tplOptionsGen, d) + if err != nil { + return + } + } + return nil +} From 55ec8e07c02e651320543c8089186bf34404066e Mon Sep 17 00:00:00 2001 From: Urban Klinc Date: Thu, 26 Nov 2020 10:23:06 +0100 Subject: [PATCH 4/6] Apply change options to app init proc --- app/options.go | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/app/options.go b/app/options.go index 4260988d1..e957b7238 100644 --- a/app/options.go +++ b/app/options.go @@ -24,29 +24,23 @@ type ( } ) -func NewOptions(prefix ...string) *Options { - var p = "" - if len(prefix) > 0 { - p = prefix[0] - } +func NewOptions() *Options { - // @todo remover prefixes on opt constructors and - // pass in EnvironmentOpt so we can have environment-dependant defaults return &Options{ Environment: *options.Environment(), ActionLog: *options.ActionLog(), Auth: *options.Auth(), - SMTP: *options.SMTP(p), - HTTPClient: *options.HttpClient(p), - DB: *options.DB(p), - Upgrade: *options.Upgrade(p), - Provision: *options.Provision(p), - Sentry: *options.Sentry(p), - ObjStore: *options.ObjectStore(p), + SMTP: *options.SMTP(), + HTTPClient: *options.HTTPClient(), + DB: *options.DB(), + Upgrade: *options.Upgrade(), + Provision: *options.Provision(), + Sentry: *options.Sentry(), + ObjStore: *options.ObjectStore(), Corredor: *options.Corredor(), - Monitor: *options.Monitor(p), - WaitFor: *options.WaitFor(p), - HTTPServer: *options.HTTP(p), - Websocket: *options.Websocket(p), + Monitor: *options.Monitor(), + WaitFor: *options.WaitFor(), + HTTPServer: *options.HTTPServer(), + Websocket: *options.Websocket(), } } From e83b5258cb45b1f133f954634d1c1ef9082980c8 Mon Sep 17 00:00:00 2001 From: Urban Klinc Date: Thu, 26 Nov 2020 10:26:36 +0100 Subject: [PATCH 5/6] Updated go deps --- go.mod | 7 ++++++- go.sum | 10 ++++++++++ vendor/modules.txt | 10 ++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index db20b5e93..545599712 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.15 require ( cloud.google.com/go v0.44.3 // indirect + github.com/0xAX/notificator v0.0.0-20191016112426-3962a5ea8da1 // indirect github.com/360EntSecGroup-Skylar/excelize/v2 v2.0.2 github.com/766b/chi-prometheus v0.0.0-20180509160047-46ac2b31aa30 github.com/99designs/basicauth-go v0.0.0-20160802081356-2a93ba0f464d @@ -14,6 +15,8 @@ require ( github.com/PaesslerAG/gval v1.0.1 // indirect github.com/PaesslerAG/jsonpath v0.1.1 // indirect github.com/SentimensRG/ctx v0.0.0-20180729130232-0bfd988c655d + github.com/codegangsta/envy v0.0.0-20141216192214-4b78388c8ce4 // indirect + github.com/codegangsta/gin v0.0.0-20171026143024-cafe2ce98974 // indirect github.com/crusttech/go-oidc v0.0.0-20180918092017-982855dad3e1 github.com/davecgh/go-spew v1.1.1 github.com/deckarep/golang-set v1.7.1 // indirect @@ -44,6 +47,7 @@ require ( github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 github.com/lib/pq v1.1.0 github.com/markbates/goth v1.50.0 + github.com/mattn/go-shellwords v1.0.10 // indirect github.com/mattn/go-sqlite3 v1.14.0 github.com/minio/minio-go/v6 v6.0.39 github.com/mitchellh/copystructure v1.0.0 // indirect @@ -73,6 +77,7 @@ require ( gopkg.in/ini.v1 v1.51.0 // indirect gopkg.in/mail.v2 v2.3.1 gopkg.in/square/go-jose.v2 v2.3.1 // indirect + gopkg.in/urfave/cli.v1 v1.20.0 // indirect gopkg.in/yaml.v2 v2.3.0 - gopkg.in/yaml.v3 v3.0.0-20200601152816-913338de1bd2 // indirect + gopkg.in/yaml.v3 v3.0.0-20200601152816-913338de1bd2 ) diff --git a/go.sum b/go.sum index 62d14c3cd..b864e34c6 100644 --- a/go.sum +++ b/go.sum @@ -6,6 +6,8 @@ cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6A cloud.google.com/go v0.44.3 h1:0sMegbmn/8uTwpNkB0q9cLEpZ2W5a6kl+wtBQgPWBJQ= cloud.google.com/go v0.44.3/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= +github.com/0xAX/notificator v0.0.0-20191016112426-3962a5ea8da1 h1:j9HaafapDbPbGRDku6e/HRs6KBMcKHiWcm1/9Sbxnl4= +github.com/0xAX/notificator v0.0.0-20191016112426-3962a5ea8da1/go.mod h1:NtXa9WwQsukMHZpjNakTTz0LArxvGYdPA9CjIcUSZ6s= github.com/360EntSecGroup-Skylar/excelize/v2 v2.0.2 h1:StMrA6UQ5Cm6206DxXGuV/NMqSIOIDoMXMYt8JPe1lE= github.com/360EntSecGroup-Skylar/excelize/v2 v2.0.2/go.mod h1:EfRHD2k+Kd7ijnqlwOrH1IifwgWB9yYJ0pdXtBZmlpU= github.com/766b/chi-prometheus v0.0.0-20180509160047-46ac2b31aa30 h1:bNHbCMKiQxpRNe4Pk2W09N1aXXc4ICOawQFKIDEicqc= @@ -44,6 +46,10 @@ github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= +github.com/codegangsta/envy v0.0.0-20141216192214-4b78388c8ce4 h1:ihrIKrLQzm6Q6NJHBMemvaIGTFxgxQUEkn2AjN0Aulw= +github.com/codegangsta/envy v0.0.0-20141216192214-4b78388c8ce4/go.mod h1:X7wHz0C25Lga6CnJ4WAQNbUQ9P/8eWSNv8qIO71YkSM= +github.com/codegangsta/gin v0.0.0-20171026143024-cafe2ce98974 h1:ysuVNDVE4LIky6I+6JlgAKG+wBNKMpVv3m3neVpvFVw= +github.com/codegangsta/gin v0.0.0-20171026143024-cafe2ce98974/go.mod h1:UBYuwaH3dMw91EZ7tGVaFF6GDj5j46S7zqB9lZPIe58= github.com/crusttech/go-oidc v0.0.0-20180918092017-982855dad3e1 h1:V2GKd4ImRY9lFUu3TclHNmqgJCADdA7muym9JuVEPlY= github.com/crusttech/go-oidc v0.0.0-20180918092017-982855dad3e1/go.mod h1:2LVBu240CBZgYkGOSRx733tkh9QUNcH+fIqmeAsdrds= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -176,6 +182,8 @@ github.com/lib/pq v1.1.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/markbates/going v1.0.0/go.mod h1:I6mnB4BPnEeqo85ynXIx1ZFLLbtiLHNXVgWeFO9OGOA= github.com/markbates/goth v1.50.0 h1:KCAErbDdHh11gQAJs/GV73LCv4NwA7Z6wNZAU32ggMc= github.com/markbates/goth v1.50.0/go.mod h1:zZmAw0Es0Dpm7TT/4AdN14QrkiWLMrrU9Xei1o+/mdA= +github.com/mattn/go-shellwords v1.0.10 h1:Y7Xqm8piKOO3v10Thp7Z36h4FYFjt5xB//6XvOrs2Gw= +github.com/mattn/go-shellwords v1.0.10/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lLtQsUlTZDWQ8Y= github.com/mattn/go-sqlite3 v1.9.0 h1:pDRiWfl+++eC2FEFRy6jXmQlvp4Yh3z1MJKg4UeYM/4= github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= github.com/mattn/go-sqlite3 v1.14.0 h1:mLyGNKR8+Vv9CAU7PphKa2hkEqxxhn8i32J6FPj1/QA= @@ -416,6 +424,8 @@ gopkg.in/mail.v2 v2.3.1 h1:WYFn/oANrAGP2C0dcV6/pbkPzv8yGzqTjPmTeO7qoXk= gopkg.in/mail.v2 v2.3.1/go.mod h1:htwXN1Qh09vZJ1NVKxQqHPBaCBbzKhp5GzuJEA4VJWw= gopkg.in/square/go-jose.v2 v2.3.1 h1:SK5KegNXmKmqE342YYN2qPHEnUYeoMiXXl1poUlI+o4= gopkg.in/square/go-jose.v2 v2.3.1/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI= +gopkg.in/urfave/cli.v1 v1.20.0 h1:NdAVW6RYxDif9DhDHaAortIu956m2c0v+09AZBPTbE0= +gopkg.in/urfave/cli.v1 v1.20.0/go.mod h1:vuBzUtMdQeixQj8LVd+/98pzhxNGQoyuPBlsXHOQNO0= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/vendor/modules.txt b/vendor/modules.txt index b8a41d0f6..511467d5c 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1,6 +1,8 @@ # cloud.google.com/go v0.44.3 ## explicit cloud.google.com/go/compute/metadata +# github.com/0xAX/notificator v0.0.0-20191016112426-3962a5ea8da1 +## explicit # github.com/360EntSecGroup-Skylar/excelize/v2 v2.0.2 ## explicit github.com/360EntSecGroup-Skylar/excelize/v2 @@ -34,6 +36,10 @@ github.com/SentimensRG/ctx github.com/SentimensRG/ctx/sigctx # github.com/beorn7/perks v1.0.0 github.com/beorn7/perks/quantile +# github.com/codegangsta/envy v0.0.0-20141216192214-4b78388c8ce4 +## explicit +# github.com/codegangsta/gin v0.0.0-20171026143024-cafe2ce98974 +## explicit # github.com/crusttech/go-oidc v0.0.0-20180918092017-982855dad3e1 ## explicit github.com/crusttech/go-oidc @@ -147,6 +153,8 @@ github.com/markbates/goth/providers/github github.com/markbates/goth/providers/google github.com/markbates/goth/providers/linkedin github.com/markbates/goth/providers/openidConnect +# github.com/mattn/go-shellwords v1.0.10 +## explicit # github.com/mattn/go-sqlite3 v1.14.0 ## explicit github.com/mattn/go-sqlite3 @@ -389,6 +397,8 @@ gopkg.in/mail.v2 gopkg.in/square/go-jose.v2 gopkg.in/square/go-jose.v2/cipher gopkg.in/square/go-jose.v2/json +# gopkg.in/urfave/cli.v1 v1.20.0 +## explicit # gopkg.in/yaml.v2 v2.3.0 ## explicit gopkg.in/yaml.v2 From efc418e5fd8155ce98275a673c8f0e03569fd73e Mon Sep 17 00:00:00 2001 From: Urban Klinc Date: Fri, 27 Nov 2020 09:37:16 +0100 Subject: [PATCH 6/6] Fix typo, rework readme --- pkg/codegen/options.go | 2 +- pkg/options/README.adoc | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/pkg/codegen/options.go b/pkg/codegen/options.go index f911e66fd..f3e355059 100644 --- a/pkg/codegen/options.go +++ b/pkg/codegen/options.go @@ -85,7 +85,7 @@ func procOptions(mm ...string) (dd []*optionsDef, err error) { return dd, nil } -// Custom UnmarshelYAML function for +// Custom UnmarshalYAML function for func (pd *optionsPropDefault) UnmarshalYAML(n *yaml.Node) error { val := n.Value diff --git a/pkg/options/README.adoc b/pkg/options/README.adoc index 581faa056..c9c87c1f4 100644 --- a/pkg/options/README.adoc +++ b/pkg/options/README.adoc @@ -6,9 +6,10 @@ The name of the .YAML will dedicate the name of the .gen.go file e.g. fileName1. The contents of the .YAML file should look like this: - name: + name: ... - imports: + imports: + - ... props - name: ... @@ -19,14 +20,13 @@ The contents of the .YAML file should look like this: **name** -It is the name of the + - It is the name of the struct -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 +**imports** + - The list of imports that are needed, if there are no imporsts you may skip this step + +**props** + - 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