fix(connectors): refuse to store a contract that has no group (#2084)
This commit is contained in:
1 file changed
+6
-4
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user