Skip to content

Commit

Permalink
bump deps, allow to run without turso (#3)
Browse files Browse the repository at this point in the history
Signed-off-by: Sarah Funkhouser <[email protected]>
  • Loading branch information
golanglemonade authored Aug 30, 2024
1 parent 3584050 commit d6bcc3a
Show file tree
Hide file tree
Showing 15 changed files with 365 additions and 225 deletions.
8 changes: 4 additions & 4 deletions .buildkite/pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ steps:
key: "lint"
plugins:
- docker#v5.11.0:
image: "registry.hub.docker.com/golangci/golangci-lint:latest-alpine"
image: "golangci-lint:latest-alpine"
command: ["golangci-lint", "run", "-v"]
always-pull: true
environment:
Expand Down Expand Up @@ -75,7 +75,7 @@ steps:
key: "gosec"
plugins:
- docker#v5.11.0:
image: "registry.hub.docker.com/securego/gosec:2.20.0"
image: "securego/gosec:2.20.0"
command: ["-no-fail", "-exclude-generated", "-fmt sonarqube", "-out", "results.txt", "./..."]
environment:
- "GOTOOLCHAIN=auto"
Expand All @@ -91,7 +91,7 @@ steps:
download: "coverage.out"
step: "go_test_libsql"
- docker#v5.11.0:
image: "sonarsource/sonar-scanner-cli:5"
image: "sonarsource/sonar-scanner-cli:11.0"
environment:
- "SONAR_TOKEN"
- "SONAR_HOST_URL=$SONAR_HOST"
Expand All @@ -107,7 +107,7 @@ steps:
download: coverage.out
step: "go_test_libsql"
- docker#v5.11.0:
image: "sonarsource/sonar-scanner-cli:5"
image: "sonarsource/sonar-scanner-cli:11.0"
environment:
- "SONAR_TOKEN"
- "SONAR_HOST_URL=$SONAR_HOST"
Expand Down
22 changes: 13 additions & 9 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (

"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/theopenlane/core/pkg/otelx"
"github.com/theopenlane/beacon/otelx"
"go.uber.org/zap"

"github.com/theopenlane/core/pkg/cache"
"github.com/theopenlane/go-turso"
"github.com/theopenlane/utils/cache"

ent "github.com/theopenlane/dbx/internal/ent/generated"
"github.com/theopenlane/dbx/internal/entdb"
Expand Down Expand Up @@ -49,18 +49,22 @@ func serve(ctx context.Context) error {

so := serveropts.NewServerOptions(serverOpts, viper.GetString("config"))

err = otelx.NewTracer(so.Config.Settings.Tracer, appName, logger)
err = otelx.NewTracer(so.Config.Settings.Tracer, appName)
if err != nil {
logger.Fatalw("failed to initialize tracer", "error", err)
}

tursoClient, err := turso.NewClient(so.Config.Settings.Turso)
if err != nil {
logger.Fatalw("failed to initialize turso client", "error", err)
}

// create ent dependency injection
entOpts := []ent.Option{ent.Logger(*logger), ent.Turso(tursoClient)}
entOpts := []ent.Option{ent.Logger(*logger)}

if so.Config.Settings.Providers.TursoEnabled {
tursoClient, err := turso.NewClient(so.Config.Settings.Turso)
if err != nil {
logger.Fatalw("failed to initialize turso client", "error", err)
}

entOpts = append(entOpts, ent.Turso(tursoClient))
}

// Setup DB connection
entdbClient, dbConfig, err := entdb.NewMultiDriverDBClient(ctx, so.Config.Settings.DB, logger, entOpts)
Expand Down
20 changes: 11 additions & 9 deletions config/.env.example
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
DBX_REFRESH_INTERVAL="10m"
DBX_REFRESHINTERVAL="10m"
DBX_SERVER_DEBUG="false"
DBX_SERVER_DEV="false"
DBX_SERVER_LISTEN=":1337"
DBX_SERVER_SHUTDOWN_GRACE_PERIOD="10s"
DBX_SERVER_READ_TIMEOUT="15s"
DBX_SERVER_WRITE_TIMEOUT="15s"
DBX_SERVER_IDLE_TIMEOUT="30s"
DBX_SERVER_READ_HEADER_TIMEOUT="2s"
DBX_SERVER_SHUTDOWNGRACEPERIOD="10s"
DBX_SERVER_READTIMEOUT="15s"
DBX_SERVER_WRITETIMEOUT="15s"
DBX_SERVER_IDLETIMEOUT="30s"
DBX_SERVER_READHEADERTIMEOUT="2s"
DBX_SERVER_TLS_ENABLED="false"
DBX_SERVER_TLS_CERT_FILE="server.crt"
DBX_SERVER_TLS_CERT_KEY="server.key"
DBX_SERVER_TLS_AUTO_CERT="false"
DBX_SERVER_TLS_CERTFILE="server.crt"
DBX_SERVER_TLS_CERTKEY="server.key"
DBX_SERVER_TLS_AUTOCERT="false"
DBX_SERVER_CORS_ENABLED="true"
DBX_SERVER_CORS_PREFIXES=""
DBX_SERVER_CORS_ALLOWORIGINS=""
Expand Down Expand Up @@ -43,6 +43,8 @@ DBX_DB_CACHETTL="1s"
DBX_DB_RUNMIGRATIONS="true"
DBX_DB_MIGRATIONPROVIDER="atlas"
DBX_DB_ENABLEHISTORY="false"
DBX_PROVIDERS_TURSOENABLED="false"
DBX_PROVIDERS_LOCALENABLED="true"
DBX_TURSO_TOKEN=""
DBX_TURSO_BASEURL="https://api.turso.tech"
DBX_TURSO_ORGNAME=""
Expand Down
4 changes: 4 additions & 0 deletions config/config-dev.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ turso:
baseUrl: https://api.turso.tech
orgName: "openlane"
token: ""

providers:
localEnabled: true
tursoEnabled: false
21 changes: 12 additions & 9 deletions config/config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ db:
primaryDbSource: file:openlane.db
runMigrations: true
secondaryDbSource: file:backup.db
providers:
localEnabled: true
tursoEnabled: false
ratelimit:
burst: 30
enabled: false
Expand All @@ -28,7 +31,7 @@ redis:
readTimeout: 0
username: ""
writeTimeout: 0
refresh_interval: 600000000000
refreshInterval: 600000000000
server:
cacheControl:
enabled: true
Expand All @@ -41,14 +44,14 @@ server:
prefixes: null
debug: false
dev: false
idle_timeout: 30000000000
idleTimeout: 30000000000
listen: :1337
mime:
defaultContentType: application/data
enabled: true
mimeTypesFile: ""
read_header_timeout: 2000000000
read_timeout: 15000000000
readHeaderTimeout: 2000000000
readTimeout: 15000000000
redirect:
code: 0
enabled: true
Expand All @@ -63,14 +66,14 @@ server:
referrerpolicy: same-origin
xframeoptions: SAMEORIGIN
xssprotection: 1; mode=block
shutdown_grace_period: 10000000000
shutdownGracePeriod: 10000000000
tls:
auto_cert: false
cert_file: server.crt
cert_key: server.key
autoCert: false
certFile: server.crt
certKey: server.key
config: null
enabled: false
write_timeout: 15000000000
writeTimeout: 15000000000
sessions:
domain: ""
encryptionKey: encryptionsecret
Expand Down
36 changes: 23 additions & 13 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ import (

turso "github.com/theopenlane/go-turso"

"github.com/theopenlane/core/pkg/cache"
"github.com/theopenlane/beacon/otelx"
"github.com/theopenlane/core/pkg/middleware/cachecontrol"
"github.com/theopenlane/core/pkg/middleware/cors"
"github.com/theopenlane/core/pkg/middleware/mime"
"github.com/theopenlane/core/pkg/middleware/ratelimit"
"github.com/theopenlane/core/pkg/middleware/redirect"
"github.com/theopenlane/core/pkg/middleware/secure"
"github.com/theopenlane/core/pkg/otelx"
"github.com/theopenlane/iam/sessions"
"github.com/theopenlane/utils/cache"
)

var (
Expand All @@ -32,14 +32,17 @@ var (
// Config contains the configuration for the openlane server
type Config struct {
// RefreshInterval determines how often to reload the config
RefreshInterval time.Duration `json:"refresh_interval" koanf:"refresh_interval" default:"10m"`
RefreshInterval time.Duration `json:"refreshInterval" koanf:"refreshInterval" default:"10m"`

// Server contains the echo server settings
Server Server `json:"server" koanf:"server"`

// DB contains the database configuration for the ent client
DB entx.Config `json:"db" koanf:"db"`

// Providers contains the configuration for the providers
Providers Providers `json:"providers" koanf:"providers"`

// Turso contains the configuration for the turso client
Turso turso.Config `json:"turso" koanf:"turso"`

Expand All @@ -56,6 +59,13 @@ type Config struct {
Ratelimit ratelimit.Config `json:"ratelimit" koanf:"ratelimit"`
}

type Providers struct {
// TursoEnabled enables the turso provider
TursoEnabled bool `json:"tursoEnabled" koanf:"tursoEnabled" default:"false"`
// LocalEnabled enables the local provider
LocalEnabled bool `json:"localEnabled" koanf:"localEnabled" default:"true"`
}

// Server settings for the echo server
type Server struct {
// Debug enables debug mode for the server
Expand All @@ -65,15 +75,15 @@ type Server struct {
// Listen sets the listen address to serve the echo server on
Listen string `json:"listen" koanf:"listen" jsonschema:"required" default:":1337"`
// ShutdownGracePeriod sets the grace period for in flight requests before shutting down
ShutdownGracePeriod time.Duration `json:"shutdown_grace_period" koanf:"shutdown_grace_period" default:"10s"`
ShutdownGracePeriod time.Duration `json:"shutdownGracePeriod" koanf:"shutdownGracePeriod" default:"10s"`
// ReadTimeout sets the maximum duration for reading the entire request including the body
ReadTimeout time.Duration `json:"read_timeout" koanf:"read_timeout" default:"15s"`
ReadTimeout time.Duration `json:"readTimeout" koanf:"readTimeout" default:"15s"`
// WriteTimeout sets the maximum duration before timing out writes of the response
WriteTimeout time.Duration `json:"write_timeout" koanf:"write_timeout" default:"15s"`
WriteTimeout time.Duration `json:"writeTimeout" koanf:"writeTimeout" default:"15s"`
// IdleTimeout sets the maximum amount of time to wait for the next request when keep-alives are enabled
IdleTimeout time.Duration `json:"idle_timeout" koanf:"idle_timeout" default:"30s"`
IdleTimeout time.Duration `json:"idleTimeout" koanf:"idleTimeout" default:"30s"`
// ReadHeaderTimeout sets the amount of time allowed to read request headers
ReadHeaderTimeout time.Duration `json:"read_header_timeout" koanf:"read_header_timeout" default:"2s"`
ReadHeaderTimeout time.Duration `json:"readHeaderTimeout" koanf:"readHeaderTimeout" default:"2s"`
// TLS contains the tls configuration settings
TLS TLS `json:"tls" koanf:"tls"`
// CORS contains settings to allow cross origin settings and insecure cookies
Expand All @@ -92,11 +102,11 @@ type Server struct {
type CORS struct {
// AllowOrigins is a list of allowed origin to indicate whether the response can be shared with
// requesting code from the given origin
AllowOrigins []string `json:"allow_origins" koanf:"allow_origins"`
AllowOrigins []string `json:"allowOrigins" koanf:"allowOrigins"`
// CookieInsecure allows CSRF cookie to be sent to servers that the browser considers
// unsecured. Useful for cases where the connection is secured via VPN rather than
// HTTPS directly.
CookieInsecure bool `json:"cookie_insecure" koanf:"cookie_insecure"`
CookieInsecure bool `json:"cookieInsecure" koanf:"cookieInsecure"`
}

// TLS settings for the server for secure connections
Expand All @@ -106,11 +116,11 @@ type TLS struct {
// Enabled turns on TLS settings for the server
Enabled bool `json:"enabled" koanf:"enabled" default:"false"`
// CertFile location for the TLS server
CertFile string `json:"cert_file" koanf:"cert_file" default:"server.crt"`
CertFile string `json:"certFile" koanf:"certFile" default:"server.crt"`
// CertKey file location for the TLS server
CertKey string `json:"cert_key" koanf:"cert_key" default:"server.key"`
CertKey string `json:"certKey" koanf:"certKey" default:"server.key"`
// AutoCert generates the cert with letsencrypt, this does not work on localhost
AutoCert bool `json:"auto_cert" koanf:"auto_cert" default:"false"`
AutoCert bool `json:"autoCert" koanf:"autoCert" default:"false"`
}

// Load is responsible for loading the configuration from a YAML file and environment variables.
Expand Down
20 changes: 11 additions & 9 deletions config/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ metadata:
annotations: {{- include "common.tplvalues.render" ( dict "value" $annotations "context" $) | nindent 4 }}
{{- end }}
data:
DBX_REFRESH_INTERVAL: {{ .Values.dbx.refresh_interval | 10m }}
DBX_REFRESHINTERVAL: {{ .Values.dbx.refreshInterval | 10m }}
DBX_SERVER_DEBUG: {{ .Values.dbx.server.debug | false }}
DBX_SERVER_DEV: {{ .Values.dbx.server.dev | false }}
DBX_SERVER_LISTEN: {{ .Values.dbx.server.listen | ":1337" }}
DBX_SERVER_SHUTDOWN_GRACE_PERIOD: {{ .Values.dbx.server.shutdown_grace_period | 10s }}
DBX_SERVER_READ_TIMEOUT: {{ .Values.dbx.server.read_timeout | 15s }}
DBX_SERVER_WRITE_TIMEOUT: {{ .Values.dbx.server.write_timeout | 15s }}
DBX_SERVER_IDLE_TIMEOUT: {{ .Values.dbx.server.idle_timeout | 30s }}
DBX_SERVER_READ_HEADER_TIMEOUT: {{ .Values.dbx.server.read_header_timeout | 2s }}
DBX_SERVER_SHUTDOWNGRACEPERIOD: {{ .Values.dbx.server.shutdownGracePeriod | 10s }}
DBX_SERVER_READTIMEOUT: {{ .Values.dbx.server.readTimeout | 15s }}
DBX_SERVER_WRITETIMEOUT: {{ .Values.dbx.server.writeTimeout | 15s }}
DBX_SERVER_IDLETIMEOUT: {{ .Values.dbx.server.idleTimeout | 30s }}
DBX_SERVER_READHEADERTIMEOUT: {{ .Values.dbx.server.readHeaderTimeout | 2s }}
DBX_SERVER_TLS_ENABLED: {{ .Values.dbx.server.tls.enabled | false }}
DBX_SERVER_TLS_CERT_FILE: {{ .Values.dbx.server.tls.cert_file | "server.crt" }}
DBX_SERVER_TLS_CERT_KEY: {{ .Values.dbx.server.tls.cert_key | "server.key" }}
DBX_SERVER_TLS_AUTO_CERT: {{ .Values.dbx.server.tls.auto_cert | false }}
DBX_SERVER_TLS_CERTFILE: {{ .Values.dbx.server.tls.certFile | "server.crt" }}
DBX_SERVER_TLS_CERTKEY: {{ .Values.dbx.server.tls.certKey | "server.key" }}
DBX_SERVER_TLS_AUTOCERT: {{ .Values.dbx.server.tls.autoCert | false }}
DBX_SERVER_CORS_ENABLED: {{ .Values.dbx.server.cors.enabled | true }}
DBX_SERVER_CORS_PREFIXES: {{ .Values.dbx.server.cors.prefixes }}
DBX_SERVER_CORS_ALLOWORIGINS: {{ .Values.dbx.server.cors.allowOrigins }}
Expand Down Expand Up @@ -55,6 +55,8 @@ data:
DBX_DB_RUNMIGRATIONS: {{ .Values.dbx.db.runMigrations | true }}
DBX_DB_MIGRATIONPROVIDER: {{ .Values.dbx.db.migrationProvider | "atlas" }}
DBX_DB_ENABLEHISTORY: {{ .Values.dbx.db.enableHistory | false }}
DBX_PROVIDERS_TURSOENABLED: {{ .Values.dbx.providers.tursoEnabled | false }}
DBX_PROVIDERS_LOCALENABLED: {{ .Values.dbx.providers.localEnabled | true }}
DBX_TURSO_TOKEN: {{ .Values.dbx.turso.token }}
DBX_TURSO_BASEURL: {{ .Values.dbx.turso.baseUrl | "https://api.turso.tech" }}
DBX_TURSO_ORGNAME: {{ .Values.dbx.turso.orgName }}
Expand Down
Loading

0 comments on commit d6bcc3a

Please sign in to comment.