mirror of
https://github.com/fosrl/pangolin.git
synced 2026-07-21 13:06:59 +02:00
Add the policy information into missing places
This commit is contained in:
@@ -26,15 +26,22 @@ import {
|
|||||||
userPolicies,
|
userPolicies,
|
||||||
users,
|
users,
|
||||||
ResourceHeaderAuthExtendedCompatibility,
|
ResourceHeaderAuthExtendedCompatibility,
|
||||||
resourceHeaderAuthExtendedCompatibility
|
resourceHeaderAuthExtendedCompatibility,
|
||||||
|
resourcePolicies,
|
||||||
|
resourcePolicyPincode,
|
||||||
|
ResourcePolicyPincode,
|
||||||
|
resourcePolicyPassword,
|
||||||
|
ResourcePolicyPassword,
|
||||||
|
resourcePolicyHeaderAuth,
|
||||||
|
ResourcePolicyHeaderAuth
|
||||||
} from "@server/db";
|
} from "@server/db";
|
||||||
import { and, eq, inArray, or, sql } from "drizzle-orm";
|
import { and, eq, inArray, or, sql } from "drizzle-orm";
|
||||||
|
|
||||||
export type ResourceWithAuth = {
|
export type ResourceWithAuth = {
|
||||||
resource: Resource | null;
|
resource: Resource | null;
|
||||||
pincode: ResourcePincode | null;
|
pincode: ResourcePincode | ResourcePolicyPincode | null;
|
||||||
password: ResourcePassword | null;
|
password: ResourcePassword | ResourcePolicyPassword | null;
|
||||||
headerAuth: ResourceHeaderAuth | null;
|
headerAuth: ResourceHeaderAuth | ResourcePolicyHeaderAuth | null;
|
||||||
headerAuthExtendedCompatibility: ResourceHeaderAuthExtendedCompatibility | null;
|
headerAuthExtendedCompatibility: ResourceHeaderAuthExtendedCompatibility | null;
|
||||||
org: Org;
|
org: Org;
|
||||||
};
|
};
|
||||||
@@ -82,6 +89,31 @@ export async function getResourceByDomain(
|
|||||||
resources.resourceId
|
resources.resourceId
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
.leftJoin(
|
||||||
|
resourcePolicies,
|
||||||
|
eq(resourcePolicies.resourcePolicyId, resources.resourcePolicyId)
|
||||||
|
)
|
||||||
|
.leftJoin(
|
||||||
|
resourcePolicyPincode,
|
||||||
|
eq(
|
||||||
|
resourcePolicyPincode.resourcePolicyId,
|
||||||
|
resourcePolicies.resourcePolicyId
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.leftJoin(
|
||||||
|
resourcePolicyPassword,
|
||||||
|
eq(
|
||||||
|
resourcePolicyPassword.resourcePolicyId,
|
||||||
|
resourcePolicies.resourcePolicyId
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.leftJoin(
|
||||||
|
resourcePolicyHeaderAuth,
|
||||||
|
eq(
|
||||||
|
resourcePolicyHeaderAuth.resourcePolicyId,
|
||||||
|
resourcePolicies.resourcePolicyId
|
||||||
|
)
|
||||||
|
)
|
||||||
.innerJoin(orgs, eq(orgs.orgId, resources.orgId))
|
.innerJoin(orgs, eq(orgs.orgId, resources.orgId))
|
||||||
.where(
|
.where(
|
||||||
or(
|
or(
|
||||||
@@ -113,11 +145,18 @@ export async function getResourceByDomain(
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
resource: result.resources,
|
resource: result.resources,
|
||||||
pincode: result.resourcePincode,
|
pincode: result.resourcePolicyPincode ?? result.resourcePincode,
|
||||||
password: result.resourcePassword,
|
password: result.resourcePolicyPassword ?? result.resourcePassword,
|
||||||
headerAuth: result.resourceHeaderAuth,
|
headerAuth:
|
||||||
headerAuthExtendedCompatibility:
|
result.resourcePolicyHeaderAuth ?? result.resourceHeaderAuth,
|
||||||
result.resourceHeaderAuthExtendedCompatibility,
|
headerAuthExtendedCompatibility: result.resourcePolicyHeaderAuth
|
||||||
|
? ({
|
||||||
|
headerAuthExtendedCompatibilityId: 0,
|
||||||
|
resourceId: result.resources.resourceId,
|
||||||
|
extendedCompatibilityIsActivated:
|
||||||
|
result.resourcePolicyHeaderAuth.extendedCompatibility
|
||||||
|
} as ResourceHeaderAuthExtendedCompatibility)
|
||||||
|
: result.resourceHeaderAuthExtendedCompatibility,
|
||||||
org: result.orgs
|
org: result.orgs
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1545,5 +1545,14 @@ export type RoundTripMessageTracker = InferSelectModel<
|
|||||||
export type StatusHistory = InferSelectModel<typeof statusHistory>;
|
export type StatusHistory = InferSelectModel<typeof statusHistory>;
|
||||||
export type Label = InferSelectModel<typeof labels>;
|
export type Label = InferSelectModel<typeof labels>;
|
||||||
export type ResourcePolicy = InferSelectModel<typeof resourcePolicies>;
|
export type ResourcePolicy = InferSelectModel<typeof resourcePolicies>;
|
||||||
|
export type ResourcePolicyPincode = InferSelectModel<
|
||||||
|
typeof resourcePolicyPincode
|
||||||
|
>;
|
||||||
|
export type ResourcePolicyPassword = InferSelectModel<
|
||||||
|
typeof resourcePolicyPassword
|
||||||
|
>;
|
||||||
|
export type ResourcePolicyHeaderAuth = InferSelectModel<
|
||||||
|
typeof resourcePolicyHeaderAuth
|
||||||
|
>;
|
||||||
export type RolePolicy = InferSelectModel<typeof rolePolicies>;
|
export type RolePolicy = InferSelectModel<typeof rolePolicies>;
|
||||||
export type UserPolicy = InferSelectModel<typeof userPolicies>;
|
export type UserPolicy = InferSelectModel<typeof userPolicies>;
|
||||||
|
|||||||
@@ -35,7 +35,14 @@ import {
|
|||||||
ResourceHeaderAuthExtendedCompatibility,
|
ResourceHeaderAuthExtendedCompatibility,
|
||||||
orgs,
|
orgs,
|
||||||
requestAuditLog,
|
requestAuditLog,
|
||||||
Org
|
Org,
|
||||||
|
resourcePolicies,
|
||||||
|
resourcePolicyPincode,
|
||||||
|
ResourcePolicyPincode,
|
||||||
|
resourcePolicyPassword,
|
||||||
|
ResourcePolicyPassword,
|
||||||
|
resourcePolicyHeaderAuth,
|
||||||
|
ResourcePolicyHeaderAuth
|
||||||
} from "@server/db";
|
} from "@server/db";
|
||||||
import {
|
import {
|
||||||
resources,
|
resources,
|
||||||
@@ -204,9 +211,9 @@ export type ValidateResourceSessionTokenBody = z.infer<
|
|||||||
// Type definitions for API responses
|
// Type definitions for API responses
|
||||||
export type ResourceWithAuth = {
|
export type ResourceWithAuth = {
|
||||||
resource: Resource | null;
|
resource: Resource | null;
|
||||||
pincode: ResourcePincode | null;
|
pincode: ResourcePincode | ResourcePolicyPincode | null;
|
||||||
password: ResourcePassword | null;
|
password: ResourcePassword | ResourcePolicyPassword | null;
|
||||||
headerAuth: ResourceHeaderAuth | null;
|
headerAuth: ResourceHeaderAuth | ResourcePolicyHeaderAuth | null;
|
||||||
headerAuthExtendedCompatibility: ResourceHeaderAuthExtendedCompatibility | null;
|
headerAuthExtendedCompatibility: ResourceHeaderAuthExtendedCompatibility | null;
|
||||||
org: Org;
|
org: Org;
|
||||||
};
|
};
|
||||||
@@ -529,6 +536,34 @@ hybridRouter.get(
|
|||||||
resources.resourceId
|
resources.resourceId
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
.leftJoin(
|
||||||
|
resourcePolicies,
|
||||||
|
eq(
|
||||||
|
resourcePolicies.resourcePolicyId,
|
||||||
|
resources.resourcePolicyId
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.leftJoin(
|
||||||
|
resourcePolicyPincode,
|
||||||
|
eq(
|
||||||
|
resourcePolicyPincode.resourcePolicyId,
|
||||||
|
resourcePolicies.resourcePolicyId
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.leftJoin(
|
||||||
|
resourcePolicyPassword,
|
||||||
|
eq(
|
||||||
|
resourcePolicyPassword.resourcePolicyId,
|
||||||
|
resourcePolicies.resourcePolicyId
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.leftJoin(
|
||||||
|
resourcePolicyHeaderAuth,
|
||||||
|
eq(
|
||||||
|
resourcePolicyHeaderAuth.resourcePolicyId,
|
||||||
|
resourcePolicies.resourcePolicyId
|
||||||
|
)
|
||||||
|
)
|
||||||
.innerJoin(orgs, eq(orgs.orgId, resources.orgId))
|
.innerJoin(orgs, eq(orgs.orgId, resources.orgId))
|
||||||
.where(
|
.where(
|
||||||
or(
|
or(
|
||||||
@@ -581,11 +616,21 @@ hybridRouter.get(
|
|||||||
|
|
||||||
const resourceWithAuth: ResourceWithAuth = {
|
const resourceWithAuth: ResourceWithAuth = {
|
||||||
resource: result.resources,
|
resource: result.resources,
|
||||||
pincode: result.resourcePincode,
|
pincode: result.resourcePolicyPincode ?? result.resourcePincode,
|
||||||
password: result.resourcePassword,
|
password:
|
||||||
headerAuth: result.resourceHeaderAuth,
|
result.resourcePolicyPassword ?? result.resourcePassword,
|
||||||
headerAuthExtendedCompatibility:
|
headerAuth:
|
||||||
result.resourceHeaderAuthExtendedCompatibility,
|
result.resourcePolicyHeaderAuth ??
|
||||||
|
result.resourceHeaderAuth,
|
||||||
|
headerAuthExtendedCompatibility: result.resourcePolicyHeaderAuth
|
||||||
|
? ({
|
||||||
|
headerAuthExtendedCompatibilityId: 0,
|
||||||
|
resourceId: result.resources.resourceId,
|
||||||
|
extendedCompatibilityIsActivated:
|
||||||
|
result.resourcePolicyHeaderAuth
|
||||||
|
.extendedCompatibility
|
||||||
|
} as ResourceHeaderAuthExtendedCompatibility)
|
||||||
|
: result.resourceHeaderAuthExtendedCompatibility,
|
||||||
org: result.orgs
|
org: result.orgs
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -78,41 +78,9 @@ export type SignSshKeyResponse = {
|
|||||||
validAfter?: string;
|
validAfter?: string;
|
||||||
validBefore?: string;
|
validBefore?: string;
|
||||||
expiresIn?: number;
|
expiresIn?: number;
|
||||||
|
authDaemonMode: "site" | "remote" | "native" | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
// registry.registerPath({
|
|
||||||
// method: "post",
|
|
||||||
// path: "/org/{orgId}/ssh/sign-key",
|
|
||||||
// description: "Sign an SSH public key for access to a resource.",
|
|
||||||
// tags: [OpenAPITags.Org, OpenAPITags.Ssh],
|
|
||||||
// request: {
|
|
||||||
// params: paramsSchema,
|
|
||||||
// body: {
|
|
||||||
// content: {
|
|
||||||
// "application/json": {
|
|
||||||
// schema: bodySchema
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
// responses: {
|
|
||||||
// 200: {
|
|
||||||
// description: "Successful response",
|
|
||||||
// content: {
|
|
||||||
// "application/json": {
|
|
||||||
// schema: z.object({
|
|
||||||
// data: z.unknown().nullable(),
|
|
||||||
// success: z.boolean(),
|
|
||||||
// error: z.boolean(),
|
|
||||||
// message: z.string(),
|
|
||||||
// status: z.number()
|
|
||||||
// })
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
export async function signSshKey(
|
export async function signSshKey(
|
||||||
req: Request,
|
req: Request,
|
||||||
res: Response,
|
res: Response,
|
||||||
@@ -654,6 +622,7 @@ export async function signSshKey(
|
|||||||
siteIds: siteIds,
|
siteIds: siteIds,
|
||||||
siteId: siteIds[0], // just pick the first one for backward compatibility with older olms
|
siteId: siteIds[0], // just pick the first one for backward compatibility with older olms
|
||||||
keyId: cert?.keyId,
|
keyId: cert?.keyId,
|
||||||
|
authDaemonMode: resource.authDaemonMode,
|
||||||
validPrincipals: cert?.validPrincipals,
|
validPrincipals: cert?.validPrincipals,
|
||||||
validAfter: cert?.validAfter.toISOString(),
|
validAfter: cert?.validAfter.toISOString(),
|
||||||
validBefore: cert?.validBefore.toISOString(),
|
validBefore: cert?.validBefore.toISOString(),
|
||||||
|
|||||||
Reference in New Issue
Block a user