package daemon import ( "context" "fmt" "github.com/samcharles93/archie-core/internal/config" "github.com/samcharles93/archie-core/internal/domain/workflow" workflowtask "github.com/samcharles93/archie-core/internal/domain/workflow/task" "github.com/samcharles93/archie-core/internal/forge" "github.com/samcharles93/archie-core/internal/worktree" ) // RepositoryAccess holds host-side clients for one authorised operation. // It is never included in the container handoff. type RepositoryAccess struct { Repository config.Repo Connection config.ForgeConnection Trees *worktree.Manager Forge forge.Forge } // Repository resolves current credentials and permissions for the run's // execution identity, never the identity that originally requested the task. func (d *Daemon) Repository(ctx context.Context, task *workflow.Task, operation string) (RepositoryAccess, error) { if d.ResolveRepository == nil { return RepositoryAccess{}, fmt.Errorf("repository connections unavailable") } run := *task if run.WorkflowDefinitionYAML != "" { iface, err := workflowtask.ParseWorkflowInterface(run.WorkflowDefinitionYAML) if err != nil || iface.Identity == "" { return RepositoryAccess{}, fmt.Errorf("workflow execution identity unavailable") } _, name, err := d.declaredIdentity(ctx, &run, iface.Identity) if err != nil { return RepositoryAccess{}, err } run.Identity = name } ctx, err := d.workflowContext(ctx, &run) if err != nil { return RepositoryAccess{}, err } if _, err := d.databaseExecutionIdentity(ctx, &run, d.publisherIdentity(run.Identity)); err != nil { return RepositoryAccess{}, err } return d.ResolveRepository(ctx, &run, operation) }