diff --git a/modules/connectors/internal/store/store.go b/modules/connectors/internal/store/store.go index ba55f01a1..9a45f0418 100644 --- a/modules/connectors/internal/store/store.go +++ b/modules/connectors/internal/store/store.go @@ -57,9 +57,8 @@ const ( GroupAgent Group = "agent" ) -// Contracts lists every contract with its group. Everything that enumerates -// contracts reads this table, and GroupOf is the only way to look a group up, -// so a contract without a group cannot be served. +// Contracts lists every known contract with its group. Upsert refuses any +// contract not in this table, so every stored package has a group. func Contracts() []ContractGroup { return []ContractGroup{ {ContractConnector, GroupIntegration}, @@ -75,7 +74,7 @@ type ContractGroup struct { Group Group } -// GroupOf returns the group of a contract in Contracts. +// GroupOf returns the group of a contract in Contracts, or "" for an unknown one. func GroupOf(contract string) Group { for _, c := range Contracts() { if c.Contract == contract { @@ -114,6 +113,9 @@ func (s *Store) List(ctx context.Context, orgID string) ([]Accepted, error) { // Upsert records an accepted connector, replacing an earlier acceptance. func (s *Store) Upsert(ctx context.Context, a Accepted) error { + if GroupOf(a.Contract) == "" { + return fmt.Errorf("accept %q: unknown contract %q", a.Name, a.Contract) + } if _, err := s.db.NamedExecContext(ctx, ` INSERT INTO connectors.accepted (org_id, name, path, sha256, egress, env, settings, contract, credentials, args, url, tools) VALUES (:org_id, :name, :path, :sha256, :egress, :env, :settings, :contract, :credentials, :args, :url, :tools)