Просмотр исходного кода

Merge branch 'master' of https://github.com/porter-dev/porter into simplified-view

Justin Rhee 3 лет назад
Родитель
Сommit
fffdacaae5

+ 0 - 14
api/server/authn/handler.go

@@ -5,7 +5,6 @@ import (
 	"fmt"
 	"net/http"
 	"strings"
-	"time"
 
 	"github.com/gorilla/sessions"
 	"github.com/porter-dev/porter/api/server/shared/apierrors"
@@ -81,19 +80,6 @@ func (authn *AuthN) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 		return
 	}
 
-	supportEmail := "support@porter.run"
-	cancelTime := time.Date(2023, 0o1, 31, 14, 30, 0, 0, time.Now().Local().Location())
-	if email, ok := session.Values["email"]; ok {
-		if email.(string) == supportEmail {
-			sess, _ := authn.config.Repo.Session().SelectSession(&models.Session{Key: session.ID})
-			if sess.CreatedAt.Before(cancelTime) {
-				_, _ = authn.config.Repo.Session().DeleteSession(sess)
-				authn.handleForbiddenForSession(w, r, fmt.Errorf("error, contact admin"), session)
-				return
-			}
-		}
-	}
-
 	if auth, ok := session.Values["authenticated"].(bool); !auth || !ok {
 		authn.handleForbiddenForSession(w, r, fmt.Errorf("stored cookie was not authenticated"), session)
 		return

+ 0 - 18
api/server/handlers/api_contract/update.go

@@ -1,9 +1,7 @@
 package api_contract
 
 import (
-	"database/sql"
 	"encoding/base64"
-	"errors"
 	"fmt"
 	"net/http"
 
@@ -49,22 +47,6 @@ func (c *APIContractUpdateHandler) ServeHTTP(w http.ResponseWriter, r *http.Requ
 		return
 	}
 
-	existingClusters, err := c.Config().Repo.Cluster().ListClustersByProjectID(uint(apiContract.Cluster.ProjectId))
-	if err != nil {
-		if !errors.Is(err, sql.ErrNoRows) {
-			e := fmt.Errorf("error listing clusters for given project ID: %w", err)
-			c.HandleAPIError(w, r, apierrors.NewErrInternal(e))
-			return
-		}
-	}
-	for _, cluster := range existingClusters {
-		if cluster.Name == apiContract.Cluster.GetEksKind().ClusterName {
-			e := fmt.Errorf("cluster already exists in project %d called %s", cluster.ProjectID, cluster.Name)
-			c.HandleAPIError(w, r, apierrors.NewErrInternal(e))
-			return
-		}
-	}
-
 	if !project.CapiProvisionerEnabled && !c.Config().EnableCAPIProvisioner {
 		// return dummy data if capi provisioner disabled in project settings, and as env var
 		// TODO: remove this stub when we can spin up all services locally, easily

+ 3 - 1
api/server/shared/config/loader/loader.go

@@ -233,7 +233,9 @@ func (e *EnvConfigLoader) LoadConfig() (res *config.Config, err error) {
 				var err error
 				defer func() {
 					// TODO: this is only used to collect data for removing the `request origin not allowed by Upgrader.CheckOrigin` error
-					res.Logger.Info().Msgf("error: %s, host: %s, origin: %s, serverURL: %s", err.Error(), r.Host, r.Header.Get("Origin"), sc.ServerURL)
+					if err != nil {
+						res.Logger.Info().Msgf("error: %s, host: %s, origin: %s, serverURL: %s", err.Error(), r.Host, r.Header.Get("Origin"), sc.ServerURL)
+					}
 				}()
 				origin := r.Header.Get("Origin")
 

+ 14 - 24
dashboard/src/components/CloudFormationForm.tsx

@@ -22,11 +22,13 @@ import Link from "./porter/Link";
 type Props = {
   goBack: () => void;
   proceed: (id: string) => void;
+  switchToCredentialFlow: () => void;
 };
 
 const CloudFormationForm: React.FC<Props> = ({
   goBack,
   proceed,
+  switchToCredentialFlow
 }) => {
   const [grantPermissionsError, setGrantPermissionsError] = useState("");
   const [roleStatus, setRoleStatus] = useState("");
@@ -90,7 +92,10 @@ const CloudFormationForm: React.FC<Props> = ({
           </Text>
           <Spacer height="15px" />
           <Text color="helper">
-            Provide your AWS account ID to log in and grant Porter access to AWS. You will need to select "Create stack" after being redirected to the AWS console below. Make sure that the stack status has changed from "CREATE_IN_PROGRESS" to "CREATE_COMPLETE" before clicking Continue.
+            Provide your AWS account ID to log in and grant Porter access to AWS by clicking 'Grant permissions' below.
+          </Text>
+          <Text color="helper">
+            You will need to select "Create stack" after being redirected to the AWS console.
           </Text>
           <Spacer y={1} />
           <Input
@@ -109,6 +114,9 @@ const CloudFormationForm: React.FC<Props> = ({
             }
             value={AWSAccountID}
             setValue={(e) => {
+              if (e === "open-sesame") {
+                switchToCredentialFlow();
+              }
               setGrantPermissionsError("");
               setAWSAccountID(e.trim());
             }}
@@ -133,6 +141,10 @@ const CloudFormationForm: React.FC<Props> = ({
           >
             <ButtonImg src={aws} /> Grant permissions
           </Button>
+          <Spacer y={1} />
+          <Text color="helper">
+            Make sure that the stack status has changed from "CREATE_IN_PROGRESS" to "CREATE_COMPLETE" before clicking Continue below.
+          </Text>
         </Fieldset>
         <Spacer y={1} />
         <Button
@@ -256,26 +268,4 @@ const BackButton = styled.div`
     margin-right: 6px;
     margin-left: -2px;
   }
-`;
-
-const StyledForm = styled.div`
-  position: relative;
-  padding: 15px 30px 25px;
-  border-radius: 5px;
-  background: #26292e;
-  border: 1px solid #494b4f;
-  font-size: 13px;
-  margin-bottom: 30px;
-`;
-
-const ErrorContainer = styled.div`
-  position: relative;
-  margin-top: 20px;
-  padding: 30px 30px 25px;
-  border-radius: 5px;
-  background: #26292e;
-  border: 1px solid #494b4f;
-  font-size: 13px;
-  margin-bottom: 30px;
-  color: red;
-`
+`;

+ 0 - 28
dashboard/src/components/CredentialsForm.tsx

@@ -22,7 +22,6 @@ import Spacer from "./porter/Spacer";
 type Props = {
   goBack: () => void;
   proceed: (cloud_provider_credentials_id: string) => void;
-  enableAssumeRole?: () => void;
 };
 
 type AWSCredential = {
@@ -37,7 +36,6 @@ type AWSCredential = {
 const CredentialsForm: React.FC<Props> = ({
   goBack,
   proceed,
-  enableAssumeRole,
 }) => {
   const { currentProject } = useContext(Context);
   const [awsCredentials, setAWSCredentials] = useState<AWSCredential[]>(null);
@@ -162,9 +160,6 @@ const CredentialsForm: React.FC<Props> = ({
             type="password"
             value={awsSecretAccessKey}
             setValue={(e: string) => {
-              if (e === "open-sesame") {
-                enableAssumeRole();
-              }
               setAWSSecretAccessKey(e)
             }}
             label="🔒 AWS secret key"
@@ -313,29 +308,6 @@ const BackButton = styled.div`
   }
 `;
 
-const BackArrow = styled.div`
-  width: 30px;
-  height: 30px;
-  margin-left: -5px;
-  margin-right: 8px;
-  display: flex;
-  align-items: center;
-  justify-content: center;
-  z-index: 1;
-  border-radius: 50%;
-  right: 10px;
-  top: 10px;
-  cursor: pointer;
-  :hover {
-    background-color: #ffffff11;
-  }
-
-  > i {
-    font-size: 20px;
-    color: #aaaabb;
-  }
-`;
-
 const Name = styled.div`
   font-size: 13px;
   font-weight: 500;

+ 10 - 12
dashboard/src/components/ProvisionerFlow.tsx

@@ -30,7 +30,7 @@ const ProvisionerFlow: React.FC<Props> = ({
   const [credentialId, setCredentialId] = useState("");
   const [showCostConfirmModal, setShowCostConfirmModal] = useState(false);
   const [confirmCost, setConfirmCost] = useState("");
-  const [useAssumeRole, setUseAssumeRole] = useState(false);
+  const [useCloudFormationForm, setUseCloudFormationForm] = useState(true);
 
   const isUsageExceeded = useMemo(() => {
     if (!hasBillingEnabled) {
@@ -42,8 +42,8 @@ const ProvisionerFlow: React.FC<Props> = ({
   const markStepCostConsent = async () => {
     try {
       const res = await api.updateOnboardingStep(
-        "<token>", 
-        { step: "cost-consent-complete" }, 
+        "<token>",
+        { step: "cost-consent-complete" },
         {}
       );
     } catch (err) {
@@ -51,8 +51,8 @@ const ProvisionerFlow: React.FC<Props> = ({
     }
     try {
       const res = await api.inviteAdmin(
-        "<token>", 
-        {}, 
+        "<token>",
+        {},
         { project_id: currentProject.id }
       );
     } catch (err) {
@@ -153,20 +153,18 @@ const ProvisionerFlow: React.FC<Props> = ({
         )}
       </>
     );
-  } else if (currentStep === "credentials" && useAssumeRole) {
-    return (
+  } else if (currentStep === "credentials") {
+    return useCloudFormationForm ? (
       <CloudFormationForm
         goBack={() => setCurrentStep("cloud")}
         proceed={(id) => {
           setCredentialId(id);
           setCurrentStep("cluster");
         }}
+        switchToCredentialFlow={() => setUseCloudFormationForm(false)}
       />
-    );
-  } else if (currentStep === "credentials" && !useAssumeRole) {
-    return (
+    ) : (
       <CredentialsForm
-        enableAssumeRole={() => setUseAssumeRole(true)}
         goBack={() => setCurrentStep("cloud")}
         proceed={(id) => {
           setCredentialId(id);
@@ -179,7 +177,7 @@ const ProvisionerFlow: React.FC<Props> = ({
       <ProvisionerForm
         goBack={() => setCurrentStep("credentials")}
         credentialId={credentialId}
-        useAssumeRole={useAssumeRole}
+        useAssumeRole={useCloudFormationForm}
       />
     );
   }

+ 4 - 0
dashboard/src/components/porter/Input.tsx

@@ -1,5 +1,6 @@
 import React, { useEffect, useState } from "react";
 import styled from "styled-components";
+import { boolean } from "zod";
 
 type Props = {
   placeholder: string;
@@ -11,6 +12,7 @@ type Props = {
   type?: string;
   error?: string;
   children?: React.ReactNode;
+  disabled?: boolean;
 };
 
 const Input: React.FC<Props> = ({
@@ -23,6 +25,7 @@ const Input: React.FC<Props> = ({
   type,
   error,
   children,
+  disabled,
 }) => {
   return (
     <Block width={width}>
@@ -39,6 +42,7 @@ const Input: React.FC<Props> = ({
         height={height}
         type={type || "text"}
         hasError={(error && true) || (error === "")}
+        disabled={disabled ? disabled : false}
       />
       {
         error && (

+ 1 - 1
dashboard/src/main/CurrentError.tsx

@@ -133,7 +133,7 @@ const StyledCurrentError = styled.div`
   border-radius: 3px;
   background: #272731cc;
   border: 1px solid #ffffff55;
-  display: none;
+  display: flex;
   align-items: center;
   color: #ffffff;
 

+ 14 - 0
dashboard/src/main/auth/Register.tsx

@@ -38,6 +38,7 @@ const Register: React.FC<Props> = ({
   const [companyNameError, setCompanyNameError] = useState(false);
   const [email, setEmail] = useState("");
   const [emailError, setEmailError] = useState(false);
+  const [disabled, setDisabled] = useState(false);
   const [password, setPassword] = useState("");
   const [passwordError, setPasswordError] = useState(false);
   const [hasBasic, setHasBasic] = useState(true);
@@ -118,6 +119,18 @@ const Register: React.FC<Props> = ({
     };
   }, [email, password, firstName, lastName]);
 
+  useEffect(() => {
+    let qs = window.location.search;
+    let urlParams = new URLSearchParams(qs);
+    let email = urlParams.get('email');
+    
+    if (email) {
+      setEmail(email);
+      setDisabled(true);
+    }
+    
+  }, []);
+
   useEffect(() => {
 
     // Get capabilities to case on login methods
@@ -273,6 +286,7 @@ const Register: React.FC<Props> = ({
               width="100%"
               height="40px"
               error={(emailError && "Please enter a valid email")}
+              disabled={disabled}
             />
             <Spacer y={1} />
             <Input