mirror of
https://github.com/cirruslabs/orchard.git
synced 2026-09-29 19:41:15 +02:00
* Regenerate .pb with protoc-gen-go v1.36.11 * Support running host processes alongside VMs * Replace existing host processes when starting a set
37 lines
1.1 KiB
Go
37 lines
1.1 KiB
Go
//nolint:err113 // Preserve host-process validation messages.
|
|
package v1
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/cirruslabs/orchard/internal/simplename"
|
|
mapset "github.com/deckarep/golang-set/v2"
|
|
)
|
|
|
|
// HostProcess describes a process run by the worker alongside a VM. Program is
|
|
// an executable path or a name resolved using the worker's PATH.
|
|
type HostProcess struct {
|
|
Name string `json:"name"`
|
|
Program string `json:"program"`
|
|
Args []string `json:"args,omitempty"`
|
|
Env map[string]string `json:"env,omitempty"`
|
|
}
|
|
|
|
func ValidateHostProcesses(processes []HostProcess) error {
|
|
seenNames := mapset.NewSetWithSize[string](len(processes))
|
|
|
|
for _, process := range processes {
|
|
if process.Name == "" || simplename.Validate(process.Name) != nil {
|
|
return fmt.Errorf("host process %q is invalid", process.Name)
|
|
}
|
|
if !seenNames.Add(process.Name) {
|
|
return fmt.Errorf("host process %q is duplicated", process.Name)
|
|
}
|
|
if process.Program == "" {
|
|
return fmt.Errorf("host process %q has an empty program", process.Name)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|