Skip to content

Commit

Permalink
many: rename registries to confdbs (#14768)
Browse files Browse the repository at this point in the history
* many: rename registries to confdbs

Signed-off-by: Miguel Pires <[email protected]>

* daemon: rename confdb API to /v2/confdbs/...

Signed-off-by: Miguel Pires <[email protected]>

---------

Signed-off-by: Miguel Pires <[email protected]>
  • Loading branch information
miguelpires authored Dec 4, 2024
1 parent 3ae65f1 commit ff58c9b
Show file tree
Hide file tree
Showing 77 changed files with 1,696 additions and 1,697 deletions.
4 changes: 2 additions & 2 deletions asserts/asserts.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ var (
PreseedType = &AssertionType{"preseed", []string{"series", "brand-id", "model", "system-label"}, nil, assemblePreseed, 0}
SnapResourceRevisionType = &AssertionType{"snap-resource-revision", []string{"snap-id", "resource-name", "resource-sha3-384", "provenance"}, map[string]string{"provenance": naming.DefaultProvenance}, assembleSnapResourceRevision, 0}
SnapResourcePairType = &AssertionType{"snap-resource-pair", []string{"snap-id", "resource-name", "resource-revision", "snap-revision", "provenance"}, map[string]string{"provenance": naming.DefaultProvenance}, assembleSnapResourcePair, 0}
RegistryType = &AssertionType{"registry", []string{"account-id", "name"}, nil, assembleRegistry, jsonBody}
ConfdbType = &AssertionType{"confdb", []string{"account-id", "name"}, nil, assembleConfdb, jsonBody}

// ...
)
Expand Down Expand Up @@ -173,7 +173,7 @@ var typeRegistry = map[string]*AssertionType{
PreseedType.Name: PreseedType,
SnapResourceRevisionType.Name: SnapResourceRevisionType,
SnapResourcePairType.Name: SnapResourcePairType,
RegistryType.Name: RegistryType,
ConfdbType.Name: ConfdbType,
// no authority
DeviceSessionRequestType.Name: DeviceSessionRequestType,
SerialRequestType.Name: SerialRequestType,
Expand Down
4 changes: 2 additions & 2 deletions asserts/asserts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ func (as *assertsSuite) TestTypeNames(c *C) {
"account-key",
"account-key-request",
"base-declaration",
"confdb",
"device-session-request",
"model",
"preseed",
"registry",
"repair",
"serial",
"serial-request",
Expand Down Expand Up @@ -1200,7 +1200,7 @@ func (as *assertsSuite) TestWithAuthority(c *C) {
"snap-developer",
"model",
"preseed",
"registry",
"confdb",
"serial",
"system-user",
"validation",
Expand Down
36 changes: 18 additions & 18 deletions asserts/registry.go → asserts/confdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,43 +24,43 @@ import (
"fmt"
"time"

"github.com/snapcore/snapd/registry"
"github.com/snapcore/snapd/confdb"
)

// Registry holds a registry assertion, which is a definition by an account of
// Confdb holds a confdb assertion, which is a definition by an account of
// access views and a storage schema for a set of related configuration options
// under the purview of the account.
type Registry struct {
type Confdb struct {
assertionBase

registry *registry.Registry
confdb *confdb.Confdb
timestamp time.Time
}

// AccountID returns the identifier of the account that signed this assertion.
func (ar *Registry) AccountID() string {
func (ar *Confdb) AccountID() string {
return ar.HeaderString("account-id")
}

// Name returns the name for the registry.
func (ar *Registry) Name() string {
// Name returns the name for the confdb.
func (ar *Confdb) Name() string {
return ar.HeaderString("name")
}

// Registry returns a Registry assembled from the assertion that can be used
// to access registry views.
func (ar *Registry) Registry() *registry.Registry {
return ar.registry
// Confdb returns a Confdb assembled from the assertion that can be used
// to access confdb views.
func (ar *Confdb) Confdb() *confdb.Confdb {
return ar.confdb
}

func assembleRegistry(assert assertionBase) (Assertion, error) {
func assembleConfdb(assert assertionBase) (Assertion, error) {
authorityID := assert.AuthorityID()
accountID := assert.HeaderString("account-id")
if accountID != authorityID {
return nil, fmt.Errorf("authority-id and account-id must match, registry assertions are expected to be signed by the issuer account: %q != %q", authorityID, accountID)
return nil, fmt.Errorf("authority-id and account-id must match, confdb assertions are expected to be signed by the issuer account: %q != %q", authorityID, accountID)
}

name, err := checkStringMatches(assert.headers, "name", registry.ValidRegistryName)
name, err := checkStringMatches(assert.headers, "name", confdb.ValidConfdbName)
if err != nil {
return nil, err
}
Expand All @@ -87,12 +87,12 @@ func assembleRegistry(assert assertionBase) (Assertion, error) {
return nil, fmt.Errorf(`body must contain a "storage" stanza`)
}

schema, err := registry.ParseSchema(schemaRaw)
schema, err := confdb.ParseSchema(schemaRaw)
if err != nil {
return nil, fmt.Errorf(`invalid schema: %w`, err)
}

registry, err := registry.New(accountID, name, viewsMap, schema)
confdb, err := confdb.New(accountID, name, viewsMap, schema)
if err != nil {
return nil, err
}
Expand All @@ -102,9 +102,9 @@ func assembleRegistry(assert assertionBase) (Assertion, error) {
return nil, err
}

return &Registry{
return &Confdb{
assertionBase: assert,
registry: registry,
confdb: confdb,
timestamp: timestamp,
}, nil
}
42 changes: 21 additions & 21 deletions asserts/registry_test.go → asserts/confdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,24 @@ import (
"github.com/snapcore/snapd/asserts"
)

type registrySuite struct {
type confdbSuite struct {
ts time.Time
tsLine string
}

var _ = Suite(&registrySuite{})
var _ = Suite(&confdbSuite{})

func (s *registrySuite) SetUpSuite(c *C) {
func (s *confdbSuite) SetUpSuite(c *C) {
s.ts = time.Now().Truncate(time.Second).UTC()
s.tsLine = "timestamp: " + s.ts.Format(time.RFC3339) + "\n"
}

const (
registryExample = `type: registry
confdbExample = `type: confdb
authority-id: brand-id1
account-id: brand-id1
name: my-network
summary: registry description
summary: confdb description
views:
wifi-setup:
rules:
Expand Down Expand Up @@ -87,34 +87,34 @@ const schema = `{
}
}`

func (s *registrySuite) TestDecodeOK(c *C) {
encoded := strings.Replace(registryExample, "TSLINE", s.tsLine, 1)
func (s *confdbSuite) TestDecodeOK(c *C) {
encoded := strings.Replace(confdbExample, "TSLINE", s.tsLine, 1)

a, err := asserts.Decode([]byte(encoded))
c.Assert(err, IsNil)
c.Check(a, NotNil)
c.Check(a.Type(), Equals, asserts.RegistryType)
ar := a.(*asserts.Registry)
c.Check(a.Type(), Equals, asserts.ConfdbType)
ar := a.(*asserts.Confdb)
c.Check(ar.AuthorityID(), Equals, "brand-id1")
c.Check(ar.AccountID(), Equals, "brand-id1")
c.Check(ar.Name(), Equals, "my-network")
registry := ar.Registry()
c.Assert(registry, NotNil)
c.Check(registry.View("wifi-setup"), NotNil)
confdb := ar.Confdb()
c.Assert(confdb, NotNil)
c.Check(confdb.View("wifi-setup"), NotNil)
}

func (s *registrySuite) TestDecodeInvalid(c *C) {
const validationSetErrPrefix = "assertion registry: "
func (s *confdbSuite) TestDecodeInvalid(c *C) {
const validationSetErrPrefix = "assertion confdb: "

encoded := strings.Replace(registryExample, "TSLINE", s.tsLine, 1)
encoded := strings.Replace(confdbExample, "TSLINE", s.tsLine, 1)

viewsStanza := encoded[strings.Index(encoded, "views:") : strings.Index(encoded, "timestamp:")+1]
body := encoded[strings.Index(encoded, "body-length:"):strings.Index(encoded, "\n\nAXN")]

invalidTests := []struct{ original, invalid, expectedErr string }{
{"account-id: brand-id1\n", "", `"account-id" header is mandatory`},
{"account-id: brand-id1\n", "account-id: \n", `"account-id" header should not be empty`},
{"account-id: brand-id1\n", "account-id: random\n", `authority-id and account-id must match, registry assertions are expected to be signed by the issuer account: "brand-id1" != "random"`},
{"account-id: brand-id1\n", "account-id: random\n", `authority-id and account-id must match, confdb assertions are expected to be signed by the issuer account: "brand-id1" != "random"`},
{"name: my-network\n", "", `"name" header is mandatory`},
{"name: my-network\n", "name: \n", `"name" header should not be empty`},
{"name: my-network\n", "name: my/network\n", `"name" primary key header cannot contain '/'`},
Expand Down Expand Up @@ -148,7 +148,7 @@ func (s *registrySuite) TestDecodeInvalid(c *C) {
}
}

func (s *registrySuite) TestAssembleAndSignChecksSchemaFormatOK(c *C) {
func (s *confdbSuite) TestAssembleAndSignChecksSchemaFormatOK(c *C) {
headers := map[string]interface{}{
"authority-id": "brand-id1",
"account-id": "brand-id1",
Expand All @@ -174,12 +174,12 @@ func (s *registrySuite) TestAssembleAndSignChecksSchemaFormatOK(c *C) {
}
}
}`
acct1, err := asserts.AssembleAndSignInTest(asserts.RegistryType, headers, []byte(schema), testPrivKey0)
acct1, err := asserts.AssembleAndSignInTest(asserts.ConfdbType, headers, []byte(schema), testPrivKey0)
c.Assert(err, IsNil)
c.Assert(string(acct1.Body()), Equals, schema)
}

func (s *registrySuite) TestAssembleAndSignChecksSchemaFormatFail(c *C) {
func (s *confdbSuite) TestAssembleAndSignChecksSchemaFormatFail(c *C) {
headers := map[string]interface{}{
"authority-id": "brand-id1",
"account-id": "brand-id1",
Expand All @@ -196,6 +196,6 @@ func (s *registrySuite) TestAssembleAndSignChecksSchemaFormatFail(c *C) {
}

schema := `{ "storage": { "schema": { "foo": "any" } } }`
_, err := asserts.AssembleAndSignInTest(asserts.RegistryType, headers, []byte(schema), testPrivKey0)
c.Assert(err, ErrorMatches, `assertion registry: JSON in body must be indented with 2 spaces and sort object entries by key`)
_, err := asserts.AssembleAndSignInTest(asserts.ConfdbType, headers, []byte(schema), testPrivKey0)
c.Assert(err, ErrorMatches, `assertion confdb: JSON in body must be indented with 2 spaces and sort object entries by key`)
}
8 changes: 4 additions & 4 deletions asserts/snapasserts/snapasserts.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,12 +509,12 @@ func FetchStore(f asserts.Fetcher, storeID string) error {
return f.Fetch(ref)
}

// FetchRegistry fetches a registry assertion described by account and registry
// FetchConfdb fetches a confdb assertion described by account and confdb
// name using the given fetcher.
func FetchRegistry(f asserts.Fetcher, account, registryName string) error {
func FetchConfdb(f asserts.Fetcher, account, confdbName string) error {
ref := &asserts.Ref{
Type: asserts.RegistryType,
PrimaryKey: []string{account, registryName},
Type: asserts.ConfdbType,
PrimaryKey: []string{account, confdbName},
}

return f.Fetch(ref)
Expand Down
8 changes: 4 additions & 4 deletions client/registry.go → client/confdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ import (
"strings"
)

func (c *Client) RegistryGetViaView(viewID string, requests []string) (result map[string]interface{}, err error) {
func (c *Client) ConfdbGetViaView(viewID string, requests []string) (result map[string]interface{}, err error) {
query := url.Values{}
query.Add("fields", strings.Join(requests, ","))

endpoint := fmt.Sprintf("/v2/registry/%s", viewID)
endpoint := fmt.Sprintf("/v2/confdbs/%s", viewID)
_, err = c.doSync("GET", endpoint, query, nil, nil, &result)
if err != nil {
return nil, err
Expand All @@ -40,7 +40,7 @@ func (c *Client) RegistryGetViaView(viewID string, requests []string) (result ma
return result, nil
}

func (c *Client) RegistrySetViaView(viewID string, requestValues map[string]interface{}) (changeID string, err error) {
func (c *Client) ConfdbSetViaView(viewID string, requestValues map[string]interface{}) (changeID string, err error) {
body, err := json.Marshal(requestValues)
if err != nil {
return "", err
Expand All @@ -49,6 +49,6 @@ func (c *Client) RegistrySetViaView(viewID string, requestValues map[string]inte
headers := make(map[string]string)
headers["Content-Type"] = "application/json"

endpoint := fmt.Sprintf("/v2/registry/%s", viewID)
endpoint := fmt.Sprintf("/v2/confdbs/%s", viewID)
return c.doAsync("PUT", endpoint, nil, headers, bytes.NewReader(body))
}
12 changes: 6 additions & 6 deletions client/registry_test.go → client/confdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,29 @@ import (
. "gopkg.in/check.v1"
)

func (cs *clientSuite) TestRegistryGet(c *C) {
func (cs *clientSuite) TestConfdbGet(c *C) {
cs.rsp = `{"type": "sync", "result":{"foo":"baz","bar":1}}`

res, err := cs.cli.RegistryGetViaView("a/b/c", []string{"foo", "bar"})
res, err := cs.cli.ConfdbGetViaView("a/b/c", []string{"foo", "bar"})
c.Check(err, IsNil)
c.Check(res, DeepEquals, map[string]interface{}{"foo": "baz", "bar": json.Number("1")})
c.Assert(cs.reqs, HasLen, 1)
c.Check(cs.reqs[0].Method, Equals, "GET")
c.Check(cs.reqs[0].URL.Path, Equals, "/v2/registry/a/b/c")
c.Check(cs.reqs[0].URL.Path, Equals, "/v2/confdbs/a/b/c")
c.Check(cs.reqs[0].URL.Query(), DeepEquals, url.Values{"fields": []string{"foo,bar"}})
}

func (cs *clientSuite) TestRegistrySet(c *C) {
func (cs *clientSuite) TestConfdbSet(c *C) {
cs.status = 202
cs.rsp = `{"type": "async", "status-code": 202, "change": "123"}`

chgID, err := cs.cli.RegistrySetViaView("a/b/c", map[string]interface{}{"foo": "bar", "baz": json.Number("1")})
chgID, err := cs.cli.ConfdbSetViaView("a/b/c", map[string]interface{}{"foo": "bar", "baz": json.Number("1")})
c.Check(err, IsNil)
c.Check(chgID, Equals, "123")
c.Assert(cs.reqs, HasLen, 1)
c.Check(cs.reqs[0].Method, Equals, "PUT")
c.Check(cs.reqs[0].Header.Get("Content-Type"), Equals, "application/json")
c.Check(cs.reqs[0].URL.Path, Equals, "/v2/registry/a/b/c")
c.Check(cs.reqs[0].URL.Path, Equals, "/v2/confdbs/a/b/c")
data, err := io.ReadAll(cs.reqs[0].Body)
c.Assert(err, IsNil)

Expand Down
30 changes: 15 additions & 15 deletions cmd/snap/cmd_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ Nested values may be retrieved via a dotted path:
frank
`)

var longRegistryGetHelp = i18n.G(`
If the first argument passed into get is a registry identifier matching the
format <account-id>/<registry>/<view>, get will use the registry API. In this
var longConfdbGetHelp = i18n.G(`
If the first argument passed into get is a confdb identifier matching the
format <account-id>/<confdb>/<view>, get will use the confdb API. In this
case, the command returns the data retrieved from the requested dot-separated
view paths.
`)
Expand All @@ -71,8 +71,8 @@ type cmdGet struct {
}

func init() {
if err := validateRegistryFeatureFlag(); err == nil {
longGetHelp += longRegistryGetHelp
if err := validateConfdbFeatureFlag(); err == nil {
longGetHelp += longConfdbGetHelp
}

addCommand("get", shortGetHelp, longGetHelp, func() flags.Commander { return &cmdGet{} },
Expand Down Expand Up @@ -256,18 +256,18 @@ func (x *cmdGet) Execute(args []string) error {

var conf map[string]interface{}
var err error
if isRegistryViewID(snapName) {
if err := validateRegistryFeatureFlag(); err != nil {
if isConfdbViewID(snapName) {
if err := validateConfdbFeatureFlag(); err != nil {
return err
}

// first argument is a registryViewID, use the registry API
registryViewID := snapName
if err := validateRegistryViewID(registryViewID); err != nil {
// first argument is a confdbViewID, use the confdb API
confdbViewID := snapName
if err := validateConfdbViewID(confdbViewID); err != nil {
return err
}

conf, err = x.client.RegistryGetViaView(registryViewID, confKeys)
conf, err = x.client.ConfdbGetViaView(confdbViewID, confKeys)
} else {
conf, err = x.client.Conf(snapName, confKeys)
}
Expand All @@ -286,10 +286,10 @@ func (x *cmdGet) Execute(args []string) error {
}
}

func validateRegistryFeatureFlag() error {
if !features.Registries.IsEnabled() {
_, confName := features.Registries.ConfigOption()
return fmt.Errorf(`the "registries" feature is disabled: set '%s' to true`, confName)
func validateConfdbFeatureFlag() error {
if !features.Confdbs.IsEnabled() {
_, confName := features.Confdbs.ConfigOption()
return fmt.Errorf(`the "confdbs" feature is disabled: set '%s' to true`, confName)
}
return nil
}
Loading

0 comments on commit ff58c9b

Please sign in to comment.