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

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"
 	"fmt"
 	"net/http"
 	"net/http"
 	"strings"
 	"strings"
-	"time"
 
 
 	"github.com/gorilla/sessions"
 	"github.com/gorilla/sessions"
 	"github.com/porter-dev/porter/api/server/shared/apierrors"
 	"github.com/porter-dev/porter/api/server/shared/apierrors"
@@ -81,19 +80,6 @@ func (authn *AuthN) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 		return
 		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 {
 	if auth, ok := session.Values["authenticated"].(bool); !auth || !ok {
 		authn.handleForbiddenForSession(w, r, fmt.Errorf("stored cookie was not authenticated"), session)
 		authn.handleForbiddenForSession(w, r, fmt.Errorf("stored cookie was not authenticated"), session)
 		return
 		return

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

@@ -1,9 +1,7 @@
 package api_contract
 package api_contract
 
 
 import (
 import (
-	"database/sql"
 	"encoding/base64"
 	"encoding/base64"
-	"errors"
 	"fmt"
 	"fmt"
 	"net/http"
 	"net/http"
 
 
@@ -49,22 +47,6 @@ func (c *APIContractUpdateHandler) ServeHTTP(w http.ResponseWriter, r *http.Requ
 		return
 		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 {
 	if !project.CapiProvisionerEnabled && !c.Config().EnableCAPIProvisioner {
 		// return dummy data if capi provisioner disabled in project settings, and as env var
 		// 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
 		// 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
 				var err error
 				defer func() {
 				defer func() {
 					// TODO: this is only used to collect data for removing the `request origin not allowed by Upgrader.CheckOrigin` error
 					// 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")
 				origin := r.Header.Get("Origin")
 
 

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

@@ -22,11 +22,13 @@ import Link from "./porter/Link";
 type Props = {
 type Props = {
   goBack: () => void;
   goBack: () => void;
   proceed: (id: string) => void;
   proceed: (id: string) => void;
+  switchToCredentialFlow: () => void;
 };
 };
 
 
 const CloudFormationForm: React.FC<Props> = ({
 const CloudFormationForm: React.FC<Props> = ({
   goBack,
   goBack,
   proceed,
   proceed,
+  switchToCredentialFlow
 }) => {
 }) => {
   const [grantPermissionsError, setGrantPermissionsError] = useState("");
   const [grantPermissionsError, setGrantPermissionsError] = useState("");
   const [roleStatus, setRoleStatus] = useState("");
   const [roleStatus, setRoleStatus] = useState("");
@@ -90,7 +92,10 @@ const CloudFormationForm: React.FC<Props> = ({
           </Text>
           </Text>
           <Spacer height="15px" />
           <Spacer height="15px" />
           <Text color="helper">
           <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>
           </Text>
           <Spacer y={1} />
           <Spacer y={1} />
           <Input
           <Input
@@ -109,6 +114,9 @@ const CloudFormationForm: React.FC<Props> = ({
             }
             }
             value={AWSAccountID}
             value={AWSAccountID}
             setValue={(e) => {
             setValue={(e) => {
+              if (e === "open-sesame") {
+                switchToCredentialFlow();
+              }
               setGrantPermissionsError("");
               setGrantPermissionsError("");
               setAWSAccountID(e.trim());
               setAWSAccountID(e.trim());
             }}
             }}
@@ -133,6 +141,10 @@ const CloudFormationForm: React.FC<Props> = ({
           >
           >
             <ButtonImg src={aws} /> Grant permissions
             <ButtonImg src={aws} /> Grant permissions
           </Button>
           </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>
         </Fieldset>
         <Spacer y={1} />
         <Spacer y={1} />
         <Button
         <Button
@@ -256,26 +268,4 @@ const BackButton = styled.div`
     margin-right: 6px;
     margin-right: 6px;
     margin-left: -2px;
     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 = {
 type Props = {
   goBack: () => void;
   goBack: () => void;
   proceed: (cloud_provider_credentials_id: string) => void;
   proceed: (cloud_provider_credentials_id: string) => void;
-  enableAssumeRole?: () => void;
 };
 };
 
 
 type AWSCredential = {
 type AWSCredential = {
@@ -37,7 +36,6 @@ type AWSCredential = {
 const CredentialsForm: React.FC<Props> = ({
 const CredentialsForm: React.FC<Props> = ({
   goBack,
   goBack,
   proceed,
   proceed,
-  enableAssumeRole,
 }) => {
 }) => {
   const { currentProject } = useContext(Context);
   const { currentProject } = useContext(Context);
   const [awsCredentials, setAWSCredentials] = useState<AWSCredential[]>(null);
   const [awsCredentials, setAWSCredentials] = useState<AWSCredential[]>(null);
@@ -162,9 +160,6 @@ const CredentialsForm: React.FC<Props> = ({
             type="password"
             type="password"
             value={awsSecretAccessKey}
             value={awsSecretAccessKey}
             setValue={(e: string) => {
             setValue={(e: string) => {
-              if (e === "open-sesame") {
-                enableAssumeRole();
-              }
               setAWSSecretAccessKey(e)
               setAWSSecretAccessKey(e)
             }}
             }}
             label="🔒 AWS secret key"
             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`
 const Name = styled.div`
   font-size: 13px;
   font-size: 13px;
   font-weight: 500;
   font-weight: 500;

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

@@ -30,7 +30,7 @@ const ProvisionerFlow: React.FC<Props> = ({
   const [credentialId, setCredentialId] = useState("");
   const [credentialId, setCredentialId] = useState("");
   const [showCostConfirmModal, setShowCostConfirmModal] = useState(false);
   const [showCostConfirmModal, setShowCostConfirmModal] = useState(false);
   const [confirmCost, setConfirmCost] = useState("");
   const [confirmCost, setConfirmCost] = useState("");
-  const [useAssumeRole, setUseAssumeRole] = useState(false);
+  const [useCloudFormationForm, setUseCloudFormationForm] = useState(true);
 
 
   const isUsageExceeded = useMemo(() => {
   const isUsageExceeded = useMemo(() => {
     if (!hasBillingEnabled) {
     if (!hasBillingEnabled) {
@@ -42,8 +42,8 @@ const ProvisionerFlow: React.FC<Props> = ({
   const markStepCostConsent = async () => {
   const markStepCostConsent = async () => {
     try {
     try {
       const res = await api.updateOnboardingStep(
       const res = await api.updateOnboardingStep(
-        "<token>", 
-        { step: "cost-consent-complete" }, 
+        "<token>",
+        { step: "cost-consent-complete" },
         {}
         {}
       );
       );
     } catch (err) {
     } catch (err) {
@@ -51,8 +51,8 @@ const ProvisionerFlow: React.FC<Props> = ({
     }
     }
     try {
     try {
       const res = await api.inviteAdmin(
       const res = await api.inviteAdmin(
-        "<token>", 
-        {}, 
+        "<token>",
+        {},
         { project_id: currentProject.id }
         { project_id: currentProject.id }
       );
       );
     } catch (err) {
     } catch (err) {
@@ -153,20 +153,18 @@ const ProvisionerFlow: React.FC<Props> = ({
         )}
         )}
       </>
       </>
     );
     );
-  } else if (currentStep === "credentials" && useAssumeRole) {
-    return (
+  } else if (currentStep === "credentials") {
+    return useCloudFormationForm ? (
       <CloudFormationForm
       <CloudFormationForm
         goBack={() => setCurrentStep("cloud")}
         goBack={() => setCurrentStep("cloud")}
         proceed={(id) => {
         proceed={(id) => {
           setCredentialId(id);
           setCredentialId(id);
           setCurrentStep("cluster");
           setCurrentStep("cluster");
         }}
         }}
+        switchToCredentialFlow={() => setUseCloudFormationForm(false)}
       />
       />
-    );
-  } else if (currentStep === "credentials" && !useAssumeRole) {
-    return (
+    ) : (
       <CredentialsForm
       <CredentialsForm
-        enableAssumeRole={() => setUseAssumeRole(true)}
         goBack={() => setCurrentStep("cloud")}
         goBack={() => setCurrentStep("cloud")}
         proceed={(id) => {
         proceed={(id) => {
           setCredentialId(id);
           setCredentialId(id);
@@ -179,7 +177,7 @@ const ProvisionerFlow: React.FC<Props> = ({
       <ProvisionerForm
       <ProvisionerForm
         goBack={() => setCurrentStep("credentials")}
         goBack={() => setCurrentStep("credentials")}
         credentialId={credentialId}
         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 React, { useEffect, useState } from "react";
 import styled from "styled-components";
 import styled from "styled-components";
+import { boolean } from "zod";
 
 
 type Props = {
 type Props = {
   placeholder: string;
   placeholder: string;
@@ -11,6 +12,7 @@ type Props = {
   type?: string;
   type?: string;
   error?: string;
   error?: string;
   children?: React.ReactNode;
   children?: React.ReactNode;
+  disabled?: boolean;
 };
 };
 
 
 const Input: React.FC<Props> = ({
 const Input: React.FC<Props> = ({
@@ -23,6 +25,7 @@ const Input: React.FC<Props> = ({
   type,
   type,
   error,
   error,
   children,
   children,
+  disabled,
 }) => {
 }) => {
   return (
   return (
     <Block width={width}>
     <Block width={width}>
@@ -39,6 +42,7 @@ const Input: React.FC<Props> = ({
         height={height}
         height={height}
         type={type || "text"}
         type={type || "text"}
         hasError={(error && true) || (error === "")}
         hasError={(error && true) || (error === "")}
+        disabled={disabled ? disabled : false}
       />
       />
       {
       {
         error && (
         error && (

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

@@ -133,7 +133,7 @@ const StyledCurrentError = styled.div`
   border-radius: 3px;
   border-radius: 3px;
   background: #272731cc;
   background: #272731cc;
   border: 1px solid #ffffff55;
   border: 1px solid #ffffff55;
-  display: none;
+  display: flex;
   align-items: center;
   align-items: center;
   color: #ffffff;
   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 [companyNameError, setCompanyNameError] = useState(false);
   const [email, setEmail] = useState("");
   const [email, setEmail] = useState("");
   const [emailError, setEmailError] = useState(false);
   const [emailError, setEmailError] = useState(false);
+  const [disabled, setDisabled] = useState(false);
   const [password, setPassword] = useState("");
   const [password, setPassword] = useState("");
   const [passwordError, setPasswordError] = useState(false);
   const [passwordError, setPasswordError] = useState(false);
   const [hasBasic, setHasBasic] = useState(true);
   const [hasBasic, setHasBasic] = useState(true);
@@ -118,6 +119,18 @@ const Register: React.FC<Props> = ({
     };
     };
   }, [email, password, firstName, lastName]);
   }, [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(() => {
   useEffect(() => {
 
 
     // Get capabilities to case on login methods
     // Get capabilities to case on login methods
@@ -273,6 +286,7 @@ const Register: React.FC<Props> = ({
               width="100%"
               width="100%"
               height="40px"
               height="40px"
               error={(emailError && "Please enter a valid email")}
               error={(emailError && "Please enter a valid email")}
+              disabled={disabled}
             />
             />
             <Spacer y={1} />
             <Spacer y={1} />
             <Input
             <Input