feat(identity): seed a narrow agent identity and run shipped workflows as it
This commit is contained in:
11 files changed
+42
-7
No files matched your search
@@ -92,6 +92,10 @@ func StableID(legacyName string) IdentityID {
|
||||
// and the request path that resolves it agree without a lookup.
|
||||
func OperatorID() IdentityID { return StableID("operator") }
|
||||
|
||||
// AgentID is the bot identity the shipped workflows run as. The org upgrade
|
||||
// seeds it on every install, so shipped YAML can name its fixed ID.
|
||||
func AgentID() IdentityID { return StableID("agent") }
|
||||
|
||||
func New(id IdentityID, kind Kind, displayName string) (Identity, error) {
|
||||
value := Identity{ID: id, Kind: kind, DisplayName: strings.TrimSpace(displayName), Lifecycle: LifecycleActive, Version: 1}
|
||||
if err := value.Validate(); err != nil {
|
||||
|
||||
@@ -70,6 +70,8 @@ type SwitchStep struct {
|
||||
}
|
||||
|
||||
// RootRef is the identity a workflow declares to run as the instance root.
|
||||
// Nothing ships with it; stored copies that still name it keep running as
|
||||
// the root until edited.
|
||||
const RootRef = "root"
|
||||
|
||||
const switchDefault = "default"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
id: feasibility
|
||||
identity: root
|
||||
identity: 6f129e29-0e26-53246-99bd-74cb4496203b
|
||||
steps:
|
||||
- type: repo.prepare
|
||||
- id: assess
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
id: implement
|
||||
identity: root
|
||||
identity: 6f129e29-0e26-53246-99bd-74cb4496203b
|
||||
steps:
|
||||
- type: repo.prepare
|
||||
- type: gate.repository
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
id: pr-review
|
||||
identity: root
|
||||
identity: 6f129e29-0e26-53246-99bd-74cb4496203b
|
||||
inputs:
|
||||
pr_number:
|
||||
type: number
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
id: remediate
|
||||
identity: root
|
||||
identity: 6f129e29-0e26-53246-99bd-74cb4496203b
|
||||
steps:
|
||||
- type: review.start-round
|
||||
- type: repo.prepare
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
id: tdd
|
||||
identity: root
|
||||
identity: 6f129e29-0e26-53246-99bd-74cb4496203b
|
||||
steps:
|
||||
- type: repo.prepare
|
||||
- type: gate.repository
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
id: triage
|
||||
identity: root
|
||||
identity: 6f129e29-0e26-53246-99bd-74cb4496203b
|
||||
steps:
|
||||
- type: repo.prepare
|
||||
- id: classify
|
||||
|
||||
@@ -305,6 +305,14 @@ func (s *Store) UpgradeDefaultOrg(ctx context.Context) error {
|
||||
{name: "operator", stamps: []func(context.Context, *postgresdb.Queries) (int64, error){
|
||||
ensureOrgOperator,
|
||||
}},
|
||||
// Its own phase so installs that recorded the operator phase before
|
||||
// the agent existed still get it. The final assignment below puts it
|
||||
// in org-sys, and every agent's developer membership grants run.
|
||||
{name: "agent", stamps: []func(context.Context, *postgresdb.Queries) (int64, error){
|
||||
func(ctx context.Context, q *postgresdb.Queries) (int64, error) {
|
||||
return q.EnsureOrgAgentIdentity(ctx, string(identity.AgentID()))
|
||||
},
|
||||
}},
|
||||
}
|
||||
for _, p := range phases {
|
||||
if _, err := s.queries().GetOrgUpgradePhase(ctx, p.name); err == nil {
|
||||
|
||||
@@ -42,6 +42,21 @@ func (q *Queries) EnsureDefaultWorkspace(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
const ensureOrgAgentIdentity = `-- name: EnsureOrgAgentIdentity :execrows
|
||||
INSERT INTO identities (id, kind, display_name, lifecycle, version, created_at, updated_at)
|
||||
VALUES ($1, 'bot', 'Agent', 'active', 1, now(), now())
|
||||
ON CONFLICT (id) DO NOTHING
|
||||
`
|
||||
|
||||
// The bot identity the shipped workflows run as.
|
||||
func (q *Queries) EnsureOrgAgentIdentity(ctx context.Context, id string) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, ensureOrgAgentIdentity, id)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
|
||||
const ensureOrgOperatorIdentity = `-- name: EnsureOrgOperatorIdentity :execrows
|
||||
|
||||
INSERT INTO identities (id, kind, display_name, lifecycle, version, created_at, updated_at)
|
||||
|
||||
@@ -83,4 +83,10 @@ WHERE NOT EXISTS (
|
||||
JOIN identities i ON i.id = m.identity_id
|
||||
WHERE m.org_id = $2 AND m.workspace_id IS NULL AND m.role = 'owner' AND i.kind = 'user'
|
||||
)
|
||||
ON CONFLICT DO NOTHING;
|
||||
ON CONFLICT DO NOTHING;
|
||||
|
||||
-- name: EnsureOrgAgentIdentity :execrows
|
||||
-- The bot identity the shipped workflows run as.
|
||||
INSERT INTO identities (id, kind, display_name, lifecycle, version, created_at, updated_at)
|
||||
VALUES ($1, 'bot', 'Agent', 'active', 1, now(), now())
|
||||
ON CONFLICT (id) DO NOTHING;
|
||||
Reference in new issue
Block a user