Skip to content

Commit

Permalink
Remove validations (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
ohkinozomu authored Nov 13, 2022
1 parent 21646d0 commit 9a67b21
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 64 deletions.
15 changes: 0 additions & 15 deletions ecr.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
package which_registry

import (
"errors"
"strings"

regions "github.com/jsonmaur/aws-regions/v2"
)

func isECRPublic(domain string) bool {
return domain == "public.ecr.aws"
}

func validateRegion(region string) error {
_, err := regions.LookupByCode(region)
if err != nil {
return errors.New("Invalid Region: " + region)
}
return nil
}

// https://docs.aws.amazon.com/AmazonECR/latest/userguide/Registries.html#registry_concepts
func isECRPrivate(d string) (bool, error) {
s := strings.Split(d, ".")
Expand All @@ -27,10 +16,6 @@ func isECRPrivate(d string) (bool, error) {
}

if s[1] == "dkr" && s[2] == "ecr" && s[4] == "amazonaws" && s[5] == "com" {
err := validateRegion(s[3])
if err != nil {
return false, err
}
return true, nil
}
return false, nil
Expand Down
19 changes: 0 additions & 19 deletions ecr_test.go

This file was deleted.

6 changes: 1 addition & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ module github.com/ohkinozomu/which-registry

go 1.19

require (
github.com/docker/distribution v2.8.1+incompatible
github.com/jsonmaur/aws-regions/v2 v2.3.1
github.com/ohkinozomu/gcp-regions v0.2.0
)
require github.com/docker/distribution v2.8.1+incompatible

require github.com/opencontainers/go-digest v1.0.0 // indirect
12 changes: 0 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
github.com/docker/distribution v2.8.0+incompatible h1:l9EaZDICImO1ngI+uTifW+ZYvvz7fKISBAKpg+MbWbY=
github.com/docker/distribution v2.8.0+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/docker/distribution v2.8.1+incompatible h1:Q50tZOPR6T/hjNsyc9g8/syEs6bk8XXApsHjKukMl68=
github.com/docker/distribution v2.8.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/jsonmaur/aws-regions/v2 v2.3.1 h1:WWt452LyhjI4ZCRKBSULVHqIGE8/9UqVQOSAzuc2woE=
github.com/jsonmaur/aws-regions/v2 v2.3.1/go.mod h1:NqtmZ2wG5HkrTYFQ+II3BDysj0yek59yjtZjAaCn8lE=
github.com/ohkinozomu/gcp-regions v0.0.1 h1:OCOCPyhwIGMR6ao0bwIMQwz5rDMDRLN9O2SH3kvzuyw=
github.com/ohkinozomu/gcp-regions v0.0.1/go.mod h1:a69vJkNVbFBMhvI68qO36vYNC76eG9eWWBtoXIz5AaY=
github.com/ohkinozomu/gcp-regions v0.0.2 h1:zEU4/ejggS7+a6J/vOPvAHj0Lv8DD1oRnJ4bRP1Y9kk=
github.com/ohkinozomu/gcp-regions v0.0.2/go.mod h1:a69vJkNVbFBMhvI68qO36vYNC76eG9eWWBtoXIz5AaY=
github.com/ohkinozomu/gcp-regions v0.1.0 h1:Pv9EYoJB0TKGXlAukbcl+o70k7BQMb2XllExNDb7hLE=
github.com/ohkinozomu/gcp-regions v0.1.0/go.mod h1:5FiT3E0SVumwPdrxQnJvVHiSCXqyC2UCWiz3fyiospQ=
github.com/ohkinozomu/gcp-regions v0.2.0 h1:+tctsMjvtmVSlGkFK6Gwq/kWwNY4SLDEdMcNo5XnKQY=
github.com/ohkinozomu/gcp-regions v0.2.0/go.mod h1:5FiT3E0SVumwPdrxQnJvVHiSCXqyC2UCWiz3fyiospQ=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
13 changes: 0 additions & 13 deletions google_artifact_registry.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
package which_registry

import (
"errors"
"regexp"
"strings"

regions "github.com/ohkinozomu/gcp-regions"
)

// https://cloud.google.com/artifact-registry/docs/repo-locations#location-mr
func isMultiRegion(l string) bool {
return l == "asia" || l == "europe" || l == "us"
}

// https://cloud.google.com/artifact-registry/docs/docker/pushing-and-pulling#tag
func isGoogleArtifactRegistry(d string) (bool, error) {
match, err := regexp.MatchString(".*-docker.pkg.dev", d)
Expand All @@ -21,10 +12,6 @@ func isGoogleArtifactRegistry(d string) (bool, error) {
}

if match {
location := strings.Replace(d, "-docker.pkg.dev", "", 1)
if !regions.IsValid(location) && !isMultiRegion(location) {
return false, errors.New("Invalid location: " + location)
}
return true, nil
}
return false, nil
Expand Down

0 comments on commit 9a67b21

Please sign in to comment.