Browse Source

add docker config

Mohammed Nafees 3 years ago
parent
commit
cb20da80de
1 changed files with 36 additions and 1 deletions
  1. 36 1
      internal/registry/registry.go

+ 36 - 1
internal/registry/registry.go

@@ -1476,7 +1476,11 @@ func (r *Registry) GetDockerConfigJSON(
 	}
 
 	if r.GCPIntegrationID != 0 {
-		conf, err = r.getGCRDockerConfigFile(repo)
+		if strings.Contains(r.URL, "pkg.dev") {
+			conf, err = r.getGARDockerConfigFile(repo)
+		} else {
+			conf, err = r.getGCRDockerConfigFile(repo)
+		}
 	}
 
 	if r.DOIntegrationID != 0 {
@@ -1586,6 +1590,37 @@ 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
+
+	if !strings.Contains(key, "http") {
+		key = "https://" + key
+	}
+
+	parsedURL, _ := url.Parse(key)
+
+	return &configfile.ConfigFile{
+		AuthConfigs: map[string]types.AuthConfig{
+			parsedURL.Host: {
+				Username: "_json_key",
+				Password: string(gcp.GCPKeyData),
+				Auth:     generateAuthToken("_json_key", string(gcp.GCPKeyData)),
+			},
+		},
+	}, nil
+}
+
 func (r *Registry) getDOCRDockerConfigFile(
 	repo repository.Repository,
 	doAuth *oauth2.Config,