Преглед изворни кода

sanitize periods in repository names (#3383)

ianedwards пре 2 година
родитељ
комит
c29c13a68e

+ 2 - 1
api/server/handlers/registry/create_repository.go

@@ -48,7 +48,8 @@ func (p *RegistryCreateRepositoryHandler) ServeHTTP(w http.ResponseWriter, r *ht
 
 	// parse the name from the registry
 	nameSpl := strings.Split(request.ImageRepoURI, "/")
-	repoName := strings.ToLower(strings.ReplaceAll(nameSpl[len(nameSpl)-1], "_", "-"))
+	sanitizedName := strings.ReplaceAll(strings.ReplaceAll(nameSpl[len(nameSpl)-1], "_", "-"), ".", "-")
+	repoName := strings.ToLower(sanitizedName)
 	telemetry.WithAttributes(span,
 		telemetry.AttributeKV{Key: "repo-name", Value: repoName},
 		telemetry.AttributeKV{Key: "registry-id", Value: reg.ID},

+ 1 - 1
cli/cmd/preview/build_image_driver.go

@@ -105,7 +105,7 @@ func (d *BuildDriver) Apply(resource *models.Resource) (*models.Resource, error)
 
 	if repoName := os.Getenv("PORTER_REPO_NAME"); repoName != "" {
 		if repoOwner := os.Getenv("PORTER_REPO_OWNER"); repoOwner != "" {
-			repoSuffix = strings.ToLower(strings.ReplaceAll(fmt.Sprintf("%s-%s", repoOwner, repoName), "_", "-"))
+			repoSuffix = sanitizedRepoSuffix(repoOwner, repoName)
 		}
 	}
 

+ 1 - 2
cli/cmd/preview/push_image_driver.go

@@ -4,7 +4,6 @@ import (
 	"context"
 	"fmt"
 	"os"
-	"strings"
 
 	"github.com/mitchellh/mapstructure"
 	"github.com/porter-dev/porter/api/types"
@@ -92,7 +91,7 @@ func (d *PushDriver) Apply(resource *models.Resource) (*models.Resource, error)
 
 		if repoName := os.Getenv("PORTER_REPO_NAME"); repoName != "" {
 			if repoOwner := os.Getenv("PORTER_REPO_OWNER"); repoOwner != "" {
-				repoSuffix = strings.ToLower(strings.ReplaceAll(fmt.Sprintf("%s-%s", repoOwner, repoName), "_", "-"))
+				repoSuffix = sanitizedRepoSuffix(repoOwner, repoName)
 			}
 		}
 

+ 1 - 1
cli/cmd/preview/update_config_driver.go

@@ -114,7 +114,7 @@ func (d *UpdateConfigDriver) Apply(resource *models.Resource) (*models.Resource,
 
 	if repoName := os.Getenv("PORTER_REPO_NAME"); repoName != "" {
 		if repoOwner := os.Getenv("PORTER_REPO_OWNER"); repoOwner != "" {
-			repoSuffix = strings.ToLower(strings.ReplaceAll(fmt.Sprintf("%s-%s", repoOwner, repoName), "_", "-"))
+			repoSuffix = sanitizedRepoSuffix(repoOwner, repoName)
 		}
 	}
 

+ 12 - 0
cli/cmd/preview/util.go

@@ -0,0 +1,12 @@
+package preview
+
+import (
+	"fmt"
+	"strings"
+)
+
+func sanitizedRepoSuffix(repoOwner, repoName string) string {
+	initialSuffix := fmt.Sprintf("%s-%s", repoOwner, repoName)
+	sanitizedSuffix := strings.ReplaceAll(strings.ReplaceAll(initialSuffix, "_", "-"), ".", "-")
+	return strings.ToLower(sanitizedSuffix)
+}

+ 1 - 1
internal/integrations/ci/actions/steps.go

@@ -57,7 +57,7 @@ func getCreatePreviewEnvStep(
 			"project": fmt.Sprintf("%d", projectID),
 			"token":   fmt.Sprintf("${{ secrets.%s }}", porterTokenSecretName),
 			"namespace": fmt.Sprintf("pr-${{ github.event.inputs.pr_number }}-%s",
-				strings.ToLower(strings.ReplaceAll(repoName, "_", "-"))),
+				strings.ToLower(strings.ReplaceAll(strings.ReplaceAll(repoName, "_", "-"), ".", "-"))),
 			"pr_id":           "${{ github.event.inputs.pr_number }}",
 			"pr_name":         "${{ github.event.inputs.pr_title }}",
 			"installation_id": fmt.Sprintf("%d", gitInstallationID),