mirror of
https://github.com/fosrl/pangolin.git
synced 2026-08-23 20:50:18 +02:00
Add some documentation; pull the override values
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { db, resources } from "@server/db";
|
import { db, resourcePolicies, resources } from "@server/db";
|
||||||
import response from "@server/lib/response";
|
import response from "@server/lib/response";
|
||||||
import stoi from "@server/lib/stoi";
|
import stoi from "@server/lib/stoi";
|
||||||
import logger from "@server/logger";
|
import logger from "@server/logger";
|
||||||
@@ -41,6 +41,15 @@ async function query(resourceId?: number, niceId?: string, orgId?: string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function queryInlinePolicy(resourcePolicyId: number) {
|
||||||
|
const [res] = await db
|
||||||
|
.select()
|
||||||
|
.from(resourcePolicies)
|
||||||
|
.where(eq(resourcePolicies.resourcePolicyId, resourcePolicyId))
|
||||||
|
.limit(1);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
export type GetResourceResponse = Omit<
|
export type GetResourceResponse = Omit<
|
||||||
NonNullable<Awaited<ReturnType<typeof query>>>,
|
NonNullable<Awaited<ReturnType<typeof query>>>,
|
||||||
"headers"
|
"headers"
|
||||||
@@ -132,12 +141,31 @@ export async function getResource(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isInlinePolicy =
|
||||||
|
resource.resourcePolicyId === null &&
|
||||||
|
resource.defaultResourcePolicyId !== null;
|
||||||
|
|
||||||
|
let returnData = resource;
|
||||||
|
if (isInlinePolicy) {
|
||||||
|
// get the policy
|
||||||
|
const policy = await queryInlinePolicy(
|
||||||
|
resource.defaultResourcePolicyId!
|
||||||
|
);
|
||||||
|
returnData = {
|
||||||
|
...returnData,
|
||||||
|
sso: policy?.sso || null,
|
||||||
|
emailWhitelistEnabled: policy?.emailWhitelistEnabled || null,
|
||||||
|
applyRules: policy?.applyRules || null,
|
||||||
|
skipToIdpId: policy?.idpId || null
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
return response<GetResourceResponse>(res, {
|
return response<GetResourceResponse>(res, {
|
||||||
data: {
|
data: {
|
||||||
...resource,
|
...returnData,
|
||||||
headers: resource.headers
|
headers: returnData.headers
|
||||||
? JSON.parse(resource.headers)
|
? JSON.parse(returnData.headers)
|
||||||
: resource.headers
|
: returnData.headers
|
||||||
},
|
},
|
||||||
success: true,
|
success: true,
|
||||||
error: false,
|
error: false,
|
||||||
|
|||||||
@@ -66,16 +66,38 @@ const updateHttpResourceBodySchema = z
|
|||||||
.optional(),
|
.optional(),
|
||||||
subdomain: z.string().nullable().optional(),
|
subdomain: z.string().nullable().optional(),
|
||||||
ssl: z.boolean().optional(),
|
ssl: z.boolean().optional(),
|
||||||
sso: z.boolean().optional(),
|
sso: z
|
||||||
|
.boolean()
|
||||||
|
.optional()
|
||||||
|
.describe(
|
||||||
|
"When no shared resource policy is assigned (resourcePolicyId is null), updates the resource's inline policy. When a shared policy is assigned, this value overrides the shared policy for this resource."
|
||||||
|
),
|
||||||
blockAccess: z.boolean().optional(),
|
blockAccess: z.boolean().optional(),
|
||||||
emailWhitelistEnabled: z.boolean().optional(),
|
emailWhitelistEnabled: z
|
||||||
applyRules: z.boolean().optional(),
|
.boolean()
|
||||||
|
.optional()
|
||||||
|
.describe(
|
||||||
|
"When no shared resource policy is assigned (resourcePolicyId is null), updates the resource's inline policy. When a shared policy is assigned, this value overrides the shared policy for this resource."
|
||||||
|
),
|
||||||
|
applyRules: z
|
||||||
|
.boolean()
|
||||||
|
.optional()
|
||||||
|
.describe(
|
||||||
|
"When no shared resource policy is assigned (resourcePolicyId is null), updates the resource's inline policy. When a shared policy is assigned, this value overrides the shared policy for this resource."
|
||||||
|
),
|
||||||
domainId: z.string().optional(),
|
domainId: z.string().optional(),
|
||||||
enabled: z.boolean().optional(),
|
enabled: z.boolean().optional(),
|
||||||
stickySession: z.boolean().optional(),
|
stickySession: z.boolean().optional(),
|
||||||
tlsServerName: z.string().nullable().optional(),
|
tlsServerName: z.string().nullable().optional(),
|
||||||
setHostHeader: z.string().nullable().optional(),
|
setHostHeader: z.string().nullable().optional(),
|
||||||
skipToIdpId: z.int().positive().nullable().optional(),
|
skipToIdpId: z
|
||||||
|
.int()
|
||||||
|
.positive()
|
||||||
|
.nullable()
|
||||||
|
.optional()
|
||||||
|
.describe(
|
||||||
|
"When no shared resource policy is assigned (resourcePolicyId is null), updates the resource's inline policy. When a shared policy is assigned, this value overrides the shared policy for this resource."
|
||||||
|
),
|
||||||
headers: z
|
headers: z
|
||||||
.array(z.strictObject({ name: z.string(), value: z.string() }))
|
.array(z.strictObject({ name: z.string(), value: z.string() }))
|
||||||
.nullable()
|
.nullable()
|
||||||
@@ -91,7 +113,13 @@ const updateHttpResourceBodySchema = z
|
|||||||
pamMode: z.enum(["passthrough", "push"]).optional(),
|
pamMode: z.enum(["passthrough", "push"]).optional(),
|
||||||
authDaemonMode: z.enum(["site", "remote", "native"]).optional(),
|
authDaemonMode: z.enum(["site", "remote", "native"]).optional(),
|
||||||
authDaemonPort: z.int().min(1).max(65535).nullable().optional(),
|
authDaemonPort: z.int().min(1).max(65535).nullable().optional(),
|
||||||
resourcePolicyId: z.number().nullable().optional()
|
resourcePolicyId: z
|
||||||
|
.number()
|
||||||
|
.nullable()
|
||||||
|
.optional()
|
||||||
|
.describe(
|
||||||
|
"ID of the resource policy to apply to this resource. Set to null to remove the resource policy and fall back to the inline policy settings."
|
||||||
|
)
|
||||||
})
|
})
|
||||||
.refine((data) => Object.keys(data).length > 0, {
|
.refine((data) => Object.keys(data).length > 0, {
|
||||||
error: "At least one field must be provided for update"
|
error: "At least one field must be provided for update"
|
||||||
|
|||||||
Reference in New Issue
Block a user