mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-08 04:27:38 +00:00
Merge pull request #4691 from Infisical/ENG-3959
feat(pam): ui improvements
This commit is contained in:
@@ -3,13 +3,13 @@ import { z } from "zod";
|
|||||||
import { THsmServiceFactory } from "@app/ee/services/hsm/hsm-service";
|
import { THsmServiceFactory } from "@app/ee/services/hsm/hsm-service";
|
||||||
import { crypto } from "@app/lib/crypto/cryptography";
|
import { crypto } from "@app/lib/crypto/cryptography";
|
||||||
import { QueueWorkerProfile } from "@app/lib/types";
|
import { QueueWorkerProfile } from "@app/lib/types";
|
||||||
|
import { TKmsRootConfigDALFactory } from "@app/services/kms/kms-root-config-dal";
|
||||||
import { TSuperAdminDALFactory } from "@app/services/super-admin/super-admin-dal";
|
import { TSuperAdminDALFactory } from "@app/services/super-admin/super-admin-dal";
|
||||||
|
|
||||||
import { BadRequestError } from "../errors";
|
import { BadRequestError } from "../errors";
|
||||||
import { removeTrailingSlash } from "../fn";
|
import { removeTrailingSlash } from "../fn";
|
||||||
import { CustomLogger } from "../logger/logger";
|
import { CustomLogger } from "../logger/logger";
|
||||||
import { zpStr } from "../zod";
|
import { zpStr } from "../zod";
|
||||||
import { TKmsRootConfigDALFactory } from "@app/services/kms/kms-root-config-dal";
|
|
||||||
|
|
||||||
export const GITLAB_URL = "https://gitlab.com";
|
export const GITLAB_URL = "https://gitlab.com";
|
||||||
|
|
||||||
|
|||||||
@@ -19,12 +19,51 @@ export const PamAccessAccountModal = ({ isOpen, onOpenChange, account }: Props)
|
|||||||
|
|
||||||
const isDurationValid = useMemo(() => duration && ms(duration || "1s") > 0, [duration]);
|
const isDurationValid = useMemo(() => duration && ms(duration || "1s") > 0, [duration]);
|
||||||
|
|
||||||
|
const cliDuration = useMemo(() => {
|
||||||
|
if (!duration) return duration;
|
||||||
|
|
||||||
|
const unit = duration.replace(/[\d\s.-]/g, "");
|
||||||
|
|
||||||
|
const dayOrLargerUnits = [
|
||||||
|
"d",
|
||||||
|
"day",
|
||||||
|
"days",
|
||||||
|
"w",
|
||||||
|
"week",
|
||||||
|
"weeks",
|
||||||
|
"y",
|
||||||
|
"yr",
|
||||||
|
"yrs",
|
||||||
|
"year",
|
||||||
|
"years"
|
||||||
|
];
|
||||||
|
|
||||||
|
// ms library does not handle months (M) so we do it separately
|
||||||
|
if (unit === "M") {
|
||||||
|
const value = parseInt(duration, 10);
|
||||||
|
if (!Number.isNaN(value) && value > 0) {
|
||||||
|
const hours = value * 30 * 24;
|
||||||
|
return `${hours}h`;
|
||||||
|
}
|
||||||
|
} else if (dayOrLargerUnits.includes(unit.toLowerCase())) {
|
||||||
|
const valueInMs = ms(duration);
|
||||||
|
const oneHourInMs = 1000 * 60 * 60;
|
||||||
|
|
||||||
|
if (typeof valueInMs === "number" && valueInMs > 0) {
|
||||||
|
const hours = Math.floor(valueInMs / oneHourInMs);
|
||||||
|
return `${hours}h`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return duration;
|
||||||
|
}, [duration]);
|
||||||
|
|
||||||
const command = useMemo(
|
const command = useMemo(
|
||||||
() =>
|
() =>
|
||||||
account && account.resource.resourceType === PamResourceType.Postgres
|
account && account.resource.resourceType === PamResourceType.Postgres
|
||||||
? `infisical pam db access-account ${account.id} --duration ${duration}`
|
? `infisical pam db access-account ${account.id} --duration ${cliDuration}`
|
||||||
: "",
|
: "",
|
||||||
[account, duration]
|
[account, cliDuration]
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!account) return null;
|
if (!account) return null;
|
||||||
@@ -48,7 +87,7 @@ export const PamAccessAccountModal = ({ isOpen, onOpenChange, account }: Props)
|
|||||||
/>
|
/>
|
||||||
<FormLabel label="CLI Command" className="mt-4" />
|
<FormLabel label="CLI Command" className="mt-4" />
|
||||||
<div className="flex gap-2">
|
<div className="flex gap-2">
|
||||||
<Input value={command} isDisabled className="opacity-50" />
|
<Input value={command} isDisabled />
|
||||||
<IconButton
|
<IconButton
|
||||||
ariaLabel="copy"
|
ariaLabel="copy"
|
||||||
variant="outline_bg"
|
variant="outline_bg"
|
||||||
|
|||||||
Reference in New Issue
Block a user