Skip to content

main · v3.2 (unreleased)

Configuration

Users · Reference · CurrentMarkdownAgent index

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 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.json

A 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.

ProgramReads
The Core test server, its command-line tool, the local API tests and the local workspace testscore/appsettings.json
The domain tests of Corecore/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 themcustom/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 override the file. In the name of a variable two underscores separate the levels of a setting:

Terminal window
export adapter=npgsql
export 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.

SettingRead byMeaning
adapterEvery programThe database adapter: snapshot, sqlclient or npgsql. Upper and lower case are equal. The database adapters explains the choice.
ConnectionStrings:DefaultConnectionEvery programThe connection string of the database. Required with sqlclient and npgsql; the Snapshot adapter keeps its population in memory and needs none.
JwtToken:KeyA serverThe 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:IssuerA serverThe issuer of a bearer token. When the setting has a value, a request with a token from another issuer receives HTTP 401.
JwtToken:AudienceA serverThe 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:ExpirationA serverThe 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.
AllowedHostsThe sample serverA 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.
populationFileThe command-line toolThe 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.
datapathThe command-line tool of CoreThe 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.

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:

Terminal window
export ALLORS_CONFIG_ROOT="$PWD/config/snapshot"
TemplateAdapterDatabase
config/snapshotsnapshotNone. The Snapshot adapter keeps the population in memory and needs no connection string.
config/sqlclientsqlclientSQL Server on localhost, with the login allors.
config/npgsqlnpgsqlPostgreSQL on localhost, with the login allors.
config/localdbsqlclientSQL 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.

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 init command 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, init makes 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 adapter init has nothing to drop or create. The command calls DatabaseProvisioning.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_ADAPTER names sqlclient or npgsql; 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.
Terminal window
export ALLORS_CONFIG_ROOT="$PWD/config/sqlclient"
export ALLORS_SQLCLIENT='Server=localhost;User Id=sa;Password=…;TrustServerCertificate=true'
  • ConfigurationBuilderExtensions, in dotnet/Core/Database/Configuration/Core, reads the file of a domain in AddAllorsConfiguration, and builds the message for a missing setting in Require. ConfigurationBuilderExtensionsTests, in dotnet/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 and Require.
  • DatabaseBuilder and DatabaseProvisioning, in dotnet/System/Database/Adapters/Allors.Database.Builder, select the adapter and manage the database through the admin connection.
  • Program of dotnet/Core/Database/Server and Program of dotnet/Core/Database/Commands name the folder of the Core test server and of its command-line tool, core.