Skip to content

Commit

Permalink
Fix more merge conflicts and continue cleaning up integrations frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
dangtony98 committed Dec 11, 2022
1 parent bacf9f2 commit d410b42
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 121 deletions.
1 change: 0 additions & 1 deletion frontend/components/integrations/CloudIntegration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ const CloudIntegration = ({
deleteIntegrationAuth,
authorizations
}: CloudIntegration) => {
console.log('cio', integration);
return (
<div
className={`relative ${
Expand Down
5 changes: 0 additions & 5 deletions frontend/components/utilities/secrets/getSecretsForProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,8 @@ const getSecretsForProject = async ({
publicKey: file.key.sender.publicKey,
privateKey: PRIVATE_KEY
});
<<<<<<< HEAD:frontend/components/utilities/secrets/getSecretsForProject.js

file.secrets.map((secretPair) => {
=======

file.secrets.map((secretPair: any) => {
>>>>>>> 158c51ff3cbcd9a8eab6c44e728232d79a1cbab9:frontend/components/utilities/secrets/getSecretsForProject.ts
// decrypt .env file with symmetric key
const plainTextKey = decryptSymmetric({
ciphertext: secretPair.secretKey.ciphertext,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import SecurityClient from "~/utilities/SecurityClient.js";
import SecurityClient from "~/utilities/SecurityClient";

interface Props {
workspaceId: string;
}

/**
* This function fetches the bot for a project
* @param {Object} obj
* @param {String} obj.workspaceId
* @returns
*/
const getBot = async ({ workspaceId }) => {
const getBot = async ({ workspaceId }: Props) => {
return SecurityClient.fetchCall(
"/api/v1/bot/" + workspaceId,
{
Expand All @@ -16,7 +20,7 @@ const getBot = async ({ workspaceId }) => {
}
}
).then(async (res) => {
if (res.status == 200) {
if (res && res.status == 200) {
return await res.json();
} else {
console.log("Failed to get bot for project");
Expand Down
31 changes: 0 additions & 31 deletions frontend/pages/api/bot/setBotActiveStatus.js

This file was deleted.

46 changes: 46 additions & 0 deletions frontend/pages/api/bot/setBotActiveStatus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import SecurityClient from "~/utilities/SecurityClient";

interface BotKey {
encryptedKey: string;
nonce: string;
}

interface Props {
botId: string;
isActive: Boolean;
botKey: BotKey;
}

/**
* This function sets the active status of a bot and shares a copy of
* the project key (encrypted under the bot's public key) with the
* project's bot
* @param {Object} obj
* @param {String} obj.botId
* @param {String} obj.isActive
* @param {Object} obj.botKey
* @returns
*/
const setBotActiveStatus = async ({ botId, isActive, botKey }: Props) => {
return SecurityClient.fetchCall(
"/api/v1/bot/" + botId + "/active",
{
method: "PATCH",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
isActive,
botKey
})
}
).then(async (res) => {
if (res && res.status == 200) {
return await res.json();
} else {
console.log("Failed to get bot for project");
}
});
};

export default setBotActiveStatus;
51 changes: 0 additions & 51 deletions frontend/pages/dashboard/[id].js
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,6 @@ import {
faPerson,
faPlus,
faShuffle,
<<<<<<< HEAD
faX,
} from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { Menu, Transition } from "@headlessui/react";

import Button from "~/components/basic/buttons/Button";
import ListBox from "~/components/basic/Listbox";
import BottonRightPopup from "~/components/basic/popups/BottomRightPopup";
import { useNotificationContext } from "~/components/context/Notifications/NotificationProvider";
import DashboardInputField from "~/components/dashboard/DashboardInputField";
import DropZone from "~/components/dashboard/DropZone";
import NavHeader from "~/components/navigation/NavHeader";
import getSecretsForProject from "~/components/utilities/secrets/getSecretsForProject";
import pushKeys from "~/components/utilities/secrets/pushKeys";
import guidGenerator from "~/utilities/randomId";

import { envMapping } from "../../public/data/frequentConstants";
import getWorkspaceIntegrations from "../api/integrations/getWorkspaceIntegrations";
import getUser from "../api/user/getUser";
import checkUserAction from "../api/userActions/checkUserAction";
import registerUserAction from "../api/userActions/registerUserAction";
import getWorkspaces from "../api/workspace/getWorkspaces";
=======
faX
} from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
Expand All @@ -65,7 +41,6 @@ import getUser from '../api/user/getUser';
import checkUserAction from '../api/userActions/checkUserAction';
import registerUserAction from '../api/userActions/registerUserAction';
import getWorkspaces from '../api/workspace/getWorkspaces';
>>>>>>> 158c51ff3cbcd9a8eab6c44e728232d79a1cbab9

/**
* This component represent a single row for an environemnt variable on the dashboard
Expand Down Expand Up @@ -426,32 +401,6 @@ export default function Dashboard() {
setButtonReady(false);
pushKeys({ obj, workspaceId: router.query.id, env });

<<<<<<< HEAD
=======
/**
* Check which integrations are active for this project and environment
* If there are any, update environment variables for those integrations
*/
let integrations = await getWorkspaceIntegrations({
workspaceId: router.query.id
});
integrations.map(async (integration) => {
if (
envMapping[env] == integration.environment &&
integration.isActive == true
) {
let objIntegration = Object.assign(
{},
...data.map((row) => ({ [row[2]]: row[3] }))
);
await pushKeysIntegration({
obj: objIntegration,
integrationId: integration._id
});
}
});

>>>>>>> 158c51ff3cbcd9a8eab6c44e728232d79a1cbab9
// If this user has never saved environment variables before, show them a prompt to read docs
if (!hasUserEverPushed) {
setCheckDocsPopUpVisible(true);
Expand Down
6 changes: 6 additions & 0 deletions frontend/pages/heroku.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const queryString = require("query-string");
import AuthorizeIntegration from "./api/integrations/authorizeIntegration";

export default function Heroku() {
console.log('HEROKU PAGE');
const router = useRouter();
const parsedUrl = queryString.parse(router.asPath.split("?")[1]);
const code = parsedUrl.code;
Expand All @@ -16,7 +17,11 @@ export default function Heroku() {
// eslint-disable-next-line react-hooks/exhaustive-deps
useEffect(async () => {
try {
console.log('A');
console.log(state);
console.log(localStorage.getItem('latestCSRFToken'));
if (state == localStorage.getItem("latestCSRFToken")) {
console.log('B');
await AuthorizeIntegration({
workspaceId: localStorage.getItem("projectData.id"),
code,
Expand All @@ -25,6 +30,7 @@ export default function Heroku() {
router.push("/integrations/" + localStorage.getItem("projectData.id"));
}
} catch (error) {
console.error(error);
console.log("Error - Not logged in yet");
}
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down
66 changes: 36 additions & 30 deletions frontend/pages/integrations/[id].js
Original file line number Diff line number Diff line change
Expand Up @@ -74,38 +74,38 @@ export default function Integrations() {
* 4. Send encrypted project key to backend and set bot status to active
*/
const handleBotActivate = async () => {
let botKey;
try {
const key = await getLatestFileKey({ workspaceId: router.query.id });

if (bot) {
// case: there is a bot
const PRIVATE_KEY = localStorage.getItem('PRIVATE_KEY');

const WORKSPACE_KEY = decryptAssymmetric({
ciphertext: key.latestKey.encryptedKey,
nonce: key.latestKey.nonce,
publicKey: key.latestKey.sender.publicKey,
privateKey: PRIVATE_KEY
});
const key = await getLatestFileKey({ workspaceId: router.query.id });
const PRIVATE_KEY = localStorage.getItem('PRIVATE_KEY');

const WORKSPACE_KEY = decryptAssymmetric({
ciphertext: key.latestKey.encryptedKey,
nonce: key.latestKey.nonce,
publicKey: key.latestKey.sender.publicKey,
privateKey: PRIVATE_KEY
});

const { ciphertext, nonce } = encryptAssymmetric({
plaintext: WORKSPACE_KEY,
publicKey: bot.publicKey,
privateKey: PRIVATE_KEY
});
const { ciphertext, nonce } = encryptAssymmetric({
plaintext: WORKSPACE_KEY,
publicKey: bot.publicKey,
privateKey: PRIVATE_KEY
});

botKey = {
encryptedKey: ciphertext,
nonce
}

// case: bot is not active
setBot((await setBotActiveStatus({
botId: bot._id,
isActive: bot.isActive ? false : true,
botKey
})).bot);
botKey = {
encryptedKey: ciphertext,
nonce
}

setBot((await setBotActiveStatus({
botId: bot._id,
isActive: bot.isActive ? false : true,
botKey
})).bot);
}
} catch (err) {
console.error(err);
}
Expand All @@ -115,27 +115,33 @@ export default function Integrations() {
* Start integration for a given integration option [integrationOption]
* @param {Object} obj
* @param {Object} obj.integrationOption - an integration option
* @param {String} obj.name
* @param {String} obj.type
* @param {String} obj.docsLink
* @returns
*/
const handleIntegrationOption = async ({ integrationOption }) => {
// TODO: modularize

// generate CSRF token for OAuth2 code-token exchange integrations
const csrfToken = crypto.randomBytes(16).toString("hex");
localStorage.setItem('latestCSRFToken', csrfToken);

switch (integrationOption.name) {
case 'Heroku':
window.location = `https://id.heroku.com/oauth/authorize?client_id=7b1311a1-1cb2-4938-8adf-f37a399ec41b&response_type=code&scope=write-protected&state=${csrfToken}`;
return;
}

}

/**
* Call [handleIntegrationOption] if bot is active, else open dialog for user to grant
* permission to share secretes with Infisical prior to starting any integration
* Open dialog to activate bot if bot is not active.
* Otherwise, start integration [integrationOption]
* @param {Object} obj
* @param {String} obj.integrationOption - an integration option
* @param {Object} obj.integrationOption - an integration option
* @param {String} obj.name
* @param {String} obj.type
* @param {String} obj.docsLink
* @returns
*/
const integrationOptionPress = ({ integrationOption }) => {
Expand Down

0 comments on commit d410b42

Please sign in to comment.