Przeglądaj źródła

Merge branch 'nico/new-onboarding-flow' of github.com:porter-dev/porter into nico/new-onboarding-flow

jnfrati 4 lat temu
rodzic
commit
a6fe67d1b9

+ 19 - 4
api/server/handlers/gitinstallation/oauth_callback.go

@@ -3,6 +3,7 @@ package gitinstallation
 import (
 	"fmt"
 	"net/http"
+	"net/url"
 
 	"github.com/porter-dev/porter/api/server/handlers"
 	"github.com/porter-dev/porter/api/server/shared"
@@ -42,8 +43,15 @@ func (c *GithubAppOAuthCallbackHandler) ServeHTTP(w http.ResponseWriter, r *http
 	token, err := c.Config().GithubAppConf.Exchange(oauth2.NoContext, r.URL.Query().Get("code"))
 
 	if err != nil || !token.Valid() {
-		if session.Values["query_params"] != "" {
-			http.Redirect(w, r, fmt.Sprintf("/dashboard?%s", session.Values["query_params"]), 302)
+		if redirectStr, ok := session.Values["redirect_uri"].(string); ok && redirectStr != "" {
+			// attempt to parse the redirect uri, if it fails just redirect to dashboard
+			redirectURI, err := url.Parse(redirectStr)
+
+			if err != nil {
+				http.Redirect(w, r, "/dashboard", 302)
+			}
+
+			http.Redirect(w, r, fmt.Sprintf("%s?%s", redirectURI.Path, redirectURI.RawQuery), 302)
 		} else {
 			http.Redirect(w, r, "/dashboard", 302)
 		}
@@ -82,8 +90,15 @@ func (c *GithubAppOAuthCallbackHandler) ServeHTTP(w http.ResponseWriter, r *http
 		},
 	))
 
-	if session.Values["query_params"] != "" {
-		http.Redirect(w, r, fmt.Sprintf("/dashboard?%s", session.Values["query_params"]), 302)
+	if redirectStr, ok := session.Values["redirect_uri"].(string); ok && redirectStr != "" {
+		// attempt to parse the redirect uri, if it fails just redirect to dashboard
+		redirectURI, err := url.Parse(redirectStr)
+
+		if err != nil {
+			http.Redirect(w, r, "/dashboard", 302)
+		}
+
+		http.Redirect(w, r, fmt.Sprintf("%s?%s", redirectURI.Path, redirectURI.RawQuery), 302)
 	} else {
 		http.Redirect(w, r, "/dashboard", 302)
 	}

+ 1 - 1
api/server/handlers/handler.go

@@ -90,7 +90,7 @@ func (d *DefaultPorterHandler) PopulateOAuthSession(w http.ResponseWriter, r *ht
 
 	// need state parameter to validate when redirected
 	session.Values["state"] = state
-	session.Values["query_params"] = r.URL.RawQuery
+	session.Values["redirect_uri"] = r.URL.Query().Get("redirect_uri")
 
 	if isProject {
 		project, _ := r.Context().Value(types.ProjectScope).(*models.Project)

+ 10 - 2
api/server/handlers/oauth_callback/digitalocean.go

@@ -3,6 +3,7 @@ package oauth_callback
 import (
 	"fmt"
 	"net/http"
+	"net/url"
 
 	"github.com/porter-dev/porter/api/server/handlers"
 	"github.com/porter-dev/porter/api/server/shared"
@@ -78,8 +79,15 @@ func (p *OAuthCallbackDOHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
 		return
 	}
 
-	if session.Values["query_params"] != "" {
-		http.Redirect(w, r, fmt.Sprintf("/dashboard?%s", session.Values["query_params"]), 302)
+	if redirectStr, ok := session.Values["redirect_uri"].(string); ok && redirectStr != "" {
+		// attempt to parse the redirect uri, if it fails just redirect to dashboard
+		redirectURI, err := url.Parse(redirectStr)
+
+		if err != nil {
+			http.Redirect(w, r, "/dashboard", 302)
+		}
+
+		http.Redirect(w, r, fmt.Sprintf("%s?%s", redirectURI.Path, redirectURI.RawQuery), 302)
 	} else {
 		http.Redirect(w, r, "/dashboard", 302)
 	}

+ 10 - 2
api/server/handlers/oauth_callback/slack.go

@@ -4,6 +4,7 @@ import (
 	"context"
 	"fmt"
 	"net/http"
+	"net/url"
 
 	"github.com/porter-dev/porter/api/server/handlers"
 	"github.com/porter-dev/porter/api/server/shared"
@@ -69,8 +70,15 @@ func (p *OAuthCallbackSlackHandler) ServeHTTP(w http.ResponseWriter, r *http.Req
 		return
 	}
 
-	if session.Values["query_params"] != "" {
-		http.Redirect(w, r, fmt.Sprintf("/dashboard?%s", session.Values["query_params"]), 302)
+	if redirectStr, ok := session.Values["redirect_uri"].(string); ok && redirectStr != "" {
+		// attempt to parse the redirect uri, if it fails just redirect to dashboard
+		redirectURI, err := url.Parse(redirectStr)
+
+		if err != nil {
+			http.Redirect(w, r, "/dashboard", 302)
+		}
+
+		http.Redirect(w, r, fmt.Sprintf("%s?%s", redirectURI.Path, redirectURI.RawQuery), 302)
 	} else {
 		http.Redirect(w, r, "/dashboard", 302)
 	}

+ 9 - 2
api/server/handlers/user/github_callback.go

@@ -88,8 +88,15 @@ func (p *UserOAuthGithubCallbackHandler) ServeHTTP(w http.ResponseWriter, r *htt
 		startEmailVerification(p.Config(), w, r, user)
 	}
 
-	if session.Values["query_params"] != "" {
-		http.Redirect(w, r, fmt.Sprintf("/dashboard?%s", session.Values["query_params"]), 302)
+	if redirectStr, ok := session.Values["redirect_uri"].(string); ok && redirectStr != "" {
+		// attempt to parse the redirect uri, if it fails just redirect to dashboard
+		redirectURI, err := url.Parse(redirectStr)
+
+		if err != nil {
+			http.Redirect(w, r, "/dashboard", 302)
+		}
+
+		http.Redirect(w, r, fmt.Sprintf("%s?%s", redirectURI.Path, redirectURI.RawQuery), 302)
 	} else {
 		http.Redirect(w, r, "/dashboard", 302)
 	}

+ 9 - 2
api/server/handlers/user/google_callback.go

@@ -91,8 +91,15 @@ func (p *UserOAuthGoogleCallbackHandler) ServeHTTP(w http.ResponseWriter, r *htt
 		startEmailVerification(p.Config(), w, r, user)
 	}
 
-	if session.Values["query_params"] != "" {
-		http.Redirect(w, r, fmt.Sprintf("/dashboard?%s", session.Values["query_params"]), 302)
+	if redirectStr, ok := session.Values["redirect_uri"].(string); ok && redirectStr != "" {
+		// attempt to parse the redirect uri, if it fails just redirect to dashboard
+		redirectURI, err := url.Parse(redirectStr)
+
+		if err != nil {
+			http.Redirect(w, r, "/dashboard", 302)
+		}
+
+		http.Redirect(w, r, fmt.Sprintf("%s?%s", redirectURI.Path, redirectURI.RawQuery), 302)
 	} else {
 		http.Redirect(w, r, "/dashboard", 302)
 	}

+ 4 - 4
api/types/infra.go

@@ -39,17 +39,17 @@ type Infra struct {
 	Status InfraStatus `json:"status"`
 
 	// The AWS integration that was used to create the infra
-	AWSIntegrationID uint
+	AWSIntegrationID uint `json:"aws_integration_id,omitempty"`
 
 	// The GCP integration that was used to create the infra
-	GCPIntegrationID uint
+	GCPIntegrationID uint `json:"gcp_integration_id,omitempty"`
 
 	// The DO integration that was used to create the infra:
 	// this points to an OAuthIntegrationID
-	DOIntegrationID uint
+	DOIntegrationID uint `json:"do_integration_id,omitempty"`
 
 	// The last-applied, non-sensitive input variables to the provisioner. For now,
 	// this is a map[string]string since we marshal into env vars anyway, but
 	// eventually this config will be more complex.
-	LastApplied map[string]string
+	LastApplied map[string]string `json:"last_applied"`
 }

+ 13 - 0
api/types/registry.go

@@ -23,6 +23,19 @@ type Registry struct {
 
 	// The infra id, if registry was provisioned with Porter
 	InfraID uint `json:"infra_id"`
+
+	// The AWS integration that was used to create or connect the registry
+	AWSIntegrationID uint `json:"aws_integration_id,omitempty"`
+
+	// The GCP integration that was used to create or connect the registry
+	GCPIntegrationID uint `json:"gcp_integration_id,omitempty"`
+
+	// The DO integration that was used to create or connect the registry:
+	// this points to an OAuthIntegrationID
+	DOIntegrationID uint `json:"do_integration_id,omitempty"`
+
+	// The basic integration that was used to connect the registry:
+	BasicIntegrationID uint `json:"basic_integration_id,omitempty"`
 }
 
 // Repository is a collection of images

+ 10 - 6
internal/models/registry.go

@@ -59,11 +59,15 @@ func (r *Registry) ToRegistryType() *types.Registry {
 	}
 
 	return &types.Registry{
-		ID:        r.ID,
-		ProjectID: r.ProjectID,
-		Name:      r.Name,
-		URL:       uri,
-		Service:   serv,
-		InfraID:   r.InfraID,
+		ID:                 r.ID,
+		ProjectID:          r.ProjectID,
+		Name:               r.Name,
+		URL:                uri,
+		Service:            serv,
+		InfraID:            r.InfraID,
+		GCPIntegrationID:   r.GCPIntegrationID,
+		AWSIntegrationID:   r.AWSIntegrationID,
+		DOIntegrationID:    r.DOIntegrationID,
+		BasicIntegrationID: r.BasicIntegrationID,
 	}
 }