Files

34 lines
1.3 KiB
Go

package daemon
import (
"context"
"github.com/samcharles93/archie-core/internal/domain/storepkg"
"github.com/samcharles93/archie-core/internal/domain/workflow"
)
// PackageAuthorities answers what the operator accepted for an installed
// package. A package that is not installed, or not accepted, has none.
type PackageAuthorities interface {
AcceptedAuthority(ctx context.Context, name string) (storepkg.Authority, error)
}
// toolAllowlist is the tool allowlist a task runs with. nil offers every tool;
// a non-nil list offers exactly its members. A run of a package's workflow is
// bounded by the tools accepted for that package, so a missing, unaccepted or
// unreadable package offers none.
func (d *Daemon) toolAllowlist(ctx context.Context, task *workflow.Task, profileTools []string) []string {
name := workflow.PackageOf(task.WorkflowDefinitionYAML)
if name == "" {
return storepkg.AllowedTools(profileTools, false, nil)
}
var accepted []string
authority, err := d.PackageAuthorities.AcceptedAuthority(ctx, name)
if err != nil {
d.Log.WarnContext(ctx, "package authority unavailable; offering no tools", "task", task.ID, "package", name, "err", err)
} else {
accepted = authority.Tools
}
return storepkg.AllowedTools(profileTools, true, accepted)
}