mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 01:27:41 +00:00
Merge pull request #585 from Infisical/gitlab-envs
Add support for custom environments in GitLab integration
This commit is contained in:
@@ -1554,8 +1554,14 @@ const syncSecretsGitLab = async ({
|
|||||||
accessToken: string;
|
accessToken: string;
|
||||||
}) => {
|
}) => {
|
||||||
try {
|
try {
|
||||||
|
interface GitLabSecret {
|
||||||
|
key: string;
|
||||||
|
value: string;
|
||||||
|
environment_scope: string;
|
||||||
|
}
|
||||||
|
|
||||||
// get secrets from gitlab
|
// get secrets from gitlab
|
||||||
const getSecretsRes = (
|
const getSecretsRes: GitLabSecret[] = (
|
||||||
await request.get(
|
await request.get(
|
||||||
`${INTEGRATION_GITLAB_API_URL}/v4/projects/${integration?.appId}/variables`,
|
`${INTEGRATION_GITLAB_API_URL}/v4/projects/${integration?.appId}/variables`,
|
||||||
{
|
{
|
||||||
@@ -1565,7 +1571,11 @@ const syncSecretsGitLab = async ({
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
).data;
|
)
|
||||||
|
.data
|
||||||
|
.filter((secret: GitLabSecret) =>
|
||||||
|
secret.environment_scope === integration.targetEnvironment
|
||||||
|
);
|
||||||
|
|
||||||
for await (const key of Object.keys(secrets)) {
|
for await (const key of Object.keys(secrets)) {
|
||||||
const existingSecret = getSecretsRes.find((s: any) => s.key == key);
|
const existingSecret = getSecretsRes.find((s: any) => s.key == key);
|
||||||
@@ -1578,7 +1588,7 @@ const syncSecretsGitLab = async ({
|
|||||||
protected: false,
|
protected: false,
|
||||||
masked: false,
|
masked: false,
|
||||||
raw: false,
|
raw: false,
|
||||||
environment_scope:'*'
|
environment_scope: integration.targetEnvironment
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
@@ -1589,9 +1599,10 @@ const syncSecretsGitLab = async ({
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
// udpate secret
|
// update secret
|
||||||
|
if (secrets[key] !== existingSecret.value) {
|
||||||
await request.put(
|
await request.put(
|
||||||
`${INTEGRATION_GITLAB_API_URL}/v4/projects/${integration?.appId}/variables/${existingSecret.key}`,
|
`${INTEGRATION_GITLAB_API_URL}/v4/projects/${integration?.appId}/variables/${existingSecret.key}?filter[environment_scope]=${integration.targetEnvironment}`,
|
||||||
{
|
{
|
||||||
...existingSecret,
|
...existingSecret,
|
||||||
value: secrets[existingSecret.key]
|
value: secrets[existingSecret.key]
|
||||||
@@ -1603,7 +1614,8 @@ const syncSecretsGitLab = async ({
|
|||||||
"Accept-Encoding": "application/json",
|
"Accept-Encoding": "application/json",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1611,7 +1623,7 @@ const syncSecretsGitLab = async ({
|
|||||||
for await (const sec of getSecretsRes) {
|
for await (const sec of getSecretsRes) {
|
||||||
if (!(sec.key in secrets)) {
|
if (!(sec.key in secrets)) {
|
||||||
await request.delete(
|
await request.delete(
|
||||||
`${INTEGRATION_GITLAB_API_URL}/v4/projects/${integration?.appId}/variables/${sec.key}`,
|
`${INTEGRATION_GITLAB_API_URL}/v4/projects/${integration?.appId}/variables/${sec.key}?filter[environment_scope]=${integration.targetEnvironment}`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
"Authorization": `Bearer ${accessToken}`,
|
"Authorization": `Bearer ${accessToken}`,
|
||||||
|
|||||||
@@ -191,6 +191,17 @@ const IntegrationTile = ({
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
case 'gitlab':
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<div className="mb-2 text-xs font-semibold text-gray-400">ENVIRONMENT</div>
|
||||||
|
<ListBox
|
||||||
|
data={null}
|
||||||
|
isSelected={integration.targetEnvironment}
|
||||||
|
onChange={setIntegrationTargetEnvironment}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
default:
|
default:
|
||||||
return <div />;
|
return <div />;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,15 @@ import { useEffect, useState } from 'react';
|
|||||||
import { useRouter } from 'next/router';
|
import { useRouter } from 'next/router';
|
||||||
import queryString from 'query-string';
|
import queryString from 'query-string';
|
||||||
|
|
||||||
import { Button, Card, CardTitle, FormControl, Select, SelectItem } from '../../../components/v2';
|
import {
|
||||||
|
Button,
|
||||||
|
Card,
|
||||||
|
CardTitle,
|
||||||
|
FormControl,
|
||||||
|
Input,
|
||||||
|
Select,
|
||||||
|
SelectItem
|
||||||
|
} from '../../../components/v2';
|
||||||
import {
|
import {
|
||||||
useGetIntegrationAuthApps,
|
useGetIntegrationAuthApps,
|
||||||
useGetIntegrationAuthById,
|
useGetIntegrationAuthById,
|
||||||
@@ -37,6 +45,7 @@ export default function GitLabCreateIntegrationPage() {
|
|||||||
const [targetEntity, setTargetEntity] = useState(gitLabEntities[0].value);
|
const [targetEntity, setTargetEntity] = useState(gitLabEntities[0].value);
|
||||||
const [selectedSourceEnvironment, setSelectedSourceEnvironment] = useState('');
|
const [selectedSourceEnvironment, setSelectedSourceEnvironment] = useState('');
|
||||||
const [targetAppId, setTargetAppId] = useState('');
|
const [targetAppId, setTargetAppId] = useState('');
|
||||||
|
const [targetEnvironment, setTargetEnvironment] = useState('');
|
||||||
|
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
|
||||||
@@ -86,7 +95,7 @@ export default function GitLabCreateIntegrationPage() {
|
|||||||
)?.name ?? null,
|
)?.name ?? null,
|
||||||
appId: targetAppId,
|
appId: targetAppId,
|
||||||
sourceEnvironment: selectedSourceEnvironment,
|
sourceEnvironment: selectedSourceEnvironment,
|
||||||
targetEnvironment: null,
|
targetEnvironment: targetEnvironment === '' ? '*' : targetEnvironment,
|
||||||
targetEnvironmentId: null,
|
targetEnvironmentId: null,
|
||||||
targetService: null,
|
targetService: null,
|
||||||
targetServiceId: null,
|
targetServiceId: null,
|
||||||
@@ -189,6 +198,15 @@ export default function GitLabCreateIntegrationPage() {
|
|||||||
)}
|
)}
|
||||||
</Select>
|
</Select>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
|
<FormControl
|
||||||
|
label="GitLab Environment Scope (Optional)"
|
||||||
|
>
|
||||||
|
<Input
|
||||||
|
placeholder="*"
|
||||||
|
value={targetEnvironment}
|
||||||
|
onChange={(e) => setTargetEnvironment(e.target.value)}
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
<Button
|
<Button
|
||||||
onClick={handleButtonClick}
|
onClick={handleButtonClick}
|
||||||
color="mineshaft"
|
color="mineshaft"
|
||||||
|
|||||||
Reference in New Issue
Block a user