Bladeren bron

adding second preflight check

Feroze Mohideen 3 jaren geleden
bovenliggende
commit
0ff5a9c964

File diff suppressed because it is too large
+ 13468 - 1
dashboard/package-lock.json


+ 8 - 5
dashboard/src/components/CloudFormationForm.tsx

@@ -19,13 +19,16 @@ import DocsHelper from "./DocsHelper";
 type Props = {
   goBack: () => void;
   proceed: () => void;
+  AWSAccountID: string;
+  setAWSAccountID: (id: string) => void;
 };
 
 const CloudFormationForm: React.FC<Props> = ({
   goBack,
   proceed,
+  AWSAccountID,
+  setAWSAccountID
 }) => {
-  const [AWSAccountID, setAWSAccountID] = useState("");
   const [grantPermissionsError, setGrantPermissionsError] = useState("");
   const [roleStatus, setRoleStatus] = useState("");
 
@@ -33,7 +36,7 @@ const CloudFormationForm: React.FC<Props> = ({
     let targetARN = `arn:aws:iam::${AWSAccountID}:role/porter-role`
     setRoleStatus("loading");
     // api
-    //   .preflightCheckAWS(
+    //   .preflightCheckAWSRole(
     //     "<token>",
     //     {
     //       target_arn: targetARN,
@@ -51,8 +54,8 @@ const CloudFormationForm: React.FC<Props> = ({
     //     console.error(err);
     //     setCreateStatus("Error creating credentials");
     //   });
-      setRoleStatus("successful");
-      proceed();
+    setRoleStatus("successful");
+    proceed();
   };
 
   const directToCloudFormation = () => {
@@ -80,7 +83,7 @@ const CloudFormationForm: React.FC<Props> = ({
             label={
               <Flex>
                 👤 AWS account ID
-                <i 
+                <i
                   className="material-icons"
                 >
                   help_outline

+ 5 - 1
dashboard/src/components/ProvisionerFlow.tsx

@@ -29,6 +29,7 @@ const ProvisionerFlow: React.FC<Props> = ({
   const [credentialId, setCredentialId] = useState("");
   const [showCostConfirmModal, setShowCostConfirmModal] = useState(false);
   const [confirmCost, setConfirmCost] = useState("");
+  const [AWSAccountID, setAWSAccountID] = useState("");
 
   const isUsageExceeded = useMemo(() => {
     if (!hasBillingEnabled) {
@@ -130,12 +131,14 @@ const ProvisionerFlow: React.FC<Props> = ({
     );
   } else if (currentStep === "credentials") {
     return (
-      <CloudFormationForm 
+      <CloudFormationForm
         goBack={() => setCurrentStep("cloud")}
         proceed={() => {
           // setCredentialId(id);
           setCurrentStep("cluster");
         }}
+        AWSAccountID={AWSAccountID}
+        setAWSAccountID={setAWSAccountID}
       />
     );
   } else if (currentStep === "cluster") {
@@ -143,6 +146,7 @@ const ProvisionerFlow: React.FC<Props> = ({
       <ProvisionerForm
         goBack={() => setCurrentStep("credentials")}
         credentialId={credentialId}
+        AWSAccountID={AWSAccountID}
       />
     );
   }

+ 4 - 2
dashboard/src/components/ProvisionerForm.tsx

@@ -10,11 +10,13 @@ import ProvisionerSettings from "./ProvisionerSettings";
 type Props = {
   goBack: () => void;
   credentialId: string;
+  AWSAccountID: string;
 };
 
 const ProvisionerForm: React.FC<Props> = ({
   goBack,
   credentialId,
+  AWSAccountID
 }) => {
   return (
     <>
@@ -28,9 +30,9 @@ const ProvisionerForm: React.FC<Props> = ({
         Configure settings
       </Heading>
       <Helper>
-        Configure settings for your new cluster. 
+        Configure settings for your new cluster.
       </Helper>
-      <ProvisionerSettings credentialId={credentialId} />
+      <ProvisionerSettings credentialId={credentialId} AWSAccountID={AWSAccountID} />
     </>
   );
 };

+ 54 - 33
dashboard/src/components/ProvisionerSettings.tsx

@@ -53,6 +53,7 @@ const clusterVersionOptions = [
 type Props = RouteComponentProps & {
   selectedClusterVersion?: Contract;
   credentialId: string;
+  AWSAccountID: string;
   clusterId?: number;
 };
 
@@ -122,40 +123,60 @@ const ProvisionerSettings: React.FC<Props> = props => {
       data["cluster"]["clusterId"] = props.clusterId;
     }
 
-    try {
-      const res = await api.createContract(
+    api
+      .preflightCheckAWSUsage(
         "<token>",
-        data,
-        { project_id: currentProject.id }
-      );
+        {
+          // TODO: change this back
+          // target_arn: `arn:aws:iam::${props.AWSAccountID}:role/porter-role`,
+          target_arn: "arn:aws:iam::844966915049:role/PorterRole-RootRole-1S8V1TYOMOXTK",
+          region: awsRegion
+        },
+        {
+          id: currentProject.id,
+        }
+      )
+      .then(({ data }) => {
+        console.log(data)
+      })
+      .catch((err) => {
+        console.error(err);
+      });
 
-      // Only refresh and set clusters on initial create
-      if (!props.clusterId) {
-        setShouldRefreshClusters(true);
-        api.getClusters(
-          "<token>",
-          {},
-          { id: currentProject.id },
-        )
-          .then(({ data }) => {
-            data.forEach((cluster: ClusterType) => {
-              if (cluster.id === res.data.contract_revision?.cluster_id) {
-                // setHasFinishedOnboarding(true);
-                setCurrentCluster(cluster);
-                OFState.actions.goTo("clean_up");
-                pushFiltered(props, "/cluster-dashboard", ["project_id"], {
-                  cluster: cluster.name,
-                });
-              }
-            });
-          })
-          .catch((err) => {
-            console.error(err);
-          });
-      }
-    } catch (err) {
-      console.log(err);
-    }
+    // try {
+    //   const res = await api.createContract(
+    //     "<token>",
+    //     data,
+    //     { project_id: currentProject.id }
+    //   );
+
+    //   // Only refresh and set clusters on initial create
+    //   if (!props.clusterId) {
+    //     setShouldRefreshClusters(true);
+    //     api.getClusters(
+    //       "<token>",
+    //       {},
+    //       { id: currentProject.id },
+    //     )
+    //       .then(({ data }) => {
+    //         data.forEach((cluster: ClusterType) => {
+    //           if (cluster.id === res.data.contract_revision?.cluster_id) {
+    //             // setHasFinishedOnboarding(true);
+    //             setCurrentCluster(cluster);
+    //             OFState.actions.goTo("clean_up");
+    //             pushFiltered(props, "/cluster-dashboard", ["project_id"], {
+    //               cluster: cluster.name,
+    //             });
+    //           }
+    //         });
+    //       })
+    //       .catch((err) => {
+    //         console.error(err);
+    //       });
+    //   }
+    // } catch (err) {
+    //   console.log(err);
+    // }
   }
 
   useEffect(() => {
@@ -186,7 +207,7 @@ const ProvisionerSettings: React.FC<Props> = props => {
   }, [props.selectedClusterVersion]);
 
   const renderForm = () => {
-    
+
     // Render simplified form if initial create
     if (!props.clusterId) {
       return (

+ 27 - 24
dashboard/src/shared/api.tsx

@@ -71,14 +71,24 @@ const getGitlabIntegration = baseApi<{}, { project_id: number }>(
   ({ project_id }) => `/api/projects/${project_id}/integrations/gitlab`
 );
 
-const preflightCheckAWS = baseApi<
+const preflightCheckAWSRole = baseApi<
   {
     target_arn: string;
     external_id: string;
   },
   { id: number }
 >("POST", (pathParams) => {
-  return `/api/projects/${pathParams.id}/integrations/aws/preflight`;
+  return `/api/projects/${pathParams.id}/integrations/aws/preflight/role`;
+});
+
+const preflightCheckAWSUsage = baseApi<
+  {
+    target_arn: string;
+    region: string;
+  },
+  { id: number }
+>("POST", (pathParams) => {
+  return `/api/projects/${pathParams.id}/integrations/aws/preflight/usage`;
 });
 
 const createAWSIntegration = baseApi<
@@ -577,11 +587,9 @@ const detectBuildpack = baseApi<
     branch: string;
   }
 >("GET", (pathParams) => {
-  return `/api/projects/${pathParams.project_id}/gitrepos/${
-    pathParams.git_repo_id
-  }/repos/${pathParams.kind}/${pathParams.owner}/${
-    pathParams.name
-  }/${encodeURIComponent(pathParams.branch)}/buildpack/detect`;
+  return `/api/projects/${pathParams.project_id}/gitrepos/${pathParams.git_repo_id
+    }/repos/${pathParams.kind}/${pathParams.owner}/${pathParams.name
+    }/${encodeURIComponent(pathParams.branch)}/buildpack/detect`;
 });
 
 const detectGitlabBuildpack = baseApi<
@@ -612,11 +620,9 @@ const getBranchContents = baseApi<
     branch: string;
   }
 >("GET", (pathParams) => {
-  return `/api/projects/${pathParams.project_id}/gitrepos/${
-    pathParams.git_repo_id
-  }/repos/${pathParams.kind}/${pathParams.owner}/${
-    pathParams.name
-  }/${encodeURIComponent(pathParams.branch)}/contents`;
+  return `/api/projects/${pathParams.project_id}/gitrepos/${pathParams.git_repo_id
+    }/repos/${pathParams.kind}/${pathParams.owner}/${pathParams.name
+    }/${encodeURIComponent(pathParams.branch)}/contents`;
 });
 
 const getProcfileContents = baseApi<
@@ -632,11 +638,9 @@ const getProcfileContents = baseApi<
     branch: string;
   }
 >("GET", (pathParams) => {
-  return `/api/projects/${pathParams.project_id}/gitrepos/${
-    pathParams.git_repo_id
-  }/repos/${pathParams.kind}/${pathParams.owner}/${
-    pathParams.name
-  }/${encodeURIComponent(pathParams.branch)}/procfile`;
+  return `/api/projects/${pathParams.project_id}/gitrepos/${pathParams.git_repo_id
+    }/repos/${pathParams.kind}/${pathParams.owner}/${pathParams.name
+    }/${encodeURIComponent(pathParams.branch)}/procfile`;
 });
 
 const getGitlabProcfileContents = baseApi<
@@ -1490,11 +1494,9 @@ const getEnvGroup = baseApi<
     version?: number;
   }
 >("GET", (pathParams) => {
-  return `/api/projects/${pathParams.id}/clusters/${
-    pathParams.cluster_id
-  }/namespaces/${pathParams.namespace}/envgroup?name=${pathParams.name}${
-    pathParams.version ? "&version=" + pathParams.version : ""
-  }`;
+  return `/api/projects/${pathParams.id}/clusters/${pathParams.cluster_id
+    }/namespaces/${pathParams.namespace}/envgroup?name=${pathParams.name}${pathParams.version ? "&version=" + pathParams.version : ""
+    }`;
 });
 
 const getConfigMap = baseApi<
@@ -2396,7 +2398,7 @@ const removeStackEnvGroup = baseApi<
     `/api/v1/projects/${project_id}/clusters/${cluster_id}/namespaces/${namespace}/stacks/${stack_id}/remove_env_group/${env_group_name}`
 );
 
-const getGithubStatus = baseApi<{}, {}>("GET", ({}) => `/api/status/github`);
+const getGithubStatus = baseApi<{}, {}>("GET", ({ }) => `/api/status/github`);
 
 // Bundle export to allow default api import (api.<method> is more readable)
 export default {
@@ -2573,7 +2575,8 @@ export default {
   addApplicationToEnvGroup,
   removeApplicationFromEnvGroup,
   provisionDatabase,
-  preflightCheckAWS,
+  preflightCheckAWSRole,
+  preflightCheckAWSUsage,
   getDatabases,
   getPreviousLogsForContainer,
   upgradePorterAgent,

Some files were not shown because too many files changed in this diff