Merge pull request #213 from Infisical/patch-integrations

Patch Vercel API teamId requirement for team integrations
This commit is contained in:
BlackMagiq
2023-01-11 17:04:21 +07:00
committed by GitHub
7 changed files with 47 additions and 42 deletions
+15 -8
View File
@@ -9,14 +9,9 @@ import {
INTEGRATION_GITHUB, INTEGRATION_GITHUB,
INTEGRATION_HEROKU_API_URL, INTEGRATION_HEROKU_API_URL,
INTEGRATION_VERCEL_API_URL, INTEGRATION_VERCEL_API_URL,
INTEGRATION_NETLIFY_API_URL, INTEGRATION_NETLIFY_API_URL
INTEGRATION_GITHUB_API_URL
} from '../variables'; } from '../variables';
interface GitHubApp {
name: string;
}
/** /**
* Return list of names of apps for integration named [integration] * Return list of names of apps for integration named [integration]
* @param {Object} obj * @param {Object} obj
@@ -47,6 +42,7 @@ const getApps = async ({
break; break;
case INTEGRATION_VERCEL: case INTEGRATION_VERCEL:
apps = await getAppsVercel({ apps = await getAppsVercel({
integrationAuth,
accessToken accessToken
}); });
break; break;
@@ -110,17 +106,28 @@ const getAppsHeroku = async ({ accessToken }: { accessToken: string }) => {
* @returns {Object[]} apps - names of Vercel apps * @returns {Object[]} apps - names of Vercel apps
* @returns {String} apps.name - name of Vercel app * @returns {String} apps.name - name of Vercel app
*/ */
const getAppsVercel = async ({ accessToken }: { accessToken: string }) => { const getAppsVercel = async ({
integrationAuth,
accessToken
}: {
integrationAuth: IIntegrationAuth;
accessToken: string;
}) => {
let apps; let apps;
try { try {
const res = ( const res = (
await axios.get(`${INTEGRATION_VERCEL_API_URL}/v9/projects`, { await axios.get(`${INTEGRATION_VERCEL_API_URL}/v9/projects`, {
headers: { headers: {
Authorization: `Bearer ${accessToken}` Authorization: `Bearer ${accessToken}`
},
...( integrationAuth?.teamId ? {
params: {
teamId: integrationAuth.teamId
} }
} : {})
}) })
).data; ).data;
apps = res.projects.map((a: any) => ({ apps = res.projects.map((a: any) => ({
name: a.name name: a.name
})); }));
+1 -2
View File
@@ -8,8 +8,7 @@ import {
INTEGRATION_HEROKU_TOKEN_URL, INTEGRATION_HEROKU_TOKEN_URL,
INTEGRATION_VERCEL_TOKEN_URL, INTEGRATION_VERCEL_TOKEN_URL,
INTEGRATION_NETLIFY_TOKEN_URL, INTEGRATION_NETLIFY_TOKEN_URL,
INTEGRATION_GITHUB_TOKEN_URL, INTEGRATION_GITHUB_TOKEN_URL
INTEGRATION_GITHUB_API_URL
} from '../variables'; } from '../variables';
import { import {
SITE_URL, SITE_URL,
+29 -24
View File
@@ -12,14 +12,10 @@ import {
INTEGRATION_GITHUB, INTEGRATION_GITHUB,
INTEGRATION_HEROKU_API_URL, INTEGRATION_HEROKU_API_URL,
INTEGRATION_VERCEL_API_URL, INTEGRATION_VERCEL_API_URL,
INTEGRATION_NETLIFY_API_URL, INTEGRATION_NETLIFY_API_URL
INTEGRATION_GITHUB_API_URL
} from '../variables'; } from '../variables';
import { access, appendFile } from 'fs'; import { access, appendFile } from 'fs';
// TODO: need a helper function in the future to handle integration
// envar priorities (i.e. prioritize secrets within integration or those on Infisical)
/** /**
* Sync/push [secrets] to [app] in integration named [integration] * Sync/push [secrets] to [app] in integration named [integration]
* @param {Object} obj * @param {Object} obj
@@ -53,6 +49,7 @@ const syncSecrets = async ({
case INTEGRATION_VERCEL: case INTEGRATION_VERCEL:
await syncSecretsVercel({ await syncSecretsVercel({
integration, integration,
integrationAuth,
secrets, secrets,
accessToken accessToken
}); });
@@ -139,10 +136,12 @@ const syncSecretsHeroku = async ({
*/ */
const syncSecretsVercel = async ({ const syncSecretsVercel = async ({
integration, integration,
integrationAuth,
secrets, secrets,
accessToken accessToken
}: { }: {
integration: IIntegration, integration: IIntegration,
integrationAuth: IIntegrationAuth,
secrets: any; secrets: any;
accessToken: string; accessToken: string;
}) => { }) => {
@@ -158,9 +157,12 @@ const syncSecretsVercel = async ({
try { try {
// Get all (decrypted) secrets back from Vercel in // Get all (decrypted) secrets back from Vercel in
// decrypted format // decrypted format
const params = new URLSearchParams({ const params: { [key: string]: string } = {
decrypt: "true" decrypt: 'true',
}); ...( integrationAuth?.teamId ? {
teamId: integrationAuth.teamId
} : {})
}
const res = (await Promise.all((await axios.get( const res = (await Promise.all((await axios.get(
`${INTEGRATION_VERCEL_API_URL}/v9/projects/${integration.app}/env`, `${INTEGRATION_VERCEL_API_URL}/v9/projects/${integration.app}/env`,
@@ -177,10 +179,10 @@ const syncSecretsVercel = async ({
.map(async (secret: VercelSecret) => (await axios.get( .map(async (secret: VercelSecret) => (await axios.get(
`${INTEGRATION_VERCEL_API_URL}/v9/projects/${integration.app}/env/${secret.id}`, `${INTEGRATION_VERCEL_API_URL}/v9/projects/${integration.app}/env/${secret.id}`,
{ {
headers: { params,
Authorization: `Bearer ${accessToken}` headers: {
} Authorization: `Bearer ${accessToken}`
}
} }
)).data) )).data)
)).reduce((obj: any, secret: any) => ({ )).reduce((obj: any, secret: any) => ({
@@ -236,9 +238,10 @@ const syncSecretsVercel = async ({
`${INTEGRATION_VERCEL_API_URL}/v10/projects/${integration.app}/env`, `${INTEGRATION_VERCEL_API_URL}/v10/projects/${integration.app}/env`,
newSecrets, newSecrets,
{ {
headers: { params,
Authorization: `Bearer ${accessToken}` headers: {
} Authorization: `Bearer ${accessToken}`
}
} }
); );
} }
@@ -254,9 +257,10 @@ const syncSecretsVercel = async ({
`${INTEGRATION_VERCEL_API_URL}/v9/projects/${integration.app}/env/${secret.id}`, `${INTEGRATION_VERCEL_API_URL}/v9/projects/${integration.app}/env/${secret.id}`,
updatedSecret, updatedSecret,
{ {
headers: { params,
Authorization: `Bearer ${accessToken}` headers: {
} Authorization: `Bearer ${accessToken}`
}
} }
); );
}); });
@@ -268,17 +272,18 @@ const syncSecretsVercel = async ({
await axios.delete( await axios.delete(
`${INTEGRATION_VERCEL_API_URL}/v9/projects/${integration.app}/env/${secret.id}`, `${INTEGRATION_VERCEL_API_URL}/v9/projects/${integration.app}/env/${secret.id}`,
{ {
headers: { params,
Authorization: `Bearer ${accessToken}` headers: {
} Authorization: `Bearer ${accessToken}`
}
} }
); );
}); });
} }
} catch (err) { } catch (err) {
Sentry.setUser(null); Sentry.setUser(null);
Sentry.captureException(err); Sentry.captureException(err);
throw new Error('Failed to sync secrets to Vercel'); throw new Error('Failed to sync secrets to Vercel');
} }
} }
-2
View File
@@ -19,7 +19,6 @@ import {
INTEGRATION_HEROKU_API_URL, INTEGRATION_HEROKU_API_URL,
INTEGRATION_VERCEL_API_URL, INTEGRATION_VERCEL_API_URL,
INTEGRATION_NETLIFY_API_URL, INTEGRATION_NETLIFY_API_URL,
INTEGRATION_GITHUB_API_URL,
INTEGRATION_OPTIONS INTEGRATION_OPTIONS
} from './integration'; } from './integration';
import { import {
@@ -66,7 +65,6 @@ export {
INTEGRATION_HEROKU_API_URL, INTEGRATION_HEROKU_API_URL,
INTEGRATION_VERCEL_API_URL, INTEGRATION_VERCEL_API_URL,
INTEGRATION_NETLIFY_API_URL, INTEGRATION_NETLIFY_API_URL,
INTEGRATION_GITHUB_API_URL,
EVENT_PUSH_SECRETS, EVENT_PUSH_SECRETS,
EVENT_PULL_SECRETS, EVENT_PULL_SECRETS,
ACTION_ADD_SECRETS, ACTION_ADD_SECRETS,
-2
View File
@@ -32,7 +32,6 @@ const INTEGRATION_GITHUB_TOKEN_URL =
const INTEGRATION_HEROKU_API_URL = 'https://api.heroku.com'; const INTEGRATION_HEROKU_API_URL = 'https://api.heroku.com';
const INTEGRATION_VERCEL_API_URL = 'https://api.vercel.com'; const INTEGRATION_VERCEL_API_URL = 'https://api.vercel.com';
const INTEGRATION_NETLIFY_API_URL = 'https://api.netlify.com'; const INTEGRATION_NETLIFY_API_URL = 'https://api.netlify.com';
const INTEGRATION_GITHUB_API_URL = 'https://api.github.com';
const INTEGRATION_OPTIONS = [ const INTEGRATION_OPTIONS = [
{ {
@@ -134,6 +133,5 @@ export {
INTEGRATION_HEROKU_API_URL, INTEGRATION_HEROKU_API_URL,
INTEGRATION_VERCEL_API_URL, INTEGRATION_VERCEL_API_URL,
INTEGRATION_NETLIFY_API_URL, INTEGRATION_NETLIFY_API_URL,
INTEGRATION_GITHUB_API_URL,
INTEGRATION_OPTIONS INTEGRATION_OPTIONS
}; };
+1
View File
@@ -222,6 +222,7 @@ export default function Dashboard() {
dataToSort?.map((item) => item.key).indexOf(item) dataToSort?.map((item) => item.key).indexOf(item)
).includes(row.key) && row.type == 'shared'))?.map((item) => item.id) ).includes(row.key) && row.type == 'shared'))?.map((item) => item.id)
) )
setIsLoading(false); setIsLoading(false);
} catch (error) { } catch (error) {
console.log('Error', error); console.log('Error', error);
+1 -4
View File
@@ -132,9 +132,6 @@ export default function Integrations() {
* @returns * @returns
*/ */
const handleIntegrationOption = async ({ integrationOption }) => { const handleIntegrationOption = async ({ integrationOption }) => {
console.log('handleIntegrationOption', integrationOption);
try { try {
// generate CSRF token for OAuth2 code-token exchange integrations // generate CSRF token for OAuth2 code-token exchange integrations
const state = crypto.randomBytes(16).toString("hex"); const state = crypto.randomBytes(16).toString("hex");
@@ -218,7 +215,7 @@ export default function Integrations() {
handleIntegrationOption={handleIntegrationOption} handleIntegrationOption={handleIntegrationOption}
/> */} /> */}
<IntegrationSection integrations={integrations} /> <IntegrationSection integrations={integrations} />
{cloudIntegrationOptions.length > 0 ? ( {(cloudIntegrationOptions.length > 0 && bot) ? (
<CloudIntegrationSection <CloudIntegrationSection
cloudIntegrationOptions={cloudIntegrationOptions} cloudIntegrationOptions={cloudIntegrationOptions}
setSelectedIntegrationOption={setSelectedIntegrationOption} setSelectedIntegrationOption={setSelectedIntegrationOption}