pi-agent: Implement progressive Target detection
This commit is contained in:
+16
-5
@@ -155,22 +155,33 @@ func (a *Adapter) DiagnosticChecks(ctx context.Context, _ *profile.Profile) []ta
|
||||
}
|
||||
|
||||
func (a *Adapter) Availability(ctx context.Context) target.Availability {
|
||||
availability, _ := a.detectAvailability(ctx)
|
||||
return availability
|
||||
}
|
||||
|
||||
func (a *Adapter) detectAvailability(ctx context.Context) (target.Availability, error) {
|
||||
marker, err := os.Stat(a.configuration.DebianVersionFile)
|
||||
if err != nil || !marker.Mode().IsRegular() {
|
||||
return target.Availability{Evidence: "Debian-family marker /etc/debian_version was not detected"}
|
||||
return target.Availability{Evidence: "Debian-family marker /etc/debian_version was not detected"}, nil
|
||||
}
|
||||
directory, err := os.Stat(a.configuration.ConfigDirectory)
|
||||
if err != nil || !directory.IsDir() {
|
||||
return target.Availability{Evidence: "APT configuration directory apt.conf.d was not detected"}
|
||||
return target.Availability{Evidence: "APT configuration directory apt.conf.d was not detected"}, nil
|
||||
}
|
||||
command, err := a.runner.LookPath("apt-config")
|
||||
if err != nil {
|
||||
return target.Availability{Evidence: "Debian APT tool apt-config was not detected"}
|
||||
return target.Availability{Evidence: "Debian APT tool apt-config was not detected"}, nil
|
||||
}
|
||||
if _, err := a.runner.Output(ctx, command, "dump"); err != nil {
|
||||
return target.Availability{Evidence: "apt-config could not inspect effective APT configuration"}
|
||||
return target.Availability{Evidence: "apt-config could not inspect effective APT configuration"}, fmt.Errorf("inspect effective APT configuration: %w", err)
|
||||
}
|
||||
return target.Availability{Available: true, Evidence: "Debian marker, apt-config, and apt.conf.d configuration capability detected"}
|
||||
return target.Availability{Available: true, Evidence: "Debian marker, apt-config, and apt.conf.d configuration capability detected"}, nil
|
||||
}
|
||||
|
||||
func (a *Adapter) Detect(ctx context.Context, active *profile.Profile) target.Detection {
|
||||
availability, availabilityErr := a.detectAvailability(ctx)
|
||||
inspection, inspectionErr := a.inspect(ctx, active)
|
||||
return target.Detection{Availability: availability, Inspection: inspection, Err: errors.Join(availabilityErr, inspectionErr)}
|
||||
}
|
||||
|
||||
func (a *Adapter) OverlayPath() string { return a.configuration.OverlayFile }
|
||||
|
||||
Reference in New Issue
Block a user