mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 12:27:28 +00:00
Optimize TeamCity integration
This commit is contained in:
@@ -1998,19 +1998,13 @@ const syncSecretsTeamCity = async ({
|
|||||||
secrets: any;
|
secrets: any;
|
||||||
accessToken: string;
|
accessToken: string;
|
||||||
}) => {
|
}) => {
|
||||||
|
interface TeamCitySecret {
|
||||||
// get projects from TeamCity
|
name: string;
|
||||||
const res = (
|
value: string;
|
||||||
await standardRequest.get(`${integrationAuth.url}/app/rest/projects`, {
|
}
|
||||||
headers: {
|
|
||||||
Authorization: `Bearer ${accessToken}`,
|
|
||||||
Accept: "application/json",
|
|
||||||
},
|
|
||||||
})
|
|
||||||
).data.project.slice(1);
|
|
||||||
|
|
||||||
// get secrets from Teamcity
|
// get secrets from Teamcity
|
||||||
const getParametersRes = (
|
const res = (
|
||||||
await standardRequest.get(
|
await standardRequest.get(
|
||||||
`${integrationAuth.url}/app/rest/projects/id:${integration.appId}/parameters`,
|
`${integrationAuth.url}/app/rest/projects/id:${integration.appId}/parameters`,
|
||||||
{
|
{
|
||||||
@@ -2019,24 +2013,24 @@ const syncSecretsTeamCity = async ({
|
|||||||
Accept: "application/json",
|
Accept: "application/json",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
).data.property;
|
)
|
||||||
|
.data
|
||||||
|
.property
|
||||||
|
.reduce(
|
||||||
|
(obj: any, secret: TeamCitySecret) => {
|
||||||
|
const secretName = secret.name.replace(/^env\./, "");
|
||||||
|
return ({
|
||||||
|
...obj,
|
||||||
|
[secretName]: secret.value
|
||||||
|
})
|
||||||
|
},
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
|
||||||
for await (const key of Object.keys(secrets)) {
|
for await (const key of Object.keys(secrets)) {
|
||||||
if (key in res) {
|
if (!(key in res) || (key in res && secrets[key] !== res[key])) {
|
||||||
await standardRequest.put(
|
// case: secret does not exist in TeamCity or secret value has changed
|
||||||
`${integrationAuth.url}/app/rest/projects/id:${integration.appId}/parameters/${res.id}`,
|
// -> create/update secret
|
||||||
{
|
|
||||||
name: `env.${key}`,
|
|
||||||
value: secrets[key]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
headers: {
|
|
||||||
Authorization: `Bearer ${accessToken}`,
|
|
||||||
Accept: "application/json"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
await standardRequest.post(
|
await standardRequest.post(
|
||||||
`${integrationAuth.url}/app/rest/projects/id:${integration.appId}/parameters`,
|
`${integrationAuth.url}/app/rest/projects/id:${integration.appId}/parameters`,
|
||||||
{
|
{
|
||||||
@@ -2053,13 +2047,11 @@ const syncSecretsTeamCity = async ({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for await (const sec of getParametersRes) {
|
for await (const key of Object.keys(res)) {
|
||||||
const originalString = sec.name;
|
if (!(key in secrets)) {
|
||||||
const modifiedString = originalString.replace(/^env\./, "");
|
// delete secret
|
||||||
|
await standardRequest.delete(
|
||||||
if (!(modifiedString in secrets)) {
|
`${integrationAuth.url}/app/rest/projects/id:${integration.appId}/parameters/env.${key}`,
|
||||||
await standardRequest.delete(
|
|
||||||
`${integrationAuth.url}/app/rest/projects/id:${integration.appId}/parameters/${sec.name}`,
|
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${accessToken}`,
|
Authorization: `Bearer ${accessToken}`,
|
||||||
@@ -2069,7 +2061,6 @@ const syncSecretsTeamCity = async ({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ export default function TeamCityCreateIntegrationPage() {
|
|||||||
setServerUrlErrorText("");
|
setServerUrlErrorText("");
|
||||||
|
|
||||||
if (apiKey.length === 0) {
|
if (apiKey.length === 0) {
|
||||||
setApiKeyErrorText("API Token cannot be blank");
|
setApiKeyErrorText("Access Token cannot be blank");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,12 +51,12 @@ export default function TeamCityCreateIntegrationPage() {
|
|||||||
<Card className="max-w-md rounded-md p-8">
|
<Card className="max-w-md rounded-md p-8">
|
||||||
<CardTitle className="text-center">TeamCity Integration</CardTitle>
|
<CardTitle className="text-center">TeamCity Integration</CardTitle>
|
||||||
<FormControl
|
<FormControl
|
||||||
label="TeamCity API Token"
|
label="TeamCity Access Token"
|
||||||
errorText={apiKeyErrorText}
|
errorText={apiKeyErrorText}
|
||||||
isError={apiKeyErrorText !== "" ?? false}
|
isError={apiKeyErrorText !== "" ?? false}
|
||||||
>
|
>
|
||||||
<Input
|
<Input
|
||||||
placeholder="API Token"
|
placeholder="Access Token"
|
||||||
value={apiKey}
|
value={apiKey}
|
||||||
onChange={(e) => setApiKey(e.target.value)}
|
onChange={(e) => setApiKey(e.target.value)}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user