mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Allow authentication using MSSQL azure-active-directory-service-principal-secret (#11141)
* Extract ignored settings requires by azure authentication * Change the way to extract initial database settings * Fix invalid names after extracting from env util * Replace missing var after solving conflicts * Add default value to poolconfig * This should unbreak it Co-authored-by: Rijk van Zanten <rijkvanzanten@me.com>
This commit is contained in:
@@ -19,21 +19,18 @@ export default function getDatabase(): Knex {
|
||||
return database;
|
||||
}
|
||||
|
||||
const connectionConfig: Record<string, any> = getConfigFromEnv('DB_', [
|
||||
'DB_CLIENT',
|
||||
'DB_VERSION',
|
||||
'DB_SEARCH_PATH',
|
||||
'DB_CONNECTION_STRING',
|
||||
'DB_POOL',
|
||||
'DB_EXCLUDE_TABLES',
|
||||
'DB_VERSION',
|
||||
]);
|
||||
|
||||
const poolConfig = getConfigFromEnv('DB_POOL');
|
||||
const {
|
||||
client,
|
||||
version,
|
||||
searchPath,
|
||||
connectionString,
|
||||
pool: poolConfig = {},
|
||||
...connectionConfig
|
||||
} = getConfigFromEnv('DB_', ['DB_EXCLUDE_TABLES']);
|
||||
|
||||
const requiredEnvVars = ['DB_CLIENT'];
|
||||
|
||||
switch (env.DB_CLIENT) {
|
||||
switch (client) {
|
||||
case 'sqlite3':
|
||||
requiredEnvVars.push('DB_FILENAME');
|
||||
break;
|
||||
@@ -48,7 +45,7 @@ export default function getDatabase(): Knex {
|
||||
|
||||
case 'cockroachdb':
|
||||
case 'pg':
|
||||
if (!env.DB_CONNECTION_STRING) {
|
||||
if (!connectionString) {
|
||||
requiredEnvVars.push('DB_HOST', 'DB_PORT', 'DB_DATABASE', 'DB_USER');
|
||||
} else {
|
||||
requiredEnvVars.push('DB_CONNECTION_STRING');
|
||||
@@ -66,10 +63,10 @@ export default function getDatabase(): Knex {
|
||||
validateEnv(requiredEnvVars);
|
||||
|
||||
const knexConfig: Knex.Config = {
|
||||
client: env.DB_CLIENT,
|
||||
version: env.DB_VERSION,
|
||||
searchPath: env.DB_SEARCH_PATH,
|
||||
connection: env.DB_CONNECTION_STRING || connectionConfig,
|
||||
client,
|
||||
version,
|
||||
searchPath,
|
||||
connection: connectionString || connectionConfig,
|
||||
log: {
|
||||
warn: (msg) => {
|
||||
// Ignore warnings about returning not being supported in some DBs
|
||||
@@ -87,7 +84,7 @@ export default function getDatabase(): Knex {
|
||||
pool: poolConfig,
|
||||
};
|
||||
|
||||
if (env.DB_CLIENT === 'sqlite3') {
|
||||
if (client === 'sqlite3') {
|
||||
knexConfig.useNullAsDefault = true;
|
||||
|
||||
poolConfig.afterCreate = async (conn: any, callback: any) => {
|
||||
@@ -100,7 +97,7 @@ export default function getDatabase(): Knex {
|
||||
};
|
||||
}
|
||||
|
||||
if (env.DB_CLIENT === 'cockroachdb') {
|
||||
if (client === 'cockroachdb') {
|
||||
poolConfig.afterCreate = async (conn: any, callback: any) => {
|
||||
logger.trace('Setting CRDB serial_normalization and default_int_size');
|
||||
const run = promisify(conn.query.bind(conn));
|
||||
@@ -112,7 +109,7 @@ export default function getDatabase(): Knex {
|
||||
};
|
||||
}
|
||||
|
||||
if (env.DB_CLIENT === 'mssql') {
|
||||
if (client === 'mssql') {
|
||||
// This brings MS SQL in line with the other DB vendors. We shouldn't do any automatic
|
||||
// timezone conversion on the database level, especially not when other database vendors don't
|
||||
// act the same
|
||||
|
||||
Reference in New Issue
Block a user