mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-18 03:30:39 +09:00
Finish scoped plugin config review fixes
This commit is contained in:
parent
0509d08f3c
commit
89cc5c4e20
2 changed files with 19631 additions and 6 deletions
19615
packages/db/src/migrations/meta/0094_snapshot.json
Normal file
19615
packages/db/src/migrations/meta/0094_snapshot.json
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -2034,7 +2034,9 @@ export function secretService(db: Db) {
|
||||||
required?: boolean;
|
required?: boolean;
|
||||||
label?: string | null;
|
label?: string | null;
|
||||||
}>,
|
}>,
|
||||||
|
options?: { db?: SecretBindingDb },
|
||||||
) => {
|
) => {
|
||||||
|
const bindingDb = options?.db ?? db;
|
||||||
const normalizedRefs: Array<{
|
const normalizedRefs: Array<{
|
||||||
secretId: string;
|
secretId: string;
|
||||||
configPath: string;
|
configPath: string;
|
||||||
|
|
@ -2043,7 +2045,7 @@ export function secretService(db: Db) {
|
||||||
label: string | null;
|
label: string | null;
|
||||||
}> = [];
|
}> = [];
|
||||||
for (const ref of refs) {
|
for (const ref of refs) {
|
||||||
await assertSecretInCompany(companyId, ref.secretId);
|
await assertSecretInCompany(companyId, ref.secretId, bindingDb);
|
||||||
normalizedRefs.push({
|
normalizedRefs.push({
|
||||||
secretId: ref.secretId,
|
secretId: ref.secretId,
|
||||||
configPath: ref.configPath,
|
configPath: ref.configPath,
|
||||||
|
|
@ -2055,10 +2057,10 @@ export function secretService(db: Db) {
|
||||||
|
|
||||||
const pathPrefixes = [...new Set(normalizedRefs.map((ref) => ref.configPath.split(".")[0]))];
|
const pathPrefixes = [...new Set(normalizedRefs.map((ref) => ref.configPath.split(".")[0]))];
|
||||||
|
|
||||||
await db.transaction(async (tx) => {
|
const writeBindings = async (targetDb: SecretBindingDb) => {
|
||||||
if (pathPrefixes.length > 0) {
|
if (pathPrefixes.length > 0) {
|
||||||
for (const pathPrefix of pathPrefixes) {
|
for (const pathPrefix of pathPrefixes) {
|
||||||
await tx
|
await targetDb
|
||||||
.delete(companySecretBindings)
|
.delete(companySecretBindings)
|
||||||
.where(
|
.where(
|
||||||
and(
|
and(
|
||||||
|
|
@ -2070,7 +2072,7 @@ export function secretService(db: Db) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
await tx
|
await targetDb
|
||||||
.delete(companySecretBindings)
|
.delete(companySecretBindings)
|
||||||
.where(
|
.where(
|
||||||
and(
|
and(
|
||||||
|
|
@ -2081,7 +2083,7 @@ export function secretService(db: Db) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (normalizedRefs.length === 0) return;
|
if (normalizedRefs.length === 0) return;
|
||||||
await tx.insert(companySecretBindings).values(
|
await targetDb.insert(companySecretBindings).values(
|
||||||
normalizedRefs.map((ref) => ({
|
normalizedRefs.map((ref) => ({
|
||||||
companyId,
|
companyId,
|
||||||
secretId: ref.secretId,
|
secretId: ref.secretId,
|
||||||
|
|
@ -2093,7 +2095,15 @@ export function secretService(db: Db) {
|
||||||
label: ref.label,
|
label: ref.label,
|
||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
});
|
};
|
||||||
|
|
||||||
|
if (options?.db) {
|
||||||
|
await writeBindings(bindingDb);
|
||||||
|
} else {
|
||||||
|
await db.transaction(async (tx) => {
|
||||||
|
await writeBindings(tx as SecretBindingDb);
|
||||||
|
});
|
||||||
|
}
|
||||||
return normalizedRefs;
|
return normalizedRefs;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue