Documentation
¶
Overview ¶
Package appconf reads the database and the address an application is set up with, from the files each technology keeps them in: .env, appsettings .json, application.properties, database.yml, env.php, settings.py, compose.yaml and the like. It never runs the project's code: PHP, Python and ERB are read as text, and what only code could compute is reported as such.
A password is read only to build a DSN when a command runs (Ref.DSN). Nothing Find returns holds one, and no error of this package quotes a value read from a file or the environment: errors name the file and the key.
Index ¶
Constants ¶
const ( Env = "env" // Key is the variable Dotenv = "dotenv" // .env files AppSettings = "appsettings" // ASP.NET appsettings*.json, or a .csproj for its layered settings Properties = "properties" // Spring, Quarkus and Micronaut application*.properties / .yml YAML = "yaml" // Rails config/database.yml, a Go config.yaml PHP = "php" // Magento app/etc/env.php Python = "python" // Django settings.py Compose = "compose" // a database service of compose.yaml )
Sources of a Ref: the format of the file it names, or the environment.
const ( MySQL = "mysql" // MySQL and MariaDB Postgres = "postgres" )
Drivers.
const ComposeHost = "compose:"
ComposeHost starts a Ref.Host that names a service of the project's compose file (compose:mysql): the setting's host is that service, and this machine reaches it at the port the service publishes, read when a command runs.
Variables ¶
var Sources = []string{Dotenv, AppSettings, Properties, YAML, PHP, Python, Compose}
Sources lists every source of a file, in the order the documentation gives them.
Functions ¶
func CheckFile ¶
CheckFile checks the file of a Ref: relative to the project root and inside it. A \ is taken for a /, so one configuration serves Windows too.
func CheckRef ¶
CheckRef checks the shape of a Ref, without reading anything: a known source, a file inside the project, the key a source needs, a host that is host or host:port.
func Convert ¶
Convert returns a DSN given in a form an application uses but DriftGate's drivers do not take, a JDBC URL or an ADO.NET connection string, as one they take (see Ref.DSN), as is libpq's host=… user=… form; any other DSN comes back as it is. It serves a DSN of the environment or 1Password.
Types ¶
type Database ¶
type Database struct {
Driver string // mysql (also MariaDB) or postgres; empty when unknown (Note says why)
Host string // as this machine reaches it (Ref.Host applied)
Port string
Name string // the database the application uses: the working database
User string
File string // where it was found: a file relative to the root with /, or the variable
Key string
Ref Ref // what driftgate.yaml would hold; zero when it cannot be referenced (Note says why)
Note string // what to check by hand, if anything
// HostNeeded is the host: the setting needs before DriftGate can use it
// (127.0.0.1:3306), "" for none: its host is one its client may take
// for the local socket (MySQL's localhost or none, PostgreSQL's none),
// and DriftGate does not guess. Note says so.
HostNeeded string
}
Database is a database setting Find found. It never holds the password.
type Found ¶
Found is everything Find found, in the order of its sources.
func Find ¶
Find looks for the database settings and the address of the application in root, where each technology keeps them: PHP (.env, Magento's app/etc/env.php), .NET (appsettings*.json through each .csproj, user secrets, launchSettings.json), Java (application*.properties and .yml), Rails (config/database.yml), Django (settings.py), Node (.env*, prisma/schema.prisma), Go (.env, config.yaml), compose (the database service and the port it publishes) and the environment (env, nil for none: DATABASE_URL, ConnectionStrings__*, SPRING_DATASOURCE_*). It reads files only; nothing it returns holds a password.
type Note ¶
Note is a setting found that DriftGate cannot use as it is: another kind of database, a value set by code, a file it cannot read.
type Ref ¶
type Ref struct {
Source string // one of Sources, or Env
File string // relative to the project root, with / (empty for Env)
Key string // where the setting is in the file (per source); for Env the variable
// Host replaces the host and port of the setting: the address the
// database is reached at from this machine, when the application's
// own is the name of a compose service (127.0.0.1:3307).
Host string
}
Ref names a database setting in the project instead of holding it: what driftgate.yaml stores in place of a DSN. It is read when a command runs.
func (Ref) DSN ¶
DSN reads the setting r names and returns it as a DSN the database drivers of DriftGate accept: mysql://user:pass@host:port/ (the driver's own form for a socket or when the file holds it) or postgres://user:pass @host:port/. The database of the setting is left out (state: and data: name the databases), as are the parameters of the application's driver that DriftGate's do not take. driver is the driver of the component; a file that names another one is an error.