Skip to content

Commit d2386dc

Browse files
authored
feat: Reserve _chamber service (#520)
The service may still be used normally, but doing so emits warnings. A future chamber version should prohibit using it entirely.
1 parent 9afd693 commit d2386dc

File tree

5 files changed

+39
-1
lines changed

5 files changed

+39
-1
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ Secret keys are normalized automatically. The `-` will be `_` and the letters wi
143143
be converted to upper case (for example a secret with key `secret_key` and
144144
`secret-key` will become `SECRET_KEY`).
145145

146+
#### Reserved Service Names
147+
148+
Starting with version 3.0, the service name "_chamber" is reserved for chamber's
149+
internal use. You will be warned when using the service for any chamber operation.
150+
146151
#### Tagging on Write
147152

148153
```bash

cmd/root.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ func validateService(service string) error {
117117
if !validServicePathFormat.MatchString(service) {
118118
return fmt.Errorf("Failed to validate service name '%s'. Only alphanumeric, dashes, forward slashes, full stops and underscores are allowed for service names. Service names must not start or end with a forward slash", service)
119119
}
120+
if store.ReservedService(service) {
121+
fmt.Fprintf(os.Stderr, "Service name %s is reserved for chamber's own use and will be prohibited in a future version. Please switch to a different service name.\n", service)
122+
}
120123

121124
return nil
122125
}
@@ -125,6 +128,9 @@ func validateServiceWithLabel(service string) error {
125128
if !validServicePathFormatWithLabel.MatchString(service) {
126129
return fmt.Errorf("Failed to validate service name '%s'. Only alphanumeric, dashes, forward slashes, full stops and underscores are allowed for service names, and colon followed by a label name. Service names must not start or end with a forward slash or colon", service)
127130
}
131+
if store.ReservedService(service) {
132+
fmt.Fprintf(os.Stderr, "Service name %s is reserved for chamber's own use and will be prohibited in a future version. Please switch to a different service name.\n", service)
133+
}
128134

129135
return nil
130136
}

cmd/root_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ func TestValidateService_Path(t *testing.T) {
5151
"foo-bar/foo-bar",
5252
"foo/bar/foo",
5353
"foo/bar/foo-bar",
54+
"_chamber", // currently valid, but will be prohibited in a future version
5455
}
5556

5657
for _, k := range validServicePathFormat {
@@ -86,6 +87,7 @@ func TestValidateService_PathLabel(t *testing.T) {
8687
"foo/bar/foo:current",
8788
"foo/bar/foo-bar:current",
8889
"foo/bar/foo-bar",
90+
"_chamber", // currently valid, but will be prohibited in a future version
8991
}
9092

9193
for _, k := range validServicePathFormatWithLabel {

store/store.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ import (
66
"time"
77
)
88

9+
const (
10+
// ChamberService is the name of the service reserved for chamber's own use.
11+
ChamberService = "_chamber"
12+
)
13+
14+
func ReservedService(service string) bool {
15+
return service == ChamberService
16+
}
17+
918
type ChangeEventType int
1019

1120
const (
@@ -29,22 +38,25 @@ var (
2938
ErrSecretNotFound = errors.New("secret not found")
3039
)
3140

41+
// SecretId is the compound key for a secret.
3242
type SecretId struct {
3343
Service string
3444
Key string
3545
}
3646

47+
// Secret is a secret with metadata.
3748
type Secret struct {
3849
Value *string
3950
Meta SecretMetadata
4051
}
4152

42-
// A secret without any metadata
53+
// RawSecret is a secret without any metadata.
4354
type RawSecret struct {
4455
Value string
4556
Key string
4657
}
4758

59+
// SecretMetadata is metadata about a secret.
4860
type SecretMetadata struct {
4961
Created time.Time
5062
CreatedBy string
@@ -59,6 +71,7 @@ type ChangeEvent struct {
5971
Version int
6072
}
6173

74+
// Store is an interface for a secret store.
6275
type Store interface {
6376
Write(ctx context.Context, id SecretId, value string) error
6477
WriteWithTags(ctx context.Context, id SecretId, value string, tags map[string]string) error

store/store_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package store
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func TestReservedService(t *testing.T) {
10+
assert.True(t, ReservedService(ChamberService))
11+
assert.False(t, ReservedService("not-reserved"))
12+
}

0 commit comments

Comments
 (0)