feat: choose which checkers may check private addresses, check types per organization
Whether platform checkers may check private addresses, including the host's Docker socket, is now a platform setting; unset, it stays as before: allowed self-hosted, forbidden in the cloud edition. Each of an organization's checkers has its own switch, on by default, settable at creation and toggled in the checker list. Both apply from the checker's next poll. Organizations choose in their settings which of the platform's check types their members are offered; existing monitors keep running, and if the platform later switches off everything an organization kept, it is offered the platform's types again rather than none. Forms marked data-autosave are sent when a field changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
1 parent
0b7f48a609
commit
465fda60dc
26 files changed
+984
-281
No files matched your search
@@ -13,18 +13,19 @@ import (
|
||||
)
|
||||
|
||||
const createAgent = `-- name: CreateAgent :one
|
||||
INSERT INTO agents (org_id, kind, name, region_id, token_hash, prefix)
|
||||
VALUES ($1, $2, $3, $4, $5, $6)
|
||||
RETURNING id, org_id, kind, name, token_hash, prefix, last_seen_at, release, created_at, region_id
|
||||
INSERT INTO agents (org_id, kind, name, region_id, token_hash, prefix, allow_private)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||
RETURNING id, org_id, kind, name, token_hash, prefix, last_seen_at, release, created_at, region_id, allow_private
|
||||
`
|
||||
|
||||
type CreateAgentParams struct {
|
||||
OrgID *uuid.UUID
|
||||
Kind string
|
||||
Name string
|
||||
RegionID *uuid.UUID
|
||||
TokenHash []byte
|
||||
Prefix string
|
||||
OrgID *uuid.UUID
|
||||
Kind string
|
||||
Name string
|
||||
RegionID *uuid.UUID
|
||||
TokenHash []byte
|
||||
Prefix string
|
||||
AllowPrivate bool
|
||||
}
|
||||
|
||||
func (q *Queries) CreateAgent(ctx context.Context, arg CreateAgentParams) (Agent, error) {
|
||||
@@ -35,6 +36,7 @@ func (q *Queries) CreateAgent(ctx context.Context, arg CreateAgentParams) (Agent
|
||||
arg.RegionID,
|
||||
arg.TokenHash,
|
||||
arg.Prefix,
|
||||
arg.AllowPrivate,
|
||||
)
|
||||
var i Agent
|
||||
err := row.Scan(
|
||||
@@ -48,6 +50,7 @@ func (q *Queries) CreateAgent(ctx context.Context, arg CreateAgentParams) (Agent
|
||||
&i.Release,
|
||||
&i.CreatedAt,
|
||||
&i.RegionID,
|
||||
&i.AllowPrivate,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -133,25 +136,26 @@ func (q *Queries) EnsurePlatformRegion(ctx context.Context, arg EnsurePlatformRe
|
||||
}
|
||||
|
||||
const getAgentByHash = `-- name: GetAgentByHash :one
|
||||
SELECT a.id, a.org_id, a.kind, a.name, a.token_hash, a.prefix, a.last_seen_at, a.release, a.created_at, a.region_id, r.key AS region_key, r.name AS region_name
|
||||
SELECT a.id, a.org_id, a.kind, a.name, a.token_hash, a.prefix, a.last_seen_at, a.release, a.created_at, a.region_id, a.allow_private, r.key AS region_key, r.name AS region_name
|
||||
FROM agents a
|
||||
LEFT JOIN regions r ON r.id = a.region_id
|
||||
WHERE a.token_hash = $1
|
||||
`
|
||||
|
||||
type GetAgentByHashRow struct {
|
||||
ID uuid.UUID
|
||||
OrgID *uuid.UUID
|
||||
Kind string
|
||||
Name string
|
||||
TokenHash []byte
|
||||
Prefix string
|
||||
LastSeenAt *time.Time
|
||||
Release *string
|
||||
CreatedAt time.Time
|
||||
RegionID *uuid.UUID
|
||||
RegionKey *string
|
||||
RegionName *string
|
||||
ID uuid.UUID
|
||||
OrgID *uuid.UUID
|
||||
Kind string
|
||||
Name string
|
||||
TokenHash []byte
|
||||
Prefix string
|
||||
LastSeenAt *time.Time
|
||||
Release *string
|
||||
CreatedAt time.Time
|
||||
RegionID *uuid.UUID
|
||||
AllowPrivate bool
|
||||
RegionKey *string
|
||||
RegionName *string
|
||||
}
|
||||
|
||||
// System scope.
|
||||
@@ -169,6 +173,7 @@ func (q *Queries) GetAgentByHash(ctx context.Context, tokenHash []byte) (GetAgen
|
||||
&i.Release,
|
||||
&i.CreatedAt,
|
||||
&i.RegionID,
|
||||
&i.AllowPrivate,
|
||||
&i.RegionKey,
|
||||
&i.RegionName,
|
||||
)
|
||||
@@ -193,7 +198,7 @@ func (q *Queries) GetRegion(ctx context.Context, id uuid.UUID) (Region, error) {
|
||||
}
|
||||
|
||||
const listAgents = `-- name: ListAgents :many
|
||||
SELECT a.id, a.org_id, a.kind, a.name, a.token_hash, a.prefix, a.last_seen_at, a.release, a.created_at, a.region_id, r.key AS region_key, r.name AS region_name
|
||||
SELECT a.id, a.org_id, a.kind, a.name, a.token_hash, a.prefix, a.last_seen_at, a.release, a.created_at, a.region_id, a.allow_private, r.key AS region_key, r.name AS region_name
|
||||
FROM agents a
|
||||
LEFT JOIN regions r ON r.id = a.region_id
|
||||
WHERE a.org_id IS NOT DISTINCT FROM $1::uuid
|
||||
@@ -201,18 +206,19 @@ ORDER BY a.kind, r.name, a.name
|
||||
`
|
||||
|
||||
type ListAgentsRow struct {
|
||||
ID uuid.UUID
|
||||
OrgID *uuid.UUID
|
||||
Kind string
|
||||
Name string
|
||||
TokenHash []byte
|
||||
Prefix string
|
||||
LastSeenAt *time.Time
|
||||
Release *string
|
||||
CreatedAt time.Time
|
||||
RegionID *uuid.UUID
|
||||
RegionKey *string
|
||||
RegionName *string
|
||||
ID uuid.UUID
|
||||
OrgID *uuid.UUID
|
||||
Kind string
|
||||
Name string
|
||||
TokenHash []byte
|
||||
Prefix string
|
||||
LastSeenAt *time.Time
|
||||
Release *string
|
||||
CreatedAt time.Time
|
||||
RegionID *uuid.UUID
|
||||
AllowPrivate bool
|
||||
RegionKey *string
|
||||
RegionName *string
|
||||
}
|
||||
|
||||
// Agents owned by org, or platform agents when org is NULL.
|
||||
@@ -236,6 +242,7 @@ func (q *Queries) ListAgents(ctx context.Context, orgID *uuid.UUID) ([]ListAgent
|
||||
&i.Release,
|
||||
&i.CreatedAt,
|
||||
&i.RegionID,
|
||||
&i.AllowPrivate,
|
||||
&i.RegionKey,
|
||||
&i.RegionName,
|
||||
); err != nil {
|
||||
@@ -311,6 +318,25 @@ func (q *Queries) ListVisibleRegions(ctx context.Context) ([]Region, error) {
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const setAgentAllowPrivate = `-- name: SetAgentAllowPrivate :execrows
|
||||
UPDATE agents SET allow_private = $1
|
||||
WHERE id = $2 AND kind = 'checker' AND org_id = $3
|
||||
`
|
||||
|
||||
type SetAgentAllowPrivateParams struct {
|
||||
AllowPrivate bool
|
||||
ID uuid.UUID
|
||||
OrgID *uuid.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) SetAgentAllowPrivate(ctx context.Context, arg SetAgentAllowPrivateParams) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, setAgentAllowPrivate, arg.AllowPrivate, arg.ID, arg.OrgID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
|
||||
const touchAgent = `-- name: TouchAgent :exec
|
||||
UPDATE agents SET last_seen_at = now(), release = $2
|
||||
WHERE id = $1 AND (last_seen_at IS NULL OR last_seen_at < now() - interval '30 seconds' OR release IS DISTINCT FROM $2)
|
||||
|
||||
Reference in new issue
Block a user