rename: setRole -> role
Signed-off-by: Joep Peeters <joep.peeters@nedap.com>
This commit is contained in:
Vendored
+2
-2
@@ -97,7 +97,7 @@ export interface Config {
|
||||
*/
|
||||
pluginDivisionMode?: 'database' | 'schema';
|
||||
/** Configures the ownership of newly created schemas in pg databases. */
|
||||
setOwner?: string;
|
||||
role?: string;
|
||||
/**
|
||||
* Arbitrary config object to pass to knex when initializing
|
||||
* (https://knexjs.org/#Installation-client). Most notable is the debug
|
||||
@@ -128,7 +128,7 @@ export interface Config {
|
||||
*/
|
||||
knexConfig?: object;
|
||||
/** Configures the ownership of newly created schemas in pg databases. */
|
||||
setOwner?: string;
|
||||
role?: string;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
@@ -698,7 +698,7 @@ describe('DatabaseManager', () => {
|
||||
host: 'localhost',
|
||||
database: 'foodb',
|
||||
},
|
||||
setOwner: 'backstage',
|
||||
role: 'backstage',
|
||||
plugin: {
|
||||
testowner: {},
|
||||
},
|
||||
@@ -711,7 +711,7 @@ describe('DatabaseManager', () => {
|
||||
const mockCalls = mocked(createDatabaseClient).mock.calls.splice(-1);
|
||||
const [baseConfig] = mockCalls[0];
|
||||
|
||||
expect(baseConfig.data.setOwner).toEqual('backstage');
|
||||
expect(baseConfig.data.role).toEqual('backstage');
|
||||
});
|
||||
|
||||
it('sets the owner config for plugin using plugin config', async () => {
|
||||
@@ -724,10 +724,10 @@ describe('DatabaseManager', () => {
|
||||
host: 'localhost',
|
||||
database: 'foodb',
|
||||
},
|
||||
setOwner: 'backstage',
|
||||
role: 'backstage',
|
||||
plugin: {
|
||||
testowner: {
|
||||
setOwner: 'backstage-plugin',
|
||||
role: 'backstage-plugin',
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -739,7 +739,7 @@ describe('DatabaseManager', () => {
|
||||
const mockCalls = mocked(createDatabaseClient).mock.calls.splice(-1);
|
||||
const [baseConfig] = mockCalls[0];
|
||||
|
||||
expect(baseConfig.data.setOwner).toEqual('backstage-plugin');
|
||||
expect(baseConfig.data.role).toEqual('backstage-plugin');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -186,10 +186,10 @@ export class DatabaseManager {
|
||||
};
|
||||
}
|
||||
|
||||
private getSetOwnerConfig(pluginId: string): string | undefined {
|
||||
private getRoleConfig(pluginId: string): string | undefined {
|
||||
return (
|
||||
this.config.getOptionalString(`${pluginPath(pluginId)}.setOwner`) ??
|
||||
this.config.getOptionalString('setOwner')
|
||||
this.config.getOptionalString(`${pluginPath(pluginId)}.role`) ??
|
||||
this.config.getOptionalString('role')
|
||||
);
|
||||
}
|
||||
|
||||
@@ -285,13 +285,13 @@ export class DatabaseManager {
|
||||
*/
|
||||
private getConfigForPlugin(pluginId: string): Knex.Config {
|
||||
const { client } = this.getClientType(pluginId);
|
||||
const setOwner = this.getSetOwnerConfig(pluginId);
|
||||
const role = this.getRoleConfig(pluginId);
|
||||
|
||||
return {
|
||||
...this.getAdditionalKnexConfig(pluginId),
|
||||
client,
|
||||
connection: this.getConnectionConfig(pluginId),
|
||||
...(setOwner && { setOwner }),
|
||||
...(role && { role }),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -36,11 +36,11 @@ export function createPgDatabaseClient(
|
||||
const knexConfig = buildPgDatabaseConfig(dbConfig, overrides);
|
||||
const database = knexFactory(knexConfig);
|
||||
|
||||
const owner = dbConfig.getOptionalString('setOwner');
|
||||
const role = dbConfig.getOptionalString('role');
|
||||
|
||||
if (owner) {
|
||||
if (role) {
|
||||
database.client.pool.on('createSuccess', (_event: any, pgClient: any) => {
|
||||
pgClient.query(`SET ROLE ${owner}`, () => {});
|
||||
pgClient.query(`SET ROLE ${role}`, () => {});
|
||||
});
|
||||
}
|
||||
return database;
|
||||
@@ -155,14 +155,14 @@ export async function ensurePgSchemaExists(
|
||||
...schemas: Array<string>
|
||||
): Promise<void> {
|
||||
const admin = createPgDatabaseClient(dbConfig);
|
||||
const setOwner = dbConfig.getOptionalString('setOwner');
|
||||
const role = dbConfig.getOptionalString('role');
|
||||
|
||||
try {
|
||||
const ensureSchema = async (database: string) => {
|
||||
if (setOwner) {
|
||||
if (role) {
|
||||
await admin.raw(`CREATE SCHEMA IF NOT EXISTS ?? AUTHORIZATION ??`, [
|
||||
database,
|
||||
setOwner,
|
||||
role,
|
||||
]);
|
||||
} else {
|
||||
await admin.raw(`CREATE SCHEMA IF NOT EXISTS ??`, [database]);
|
||||
|
||||
Reference in New Issue
Block a user