fix(connectors): keep published settings and let admins reset the catalogue (#2119)
This commit is contained in:
7 files changed
+43
-10
No files matched your search
@@ -185,6 +185,12 @@ func packageEntry(p publishedPackage, meta packageMetadata, binary *ociBinary) E
|
||||
Env: append(meta.Grants.Env, meta.Authority.Env...),
|
||||
Credentials: append(meta.Grants.Credentials, meta.Authority.CredentialServices...),
|
||||
}
|
||||
for i, field := range meta.Settings {
|
||||
if field.Secret && !strings.HasSuffix(field.Key, "_ref") {
|
||||
// Archie stores a reference and passes the resolved value under the original key.
|
||||
meta.Settings[i].Key += "_ref"
|
||||
}
|
||||
}
|
||||
return Entry{
|
||||
Name: p.Name, DisplayName: meta.DisplayName, Description: p.Description, Contract: contractOf(p.Surface),
|
||||
Versions: []Version{{Version: p.Version, Artifact: p.Reference, Digest: p.Digest, Grants: grants, Settings: meta.Settings, binary: binary}},
|
||||
|
||||
@@ -28,6 +28,9 @@ version: 1.0.0
|
||||
settings:
|
||||
- key: timezone
|
||||
label: Time zone
|
||||
- key: judge_api_key
|
||||
label: Judge API key
|
||||
secret: true
|
||||
grants:
|
||||
egress: [example.test:443]
|
||||
contributes:
|
||||
@@ -93,7 +96,7 @@ files:
|
||||
}
|
||||
entry, ok := doc.Entry("hours")
|
||||
v, offered := entry.Latest()
|
||||
if !ok || !offered || len(v.Settings) != 1 || v.Settings[0].Key != "timezone" || !v.Grants.Covers(Grants{Egress: []string{"example.test:443"}}) {
|
||||
if !ok || !offered || len(v.Settings) != 2 || v.Settings[0].Key != "timezone" || v.Settings[1].Key != "judge_api_key_ref" || !v.Grants.Covers(Grants{Egress: []string{"example.test:443"}}) {
|
||||
t.Fatalf("missing declared settings or grants: %+v", v)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,15 +188,13 @@ func (m *Module) viewOf(a store.Installed, editable bool) (ExtensionView, error)
|
||||
return view, nil
|
||||
}
|
||||
|
||||
// formSchema is the settings form an installation shows. A stopped extension's
|
||||
// form comes from what its version declared in the catalogue, and a running
|
||||
// one's own declaration replaces it. A caller who may not change the
|
||||
// installation gets none.
|
||||
// formSchema uses the published settings when the extension doesn't report any
|
||||
// at runtime. Callers who can't edit the installation don't get its form.
|
||||
func formSchema(a store.Installed, running []Setting, editable bool) ([]Setting, error) {
|
||||
switch {
|
||||
case !editable:
|
||||
return []Setting{}, nil
|
||||
case running != nil:
|
||||
case len(running) != 0:
|
||||
return running, nil
|
||||
}
|
||||
return settingsOf(a.DeclaredSettings)
|
||||
@@ -268,10 +266,14 @@ func (m *Module) schemaOf(id string) ([]Setting, bool) {
|
||||
// checkInstalled checks an installation's settings against the schema the
|
||||
// package declared, once it is known.
|
||||
func (m *Module) checkInstalled(a store.Installed) error {
|
||||
schema, ok := m.schemaOf(a.ID.String())
|
||||
if !ok || len(schema) == 0 {
|
||||
running, ok := m.schemaOf(a.ID.String())
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
schema, err := formSchema(a, running, true)
|
||||
if err != nil || len(schema) == 0 {
|
||||
return err
|
||||
}
|
||||
return checkSettingValues(schema, a.Settings)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package connectors
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/samcharles93/archie-core/modules/connectors/internal/store"
|
||||
)
|
||||
|
||||
// TestFormSchemaUsesCatalogueWhenRuntimeOmitsSettings checks that starting an
|
||||
// extension doesn't hide the settings published in its signed descriptor.
|
||||
func TestFormSchemaUsesCatalogueWhenRuntimeOmitsSettings(t *testing.T) {
|
||||
a := store.Installed{DeclaredSettings: []byte(`[{"key":"timezone","label":"Time zone"}]`)}
|
||||
got, err := formSchema(a, []Setting{}, true)
|
||||
if err != nil || len(got) != 1 || got[0].Key != "timezone" {
|
||||
t.Fatalf("settings = %v, error = %v; want the catalogue's timezone setting", got, err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user