fix(connectors): keep published settings and let admins reset the catalogue (#2119)

This commit is contained in:
sam committed 2026-11-27 02:29:39 +11:00
1 parent bc4ac4436d
commit 24a3efcf60
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)
}
}
+9 -7
View File
@@ -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)
}
+17
View File
@@ -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)
}
}
+3
View File
@@ -309,6 +309,8 @@ export const api = {
catalogueSource: () => request<CatalogueSourceView>("/api/extensions/catalogue-source"),
putCatalogueSource: (source: CatalogueSourceInput) =>
request<CatalogueSourceView>("/api/extensions/catalogue-source", { method: "PUT", body: source }),
resetCatalogueSource: () =>
request<CatalogueSourceView>("/api/extensions/catalogue-source", { method: "DELETE" }),
acceptExtension: (kind: ExtensionKind, name: string, body: ExtensionInput) =>
request<{ name: string; state: string }>(`/api/${kind}/${encodeURIComponent(name)}`, { method: "PUT", body, timeoutMs: 60_000 }),
removeExtension: (kind: ExtensionKind, name: string) =>
@@ -1418,6 +1420,7 @@ export interface CatalogueSource {
export interface CatalogueSourceView {
configured: boolean;
default?: boolean;
source?: CatalogueSource;
}
+3 -2
View File
@@ -347,15 +347,16 @@ const active = computed(() => (kinds.data.value ?? []).find((kind) => kind.kind
</TabsContent>
<TabsContent value="marketplace">
<Collapsible class="mb-3" :default-open="!store.source.configured && !!store.catalogueError">
<Collapsible v-if="org.instanceAdmin" class="mb-3" :default-open="!store.source.configured && !!store.catalogueError">
<CollapsibleTrigger class="cursor-pointer text-caption text-fg-muted">
Catalogue source<span v-if="store.source.source?.location" class="ml-1.5 font-mono text-fg-subtle">({{ store.source.source.location }})</span>
Catalogue source<span v-if="store.source.default" class="ml-1.5">(Archipelago)</span><span v-else-if="store.source.source?.location" class="ml-1.5 font-mono text-fg-subtle">({{ store.source.source.location }})</span>
</CollapsibleTrigger>
<CollapsibleContent>
<form class="mt-2 flex flex-wrap items-end gap-2" @submit.prevent="saveSource">
<Input v-model="sourceLocation" class="max-w-96 font-mono" placeholder="https://… or /path/to/catalogue.json" aria-label="Catalogue location" />
<Input v-model="sourceKey" class="max-w-96 font-mono" placeholder="base64 Ed25519 public key" aria-label="Catalogue public key" />
<Button type="submit" size="sm" :disabled="!!store.busy"><Plus data-icon="inline-start" />Save</Button>
<Button v-if="store.source.default === false" type="button" variant="outline" size="sm" :disabled="!!store.busy" @click="store.resetSource()">Reset to Archipelago</Button>
</form>
</CollapsibleContent>
</Collapsible>
+1
View File
@@ -132,5 +132,6 @@ export const useExtensionsStore = defineStore("extensions", () => {
mutate(extension.id, () => api.updateInstallation(extension.id, { ...installationBody(extension), settings })),
remove: (name: string) => mutate(name, () => api.removePackage(name)),
saveSource: (location: string, publicKey: string) => mutate("source", () => api.putCatalogueSource({ location, public_key: publicKey })),
resetSource: () => mutate("source", api.resetCatalogueSource),
};
});