fix: complete target diagnostics and reset inspection
This commit is contained in:
+69
-1
@@ -34,6 +34,12 @@ const (
|
||||
|
||||
var requiredSchemas = []string{proxySchema, httpSchema, httpsSchema, socksSchema}
|
||||
|
||||
var managedSettings = []struct{ schema, key string }{
|
||||
{proxySchema, "mode"}, {proxySchema, "autoconfig-url"}, {proxySchema, "ignore-hosts"},
|
||||
{httpSchema, "host"}, {httpSchema, "port"}, {httpSchema, "use-authentication"}, {httpSchema, "authentication-user"}, {httpSchema, "authentication-password"},
|
||||
{httpsSchema, "host"}, {httpsSchema, "port"}, {socksSchema, "host"}, {socksSchema, "port"},
|
||||
}
|
||||
|
||||
// Command is the complete command contract used by the adapter. UID, GID, and
|
||||
// Env make user-session identity explicit when proxyctl itself runs under sudo.
|
||||
type Command struct {
|
||||
@@ -230,7 +236,10 @@ type Adapter struct {
|
||||
state StateStore
|
||||
}
|
||||
|
||||
var _ target.Target = (*Adapter)(nil)
|
||||
var (
|
||||
_ target.Target = (*Adapter)(nil)
|
||||
_ target.Diagnosable = (*Adapter)(nil)
|
||||
)
|
||||
|
||||
func New(configuration Configuration, runner CommandRunner, state StateStore) *Adapter {
|
||||
if configuration.CommandName == "" {
|
||||
@@ -271,6 +280,65 @@ func (a *Adapter) Description() target.Description {
|
||||
|
||||
func (a *Adapter) Confirmation(bool) string { return "" }
|
||||
|
||||
// DiagnosticChecks uses only gsettings list/get operations and filesystem
|
||||
// metadata probes. In particular, it never invokes gsettings set or locks or
|
||||
// writes the recovery StateStore.
|
||||
func (a *Adapter) DiagnosticChecks(ctx context.Context, _ *profile.Profile) []target.Check {
|
||||
commandCheck := target.Check{Name: "required command", OK: true, Evidence: a.configuration.CommandName + " is usable for the owning user"}
|
||||
schemaCheck := target.Check{Name: "required schemas", OK: true, Evidence: "all GNOME proxy schemas are present"}
|
||||
sessionCheck := target.Check{Name: "desktop session", OK: true, Evidence: "GNOME proxy settings are readable through the configured session bus"}
|
||||
output, err := a.run(ctx, "list-schemas")
|
||||
if err != nil {
|
||||
commandCheck.OK = false
|
||||
commandCheck.Evidence = profile.RedactText(a.configuration.CommandName + " failed: " + err.Error())
|
||||
schemaCheck.OK = false
|
||||
schemaCheck.Evidence = "GNOME schemas could not be listed"
|
||||
sessionCheck.OK = false
|
||||
sessionCheck.Evidence = "desktop session could not be inspected"
|
||||
} else {
|
||||
present := make(map[string]bool)
|
||||
for _, schema := range strings.Fields(output) {
|
||||
present[schema] = true
|
||||
}
|
||||
var missing []string
|
||||
for _, schema := range requiredSchemas {
|
||||
if !present[schema] {
|
||||
missing = append(missing, schema)
|
||||
}
|
||||
}
|
||||
if len(missing) != 0 {
|
||||
schemaCheck.OK = false
|
||||
schemaCheck.Evidence = "missing GNOME proxy schemas: " + strings.Join(missing, ", ")
|
||||
sessionCheck.OK = false
|
||||
sessionCheck.Evidence = "desktop session settings cannot be checked without required schemas"
|
||||
} else if _, err := a.readSettings(ctx); err != nil {
|
||||
sessionCheck.OK = false
|
||||
sessionCheck.Evidence = profile.RedactText("GNOME proxy settings are unreadable: " + err.Error())
|
||||
}
|
||||
}
|
||||
authorityCheck := target.ReadOnlyWriteAuthority(a.configuration.StateFile)
|
||||
if !commandCheck.OK || !schemaCheck.OK || !sessionCheck.OK {
|
||||
authorityCheck.OK = false
|
||||
authorityCheck.Evidence += "; GNOME setting authority could not be inspected"
|
||||
} else {
|
||||
for _, setting := range managedSettings {
|
||||
output, err := a.run(ctx, "writable", setting.schema, setting.key)
|
||||
if err != nil || strings.TrimSpace(output) != "true" {
|
||||
authorityCheck.OK = false
|
||||
detail := strings.TrimSpace(output)
|
||||
if err != nil {
|
||||
detail = err.Error()
|
||||
}
|
||||
authorityCheck.Evidence += profile.RedactText(fmt.Sprintf("; %s %s is not writable: %s", setting.schema, setting.key, detail))
|
||||
}
|
||||
}
|
||||
if authorityCheck.OK {
|
||||
authorityCheck.Evidence += "; all managed GNOME settings report writable"
|
||||
}
|
||||
}
|
||||
return []target.Check{commandCheck, schemaCheck, sessionCheck, authorityCheck}
|
||||
}
|
||||
|
||||
func (a *Adapter) Availability(ctx context.Context) target.Availability {
|
||||
output, err := a.run(ctx, "list-schemas")
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user