mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 11:38:55 +00:00
Checkpoint GCP secret manager integration
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import {
|
||||
INTEGRATION_GCP_SECRET_MANAGER,
|
||||
INTEGRATION_GCP_API_URL,
|
||||
INTEGRATION_AWS_PARAMETER_STORE,
|
||||
INTEGRATION_AWS_SECRET_MANAGER,
|
||||
INTEGRATION_AZURE_KEY_VAULT,
|
||||
@@ -79,6 +81,11 @@ const getApps = async ({
|
||||
}) => {
|
||||
let apps: App[] = [];
|
||||
switch (integrationAuth.integration) {
|
||||
case INTEGRATION_GCP_SECRET_MANAGER:
|
||||
apps = await getAppsGCPSecretManager({
|
||||
accessToken,
|
||||
});
|
||||
break;
|
||||
case INTEGRATION_AZURE_KEY_VAULT:
|
||||
apps = [];
|
||||
break;
|
||||
@@ -210,6 +217,91 @@ const getApps = async ({
|
||||
return apps;
|
||||
};
|
||||
|
||||
/**
|
||||
* Return list of apps for Heroku integration
|
||||
* @param {Object} obj
|
||||
* @param {String} obj.accessToken - access token for Heroku API
|
||||
* @returns {Object[]} apps - names of Heroku apps
|
||||
* @returns {String} apps.name - name of Heroku app
|
||||
*/
|
||||
const getAppsGCPSecretManager = async ({ accessToken }: { accessToken: string }) => {
|
||||
console.log("getAppsGCPSecretManager");
|
||||
console.log("getAppsGCPSecretManager accessToken: ", accessToken);
|
||||
|
||||
let apps: any = [];
|
||||
|
||||
interface GCPApp {
|
||||
projectNumber: string;
|
||||
projectId: string;
|
||||
lifecycleState: "ACTIVE" | "LIFECYCLE_STATE_UNSPECIFIED" | "DELETE_REQUESTED" | "DELETE_IN_PROGRESS";
|
||||
name: string;
|
||||
createTime: string;
|
||||
parent: {
|
||||
type: "organization" | "folder" | "project";
|
||||
id: string;
|
||||
}
|
||||
}
|
||||
|
||||
interface GCPRes {
|
||||
projects: GCPApp[];
|
||||
nextPageToken?: string;
|
||||
}
|
||||
|
||||
const pageSize = 10;
|
||||
let pageToken: string | undefined;
|
||||
let hasMorePages = true;
|
||||
|
||||
while (hasMorePages) {
|
||||
console.log("iterrr");
|
||||
const params = new URLSearchParams({
|
||||
pageSize: String(pageSize),
|
||||
...(pageToken ? { pageToken } : {})
|
||||
});
|
||||
console.log("params: ", params);
|
||||
|
||||
const res: GCPRes = (await standardRequest.get(`${INTEGRATION_GCP_API_URL}/v1/projects`, {
|
||||
params,
|
||||
headers: {
|
||||
"Authorization": `Bearer ${accessToken}`,
|
||||
"Accept-Encoding": "application/json"
|
||||
}
|
||||
})
|
||||
)
|
||||
.data;
|
||||
|
||||
res.projects.forEach((project) => {
|
||||
apps.push({
|
||||
name: project.name,
|
||||
appId: project.projectId
|
||||
});
|
||||
});
|
||||
|
||||
if (!res.nextPageToken) {
|
||||
hasMorePages = false;
|
||||
}
|
||||
|
||||
pageToken = res.nextPageToken;
|
||||
}
|
||||
|
||||
// const projects: GCPApp[] = (
|
||||
// .projects
|
||||
|
||||
// console.log("res: ", res);
|
||||
|
||||
// .filter((project: GCPApp) => project.lifecycleState === "ACTIVE");
|
||||
|
||||
// console.log("projects: ", projects);
|
||||
|
||||
// const apps = projects.map((project) => ({
|
||||
// name: project.name,
|
||||
// appId: project.projectId
|
||||
// }));
|
||||
|
||||
console.log("apps: ", apps);
|
||||
|
||||
return [];
|
||||
};
|
||||
|
||||
/**
|
||||
* Return list of apps for Heroku integration
|
||||
* @param {Object} obj
|
||||
|
||||
@@ -14,8 +14,12 @@ import {
|
||||
INTEGRATION_NETLIFY_TOKEN_URL,
|
||||
INTEGRATION_VERCEL,
|
||||
INTEGRATION_VERCEL_TOKEN_URL,
|
||||
INTEGRATION_GCP_SECRET_MANAGER,
|
||||
INTEGRATION_GCP_TOKEN_URL
|
||||
} from "../variables";
|
||||
import {
|
||||
getClientIdGCPSecretManager,
|
||||
getClientSecretGCPSecretManager,
|
||||
getClientIdAzure,
|
||||
getClientIdBitBucket,
|
||||
getClientIdGitHub,
|
||||
@@ -113,6 +117,11 @@ const exchangeCode = async ({
|
||||
let obj = {} as any;
|
||||
|
||||
switch (integration) {
|
||||
case INTEGRATION_GCP_SECRET_MANAGER:
|
||||
obj = await exchangeCodeGCP({
|
||||
code,
|
||||
});
|
||||
break;
|
||||
case INTEGRATION_AZURE_KEY_VAULT:
|
||||
obj = await exchangeCodeAzure({
|
||||
code,
|
||||
@@ -153,6 +162,40 @@ const exchangeCode = async ({
|
||||
return obj;
|
||||
};
|
||||
|
||||
/**
|
||||
* Return [accessToken] for GCP OAuth2 code-token exchange
|
||||
* @param {Object} obj
|
||||
* @param {String} obj.code - code for code-token exchange
|
||||
* @returns {Object} obj2
|
||||
* @returns {String} obj2.accessToken - access token for GCP API
|
||||
* @returns {String} obj2.refreshToken - refresh token for GCP API
|
||||
* @returns {Date} obj2.accessExpiresAt - date of expiration for access token
|
||||
*/
|
||||
const exchangeCodeGCP = async ({ code }: { code: string }) => {
|
||||
const accessExpiresAt = new Date();
|
||||
|
||||
const res: ExchangeCodeAzureResponse = (
|
||||
await standardRequest.post(
|
||||
INTEGRATION_GCP_TOKEN_URL,
|
||||
new URLSearchParams({
|
||||
grant_type: "authorization_code",
|
||||
code: code,
|
||||
client_id: await getClientIdGCPSecretManager(),
|
||||
client_secret: await getClientSecretGCPSecretManager(),
|
||||
redirect_uri: `${await getSiteURL()}/integrations/gcp-secret-manager/oauth2/callback`,
|
||||
} as any)
|
||||
)
|
||||
).data;
|
||||
|
||||
accessExpiresAt.setSeconds(accessExpiresAt.getSeconds() + res.expires_in);
|
||||
|
||||
return {
|
||||
accessToken: res.access_token,
|
||||
refreshToken: res.refresh_token,
|
||||
accessExpiresAt,
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Return [accessToken] for Azure OAuth2 code-token exchange
|
||||
* @param param0
|
||||
|
||||
Reference in New Issue
Block a user