Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
Merge remote-tracking branch 'refs/remotes/origin/main' into circleci-integration-branch
Aashish-Upadhyay-101e6539a5566ec
diff --cc backend/src/controllers/v1/integrationAuthController.tsindex cb5952986c,be42647deb..2153534459--- a/backend/src/controllers/v1/integrationAuthController.ts+++ b/backend/src/controllers/v1/integrationAuthController.ts@@@ -1,16 -1,48 +1,45 @@@- import { Request, Response } from "express";- import { Types } from "mongoose";- import * as Sentry from "@sentry/node";- import { Integration, IntegrationAuth, Bot } from "../../models";- import { INTEGRATION_SET, INTEGRATION_OPTIONS } from "../../variables";- import { IntegrationService } from "../../services";- import { getApps, revokeAccess } from "../../integrations";+ import { Request, Response } from 'express';+ import { Types } from 'mongoose';+ import * as Sentry from '@sentry/node';+ import {+ Integration,+ IntegrationAuth,+ Bot+ } from '../../models';+ import { INTEGRATION_SET, INTEGRATION_OPTIONS } from '../../variables';+ import { IntegrationService } from '../../services';+ import { getApps, revokeAccess } from '../../integrations';++ /***+ * Return integration authorization with id [integrationAuthId]+ */+ export const getIntegrationAuth = async (req: Request, res: Response) => {+ let integrationAuth;+ try {+ const { integrationAuthId } = req.params;+ integrationAuth = await IntegrationAuth.findById(integrationAuthId);++ if (!integrationAuth) return res.status(400).send({+ message: 'Failed to find integration authorization'+ });+ } catch (err) {+ Sentry.setUser({ email: req.user.email });+ Sentry.captureException(err);+ return res.status(400).send({+ message: 'Failed to get integration authorization'+ });+ }++ return res.status(200).send({+ integrationAuth+ });+ }-export const getIntegrationOptions = async (- req: Request,- res: Response-) => {- return res.status(200).send({- integrationOptions: INTEGRATION_OPTIONS- });-}+export const getIntegrationOptions = async (req: Request, res: Response) => {+ return res.status(200).send({+ integrationOptions: INTEGRATION_OPTIONS,+ });+};/*** Perform OAuth2 code-token exchange as part of integration [integration] for workspace with id [workspaceId]@@@ -51,70 -85,64 +82,64 @@@ export const oAuthExchange = async/*** Save integration access token as part of integration [integration] for workspace with id [workspaceId]- * @param req- * @param res+ * @param req+ * @param res*/export const saveIntegrationAccessToken = async (- req: Request,- res: Response+ req: Request,+ res: Response) => {- // TODO: refactor- let integrationAuth;- try {- const {- workspaceId,- accessToken,- integration- }: {- workspaceId: string;- accessToken: string;- integration: string;- } = req.body;+ // TODO: refactor+ let integrationAuth;+ try {+ const {+ workspaceId,+ accessToken,+ integration,+ }: {+ workspaceId: string;+ accessToken: string;+ integration: string;+ } = req.body;- integrationAuth = await IntegrationAuth.findOneAndUpdate(- {- workspace: new Types.ObjectId(workspaceId),- integration,- },- {- workspace: new Types.ObjectId(workspaceId),- integration,- },- {- new: true,- upsert: true,- }- );-- const bot = await Bot.findOne({- workspace: new Types.ObjectId(workspaceId),- isActive: true,- });-- if (!bot)- throw new Error("Bot must be enabled to save integration access token");-- // encrypt and save integration access token- integrationAuth = await IntegrationService.setIntegrationAuthAccess({- integrationAuthId: integrationAuth._id.toString(),- accessToken,- accessExpiresAt: undefined,- });-- if (!integrationAuth)- throw new Error("Failed to save integration access token");- } catch (err) {- Sentry.setUser({ email: req.user.email });- Sentry.captureException(err);- return res.status(400).send({- message: "Failed to save access token for integration",- });- }+ const bot = await Bot.findOne({+ workspace: new Types.ObjectId(workspaceId),+ isActive: true+ });++ if (!bot) throw new Error('Bot must be enabled to save integration access token');- return res.status(200).send({- integrationAuth,- });- };+ integrationAuth = await IntegrationAuth.findOneAndUpdate({+ workspace: new Types.ObjectId(workspaceId),+ integration+ }, {+ workspace: new Types.ObjectId(workspaceId),+ integration+ }, {+ new: true,+ upsert: true+ });++ // encrypt and save integration access token+ integrationAuth = await IntegrationService.setIntegrationAuthAccess({+ integrationAuthId: integrationAuth._id.toString(),+ accessToken,+ accessExpiresAt: undefined+ });++ if (!integrationAuth) throw new Error('Failed to save integration access token');+ } catch (err) {+ Sentry.setUser({ email: req.user.email });+ Sentry.captureException(err);+ return res.status(400).send({+ message: 'Failed to save access token for integration'+ });+ }++ return res.status(200).send({+ integrationAuth+ });+ }/*** Return list of applications allowed for integration with integration authorization id [integrationAuthId]diff --cc backend/src/controllers/v1/integrationController.tsindex cdd30e7a7a,779cb3cb72..631d035ca3--- a/backend/src/controllers/v1/integrationController.ts+++ b/backend/src/controllers/v1/integrationController.ts@@@ -6,34 -12,59 +12,59 @@@ import { eventPushSecrets } from '../../*** Create/initialize an (empty) integration for integration authorization- * @param req- * @param res- * @returns+ * @param req+ * @param res+ * @returns*/export const createIntegration = async (req: Request, res: Response) => {- let integration;- try {- // initialize new integration after saving integration access token- integration = await new Integration({- workspace: req.integrationAuth.workspace._id,- isActive: false,- app: null,- environment: req.integrationAuth.workspace?.environments[0].slug,- integration: req.integrationAuth.integration,- integrationAuth: req.integrationAuth._id,- }).save();- } catch (err) {- Sentry.setUser({ email: req.user.email });- Sentry.captureException(err);- return res.status(400).send({- message: "Failed to create integration",- });- }+ let integration;+ try {+ const {+ integrationAuthId,+ app,+ appId,+ isActive,+ sourceEnvironment,+ targetEnvironment,+ owner+ } = req.body;++ // TODO: validate [sourceEnvironment] and [targetEnvironment]++ // initialize new integration after saving integration access token+ integration = await new Integration({+ workspace: req.integrationAuth.workspace._id,+ environment: sourceEnvironment,+ isActive,+ app,+ appId,+ targetEnvironment,+ owner,+ integration: req.integrationAuth.integration,+ integrationAuth: new Types.ObjectId(integrationAuthId)+ }).save();++ if (integration) {+ // trigger event - push secrets+ EventService.handleEvent({+ event: eventPushSecrets({+ workspaceId: integration.workspace.toString()+ })+ });+ }++ } catch (err) {+ Sentry.setUser({ email: req.user.email });+ Sentry.captureException(err);+ return res.status(400).send({+ message: 'Failed to create integration'+ });+ }- return res.status(200).send({- integration- });-}+ return res.status(200).send({+ integration,+ });+};/*** Change environment or name of integration with id [integrationId]diff --cc backend/src/integrations/apps.tsindex 2369a44e6b,3d834d8768..ef0e36455b--- a/backend/src/integrations/apps.ts+++ b/backend/src/integrations/apps.ts@@@ -1,8 -1,9 +1,9 @@@-import axios from 'axios';-import * as Sentry from '@sentry/node';-import { Octokit } from '@octokit/rest';-import { IIntegrationAuth } from '../models';+import axios from "axios";+import * as Sentry from "@sentry/node";+import { Octokit } from "@octokit/rest";+import { IIntegrationAuth } from "../models";import {+ INTEGRATION_AZURE_KEY_VAULT,INTEGRATION_HEROKU,INTEGRATION_VERCEL,INTEGRATION_NETLIFY,@@@ -42,9 -41,14 +43,14 @@@ const getApps = async (let apps: App[];try {switch (integrationAuth.integration) {+ case INTEGRATION_AZURE_KEY_VAULT:+ apps = await getAppsAzureKeyVault({+ accessToken+ });+ break;case INTEGRATION_HEROKU:apps = await getAppsHeroku({- accessToken+ accessToken,});break;case INTEGRATION_VERCEL:@@@ -246,14 -263,18 +261,18 @@@ const getAppsRender = async ({ accessToawait axios.get(`${INTEGRATION_RENDER_API_URL}/v1/services`, {headers: {Authorization: `Bearer ${accessToken}`,+ Accept: 'application/json',- 'Accept-Encoding': 'application/json'- }++ 'Accept-Encoding': 'application/json',+ },})).data;-- apps = res.map((a: any) => ({- name: a.service.name,- appId: a.service.id,- }));++ apps = res+ .map((a: any) => ({+ name: a.service.name,+ appId: a.service.id+ }));+} catch (err) {Sentry.setUser(null);Sentry.captureException(err);@@@ -284,65 -309,27 +303,67 @@@ const getAppsFlyio = async ({ accessTok}}`;-- const res = (await axios({- url: INTEGRATION_FLYIO_API_URL,- method: 'post',- headers: {- 'Authorization': 'Bearer ' + accessToken,++ const res = (+ await axios({+ url: INTEGRATION_FLYIO_API_URL,+ method: "post",+ headers: {+ Authorization: "Bearer " + accessToken,+ 'Accept': 'application/json',- 'Accept-Encoding': 'application/json'- },- data: {- query,- variables: {- role: null++ 'Accept-Encoding': 'application/json',+ },+ data: {+ query,+ variables: {+ role: null,+ },+ },+ })+ ).data.data.apps.nodes;++ apps = res.map((a: any) => ({+ name: a.name,+ }));+ } catch (err) {+ Sentry.setUser(null);+ Sentry.captureException(err);+ throw new Error("Failed to get Fly.io apps");+ }++ return apps;+};++const getAppsCircleci = async ({ accessToken }: { accessToken: string }) => {+ // in place of accessToken we have to send Circle-Token i.e. Personal API token from CircleCi+ let apps: any;+ try {+ const circleciOrganizationDetail = (+ await axios.get(`${INTEGRATION_CIRCLECI_API_URL}/v2/me/collaborations`, {+ headers: {+ "Circle-Token": accessToken,+ "Accept-Encoding": "application/json",+ },+ })+ ).data[0];++ const { slug } = circleciOrganizationDetail;++ const res = (+ await axios.get(+ `${INTEGRATION_CIRCLECI_API_URL}/v2/pipeline/?org-slug=${slug}`,+ {+ headers: {+ "Circle-Token": accessToken,+ "Accept-Encoding": "application/json",+ },}- }- })).data.data.apps.nodes;-- apps = res- .map((a: any) => ({- name: a.name- }));+ )+ ).data?.items;++ apps = res.map((a: any) => ({+ name: a?.project_slug?.split("/")[2],+ }));} catch (err) {Sentry.setUser(null);Sentry.captureException(err);diff --cc backend/src/integrations/sync.tsindex f56157205f,8e44d591df..bfa559c74a--- a/backend/src/integrations/sync.ts+++ b/backend/src/integrations/sync.ts@@@ -1,11 -1,10 +1,10 @@@-import axios from 'axios';-import * as Sentry from '@sentry/node';-import { Octokit } from '@octokit/rest';-import sodium from 'libsodium-wrappers';-import { IIntegration, IIntegrationAuth } from '../models';+import axios from "axios";+import * as Sentry from "@sentry/node";+import { Octokit } from "@octokit/rest";- // import * as sodium from 'libsodium-wrappers';+import sodium from "libsodium-wrappers";- // const sodium = require('libsodium-wrappers');+import { IIntegration, IIntegrationAuth } from "../models";import {+ INTEGRATION_AZURE_KEY_VAULT,INTEGRATION_HEROKU,INTEGRATION_VERCEL,INTEGRATION_NETLIFY,@@@ -767,13 -882,13 +918,14 @@@ const syncSecretsFlyio = async (}}`;- const getSecretsRes = (await axios({- method: 'post',+ const getSecretsRes = (+ await axios({+ method: "post",url: INTEGRATION_FLYIO_API_URL,headers: {- Authorization: "Bearer " + accessToken,- "Content-Type": "application/json",+ 'Authorization': 'Bearer ' + accessToken,+ 'Content-Type': 'application/json',+ 'Accept-Encoding': 'application/json'},data: {query: GetSecrets,diff --cc backend/src/models/integration.tsindex 6417f2bebe,9c1214fb51..95ed9f4a98--- a/backend/src/models/integration.ts+++ b/backend/src/models/integration.ts@@@ -1,5 -1,6 +1,6 @@@-import { Schema, model, Types } from 'mongoose';+import { Schema, model, Types } from "mongoose";import {+ INTEGRATION_AZURE_KEY_VAULT,INTEGRATION_HEROKU,INTEGRATION_VERCEL,INTEGRATION_NETLIFY,@@@ -18,14 -18,7 +19,15 @@@ export interface IIntegrationowner: string;targetEnvironment: string;appId: string;- integration: 'heroku' | 'vercel' | 'netlify' | 'github' | 'render' | 'flyio' | 'azure-key-vault';+ integration:+ | "heroku"+ | "vercel"+ | "netlify"+ | "github"+ | "render"+ | "flyio"++ | "azure-key-vault"+ | "circleci";integrationAuth: Types.ObjectId;}diff --cc backend/src/models/integrationAuth.tsindex c219d3292c,0eaa8c9e15..858a2e4140--- a/backend/src/models/integrationAuth.ts+++ b/backend/src/models/integrationAuth.ts@@@ -1,5 -1,6 +1,6 @@@-import { Schema, model, Types } from 'mongoose';+import { Schema, model, Types } from "mongoose";import {+ INTEGRATION_AZURE_KEY_VAULT,INTEGRATION_HEROKU,INTEGRATION_VERCEL,INTEGRATION_NETLIFY,@@@ -10,14 -10,7 +11,15 @@@export interface IIntegrationAuth {_id: Types.ObjectId;workspace: Types.ObjectId;- integration: 'heroku' | 'vercel' | 'netlify' | 'github' | 'render' | 'flyio' | 'azure-key-vault';+ integration:+ | "heroku"+ | "vercel"+ | "netlify"+ | "github"+ | "render"- | "flyio"++ | "flyio"++ | "azure-key-vault"+ | "circleci";teamId: string;accountId: string;refreshCiphertext?: string;diff --cc backend/src/variables/index.tsindex 4196a374f2,cf061520c9..33307af4b0--- a/backend/src/variables/index.ts+++ b/backend/src/variables/index.ts@@@ -3,18 -3,19 +3,20 @@@ importENV_TESTING,ENV_STAGING,ENV_PROD,- ENV_SET-} from './environment';+ ENV_SET,+} from "./environment";import {+ INTEGRATION_AZURE_KEY_VAULT,INTEGRATION_HEROKU,INTEGRATION_VERCEL,INTEGRATION_NETLIFY,INTEGRATION_GITHUB,INTEGRATION_RENDER,INTEGRATION_FLYIO,+ INTEGRATION_CIRCLECI,INTEGRATION_SET,INTEGRATION_OAUTH2,+ INTEGRATION_AZURE_TOKEN_URL,INTEGRATION_HEROKU_TOKEN_URL,INTEGRATION_VERCEL_TOKEN_URL,INTEGRATION_NETLIFY_TOKEN_URL,@@@ -24,13 -25,20 +26,15 @@@INTEGRATION_NETLIFY_API_URL,INTEGRATION_RENDER_API_URL,INTEGRATION_FLYIO_API_URL,- INTEGRATION_OPTIONS-} from './integration';-import {- OWNER,- ADMIN,- MEMBER,- INVITED,- ACCEPTED,-} from './organization';-import { SECRET_SHARED, SECRET_PERSONAL } from './secret';-import { EVENT_PUSH_SECRETS, EVENT_PULL_SECRETS } from './event';+ INTEGRATION_CIRCLECI_API_URL,+ INTEGRATION_OPTIONS,+} from "./integration";+import { OWNER, ADMIN, MEMBER, INVITED, ACCEPTED } from "./organization";+import { SECRET_SHARED, SECRET_PERSONAL } from "./secret";+import { EVENT_PUSH_SECRETS, EVENT_PULL_SECRETS } from "./event";import {+ ACTION_LOGIN,+ ACTION_LOGOUT,ACTION_ADD_SECRETS,ACTION_UPDATE_SECRETS,ACTION_DELETE_SECRETS,@@@ -58,9 -67,9 +63,10 @@@ exportINTEGRATION_GITHUB,INTEGRATION_RENDER,INTEGRATION_FLYIO,+ INTEGRATION_CIRCLECI,INTEGRATION_SET,INTEGRATION_OAUTH2,+ INTEGRATION_AZURE_TOKEN_URL,INTEGRATION_HEROKU_TOKEN_URL,INTEGRATION_VERCEL_TOKEN_URL,INTEGRATION_NETLIFY_TOKEN_URL,@@@ -70,9 -79,10 +76,11 @@@INTEGRATION_NETLIFY_API_URL,INTEGRATION_RENDER_API_URL,INTEGRATION_FLYIO_API_URL,+ INTEGRATION_CIRCLECI_API_URL,EVENT_PUSH_SECRETS,EVENT_PULL_SECRETS,+ ACTION_LOGIN,+ ACTION_LOGOUT,ACTION_ADD_SECRETS,ACTION_UPDATE_SECRETS,ACTION_DELETE_SECRETS,diff --cc backend/src/variables/integration.tsindex 883e8a7307,d1ad078ea0..77b3a80a16--- a/backend/src/variables/integration.ts+++ b/backend/src/variables/integration.ts@@@ -1,169 -1,183 +1,188 @@@+ import {+ CLIENT_ID_AZURE,+ TENANT_ID_AZURE+ } from '../config';import {- CLIENT_ID_HEROKU,- CLIENT_ID_NETLIFY,- CLIENT_ID_GITHUB,- CLIENT_SLUG_VERCEL-} from '../config';+ CLIENT_ID_HEROKU,+ CLIENT_ID_NETLIFY,+ CLIENT_ID_GITHUB,+ CLIENT_SLUG_VERCEL,+} from "../config";// integrations+ const INTEGRATION_AZURE_KEY_VAULT = 'azure-key-vault';-const INTEGRATION_HEROKU = 'heroku';-const INTEGRATION_VERCEL = 'vercel';-const INTEGRATION_NETLIFY = 'netlify';-const INTEGRATION_GITHUB = 'github';-const INTEGRATION_RENDER = 'render';-const INTEGRATION_FLYIO = 'flyio';+const INTEGRATION_HEROKU = "heroku";+const INTEGRATION_VERCEL = "vercel";+const INTEGRATION_NETLIFY = "netlify";+const INTEGRATION_GITHUB = "github";+const INTEGRATION_RENDER = "render";+const INTEGRATION_FLYIO = "flyio";+const INTEGRATION_CIRCLECI = "circleci";const INTEGRATION_SET = new Set([+ INTEGRATION_AZURE_KEY_VAULT,- INTEGRATION_HEROKU,- INTEGRATION_VERCEL,- INTEGRATION_NETLIFY,- INTEGRATION_GITHUB,- INTEGRATION_RENDER,- INTEGRATION_FLYIO+ INTEGRATION_HEROKU,+ INTEGRATION_VERCEL,+ INTEGRATION_NETLIFY,+ INTEGRATION_GITHUB,+ INTEGRATION_RENDER,+ INTEGRATION_FLYIO,+ INTEGRATION_CIRCLECI,]);// integration types-const INTEGRATION_OAUTH2 = 'oauth2';+const INTEGRATION_OAUTH2 = "oauth2";// integration oauth endpoints- const INTEGRATION_HEROKU_TOKEN_URL = "https://id.heroku.com/oauth/token";+ const INTEGRATION_AZURE_TOKEN_URL = `https://login.microsoftonline.com/${TENANT_ID_AZURE}/oauth2/v2.0/token`;+ const INTEGRATION_HEROKU_TOKEN_URL = 'https://id.heroku.com/oauth/token';const INTEGRATION_VERCEL_TOKEN_URL =- 'https://api.vercel.com/v2/oauth/access_token';-const INTEGRATION_NETLIFY_TOKEN_URL = 'https://api.netlify.com/oauth/token';+ "https://api.vercel.com/v2/oauth/access_token";+const INTEGRATION_NETLIFY_TOKEN_URL = "https://api.netlify.com/oauth/token";const INTEGRATION_GITHUB_TOKEN_URL =- 'https://github.com/login/oauth/access_token';+ "https://github.com/login/oauth/access_token";// integration apps endpoints-const INTEGRATION_HEROKU_API_URL = 'https://api.heroku.com';-const INTEGRATION_VERCEL_API_URL = 'https://api.vercel.com';-const INTEGRATION_NETLIFY_API_URL = 'https://api.netlify.com';-const INTEGRATION_RENDER_API_URL = 'https://api.render.com';-const INTEGRATION_FLYIO_API_URL = 'https://api.fly.io/graphql';+const INTEGRATION_HEROKU_API_URL = "https://api.heroku.com";+const INTEGRATION_VERCEL_API_URL = "https://api.vercel.com";+const INTEGRATION_NETLIFY_API_URL = "https://api.netlify.com";+const INTEGRATION_RENDER_API_URL = "https://api.render.com";+const INTEGRATION_FLYIO_API_URL = "https://api.fly.io/graphql";+const INTEGRATION_CIRCLECI_API_URL = "https://circleci.com/api";const INTEGRATION_OPTIONS = [+ {+ name: 'Azure Key Vault',+ slug: 'azure-key-vault',+ image: 'Microsoft Azure.png',+ isAvailable: false,+ type: 'oauth',+ clientId: CLIENT_ID_AZURE,+ tenantId: TENANT_ID_AZURE,+ docsLink: ''+ },- {- name: 'Heroku',- slug: 'heroku',- image: 'Heroku.png',- isAvailable: true,- type: 'oauth',- clientId: CLIENT_ID_HEROKU,- docsLink: ''- },- {- name: 'Vercel',- slug: 'vercel',- image: 'Vercel.png',- isAvailable: true,- type: 'oauth',- clientId: '',- clientSlug: CLIENT_SLUG_VERCEL,- docsLink: ''- },- {- name: 'Netlify',- slug: 'netlify',- image: 'Netlify.png',- isAvailable: true,- type: 'oauth',- clientId: CLIENT_ID_NETLIFY,- docsLink: ''- },- {- name: 'GitHub',- slug: 'github',- image: 'GitHub.png',- isAvailable: true,- type: 'oauth',- clientId: CLIENT_ID_GITHUB,- docsLink: ''- },- {- name: 'Render',- slug: 'render',- image: 'Render.png',- isAvailable: true,- type: 'pat',- clientId: '',- docsLink: ''- },- {- name: 'Fly.io',- slug: 'flyio',- image: 'Flyio.svg',- isAvailable: true,- type: 'pat',- clientId: '',- docsLink: ''- },- {- name: 'Google Cloud Platform',- slug: 'gcp',- image: 'Google Cloud Platform.png',- isAvailable: false,- type: '',- clientId: '',- docsLink: ''- },- {- name: 'Amazon Web Services',- slug: 'aws',- image: 'Amazon Web Services.png',- isAvailable: false,- type: '',- clientId: '',- docsLink: ''- },- {- name: 'Microsoft Azure',- slug: 'azure',- image: 'Microsoft Azure.png',- isAvailable: false,- type: '',- clientId: '',- docsLink: ''- },- {- name: 'Travis CI',- slug: 'travisci',- image: 'Travis CI.png',- isAvailable: false,- type: '',- clientId: '',- docsLink: ''- },- {- name: 'Circle CI',- slug: 'circleci',- image: 'Circle CI.png',- isAvailable: false,- type: '',- clientId: '',- docsLink: ''- }-]+ {+ name: "Heroku",+ slug: "heroku",+ image: "Heroku.png",+ isAvailable: true,+ type: "oauth",+ clientId: CLIENT_ID_HEROKU,+ docsLink: "",+ },+ {+ name: "Vercel",+ slug: "vercel",+ image: "Vercel.png",+ isAvailable: true,+ type: "oauth",+ clientId: "",+ clientSlug: CLIENT_SLUG_VERCEL,+ docsLink: "",+ },+ {+ name: "Netlify",+ slug: "netlify",+ image: "Netlify.png",+ isAvailable: true,+ type: "oauth",+ clientId: CLIENT_ID_NETLIFY,+ docsLink: "",+ },+ {+ name: "GitHub",+ slug: "github",+ image: "GitHub.png",+ isAvailable: true,+ type: "oauth",+ clientId: CLIENT_ID_GITHUB,+ docsLink: "",+ },+ {+ name: "Render",+ slug: "render",+ image: "Render.png",+ isAvailable: true,+ type: "pat",+ clientId: "",+ docsLink: "",+ },+ {+ name: "Fly.io",+ slug: "flyio",+ image: "Flyio.svg",+ isAvailable: true,+ type: "pat",+ clientId: "",+ docsLink: "",+ },+ {+ name: "Google Cloud Platform",+ slug: "gcp",+ image: "Google Cloud Platform.png",+ isAvailable: false,+ type: "",+ clientId: "",+ docsLink: "",+ },+ {+ name: "Amazon Web Services",+ slug: "aws",+ image: "Amazon Web Services.png",+ isAvailable: false,+ type: "",+ clientId: "",+ docsLink: "",+ },+ {+ name: "Microsoft Azure",+ slug: "azure",+ image: "Microsoft Azure.png",+ isAvailable: false,+ type: "",+ clientId: "",+ docsLink: "",+ },+ {+ name: "Travis CI",+ slug: "travisci",+ image: "Travis CI.png",+ isAvailable: false,+ type: "",+ clientId: "",+ docsLink: "",+ },+ {+ name: "Circle CI",+ slug: "circleci",+ image: "Circle CI.png",+ isAvailable: true,+ type: "pat",+ clientId: "",+ docsLink: "",+ },+];export {+ INTEGRATION_AZURE_KEY_VAULT,- INTEGRATION_HEROKU,- INTEGRATION_VERCEL,- INTEGRATION_NETLIFY,- INTEGRATION_GITHUB,- INTEGRATION_RENDER,- INTEGRATION_FLYIO,- INTEGRATION_SET,- INTEGRATION_OAUTH2,+ INTEGRATION_HEROKU,+ INTEGRATION_VERCEL,+ INTEGRATION_NETLIFY,+ INTEGRATION_GITHUB,+ INTEGRATION_RENDER,+ INTEGRATION_FLYIO,+ INTEGRATION_CIRCLECI,+ INTEGRATION_SET,+ INTEGRATION_OAUTH2,+ INTEGRATION_AZURE_TOKEN_URL,- INTEGRATION_HEROKU_TOKEN_URL,- INTEGRATION_VERCEL_TOKEN_URL,- INTEGRATION_NETLIFY_TOKEN_URL,- INTEGRATION_GITHUB_TOKEN_URL,- INTEGRATION_HEROKU_API_URL,- INTEGRATION_VERCEL_API_URL,- INTEGRATION_NETLIFY_API_URL,- INTEGRATION_RENDER_API_URL,- INTEGRATION_FLYIO_API_URL,- INTEGRATION_OPTIONS+ INTEGRATION_HEROKU_TOKEN_URL,+ INTEGRATION_VERCEL_TOKEN_URL,+ INTEGRATION_NETLIFY_TOKEN_URL,+ INTEGRATION_GITHUB_TOKEN_URL,+ INTEGRATION_HEROKU_API_URL,+ INTEGRATION_VERCEL_API_URL,+ INTEGRATION_NETLIFY_API_URL,+ INTEGRATION_RENDER_API_URL,+ INTEGRATION_FLYIO_API_URL,+ INTEGRATION_CIRCLECI_API_URL,+ INTEGRATION_OPTIONS,};diff --cc frontend/src/components/integrations/Integration.tsxindex e177f462c1,6bbecad43d..0d2371b310--- a/frontend/src/components/integrations/Integration.tsx+++ b/frontend/src/components/integrations/Integration.tsx@@@ -52,9 -52,10 +52,10 @@@ const IntegrationTile = (environments = [],handleDeleteIntegration}: Props) => {+// set initial environment. This find will only execute when component is mountingconst [integrationEnvironment, setIntegrationEnvironment] = useState<Props['environments'][0]>(- environments.find(({ slug }) => slug === integration.environment) || {+ environments.find(({ slug }) => slug === integration?.environment) || {name: '',slug: ''}@@@ -66,12 -67,20 +67,19 @@@useEffect(() => {const loadIntegration = async () => {-const tempApps: [IntegrationApp] = await getIntegrationApps({- integrationAuthId: integration.integrationAuth+ integrationAuthId: integration?.integrationAuth});-+setApps(tempApps);- setIntegrationApp(integration?.app ? integration.app : tempApps[0].name);++ if (integration?.app) {+ setIntegrationApp(integration.app);+ } else if (tempApps.length > 0) {+ setIntegrationApp(tempApps[0].name)+ } else {+ setIntegrationApp('');+ }switch (integration.integration) {case 'vercel':@@@ -174,13 -182,13 +182,13 @@@return <div />;};- if (!integrationApp || apps.length === 0) return <div />;+ if (!integrationApp) return <div />;return (- <div className="max-w-5xl p-6 mx-6 mb-8 rounded-md bg-white/5 flex justify-between">+ <div className="mx-6 mb-8 flex max-w-5xl justify-between rounded-md bg-white/5 p-6"><div className="flex"><div>- <p className="text-gray-400 text-xs font-semibold mb-2">ENVIRONMENT</p>+ <p className="mb-2 text-xs font-semibold text-gray-400">ENVIRONMENT</p><ListBoxdata={!integration.isActive ? environments.map(({ name }) => name) : null}isSelected={integrationEnvironment.name}@@@ -196,12 -204,13 +204,13 @@@/></div><div className="pt-2">- <FontAwesomeIcon icon={faArrowRight} className="mx-4 text-gray-400 mt-8" />+ <FontAwesomeIcon icon={faArrowRight} className="mx-4 mt-8 text-gray-400" /></div><div className="mr-2">- <p className="mb-2 text-xs font-semibold text-gray-400">INTEGRATION</p>- <div className="rounded-md bg-white/[.07] py-2.5 pl-4 pr-10 text-sm font-semibold text-gray-300">- {integration.integration.charAt(0).toUpperCase() + integration.integration.slice(1)}+ <p className="text-gray-400 text-xs font-semibold mb-2">INTEGRATION</p>+ <div className="py-2.5 bg-white/[.07] rounded-md pl-4 pr-10 text-sm font-semibold text-gray-300">+ {/* {integration.integration.charAt(0).toUpperCase() + integration.integration.slice(1)} */}+ {integrationSlugNameMapping[integration.integration]}</div></div><div className="mr-2">diff --cc frontend/src/views/Settings/ProjectSettingsPage/ProjectSettingsPage.tsxindex 0000000000,1b30eb4e95..8e5dcf78bamode 000000,100644..100644--- a/frontend/src/views/Settings/ProjectSettingsPage/ProjectSettingsPage.tsx+++ b/frontend/src/views/Settings/ProjectSettingsPage/ProjectSettingsPage.tsx@@@ -1,0 -1,377 +1,374 @@@+ import crypto from 'crypto';++ import { useState } from 'react';+ import { useTranslation } from 'react-i18next';+ import { useRouter } from 'next/router';++ import { useNotificationContext } from '@app/components/context/Notifications/NotificationProvider';+ import NavHeader from '@app/components/navigation/NavHeader';+ // TODO(akhilmhdh):Refactor this into a better utility module package+ import {+ decryptAssymmetric,+ encryptSymmetric+ } from '@app/components/utilities/cryptography/crypto';+ import { Button, FormControl, Input } from '@app/components/v2';+ import { plans } from '@app/const';+ import { useSubscription, useWorkspace } from '@app/context';+ import { useToggle } from '@app/hooks';+ import {+ useCreateServiceToken,+ useCreateWsEnvironment,+ useCreateWsTag,+ useDeleteServiceToken,+ useDeleteWorkspace,+ useDeleteWsEnvironment,+ useDeleteWsTag,+ useGetUserWsKey,+ useGetUserWsServiceTokens,+ useGetWsTags,+ useRenameWorkspace,+ useToggleAutoCapitalization,+ useUpdateWsEnvironment+ } from '@app/hooks/api';+-+ import { AutoCapitalizationSection } from './components/AutoCapitalizationSection/AutoCapitalizationSection';-+ import { SecretTagsSection } from './components/SecretTagsSection';-+ import {+ CopyProjectIDSection,+ CreateServiceToken,+ CreateUpdateEnvFormData,+ CreateWsTag,+ EnvironmentSection,+ ProjectNameChangeSection,+ ServiceTokenSection+ } from './components';++ export const ProjectSettingsPage = () => {+ const { t } = useTranslation();+ const { currentWorkspace, workspaces } = useWorkspace();+ const router = useRouter();+ const { data: serviceTokens } = useGetUserWsServiceTokens({+ workspaceID: currentWorkspace?._id || ''+ });+ const workspaceID = currentWorkspace?._id || '';+ const { createNotification } = useNotificationContext();+ // delete action worksapce+ const [deleteProjectInput, setDeleteProjectInput] = useState('');+ const [isDeleting, setIsDeleting] = useToggle();++ const renameWorkspace = useRenameWorkspace();+ const toggleAutoCapitalization = useToggleAutoCapitalization();++ const deleteWorkspace = useDeleteWorkspace();+ // env crud operation+ const createWsEnv = useCreateWsEnvironment();+ const updateWsEnv = useUpdateWsEnvironment();+ const deleteWsEnv = useDeleteWsEnvironment();++ // service token+ const { data: latestFileKey } = useGetUserWsKey(workspaceID);+ const createServiceToken = useCreateServiceToken();+ const deleteServiceToken = useDeleteServiceToken();++ // tag+ const { data: wsTags } = useGetWsTags(workspaceID);+ const createWsTag = useCreateWsTag();+ const deleteWsTag = useDeleteWsTag();++ // get user subscription+ const { subscriptionPlan } = useSubscription();+ const host = window.location.origin;+ const isEnvServiceAllowed =+ subscriptionPlan !== plans.starter || host !== 'https://app.infisical.com';++ const onRenameWorkspace = async (name: string) => {+ try {+ await renameWorkspace.mutateAsync({ workspaceID, newWorkspaceName: name });+ createNotification({+ text: 'Successfully renamed workspace',+ type: 'success'+ });+ } catch (error) {+ console.error(error);+ createNotification({+ text: 'Failed to rename workspace',+ type: 'error'+ });+ }+ };++ const onAutoCapitalizationToggle = async (state: boolean) => {+ try {+ await toggleAutoCapitalization.mutateAsync({+ workspaceID,+ state+ });+ const text = `Successfully ${state ? 'enabled' : 'disabled'} auto capitalization`;+ createNotification({+ text,+ type: 'success'+ });+ } catch (error) {+ console.error(error);+ createNotification({+ text: 'Failed to update auto capitalization',+ type: 'error'+ });+ }+ };++ const onDeleteWorkspace = async () => {+ setIsDeleting.on();+ try {+ await deleteWorkspace.mutateAsync({ workspaceID });+ // redirect user to first workspace user is part of+ const ws = workspaces.find(({ _id }) => _id !== workspaceID);+ router.push(`/dashboard/${ws?._id}`);+ createNotification({+ text: 'Successfully deleted workspace',+ type: 'success'+ });+ } catch (error) {+ console.error(error);+ createNotification({+ text: 'Failed to delete workspace',+ type: 'error'+ });+ } finally {+ setIsDeleting.off();+ }+ };++ // workspace environment operation+ const onCreateWsEnv = async ({ environmentName, environmentSlug }: CreateUpdateEnvFormData) => {+ try {+ await createWsEnv.mutateAsync({ workspaceID, environmentName, environmentSlug });+ createNotification({+ text: 'Successfully created environment',+ type: 'success'+ });+ } catch (error) {+ console.error(error);+ createNotification({+ text: 'Failed to create environment',+ type: 'error'+ });+ }+ };++ const onUpdateWsEnv = async (+ oldEnvironmentSlug: string,+ { environmentName, environmentSlug }: CreateUpdateEnvFormData+ ) => {+ try {+ await updateWsEnv.mutateAsync({+ workspaceID,+ environmentName,+ environmentSlug,+ oldEnvironmentSlug+ });+ createNotification({+ text: 'Successfully updated environment',+ type: 'success'+ });+ } catch (error) {+ console.error(error);+ createNotification({+ text: 'Failed to update environment',+ type: 'error'+ });+ }+ };++ const onDeleteWsEnv = async (environmentSlug: string) => {+ try {+ await deleteWsEnv.mutateAsync({+ workspaceID,+ environmentSlug+ });+ createNotification({+ text: 'Successfully deleted environment',+ type: 'success'+ });+ } catch (error) {+ console.error(error);+ createNotification({+ text: 'Failed to delete environment',+ type: 'error'+ });+ }+ };++ const onCreateServiceToken = async ({ environment, expiresIn, name }: CreateServiceToken) => {+ // type guard+ if (!latestFileKey) return '';+ try {+ // crypo calculation to generate the key+ const key = decryptAssymmetric({+ ciphertext: latestFileKey.encryptedKey,+ nonce: latestFileKey.nonce,+ publicKey: latestFileKey.sender.publicKey,+ privateKey: localStorage.getItem('PRIVATE_KEY') as string+ });+ const randomBytes = crypto.randomBytes(16).toString('hex');+ const { ciphertext, iv, tag } = encryptSymmetric({+ plaintext: key,+ key: randomBytes+ });++ const res = await createServiceToken.mutateAsync({+ encryptedKey: ciphertext,+ iv,+ tag,+ environment,+ expiresIn: Number(expiresIn),+ name,+ workspaceId: workspaceID+ });+ console.log(res);+ createNotification({+ text: 'Successfully created a service token',+ type: 'success'+ });+ return res.serviceToken;+ } catch (error) {+ console.error(error);+ createNotification({+ text: 'Failed to create a service token',+ type: 'error'+ });+ }+ return '';+ };++ const onCreateWsTag = async ({ name }: CreateWsTag) => {+ try {+ const res = await createWsTag.mutateAsync({+ workspaceID,+ tagName: name,+ tagSlug: name.replace(" ", "_")+ });+ createNotification({+ text: 'Successfully created a tag',+ type: 'success'+ });+ return res.name;+ } catch (error) {+ console.error(error);+ createNotification({+ text: 'Failed to create a tag',+ type: 'error'+ });+ }+ return '';+ };++ const onDeleteTag = async (tagID: string) => {+ try {+ await deleteWsTag.mutateAsync({ tagID });+ createNotification({+ text: 'Successfully deleted tag',+ type: 'success'+ });+ } catch (error) {+ console.error(error);+ createNotification({+ text: 'Failed to delete the tag',+ type: 'error'+ });+ }+ };++ const onDeleteServiceToken = async (tokenID: string) => {+ try {+ await deleteServiceToken.mutateAsync(tokenID);+ createNotification({+ text: 'Successfully revoked service token',+ type: 'success'+ });+ } catch (error) {+ console.error(error);+ createNotification({+ text: 'Failed to delete service token',+ type: 'error'+ });+ }+ };++ return (+ <div className="container mx-auto flex flex-col px-8 text-mineshaft-50 dark dark:[color-scheme:dark]">+ {/* TODO(akhilmhdh): Remove this right when layout is refactored */}+ <div className="relative right-5">+ <NavHeader pageName={t('settings-project:title')} isProjectRelated />+ </div>+ <div className="my-8 flex max-w-5xl flex-row items-center justify-between text-xl">+ <div className="flex flex-col items-start justify-start text-3xl">+ <p className="mr-4 font-semibold text-gray-200">{t('settings-project:title')}</p>+ <p className="mr-4 text-base font-normal text-gray-400">+ {t('settings-project:description')}+ </p>+ </div>+ </div>+ <ProjectNameChangeSection+ workspaceName={currentWorkspace?.name}+ onProjectNameChange={onRenameWorkspace}+ />+ <AutoCapitalizationSection+ workspaceAutoCapitalization={currentWorkspace?.autoCapitalization}+ onAutoCapitalizationChange={onAutoCapitalizationToggle}+ />+ <CopyProjectIDSection workspaceID={currentWorkspace?._id || ''} />+ <EnvironmentSection+ environments={currentWorkspace?.environments || []}+ onCreate={onCreateWsEnv}+ onDelete={onDeleteWsEnv}+ onUpdate={onUpdateWsEnv}+ isEnvServiceAllowed={isEnvServiceAllowed}+ />+ <ServiceTokenSection+ tokens={serviceTokens || []}+ environments={currentWorkspace?.environments || []}+ onDeleteToken={onDeleteServiceToken}+ workspaceName={currentWorkspace?.name || ''}+ onCreateToken={onCreateServiceToken}+ />+ <SecretTagsSection+ tags={wsTags || []}+ onDeleteTag={onDeleteTag}+ workspaceName={currentWorkspace?.name || ''}+ onCreateTag={onCreateWsTag}+ />+ <div className="mb-6 mt-4 flex w-full flex-col items-start rounded-md border-l border-red bg-white/5 px-6 pl-6 pb-4 pt-4">+ <p className="text-xl font-bold text-red">{t('settings-project:danger-zone')}</p>+ <p className="text-md mt-2 text-gray-400">{t('settings-project:danger-zone-note')}</p>+ <div className="mr-auto mt-4 max-h-28 w-full max-w-md">+ <FormControl+ label={+ <div className="mb-0.5 text-sm font-normal text-gray-400">+ Type <span className="font-bold">{currentWorkspace?.name}</span> to delete the+ workspace+ </div>+ }+ >+ <Input+ onChange={(e) => setDeleteProjectInput(e.target.value)}+ value={deleteProjectInput}+ placeholder="Type the project name to delete"+ />+ </FormControl>+ </div>+ <Button+ colorSchema="danger"+ onClick={onDeleteWorkspace}+ isDisabled={deleteProjectInput !== currentWorkspace?.name || isDeleting}+ isLoading={isDeleting}+ >+ {t('settings-project:delete-project')}+ </Button>+ <p className="mt-3 ml-0.5 text-xs text-gray-500">+ {t('settings-project:delete-project-note')}+ </p>+ </div>+ </div>+ );+ };