فهرست منبع

fix gar pull requests

Mohammed Nafees 3 سال پیش
والد
کامیت
77a90bf9b0
4فایلهای تغییر یافته به همراه55 افزوده شده و 51 حذف شده
  1. 10 8
      cli/cmd/deploy/create.go
  2. 13 0
      cli/cmd/docker/auth.go
  3. 31 0
      internal/helm/postrenderer.go
  4. 1 43
      internal/registry/registry.go

+ 10 - 8
cli/cmd/deploy/create.go

@@ -411,15 +411,17 @@ func (c *CreateAgent) GetImageRepoURL(name, namespace string) (uint, string, err
 	var regID uint
 
 	for _, reg := range registries {
-		if c.CreateOpts.RegistryURL != "" && c.CreateOpts.RegistryURL == reg.URL {
-			regID = reg.ID
-			if c.CreateOpts.RepoSuffix != "" {
-				imageURI = fmt.Sprintf("%s/%s-%s", reg.URL, name, c.CreateOpts.RepoSuffix)
-			} else {
-				imageURI = fmt.Sprintf("%s/%s-%s", reg.URL, name, namespace)
-			}
+		if c.CreateOpts.RegistryURL != "" {
+			if c.CreateOpts.RegistryURL == reg.URL {
+				regID = reg.ID
+				if c.CreateOpts.RepoSuffix != "" {
+					imageURI = fmt.Sprintf("%s/%s-%s", reg.URL, name, c.CreateOpts.RepoSuffix)
+				} else {
+					imageURI = fmt.Sprintf("%s/%s-%s", reg.URL, name, namespace)
+				}
 
-			break
+				break
+			}
 		} else if reg.URL != "" {
 			regID = reg.ID
 

+ 13 - 0
cli/cmd/docker/auth.go

@@ -6,6 +6,7 @@ import (
 	"encoding/json"
 	"fmt"
 	"io/ioutil"
+	"net/url"
 	"os"
 	"path/filepath"
 	"regexp"
@@ -106,6 +107,18 @@ func (a *AuthGetter) GetGARCredentials(serverURL string, projID uint) (user stri
 
 	cachedEntry := a.Cache.Get(serverURL)
 
+	if !strings.HasPrefix(serverURL, "https://") {
+		serverURL = "https://" + serverURL
+	}
+
+	parsedURL, err := url.Parse(serverURL)
+
+	if err != nil {
+		return "", "", err
+	}
+
+	serverURL = parsedURL.Host + "/" + strings.Split(parsedURL.Path, "/")[0]
+
 	var token string
 
 	if cachedEntry != nil && cachedEntry.IsValid(time.Now()) {

+ 31 - 0
internal/helm/postrenderer.go

@@ -12,6 +12,7 @@ import (
 	"github.com/aws/aws-sdk-go/aws/arn"
 	"github.com/porter-dev/porter/internal/kubernetes"
 	"github.com/porter-dev/porter/internal/models"
+	"github.com/porter-dev/porter/internal/models/integrations"
 	"github.com/porter-dev/porter/internal/repository"
 	"golang.org/x/oauth2"
 	"gopkg.in/yaml.v2"
@@ -515,6 +516,36 @@ func (d *DockerSecretsPostRenderer) isRegistryNative(regName string) bool {
 		}
 
 		isNative = parsedARN.AccountID == eksAccountID && parsedARN.Region == eksRegion
+	} else if strings.Contains(regName, "pkg.dev") && d.Cluster.AuthMechanism == models.GCP {
+		// get the project id of the cluster
+		gcpInt, err := d.Repo.GCPIntegration().ReadGCPIntegration(d.Cluster.ProjectID, d.Cluster.GCPIntegrationID)
+
+		if err != nil {
+			return false
+		}
+
+		gkeProjectID, err := integrations.GCPProjectIDFromJSON(gcpInt.GCPKeyData)
+
+		if err != nil {
+			return false
+		}
+
+		regURL := regName
+
+		if !strings.HasSuffix(regURL, "https://") {
+			regURL = "https://" + regURL
+		}
+
+		parsedURL, err := url.Parse(regURL)
+
+		if err != nil {
+			return false
+		}
+
+		// parse the project id of the gcr url
+		regNameSlice := strings.Split(parsedURL.Path, "/")
+
+		isNative = gkeProjectID == regNameSlice[0]
 	}
 
 	return isNative

+ 1 - 43
internal/registry/registry.go

@@ -1476,11 +1476,7 @@ func (r *Registry) GetDockerConfigJSON(
 	}
 
 	if r.GCPIntegrationID != 0 {
-		if strings.Contains(r.URL, "pkg.dev") {
-			conf, err = r.getGARDockerConfigFile(repo)
-		} else {
-			conf, err = r.getGCRDockerConfigFile(repo)
-		}
+		conf, err = r.getGCRDockerConfigFile(repo)
 	}
 
 	if r.DOIntegrationID != 0 {
@@ -1590,44 +1586,6 @@ func (r *Registry) getGCRDockerConfigFile(
 	}, nil
 }
 
-func (r *Registry) getGARDockerConfigFile(
-	repo repository.Repository,
-) (*configfile.ConfigFile, error) {
-	gcp, err := repo.GCPIntegration().ReadGCPIntegration(
-		r.ProjectID,
-		r.GCPIntegrationID,
-	)
-
-	if err != nil {
-		return nil, err
-	}
-
-	key := r.URL
-
-	tok, err := gcp.GetBearerToken(r.getTokenCacheFunc(repo), r.setTokenCacheFunc(repo),
-		"https://www.googleapis.com/auth/cloud-platform")
-
-	if err != nil {
-		return nil, err
-	}
-
-	if !strings.Contains(key, "http") {
-		key = "https://" + key
-	}
-
-	parsedURL, _ := url.Parse(key)
-
-	return &configfile.ConfigFile{
-		AuthConfigs: map[string]types.AuthConfig{
-			parsedURL.Host: {
-				Username: "oauth2accesstoken",
-				Password: tok.AccessToken,
-				Auth:     generateAuthToken("oauth2accesstoken", tok.AccessToken),
-			},
-		},
-	}, nil
-}
-
 func (r *Registry) getDOCRDockerConfigFile(
 	repo repository.Repository,
 	doAuth *oauth2.Config,