Răsfoiți Sursa

Log the external id in analytics (#3251)

Feroze Mohideen 2 ani în urmă
părinte
comite
6bb9d6aa37

+ 2 - 0
api/server/handlers/user/update_onboarding_step.go

@@ -87,6 +87,7 @@ func (v *UpdateOnboardingStepHandler) ServeHTTP(w http.ResponseWriter, r *http.R
 			CompanyName:         user.CompanyName,
 			AccountId:           request.AccountId,
 			CloudformationURL:   request.CloudformationURL,
+			ExternalId:          request.ExternalId,
 		}))
 	}
 
@@ -110,6 +111,7 @@ func (v *UpdateOnboardingStepHandler) ServeHTTP(w http.ResponseWriter, r *http.R
 			CompanyName:         user.CompanyName,
 			AccountId:           request.AccountId,
 			ErrorMessage:        request.ErrorMessage,
+			ExternalId:          request.ExternalId,
 		}))
 	}
 

+ 2 - 0
api/types/user.go

@@ -88,4 +88,6 @@ type UpdateOnboardingStepRequest struct {
 	CloudformationURL string `json:"cloudformation_url"`
 	ErrorMessage      string `json:"error_message"`
 	LoginURL          string `json:"login_url"`
+	// used as a 'password' for the aws assume role chain to porter-manager role
+	ExternalId string `json:"external_id"`
 }

+ 12 - 21
dashboard/src/components/CloudFormationForm.tsx

@@ -29,7 +29,6 @@ const CloudFormationForm: React.FC<Props> = ({
   switchToCredentialFlow
 }) => {
   const [hasSentAWSNotif, setHasSentAWSNotif] = useState(false);
-  const [grantPermissionsError, setGrantPermissionsError] = useState("");
   const [roleStatus, setRoleStatus] = useState("");
   const [errorMessage, setErrorMessage] = useState<string | undefined>(undefined);
   const [AWSAccountID, setAWSAccountID] = useState("");
@@ -44,17 +43,19 @@ const CloudFormationForm: React.FC<Props> = ({
       cloudformation_url = "",
       error_message = "",
       login_url = "",
+      external_id = "",
     }:
       {
         step: string;
-        account_id?: string
-        cloudformation_url?: string
-        error_message?: string
-        login_url?: string
+        account_id?: string;
+        cloudformation_url?: string;
+        error_message?: string;
+        login_url?: string;
+        external_id?: string;
       }
   ) => {
     try {
-      await api.updateOnboardingStep("<token>", { step, account_id, cloudformation_url, error_message, login_url }, {});
+      await api.updateOnboardingStep("<token>", { step, account_id, cloudformation_url, error_message, login_url, external_id }, {});
     } catch (err) {
       // console.log(err);
     }
@@ -136,7 +137,8 @@ const CloudFormationForm: React.FC<Props> = ({
         step: "aws-create-integration-failure",
         account_id: AWSAccountID,
         error_message: err?.response?.data?.error ??
-          err?.toString() ?? "unable to determine error - check honeycomb"
+          err?.toString() ?? "unable to determine error - check honeycomb",
+        external_id: externalId,
       })
     }
   };
@@ -149,10 +151,10 @@ const CloudFormationForm: React.FC<Props> = ({
   }
 
   const directToCloudFormationAndProceedStep = () => {
-    let externalId = getExternalId();
+    const externalId = getExternalId();
     let trustArn = process.env.TRUST_ARN ? process.env.TRUST_ARN : "arn:aws:iam::108458755588:role/CAPIManagement";
     const cloudformation_url = `https://console.aws.amazon.com/cloudformation/home?#/stacks/create/review?templateURL=https://porter-role.s3.us-east-2.amazonaws.com/cloudformation-policy.json&stackName=PorterRole&param_ExternalIdParameter=${externalId}&param_TrustArnParameter=${trustArn}`
-    markStepStarted({ step: "aws-cloudformation-redirect-success", account_id: AWSAccountID, cloudformation_url })
+    markStepStarted({ step: "aws-cloudformation-redirect-success", account_id: AWSAccountID, cloudformation_url, external_id: externalId })
     setCurrentStep(3);
     window.open(cloudformation_url, "_blank")
   }
@@ -226,18 +228,7 @@ const CloudFormationForm: React.FC<Props> = ({
                   <ButtonImg src={aws} />
                   <Button
                     width={"170px"}
-                    onClick={() => {
-                      if (AWSAccountID.length === 12 && !isNaN(Number(AWSAccountID))) {
-                        directToCloudFormationAndProceedStep();
-                      } else {
-                        setGrantPermissionsError("Invalid AWS account ID");
-                      }
-                    }}
-                    status={
-                      grantPermissionsError && (
-                        <Error message={grantPermissionsError} />
-                      )
-                    }
+                    onClick={directToCloudFormationAndProceedStep}
                     color="#1E2631"
                     withBorder
                   >

+ 1 - 0
dashboard/src/shared/api.tsx

@@ -2452,6 +2452,7 @@ const updateOnboardingStep = baseApi<
     cloudformation_url?: string;
     error_message?: string;
     login_url?: string;
+    external_id?: string;
   },
   {}
 >("POST", (pathParams) => {

+ 4 - 0
internal/analytics/tracks.go

@@ -215,6 +215,7 @@ type AWSRedirectOpts struct {
 	AccountId         string
 	CloudformationURL string
 	LoginURL          string
+	ExternalId        string
 }
 
 // AWSCloudformationRedirectSuccess returns a track for when a user clicks 'grant permissions' and gets redirected to cloudformation
@@ -225,6 +226,7 @@ func AWSCloudformationRedirectSuccess(opts *AWSRedirectOpts) segmentTrack {
 	additionalProps["company"] = opts.CompanyName
 	additionalProps["account_id"] = opts.AccountId
 	additionalProps["cloudformation_url"] = opts.CloudformationURL
+	additionalProps["external_id"] = opts.ExternalId
 
 	return getSegmentUserTrack(
 		opts.UserScopedTrackOpts,
@@ -255,6 +257,7 @@ type AWSCreateIntegrationOpts struct {
 	LastName     string
 	CompanyName  string
 	AccountId    string
+	ExternalId   string
 	ErrorMessage string
 }
 
@@ -280,6 +283,7 @@ func AWSCreateIntegrationFailed(opts *AWSCreateIntegrationOpts) segmentTrack {
 	additionalProps["company"] = opts.CompanyName
 	additionalProps["account_id"] = opts.AccountId
 	additionalProps["error_message"] = opts.ErrorMessage
+	additionalProps["external_id"] = opts.ExternalId
 
 	return getSegmentUserTrack(
 		opts.UserScopedTrackOpts,