Skip to content

Commit

Permalink
refactor(cr): validate stages storage repo address
Browse files Browse the repository at this point in the history
Signed-off-by: Alexey Igrychev <alexey.igrychev@flant.com>
  • Loading branch information
alexey-igrychev committed Apr 4, 2022
1 parent b3f99ae commit abffc62
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/docker_registry/api.go
Expand Up @@ -8,6 +8,7 @@ import (
"math/rand"
"net/http"
"os"
"regexp"
"strings"
"time"

Expand Down Expand Up @@ -379,6 +380,15 @@ func (api *api) parseReferenceParts(reference string) (referenceParts, error) {
return referenceParts, nil
}

func ValidateRepositoryReference(reference string) error {
reg := regexp.MustCompile(`^` + dockerReference.NameRegexp.String() + `$`)
if !reg.MatchString(reference) {
return fmt.Errorf("invalid repository address %q", reference)
}

return nil
}

func IsStatusNotFoundErr(err error) bool {
var transportError *transport.Error
if errors.As(err, &transportError) && transportError.StatusCode == 404 {
Expand Down
4 changes: 4 additions & 0 deletions pkg/docker_registry/docker_registry.go
Expand Up @@ -102,6 +102,10 @@ func NewDockerRegistry(repositoryAddress string, implementation string, options
}

func newDockerRegistry(repositoryAddress string, implementation string, options DockerRegistryOptions) (Interface, error) {
if err := ValidateRepositoryReference(repositoryAddress); err != nil {
return nil, err
}

switch implementation {
case AwsEcrImplementationName:
return newAwsEcr(options.awsEcrOptions())
Expand Down

0 comments on commit abffc62

Please sign in to comment.