mirror of
https://github.com/lightninglabs/aperture.git
synced 2025-12-19 10:04:19 +01:00
config: support params for different database backends
This commit is contained in:
31
config.go
31
config.go
@@ -3,9 +3,11 @@ package aperture
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/btcutil"
|
"github.com/btcsuite/btcd/btcutil"
|
||||||
|
"github.com/lightninglabs/aperture/aperturedb"
|
||||||
"github.com/lightninglabs/aperture/proxy"
|
"github.com/lightninglabs/aperture/proxy"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -18,6 +20,14 @@ var (
|
|||||||
defaultLogFilename = "aperture.log"
|
defaultLogFilename = "aperture.log"
|
||||||
defaultMaxLogFiles = 3
|
defaultMaxLogFiles = 3
|
||||||
defaultMaxLogFileSize = 10
|
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 {
|
type EtcdConfig struct {
|
||||||
@@ -98,6 +108,16 @@ type Config struct {
|
|||||||
// directory defined by StaticRoot.
|
// directory defined by StaticRoot.
|
||||||
ServeStatic bool `long:"servestatic" description:"Flag to enable or disable static content serving."`
|
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"`
|
Etcd *EtcdConfig `group:"etcd" namespace:"etcd"`
|
||||||
|
|
||||||
Authenticator *AuthConfig `group:"authenticator" namespace:"authenticator"`
|
Authenticator *AuthConfig `group:"authenticator" namespace:"authenticator"`
|
||||||
@@ -142,10 +162,21 @@ func (c *Config) validate() error {
|
|||||||
return nil
|
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.
|
// NewConfig initializes a new Config variable.
|
||||||
func NewConfig() *Config {
|
func NewConfig() *Config {
|
||||||
return &Config{
|
return &Config{
|
||||||
|
DatabaseBackend: "etcd",
|
||||||
Etcd: &EtcdConfig{},
|
Etcd: &EtcdConfig{},
|
||||||
|
Sqlite: DefaultSqliteConfig(),
|
||||||
|
Postgres: &aperturedb.PostgresConfig{},
|
||||||
Authenticator: &AuthConfig{},
|
Authenticator: &AuthConfig{},
|
||||||
Tor: &TorConfig{},
|
Tor: &TorConfig{},
|
||||||
HashMail: &HashMailConfig{},
|
HashMail: &HashMailConfig{},
|
||||||
|
|||||||
@@ -160,6 +160,7 @@ func setupAperture(t *testing.T) {
|
|||||||
Authenticator: &AuthConfig{
|
Authenticator: &AuthConfig{
|
||||||
Disable: true,
|
Disable: true,
|
||||||
},
|
},
|
||||||
|
DatabaseBackend: "etcd",
|
||||||
Etcd: &EtcdConfig{},
|
Etcd: &EtcdConfig{},
|
||||||
HashMail: &HashMailConfig{
|
HashMail: &HashMailConfig{
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
|
|||||||
@@ -38,6 +38,34 @@ authenticator:
|
|||||||
# The chain network the lnd is active on.
|
# The chain network the lnd is active on.
|
||||||
network: "simnet"
|
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
|
# Settings for the etcd instance which the proxy will use to reliably store and
|
||||||
# retrieve token information.
|
# retrieve token information.
|
||||||
etcd:
|
etcd:
|
||||||
|
|||||||
Reference in New Issue
Block a user