pi-agent: Implement progressive Target detection
This commit is contained in:
+16
-4
@@ -348,9 +348,15 @@ 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) {
|
||||
output, err := a.run(ctx, "list-schemas")
|
||||
if err != nil {
|
||||
return target.Availability{Evidence: fmt.Sprintf("GNOME Target requires a usable %s command: %v", a.configuration.CommandName, redact(err))}
|
||||
safeErr := redact(err)
|
||||
return target.Availability{Evidence: fmt.Sprintf("GNOME Target requires a usable %s command: %v", a.configuration.CommandName, safeErr)}, safeErr
|
||||
}
|
||||
present := make(map[string]bool)
|
||||
for _, schema := range strings.Fields(output) {
|
||||
@@ -358,13 +364,19 @@ func (a *Adapter) Availability(ctx context.Context) target.Availability {
|
||||
}
|
||||
for _, schema := range requiredSchemas {
|
||||
if !present[schema] {
|
||||
return target.Availability{Evidence: "required GNOME settings schema is unavailable: " + schema}
|
||||
return target.Availability{Evidence: "required GNOME settings schema is unavailable: " + schema}, nil
|
||||
}
|
||||
}
|
||||
if _, err := a.readSettings(ctx); err != nil {
|
||||
return target.Availability{Evidence: fmt.Sprintf("GNOME proxy schema is present but unusable for the desktop session: %v", redact(err))}
|
||||
safeErr := redact(err)
|
||||
return target.Availability{Evidence: fmt.Sprintf("GNOME proxy schema is present but unusable for the desktop session: %v", safeErr)}, safeErr
|
||||
}
|
||||
return target.Availability{Available: true, Evidence: "gsettings command and GNOME proxy schemas are usable for the owning user"}
|
||||
return target.Availability{Available: true, Evidence: "gsettings command and GNOME proxy schemas are usable for the owning user"}, nil
|
||||
}
|
||||
|
||||
func (a *Adapter) Detect(ctx context.Context, active *profile.Profile) target.Detection {
|
||||
availability, err := a.detectAvailability(ctx)
|
||||
return target.Detection{Availability: availability, Inspection: a.Inspect(ctx, active), Err: err}
|
||||
}
|
||||
|
||||
func (a *Adapter) Inspect(ctx context.Context, active *profile.Profile) target.Inspection {
|
||||
|
||||
Reference in New Issue
Block a user