Update resource policy pincode

This commit is contained in:
Fred KISSIE
2026-03-03 19:49:24 +01:00
parent 1dc8be373c
commit 20b65f549e
2 changed files with 97 additions and 31 deletions

View File

@@ -15,9 +15,13 @@ const setResourcePolicyHeaderAuthParamsSchema = z.object({
});
const setResourcePolicyHeaderAuthBodySchema = z.strictObject({
user: z.string().min(4).max(100).nullable(),
password: z.string().min(4).max(100).nullable(),
extendedCompatibility: z.boolean().nullable()
headerAuth: z
.object({
user: z.string().min(4).max(100),
password: z.string().min(4).max(100),
extendedCompatibility: z.boolean()
})
.nullable()
});
registry.registerPath({
@@ -70,7 +74,7 @@ export async function setResourcePolicyHeaderAuth(
}
const { resourcePolicyId } = parsedParams.data;
const { user, password, extendedCompatibility } = parsedBody.data;
const { headerAuth } = parsedBody.data;
await db.transaction(async (trx) => {
await trx
@@ -82,15 +86,17 @@ export async function setResourcePolicyHeaderAuth(
)
);
if (user && password && extendedCompatibility !== null) {
if (headerAuth !== null) {
const headerAuthHash = await hashPassword(
Buffer.from(`${user}:${password}`).toString("base64")
Buffer.from(
`${headerAuth.user}:${headerAuth.password}`
).toString("base64")
);
await trx.insert(resourcePolicyHeaderAuth).values({
resourcePolicyId,
headerAuthHash,
extendedCompatibility: extendedCompatibility
extendedCompatibility: headerAuth.extendedCompatibility
});
}
});