Status: Current. Where this is implemented names the code and the tests.
A server, the command-line tool and the tests that need settings read one file: the
appsettings.json of their domain, below the configuration root. Environment variables
override that file. No appsettings file is read from the folder of a project.
The configuration root
Section titled “The configuration root”The configuration root is the folder that the environment variable ALLORS_CONFIG_ROOT names.
Below it every domain has a folder, and that folder holds the settings of the domain’s programs in
one file, appsettings.json:
<configuration root>/core/appsettings.json<configuration root>/custom/appsettings.jsonA program names the folder of its domain when it calls AddAllorsConfiguration. Core’s folder is
core, and the sample’s is custom, after its domain; an application that starts from the sample
keeps that name or passes one of its own. The command-line tool and the server of an application
read the same file.
| Program | Reads |
|---|---|
| The Core test server, its command-line tool, the local API tests and the local workspace tests | core/appsettings.json |
| The domain tests of Core | core/appsettings.json. They run on the Memory adapter unless the setting adapter names SQL Server or PostgreSQL. |
| The sample’s command-line tool and server, and the tests that run them | custom/appsettings.json |
The domain tests of the sample read no configuration root; Test on PostgreSQL or SQL Server says how they choose their adapter.
The configuration root is mandatory, and nothing takes its place: no program, no test and no build
falls back to another folder. A program stops with a message when ALLORS_CONFIG_ROOT is not set,
when its value is not an absolute path, and when the file of its domain does not exist:
ALLORS_CONFIG_ROOT is not set. Set it to the folder that holds 'core/appsettings.json'.A relative path is refused because it names another folder for every working directory.
Nothing else in the folder of a domain is read: no file for an environment, such as
appsettings.Development.json, no file for an operating system, and no folder below it.
The Core test server and the sample server read no setting from the command line except --urls,
which sets their listening addresses.
Environment variables
Section titled “Environment variables”Environment variables override the file. In the name of a variable two underscores separate the levels of a setting:
export adapter=npgsqlexport ConnectionStrings__DefaultConnection='Host=localhost;Database=core;Username=allors;Password=…'export JwtToken__Key=…A variable holds for every program that starts in that environment, whatever its domain. A setting that only the server of an application needs, such as the signing key, can be given to the server alone in this way.
Settings
Section titled “Settings”| Setting | Read by | Meaning |
|---|---|---|
adapter | Every program | The database adapter: snapshot, sqlclient or npgsql. Upper and lower case are equal. The database adapters explains the choice. |
ConnectionStrings:DefaultConnection | Every program | The connection string of the database. Required with sqlclient and npgsql; the Snapshot adapter keeps its population in memory and needs none. |
JwtToken:Key | A server | The key that signs and validates bearer tokens. The server requires at least 32 UTF-8 bytes at startup. The token describes the tokens and these settings. |
JwtToken:Issuer | A server | The issuer of a bearer token. When the setting has a value, a request with a token from another issuer receives HTTP 401. |
JwtToken:Audience | A server | The audience of a bearer token. Without the setting it is the issuer. When the audience has a value, a request with a token for another audience receives HTTP 401. |
JwtToken:Expiration | A server | The lifetime of a bearer token, as a .NET TimeSpan such as 7.00:00:00 for seven days. Without a value that is a TimeSpan, the lifetime is 30 days. |
AllowedHosts | The sample server | A semicolon-separated list of host names without ports. An explicit list replaces the default, localhost. Every accepted host uses the Default workspace. An unlisted host receives HTTP 400 before authentication. |
populationFile | The command-line tool | The file that load reads and save writes, and that the upgrade of the sample application reads, when the -f option is absent. Without the setting the file is population.xml. |
datapath | The command-line tool of Core | The name of a folder. The tool looks for a folder of that name next to its working directory, and then next to each folder above it, and passes it to the setup of populate and to upgrade. Core’s own setup does not read it. |
A program stops when a setting that it needs has no value. The message names the setting, the file of the domain and the environment variable:
The configuration has no value for 'adapter'. Add the value to '/srv/allors/core/appsettings.json', or set 'adapter' in the environment.Templates
Section titled “Templates”The repository holds four templates for a configuration root. Point ALLORS_CONFIG_ROOT at one
of them, or at a copy that holds your own values:
export ALLORS_CONFIG_ROOT="$PWD/config/snapshot"| Template | Adapter | Database |
|---|---|---|
config/snapshot | snapshot | None. The Snapshot adapter keeps the population in memory and needs no connection string. |
config/sqlclient | sqlclient | SQL Server on localhost, with the login allors. |
config/npgsql | npgsql | PostgreSQL on localhost, with the login allors. |
config/localdb | sqlclient | SQL Server LocalDB on Windows, with Windows authentication. |
Each template holds core/appsettings.json. The template config/snapshot holds
custom/appsettings.json as well, for the tests that run the sample’s command-line tool and
server.
The templates are for development and testing. Their signing key and their passwords are published in the repository: give a deployment its own values.
With the Snapshot adapter a population lasts as long as its process. A population that the
command-line tool builds ends with the tool, and the Core test server builds its own through its
endpoint Test/Setup.
Admin connections
Section titled “Admin connections”ALLORS_SQLCLIENT and ALLORS_NPGSQL hold an admin connection to the server of the configured
database: SQL Server for sqlclient, PostgreSQL for npgsql. They serve database management
only; no program runs on them.
- The
initcommand of Core’s command-line tool drops and creates the database of the configured connection. When that connection names a user, and on SQL Server does not use integrated security,initmakes the login of that user the owner of the database, and creates the login when the server does not know it. Otherwise the database belongs to the user of the admin connection. With the Snapshot adapterinithas nothing to drop or create. The command callsDatabaseProvisioning.DropCreate, which the command-line tool of an application can call as well. - The adapter test suites create and open their test databases with the admin connection.
- The domain tests of the sample create and open their database with it when
ALLORS_TEST_ADAPTERnamessqlclientornpgsql; see Test on PostgreSQL or SQL Server. - Without the variable of its adapter, database management stops with a message that names the
variable. SQL Server LocalDB is named like any other server:
Server=(localdb)\MSSQLLocalDB;Integrated Security=true;TrustServerCertificate=true.
export ALLORS_CONFIG_ROOT="$PWD/config/sqlclient"export ALLORS_SQLCLIENT='Server=localhost;User Id=sa;Password=…;TrustServerCertificate=true'Where this is implemented
Section titled “Where this is implemented”ConfigurationBuilderExtensions, indotnet/Core/Database/Configuration/Core, reads the file of a domain inAddAllorsConfiguration, and builds the message for a missing setting inRequire.ConfigurationBuilderExtensionsTests, indotnet/Core/Database/Server.Local.Tests, checks that the configuration stops without a configuration root, with a relative one and without the file of the domain, that no other file is read, the override by environment variables andRequire.DatabaseBuilderandDatabaseProvisioning, indotnet/System/Database/Adapters/Allors.Database.Builder, select the adapter and manage the database through the admin connection.Programofdotnet/Core/Database/ServerandProgramofdotnet/Core/Database/Commandsname the folder of the Core test server and of its command-line tool,core.