mirror of
https://github.com/lightninglabs/aperture.git
synced 2025-12-18 17:44:20 +01:00
config: support params for different database backends
This commit is contained in:
41
config.go
41
config.go
@@ -3,9 +3,11 @@ package aperture
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcd/btcutil"
|
||||
"github.com/lightninglabs/aperture/aperturedb"
|
||||
"github.com/lightninglabs/aperture/proxy"
|
||||
)
|
||||
|
||||
@@ -18,6 +20,14 @@ var (
|
||||
defaultLogFilename = "aperture.log"
|
||||
defaultMaxLogFiles = 3
|
||||
defaultMaxLogFileSize = 10
|
||||
|
||||
defaultSqliteDatabaseFileName = "aperture.db"
|
||||
|
||||
// defaultSqliteDatabasePath is the default path under which we store
|
||||
// the SQLite database file.
|
||||
defaultSqliteDatabasePath = filepath.Join(
|
||||
apertureDataDir, defaultSqliteDatabaseFileName,
|
||||
)
|
||||
)
|
||||
|
||||
type EtcdConfig struct {
|
||||
@@ -98,6 +108,16 @@ type Config struct {
|
||||
// directory defined by StaticRoot.
|
||||
ServeStatic bool `long:"servestatic" description:"Flag to enable or disable static content serving."`
|
||||
|
||||
// DatabaseBackend is the database backend to be used by the server.
|
||||
DatabaseBackend string `long:"dbbackend" description:"The database backend to use for storing all asset related data." choice:"sqlite" choice:"postgres"`
|
||||
|
||||
// Sqlite is the configuration section for the SQLite database backend.
|
||||
Sqlite *aperturedb.SqliteConfig `group:"sqlite" namespace:"sqlite"`
|
||||
|
||||
// Postgres is the configuration section for the Postgres database backend.
|
||||
Postgres *aperturedb.PostgresConfig `group:"postgres" namespace:"postgres"`
|
||||
|
||||
// Etcd is the configuration section for the Etcd database backend.
|
||||
Etcd *EtcdConfig `group:"etcd" namespace:"etcd"`
|
||||
|
||||
Authenticator *AuthConfig `group:"authenticator" namespace:"authenticator"`
|
||||
@@ -142,13 +162,24 @@ func (c *Config) validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// DefaultConfig returns the default configuration for a sqlite backend.
|
||||
func DefaultSqliteConfig() *aperturedb.SqliteConfig {
|
||||
return &aperturedb.SqliteConfig{
|
||||
SkipMigrations: false,
|
||||
DatabaseFileName: defaultSqliteDatabasePath,
|
||||
}
|
||||
}
|
||||
|
||||
// NewConfig initializes a new Config variable.
|
||||
func NewConfig() *Config {
|
||||
return &Config{
|
||||
Etcd: &EtcdConfig{},
|
||||
Authenticator: &AuthConfig{},
|
||||
Tor: &TorConfig{},
|
||||
HashMail: &HashMailConfig{},
|
||||
Prometheus: &PrometheusConfig{},
|
||||
DatabaseBackend: "etcd",
|
||||
Etcd: &EtcdConfig{},
|
||||
Sqlite: DefaultSqliteConfig(),
|
||||
Postgres: &aperturedb.PostgresConfig{},
|
||||
Authenticator: &AuthConfig{},
|
||||
Tor: &TorConfig{},
|
||||
HashMail: &HashMailConfig{},
|
||||
Prometheus: &PrometheusConfig{},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,7 +160,8 @@ func setupAperture(t *testing.T) {
|
||||
Authenticator: &AuthConfig{
|
||||
Disable: true,
|
||||
},
|
||||
Etcd: &EtcdConfig{},
|
||||
DatabaseBackend: "etcd",
|
||||
Etcd: &EtcdConfig{},
|
||||
HashMail: &HashMailConfig{
|
||||
Enabled: true,
|
||||
MessageRate: time.Millisecond,
|
||||
|
||||
@@ -38,6 +38,34 @@ authenticator:
|
||||
# The chain network the lnd is active on.
|
||||
network: "simnet"
|
||||
|
||||
# The selected database backend. The current default backend is "sqlite".
|
||||
# Aperture also has support for postgres and etcd.
|
||||
dbbackend: "sqlite"
|
||||
|
||||
# Settings for the sqlite process which the proxy will use to reliably store and
|
||||
# retrieve token information.
|
||||
sqlite:
|
||||
# The full path to the database.
|
||||
dbfile: "/path/to/.aperture/aperture.db"
|
||||
|
||||
# Settings for the postgres instance which the proxy will use to reliably store
|
||||
# and retrieve token information.
|
||||
postgres:
|
||||
# Connection parameters.
|
||||
host: "localhost"
|
||||
port: 5432
|
||||
user: "user"
|
||||
password: "password"
|
||||
dbname: "aperture"
|
||||
|
||||
# Max open connections to keep alive to the database server.
|
||||
maxconnections: 25
|
||||
|
||||
# Whether to require using SSL (mode: require) when connecting to the
|
||||
# server.
|
||||
requireSSL: true
|
||||
|
||||
|
||||
# Settings for the etcd instance which the proxy will use to reliably store and
|
||||
# retrieve token information.
|
||||
etcd:
|
||||
|
||||
Reference in New Issue
Block a user