Skip to content

Commit 98b2502

Browse files
authored
Merge pull request #435 from docker/x/secrets/id
feat: support colon ':' in secret ID
2 parents 0366099 + 93ed4b4 commit 98b2502

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

x/secrets/identifiers.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ type ErrInvalidID struct {
1010
}
1111

1212
func (e ErrInvalidID) Error() string {
13-
return fmt.Sprintf("invalid identifier: %q must match [A-Za-z0-9.-]+(/[A-Za-z0-9.-]+)*?", e.ID)
13+
return fmt.Sprintf("invalid identifier: %q must match ^[A-Za-z0-9._:-]+(?:/[A-Za-z0-9._:-]+)*$", e.ID)
1414
}
1515

1616
// validIdentifier checks if an identifier is valid without using regexp or unicode.
1717
// Rules:
1818
// - Components separated by '/'
1919
// - Each component is non-empty
20-
// - Only characters A-Z, a-z, 0-9, '.', '_' or '-'
20+
// - Only characters A-Z, a-z, 0-9, '.', '_', '-' or ':'
2121
// - No leading, trailing, or double slashes
2222
func validIdentifier(s string) bool {
2323
if len(s) == 0 {
@@ -49,7 +49,7 @@ func isValidRune(c rune) bool {
4949
return (c >= 'A' && c <= 'Z') ||
5050
(c >= 'a' && c <= 'z') ||
5151
(c >= '0' && c <= '9') ||
52-
c == '.' || c == '-' || c == '_'
52+
c == '.' || c == '-' || c == '_' || c == ':'
5353
}
5454

5555
func split(s string) []string {
@@ -108,7 +108,7 @@ func valid(id string) error {
108108
}
109109

110110
// ID contains a secret identifier.
111-
// Valid secret identifiers must match the format [A-Za-z0-9.-]+(/[A-Za-z0-9.-]+)+?.
111+
// Valid secret identifiers must match the format ^[A-Za-z0-9._:-]+(?:/[A-Za-z0-9._:-]+)*$.
112112
//
113113
// For storage, we don't really differentiate much about the ID format but
114114
// by convention we do simple, slash-separated management, providing a
@@ -142,7 +142,7 @@ func (i id) String() string {
142142
// Rules:
143143
// - Components separated by '/'
144144
// - Each component is non-empty
145-
// - Only characters A-Z, a-z, 0-9, '.', '_' or '-'
145+
// - Only characters A-Z, a-z, 0-9, '.', '_', '-' or ':'
146146
// - No leading, trailing, or double slashes
147147
func ParseID(s string) (ID, error) {
148148
if err := valid(s); err != nil {

x/secrets/identifiers_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ func TestParseIDNew(t *testing.T) {
1616
{"valid name with dot", "my.secretA9", nil},
1717
{"valid name with slash", "my/secret", nil},
1818
{"valid name with underscore", "my_secretA9", nil},
19+
{"valid name with colon", "127.0.0.1:8080", nil},
1920
{"invalid name with trailing slash", "my/secret/", ErrInvalidID{"my/secret/"}},
2021
{"invalid name with leading slash", "/my/secret", ErrInvalidID{"/my/secret"}},
2122
{"invalid name with empty component", "my//secret", ErrInvalidID{"my//secret"}},
22-
{"invalid name with colon", "my:secret", ErrInvalidID{"my:secret"}},
2323
{"invalid name with space", "my secret", ErrInvalidID{"my secret"}},
2424
{"invalid name with hashtag", "my#secret", ErrInvalidID{"my#secret"}},
2525
}
@@ -98,6 +98,11 @@ func TestMatchNew(t *testing.T) {
9898
ids: []string{"com.test.test/test/bob", "com.test.test/test/alice"},
9999
expected: true,
100100
},
101+
{
102+
pattern: "foo/127.0.0.1:8080/**",
103+
ids: []string{"foo/127.0.0.1:8080/bob", "foo/127.0.0.1:8080/jeff/test"},
104+
expected: true,
105+
},
101106
}
102107
for _, tc := range tests {
103108
t.Run(tc.pattern, func(t *testing.T) {

0 commit comments

Comments
 (0)