ソースを参照

check if capi is enabled before running preflight checks (#2935)

check if capi is enabled before running preflight checks (#2935)

---------

Co-authored-by: David Townley <davidtownley@Davids-MacBook-Air.local>
dt3-5 3 年 前
コミット
aeca8e4919

+ 8 - 1
api/server/handlers/project_integration/preflight_check_aws_usage.go

@@ -29,8 +29,15 @@ func NewCreatePreflightCheckAWSUsageHandler(
 }
 
 func (p *CreatePreflightCheckAWSUsageHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
-	project, _ := r.Context().Value(types.ProjectScope).(*models.Project)
 	ctx := r.Context()
+	project, _ := ctx.Value(types.ProjectScope).(*models.Project)
+
+	if !p.Config().EnableCAPIProvisioner {
+		message := "Trying to run preflight checks but CAPI Provisioner is disabled. If you want to provision through CAPI, make sure that the environment variable ENABLE_CAPI_PROVISIONER is set to true"
+		e := fmt.Errorf(message)
+		p.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(e, http.StatusServiceUnavailable, message))
+		return
+	}
 
 	request := &types.QuotaPreflightCheckRequest{}
 	if ok := p.DecodeAndValidate(w, r, request); !ok {