mirror of
https://github.com/fosrl/pangolin.git
synced 2026-07-06 20:29:50 +00:00
Move hashing outside of transaction
This commit is contained in:
@@ -76,6 +76,15 @@ export async function setResourcePolicyHeaderAuth(
|
|||||||
const { resourcePolicyId } = parsedParams.data;
|
const { resourcePolicyId } = parsedParams.data;
|
||||||
const { headerAuth } = parsedBody.data;
|
const { headerAuth } = parsedBody.data;
|
||||||
|
|
||||||
|
const headerAuthHash =
|
||||||
|
headerAuth !== null
|
||||||
|
? await hashPassword(
|
||||||
|
Buffer.from(
|
||||||
|
`${headerAuth.user}:${headerAuth.password}`
|
||||||
|
).toString("base64")
|
||||||
|
)
|
||||||
|
: null;
|
||||||
|
|
||||||
await db.transaction(async (trx) => {
|
await db.transaction(async (trx) => {
|
||||||
await trx
|
await trx
|
||||||
.delete(resourcePolicyHeaderAuth)
|
.delete(resourcePolicyHeaderAuth)
|
||||||
@@ -86,13 +95,7 @@ export async function setResourcePolicyHeaderAuth(
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (headerAuth !== null) {
|
if (headerAuth !== null && headerAuthHash !== null) {
|
||||||
const headerAuthHash = await hashPassword(
|
|
||||||
Buffer.from(
|
|
||||||
`${headerAuth.user}:${headerAuth.password}`
|
|
||||||
).toString("base64")
|
|
||||||
);
|
|
||||||
|
|
||||||
await trx.insert(resourcePolicyHeaderAuth).values({
|
await trx.insert(resourcePolicyHeaderAuth).values({
|
||||||
resourcePolicyId,
|
resourcePolicyId,
|
||||||
headerAuthHash,
|
headerAuthHash,
|
||||||
|
|||||||
@@ -107,6 +107,13 @@ export async function setResourceHeaderAuth(
|
|||||||
resource.resourcePolicyId === null &&
|
resource.resourcePolicyId === null &&
|
||||||
resource.defaultResourcePolicyId !== null;
|
resource.defaultResourcePolicyId !== null;
|
||||||
|
|
||||||
|
const headerAuthHash =
|
||||||
|
user && password && extendedCompatibility !== null
|
||||||
|
? await hashPassword(
|
||||||
|
Buffer.from(`${user}:${password}`).toString("base64")
|
||||||
|
)
|
||||||
|
: null;
|
||||||
|
|
||||||
await db.transaction(async (trx) => {
|
await db.transaction(async (trx) => {
|
||||||
if (isInlinePolicy) {
|
if (isInlinePolicy) {
|
||||||
const policyId = resource.defaultResourcePolicyId!;
|
const policyId = resource.defaultResourcePolicyId!;
|
||||||
@@ -116,11 +123,7 @@ export async function setResourceHeaderAuth(
|
|||||||
eq(resourcePolicyHeaderAuth.resourcePolicyId, policyId)
|
eq(resourcePolicyHeaderAuth.resourcePolicyId, policyId)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (user && password && extendedCompatibility !== null) {
|
if (headerAuthHash !== null && extendedCompatibility !== null) {
|
||||||
const headerAuthHash = await hashPassword(
|
|
||||||
Buffer.from(`${user}:${password}`).toString("base64")
|
|
||||||
);
|
|
||||||
|
|
||||||
await trx.insert(resourcePolicyHeaderAuth).values({
|
await trx.insert(resourcePolicyHeaderAuth).values({
|
||||||
resourcePolicyId: policyId,
|
resourcePolicyId: policyId,
|
||||||
headerAuthHash,
|
headerAuthHash,
|
||||||
@@ -140,11 +143,7 @@ export async function setResourceHeaderAuth(
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (user && password && extendedCompatibility !== null) {
|
if (headerAuthHash !== null && extendedCompatibility !== null) {
|
||||||
const headerAuthHash = await hashPassword(
|
|
||||||
Buffer.from(`${user}:${password}`).toString("base64")
|
|
||||||
);
|
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
trx
|
trx
|
||||||
.insert(resourceHeaderAuth)
|
.insert(resourceHeaderAuth)
|
||||||
|
|||||||
Reference in New Issue
Block a user