config: support params for different database backends

This commit is contained in:
positiveblue
2023-05-28 08:22:08 -07:00
parent 680da97b62
commit a9fb600044
3 changed files with 66 additions and 6 deletions

View File

@@ -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{},
}
}

View File

@@ -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,

View File

@@ -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: