Skip to content

Commit

Permalink
chore: use RFC2602 domain (example.com) in custom notice examples (#407)
Browse files Browse the repository at this point in the history
Also use consistent "/path" to indicate it can be a path (with multiple
segments).
  • Loading branch information
benhoyt authored Apr 9, 2024
1 parent 3c7d436 commit 18c93cb
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ These notice types are currently available:

<!-- TODO: * `change-update`: recorded whenever a change is first spawned or its status is updated. The key for this type of notice is the change ID, and the notice's data includes the change `kind`. -->

* `custom`: a custom client notice reported via `pebble notify`. The key and any data is provided by the user. The key must be in the format `mydomain.io/mykey` to ensure well-namespaced notice keys.
* `custom`: a custom client notice reported via `pebble notify`. The key and any data is provided by the user. The key must be in the format `example.com/path` to ensure well-namespaced notice keys.

<!-- TODO: * `warning`: Pebble warnings are implemented in terms of notices. The key for this type of notice is the human-readable warning message.

Expand Down
4 changes: 2 additions & 2 deletions client/notices.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type NotifyOptions struct {
Type NoticeType

// Key is the notice's key. For "custom" notices, this must be in
// "domain.com/key" format.
// "example.com/path" format.
Key string

// Data are optional key=value pairs for this occurrence of the notice.
Expand Down Expand Up @@ -128,7 +128,7 @@ const (

// A custom notice reported via the Pebble client API or "pebble notify".
// The key and data fields are provided by the user. The key must be in
// the format "mydomain.io/mykey" to ensure well-namespaced notice keys.
// the format "example.com/path" to ensure well-namespaced notice keys.
CustomNotice NoticeType = "custom"
)

Expand Down
4 changes: 2 additions & 2 deletions internals/daemon/api_notices.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"github.com/canonical/pebble/internals/overlord/state"
)

// Ensure custom keys are in the form "domain.com/key" (but somewhat more restrictive).
// Ensure custom keys are in the form "example.com/path" (but somewhat more restrictive).
var customKeyRegexp = regexp.MustCompile(
`^[a-z0-9]+(-[a-z0-9]+)*(\.[a-z0-9]+(-[a-z0-9]+)*)+(/[a-z0-9]+(-[a-z0-9]+)*)+$`)

Expand Down Expand Up @@ -216,7 +216,7 @@ func v1PostNotices(c *Command, r *http.Request, _ *UserState) Response {
return BadRequest(`invalid type %q (can only add "custom" notices)`, payload.Type)
}
if !customKeyRegexp.MatchString(payload.Key) {
return BadRequest(`invalid key %q (must be in "domain.com/key" format)`, payload.Key)
return BadRequest(`invalid key %q (must be in "example.com/path" format)`, payload.Key)
}
if len(payload.Key) > maxNoticeKeyLength {
return BadRequest("key must be %d bytes or less", maxNoticeKeyLength)
Expand Down
2 changes: 1 addition & 1 deletion internals/overlord/state/notices.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ const (

// A custom notice reported via the Pebble client API or "pebble notify".
// The key and data fields are provided by the user. The key must be in
// the format "mydomain.io/mykey" to ensure well-namespaced notice keys.
// the format "example.com/path" to ensure well-namespaced notice keys.
CustomNotice NoticeType = "custom"

// Warnings are a subset of notices where the key is a human-readable
Expand Down

0 comments on commit 18c93cb

Please sign in to comment.