Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1282 from weaveworks/issue/1277-allow-later-colons
Browse files Browse the repository at this point in the history
Allow colons in the name component of resource IDs
  • Loading branch information
squaremo authored Aug 10, 2018
2 parents 8f995fa + 86d999b commit 082bbe8
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
11 changes: 8 additions & 3 deletions flux.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ import (
var (
ErrInvalidServiceID = errors.New("invalid service ID")

LegacyServiceIDRegexp = regexp.MustCompile("^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$")
ResourceIDRegexp = regexp.MustCompile("^([a-zA-Z0-9_-]+):([a-zA-Z0-9_-]+)/([a-zA-Z0-9_.-]+)$")
UnqualifiedResourceIDRegexp = regexp.MustCompile("^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_.-]+)$")
LegacyServiceIDRegexp = regexp.MustCompile("^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$")
// The namespace and name commponents are (apparently
// non-normatively) defined in
// https://github.com/kubernetes/community/blob/master/contributors/design-proposals/architecture/identifiers.md
// In practice, more punctuation is used than allowed there;
// specifically, people use underscores as well as dashes and dots, and in names, colons.
ResourceIDRegexp = regexp.MustCompile("^([a-zA-Z0-9_-]+):([a-zA-Z0-9_-]+)/([a-zA-Z0-9_.:-]+)$")
UnqualifiedResourceIDRegexp = regexp.MustCompile("^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_.:-]+)$")
)

// ResourceID is an opaque type which uniquely identifies a resource in an
Expand Down
38 changes: 38 additions & 0 deletions resourceid_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package flux

import (
"testing"
)

func TestResourceIDParsing(t *testing.T) {
type test struct {
name, id string
}
valid := []test{
{"full", "namespace:kind/name"},
{"legacy", "namespace/service"},
{"dots", "namespace:kind/name.with.dots"},
{"colons", "namespace:kind/name:with:colons"},
{"punctuation in general", "name-space:ki_nd/punc_tu:a.tion-rules"},
}
invalid := []test{
{"unqualified", "justname"},
{"dots in namespace", "name.space:kind/name"},
{"too many colons", "namespace:kind:name"},
}

for _, tc := range valid {
t.Run(tc.name, func(t *testing.T) {
if _, err := ParseResourceID(tc.id); err != nil {
t.Error(err)
}
})
}
for _, tc := range invalid {
t.Run(tc.name, func(t *testing.T) {
if _, err := ParseResourceID(tc.id); err == nil {
t.Errorf("expected %q to be considered invalid", tc.id)
}
})
}
}

0 comments on commit 082bbe8

Please sign in to comment.