mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 22:27:48 +00:00
Merge pull request #1064 from Infisical/github-checkly-suffixes
allow multiple simultaneous integrations with checkly and github
This commit is contained in:
@@ -87,13 +87,15 @@ const syncSecrets = async ({
|
|||||||
integrationAuth,
|
integrationAuth,
|
||||||
secrets,
|
secrets,
|
||||||
accessId,
|
accessId,
|
||||||
accessToken
|
accessToken,
|
||||||
|
appendices
|
||||||
}: {
|
}: {
|
||||||
integration: IIntegration;
|
integration: IIntegration;
|
||||||
integrationAuth: IIntegrationAuth;
|
integrationAuth: IIntegrationAuth;
|
||||||
secrets: Record<string, { value: string; comment?: string }>;
|
secrets: Record<string, { value: string; comment?: string }>;
|
||||||
accessId: string | null;
|
accessId: string | null;
|
||||||
accessToken: string;
|
accessToken: string;
|
||||||
|
appendices?: { prefix: string, suffix: string };
|
||||||
}) => {
|
}) => {
|
||||||
switch (integration.integration) {
|
switch (integration.integration) {
|
||||||
case INTEGRATION_GCP_SECRET_MANAGER:
|
case INTEGRATION_GCP_SECRET_MANAGER:
|
||||||
@@ -153,7 +155,8 @@ const syncSecrets = async ({
|
|||||||
await syncSecretsGitHub({
|
await syncSecretsGitHub({
|
||||||
integration,
|
integration,
|
||||||
secrets,
|
secrets,
|
||||||
accessToken
|
accessToken,
|
||||||
|
appendices
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case INTEGRATION_GITLAB:
|
case INTEGRATION_GITLAB:
|
||||||
@@ -218,7 +221,8 @@ const syncSecrets = async ({
|
|||||||
await syncSecretsCheckly({
|
await syncSecretsCheckly({
|
||||||
integration,
|
integration,
|
||||||
secrets,
|
secrets,
|
||||||
accessToken
|
accessToken,
|
||||||
|
appendices
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case INTEGRATION_QOVERY:
|
case INTEGRATION_QOVERY:
|
||||||
@@ -1342,11 +1346,13 @@ const syncSecretsNetlify = async ({
|
|||||||
const syncSecretsGitHub = async ({
|
const syncSecretsGitHub = async ({
|
||||||
integration,
|
integration,
|
||||||
secrets,
|
secrets,
|
||||||
accessToken
|
accessToken,
|
||||||
|
appendices
|
||||||
}: {
|
}: {
|
||||||
integration: IIntegration;
|
integration: IIntegration;
|
||||||
secrets: Record<string, { value: string; comment?: string }>;
|
secrets: Record<string, { value: string; comment?: string }>;
|
||||||
accessToken: string;
|
accessToken: string;
|
||||||
|
appendices?: { prefix: string, suffix: string };
|
||||||
}) => {
|
}) => {
|
||||||
interface GitHubRepoKey {
|
interface GitHubRepoKey {
|
||||||
key_id: string;
|
key_id: string;
|
||||||
@@ -1376,7 +1382,7 @@ const syncSecretsGitHub = async ({
|
|||||||
).data;
|
).data;
|
||||||
|
|
||||||
// Get local copy of decrypted secrets. We cannot decrypt them as we dont have access to GH private key
|
// Get local copy of decrypted secrets. We cannot decrypt them as we dont have access to GH private key
|
||||||
const encryptedSecrets: GitHubSecretRes = (
|
let encryptedSecrets: GitHubSecretRes = (
|
||||||
await octokit.request("GET /repos/{owner}/{repo}/actions/secrets", {
|
await octokit.request("GET /repos/{owner}/{repo}/actions/secrets", {
|
||||||
owner: integration.owner,
|
owner: integration.owner,
|
||||||
repo: integration.app
|
repo: integration.app
|
||||||
@@ -1389,6 +1395,15 @@ const syncSecretsGitHub = async ({
|
|||||||
{}
|
{}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
encryptedSecrets = Object.keys(encryptedSecrets).reduce((result: {
|
||||||
|
[key: string]: GitHubSecret;
|
||||||
|
}, key) => {
|
||||||
|
if ((appendices?.prefix !== undefined ? key.startsWith(appendices?.prefix) : true) && (appendices?.suffix !== undefined ? key.endsWith(appendices?.suffix) : true)) {
|
||||||
|
result[key] = encryptedSecrets[key];
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}, {});
|
||||||
|
|
||||||
Object.keys(encryptedSecrets).map(async (key) => {
|
Object.keys(encryptedSecrets).map(async (key) => {
|
||||||
if (!(key in secrets)) {
|
if (!(key in secrets)) {
|
||||||
await octokit.request("DELETE /repos/{owner}/{repo}/actions/secrets/{secret_name}", {
|
await octokit.request("DELETE /repos/{owner}/{repo}/actions/secrets/{secret_name}", {
|
||||||
@@ -2074,13 +2089,15 @@ const syncSecretsSupabase = async ({
|
|||||||
const syncSecretsCheckly = async ({
|
const syncSecretsCheckly = async ({
|
||||||
integration,
|
integration,
|
||||||
secrets,
|
secrets,
|
||||||
accessToken
|
accessToken,
|
||||||
|
appendices
|
||||||
}: {
|
}: {
|
||||||
integration: IIntegration;
|
integration: IIntegration;
|
||||||
secrets: Record<string, { value: string; comment?: string }>;
|
secrets: Record<string, { value: string; comment?: string }>;
|
||||||
accessToken: string;
|
accessToken: string;
|
||||||
|
appendices?: { prefix: string, suffix: string };
|
||||||
}) => {
|
}) => {
|
||||||
const getSecretsRes = (
|
let getSecretsRes = (
|
||||||
await standardRequest.get(`${INTEGRATION_CHECKLY_API_URL}/v1/variables`, {
|
await standardRequest.get(`${INTEGRATION_CHECKLY_API_URL}/v1/variables`, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${accessToken}`,
|
Authorization: `Bearer ${accessToken}`,
|
||||||
@@ -2096,6 +2113,15 @@ const syncSecretsCheckly = async ({
|
|||||||
{}
|
{}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
getSecretsRes = Object.keys(getSecretsRes).reduce((result: {
|
||||||
|
[key: string]: string;
|
||||||
|
}, key) => {
|
||||||
|
if ((appendices?.prefix !== undefined ? key.startsWith(appendices?.prefix) : true) && (appendices?.suffix !== undefined ? key.endsWith(appendices?.suffix) : true)) {
|
||||||
|
result[key] = getSecretsRes[key];
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}, {});
|
||||||
|
|
||||||
// add secrets
|
// add secrets
|
||||||
for await (const key of Object.keys(secrets)) {
|
for await (const key of Object.keys(secrets)) {
|
||||||
if (!(key in getSecretsRes)) {
|
if (!(key in getSecretsRes)) {
|
||||||
|
|||||||
@@ -60,7 +60,8 @@ syncSecretsToThirdPartyServices.process(async (job: Job) => {
|
|||||||
integrationAuth,
|
integrationAuth,
|
||||||
secrets: Object.keys(suffixedSecrets).length !== 0 ? suffixedSecrets : secrets,
|
secrets: Object.keys(suffixedSecrets).length !== 0 ? suffixedSecrets : secrets,
|
||||||
accessId: access.accessId === undefined ? null : access.accessId,
|
accessId: access.accessId === undefined ? null : access.accessId,
|
||||||
accessToken: access.accessToken
|
accessToken: access.accessToken,
|
||||||
|
appendices: { prefix: integration.metadata?.secretPrefix || "", suffix: integration.metadata?.secretSuffix || "" }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ const sanitizeConf = {
|
|||||||
|
|
||||||
const syntaxHighlight = (content?: string | null, isVisible?: boolean) => {
|
const syntaxHighlight = (content?: string | null, isVisible?: boolean) => {
|
||||||
if (content === "") return "EMPTY";
|
if (content === "") return "EMPTY";
|
||||||
if (!content) return "missing";
|
if (!content) return "EMPTY";
|
||||||
if (!isVisible) return replaceContentWithDot(content);
|
if (!isVisible) return replaceContentWithDot(content);
|
||||||
|
|
||||||
const sanitizedContent = sanitizeHtml(
|
const sanitizedContent = sanitizeHtml(
|
||||||
|
|||||||
@@ -3,8 +3,9 @@ import Head from "next/head";
|
|||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import { faArrowUpRightFromSquare, faBookOpen, faBugs, faCircleInfo } from "@fortawesome/free-solid-svg-icons";
|
import { faAngleDown, faArrowUpRightFromSquare, faBookOpen, faBugs, faCheckCircle, faCircleInfo } from "@fortawesome/free-solid-svg-icons";
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
|
import { motion } from "framer-motion";
|
||||||
import queryString from "query-string";
|
import queryString from "query-string";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -15,10 +16,18 @@ import {
|
|||||||
Button,
|
Button,
|
||||||
Card,
|
Card,
|
||||||
CardTitle,
|
CardTitle,
|
||||||
|
DropdownMenu,
|
||||||
|
DropdownMenuContent,
|
||||||
|
DropdownMenuItem,
|
||||||
|
DropdownMenuTrigger,
|
||||||
FormControl,
|
FormControl,
|
||||||
Input,
|
Input,
|
||||||
Select,
|
Select,
|
||||||
SelectItem
|
SelectItem,
|
||||||
|
Tab,
|
||||||
|
TabList,
|
||||||
|
TabPanel,
|
||||||
|
Tabs
|
||||||
} from "../../../components/v2";
|
} from "../../../components/v2";
|
||||||
import {
|
import {
|
||||||
useGetIntegrationAuthApps,
|
useGetIntegrationAuthApps,
|
||||||
@@ -26,6 +35,11 @@ import {
|
|||||||
} from "../../../hooks/api/integrationAuth";
|
} from "../../../hooks/api/integrationAuth";
|
||||||
import { useGetWorkspaceById } from "../../../hooks/api/workspace";
|
import { useGetWorkspaceById } from "../../../hooks/api/workspace";
|
||||||
|
|
||||||
|
enum TabSections {
|
||||||
|
Connection = "connection",
|
||||||
|
Options = "options"
|
||||||
|
}
|
||||||
|
|
||||||
export default function GitHubCreateIntegrationPage() {
|
export default function GitHubCreateIntegrationPage() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { mutateAsync } = useCreateIntegration();
|
const { mutateAsync } = useCreateIntegration();
|
||||||
@@ -40,7 +54,8 @@ export default function GitHubCreateIntegrationPage() {
|
|||||||
|
|
||||||
const [selectedSourceEnvironment, setSelectedSourceEnvironment] = useState("");
|
const [selectedSourceEnvironment, setSelectedSourceEnvironment] = useState("");
|
||||||
const [secretPath, setSecretPath] = useState("/");
|
const [secretPath, setSecretPath] = useState("/");
|
||||||
const [targetAppId, setTargetAppId] = useState("");
|
const [targetAppIds, setTargetAppIds] = useState<string[]>([]);
|
||||||
|
const [secretSuffix, setSecretSuffix] = useState("");
|
||||||
|
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
|
||||||
@@ -53,9 +68,9 @@ export default function GitHubCreateIntegrationPage() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (integrationAuthApps) {
|
if (integrationAuthApps) {
|
||||||
if (integrationAuthApps.length > 0) {
|
if (integrationAuthApps.length > 0) {
|
||||||
setTargetAppId(integrationAuthApps[0].appId as string);
|
setTargetAppIds([String(integrationAuthApps[0].appId)]);
|
||||||
} else {
|
} else {
|
||||||
setTargetAppId("none");
|
setTargetAppIds(["none"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [integrationAuthApps]);
|
}, [integrationAuthApps]);
|
||||||
@@ -66,20 +81,27 @@ export default function GitHubCreateIntegrationPage() {
|
|||||||
|
|
||||||
if (!integrationAuth?._id) return;
|
if (!integrationAuth?._id) return;
|
||||||
|
|
||||||
const targetApp = integrationAuthApps?.find(
|
const targetApps = integrationAuthApps?.filter(
|
||||||
(integrationAuthApp) => integrationAuthApp.appId === targetAppId
|
(integrationAuthApp) => targetAppIds.includes(String(integrationAuthApp.appId))
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!targetApp || !targetApp.owner) return;
|
if (!targetApps) return;
|
||||||
|
|
||||||
|
await Promise.all(
|
||||||
|
targetApps.map(async (targetApp) => {
|
||||||
await mutateAsync({
|
await mutateAsync({
|
||||||
integrationAuthId: integrationAuth?._id,
|
integrationAuthId: integrationAuth?._id,
|
||||||
isActive: true,
|
isActive: true,
|
||||||
app: targetApp.name,
|
app: targetApp.name,
|
||||||
sourceEnvironment: selectedSourceEnvironment,
|
sourceEnvironment: selectedSourceEnvironment,
|
||||||
owner: targetApp.owner,
|
owner: targetApp.owner,
|
||||||
secretPath
|
secretPath,
|
||||||
});
|
metadata: {
|
||||||
|
secretSuffix
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
router.push(`/integrations/${localStorage.getItem("projectData.id")}`);
|
router.push(`/integrations/${localStorage.getItem("projectData.id")}`);
|
||||||
@@ -92,7 +114,7 @@ export default function GitHubCreateIntegrationPage() {
|
|||||||
workspace &&
|
workspace &&
|
||||||
selectedSourceEnvironment &&
|
selectedSourceEnvironment &&
|
||||||
integrationAuthApps &&
|
integrationAuthApps &&
|
||||||
targetAppId ? (
|
targetAppIds ? (
|
||||||
<div className="flex flex-col h-full w-full items-center justify-center">
|
<div className="flex flex-col h-full w-full items-center justify-center">
|
||||||
<Head>
|
<Head>
|
||||||
<title>Set Up GitHub Integration</title>
|
<title>Set Up GitHub Integration</title>
|
||||||
@@ -124,7 +146,22 @@ export default function GitHubCreateIntegrationPage() {
|
|||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
</CardTitle>
|
</CardTitle>
|
||||||
<FormControl label="Project Environment" className="px-6">
|
<Tabs defaultValue={TabSections.Connection} className="px-6">
|
||||||
|
<TabList>
|
||||||
|
<div className="flex flex-row border-b border-mineshaft-600 w-full">
|
||||||
|
<Tab value={TabSections.Connection}>Connection</Tab>
|
||||||
|
<Tab value={TabSections.Options}>Options</Tab>
|
||||||
|
</div>
|
||||||
|
</TabList>
|
||||||
|
<TabPanel value={TabSections.Connection}>
|
||||||
|
<motion.div
|
||||||
|
key="panel-1"
|
||||||
|
transition={{ duration: 0.15 }}
|
||||||
|
initial={{ opacity: 0, translateX: 30 }}
|
||||||
|
animate={{ opacity: 1, translateX: 0 }}
|
||||||
|
exit={{ opacity: 0, translateX: 30 }}
|
||||||
|
>
|
||||||
|
<FormControl label="Project Environment">
|
||||||
<Select
|
<Select
|
||||||
value={selectedSourceEnvironment}
|
value={selectedSourceEnvironment}
|
||||||
onValueChange={(val) => setSelectedSourceEnvironment(val)}
|
onValueChange={(val) => setSelectedSourceEnvironment(val)}
|
||||||
@@ -140,43 +177,78 @@ export default function GitHubCreateIntegrationPage() {
|
|||||||
))}
|
))}
|
||||||
</Select>
|
</Select>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormControl label="Secrets Path" className="px-6">
|
<FormControl label="Secrets Path">
|
||||||
<Input
|
<Input
|
||||||
value={secretPath}
|
value={secretPath}
|
||||||
onChange={(evt) => setSecretPath(evt.target.value)}
|
onChange={(evt) => setSecretPath(evt.target.value)}
|
||||||
placeholder="Provide a path, default is /"
|
placeholder="Provide a path, default is /"
|
||||||
/>
|
/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormControl label="GitHub Repo" className="px-6">
|
<FormControl label="GitHub Repo">
|
||||||
<Select
|
<DropdownMenu>
|
||||||
value={targetAppId}
|
<DropdownMenuTrigger asChild>
|
||||||
onValueChange={(val) => setTargetAppId(val)}
|
{(integrationAuthApps.length > 0) ? <div className="w-full cursor-pointer border border-mineshaft-600 inline-flex items-center justify-between rounded-md bg-mineshaft-900 px-3 py-2 font-inter text-sm font-normal text-bunker-200 outline-none data-[placeholder]:text-mineshaft-200">
|
||||||
className="w-full border border-mineshaft-500"
|
{targetAppIds.length === 1 ? integrationAuthApps?.find(
|
||||||
isDisabled={integrationAuthApps.length === 0}
|
(integrationAuthApp) => targetAppIds[0] === String(integrationAuthApp.appId)
|
||||||
>
|
)?.name : `${targetAppIds.length} repositories selected`}
|
||||||
{integrationAuthApps.length > 0 ? (
|
<FontAwesomeIcon icon={faAngleDown} className="text-xs" />
|
||||||
integrationAuthApps.map((integrationAuthApp) => (
|
</div> : <div className="w-full cursor-default border border-mineshaft-600 inline-flex items-center justify-between rounded-md bg-mineshaft-900 px-3 py-2 font-inter text-sm font-normal text-bunker-200 outline-none data-[placeholder]:text-mineshaft-200">
|
||||||
<SelectItem
|
No repositories found
|
||||||
value={integrationAuthApp.appId as string}
|
</div>}
|
||||||
key={`github-repo-${integrationAuthApp.appId}`}
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent align="start" className="z-[100] max-h-80 overflow-y-scroll thin-scrollbar">
|
||||||
|
{(integrationAuthApps.length > 0) ? (
|
||||||
|
integrationAuthApps.map((integrationAuthApp) => {
|
||||||
|
const isSelected = targetAppIds.includes(String(integrationAuthApp.appId));
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DropdownMenuItem
|
||||||
|
onClick={() => {
|
||||||
|
if (targetAppIds.includes(String(integrationAuthApp.appId))) {
|
||||||
|
setTargetAppIds(targetAppIds.filter((appId) => appId !== String(integrationAuthApp.appId)));
|
||||||
|
} else {
|
||||||
|
setTargetAppIds([...targetAppIds, String(integrationAuthApp.appId)]);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
key={integrationAuthApp.appId}
|
||||||
|
icon={isSelected ? <FontAwesomeIcon icon={faCheckCircle} className="text-primary pr-0.5" /> : <div className="pl-[1.01rem]"/>}
|
||||||
|
iconPos="left"
|
||||||
|
className="w-[28.4rem] text-sm"
|
||||||
>
|
>
|
||||||
{integrationAuthApp.name}
|
{integrationAuthApp.name}
|
||||||
</SelectItem>
|
</DropdownMenuItem>
|
||||||
))
|
)})
|
||||||
) : (
|
) : <div/>}
|
||||||
<SelectItem value="none" key="target-app-none">
|
</DropdownMenuContent>
|
||||||
No repositories found
|
</DropdownMenu>
|
||||||
</SelectItem>
|
|
||||||
)}
|
|
||||||
</Select>
|
|
||||||
</FormControl>
|
</FormControl>
|
||||||
|
</motion.div>
|
||||||
|
</TabPanel>
|
||||||
|
<TabPanel value={TabSections.Options}>
|
||||||
|
<motion.div
|
||||||
|
key="panel-1"
|
||||||
|
transition={{ duration: 0.15 }}
|
||||||
|
initial={{ opacity: 0, translateX: -30 }}
|
||||||
|
animate={{ opacity: 1, translateX: 0 }}
|
||||||
|
exit={{ opacity: 0, translateX: 30 }}
|
||||||
|
>
|
||||||
|
<FormControl label="Append Secret Names with..." className="pb-[9.75rem]">
|
||||||
|
<Input
|
||||||
|
value={secretSuffix}
|
||||||
|
onChange={(evt) => setSecretSuffix(evt.target.value)}
|
||||||
|
placeholder="Provide a suffix for secret names, default is no suffix"
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
</motion.div>
|
||||||
|
</TabPanel>
|
||||||
|
</Tabs>
|
||||||
<Button
|
<Button
|
||||||
onClick={handleButtonClick}
|
onClick={handleButtonClick}
|
||||||
color="mineshaft"
|
color="mineshaft"
|
||||||
variant="outline_bg"
|
variant="outline_bg"
|
||||||
className="mt-2 mb-6 ml-auto mr-6"
|
className="mb-6 ml-auto mr-6"
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
isDisabled={integrationAuthApps.length === 0}
|
isDisabled={integrationAuthApps.length === 0 || targetAppIds.length === 0}
|
||||||
>
|
>
|
||||||
Create Integration
|
Create Integration
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
+1
-1
@@ -139,7 +139,7 @@ export const IntegrationsSection = ({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{(integration.integration === "checkly") && (
|
{((integration.integration === "checkly") || (integration.integration === "github")) && (
|
||||||
<div className="ml-2 flex flex-col">
|
<div className="ml-2 flex flex-col">
|
||||||
<FormLabel label="Secret Suffix" />
|
<FormLabel label="Secret Suffix" />
|
||||||
<div className="rounded-md border border-mineshaft-700 bg-mineshaft-900 px-3 py-2 font-inter text-sm text-bunker-200">
|
<div className="rounded-md border border-mineshaft-700 bg-mineshaft-900 px-3 py-2 font-inter text-sm text-bunker-200">
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ export const SecretApprovalPage = () => {
|
|||||||
const workspaceId = currentWorkspace?._id || "";
|
const workspaceId = currentWorkspace?._id || "";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="container mx-auto bg-bunker-800 text-white w-full h-full max-w-7xl">
|
<div className="container mx-auto bg-bunker-800 text-white w-full h-full max-w-7xl px-6">
|
||||||
<div className="my-6">
|
<div className="my-6">
|
||||||
<p className="text-3xl font-semibold text-gray-200">Secret Approvals</p>
|
<p className="text-3xl font-semibold text-gray-200">Secret Approvals</p>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user