package ppauth import ( "bytes" "context" "encoding/json" "os" "os/exec" "time" ) // CommandProbe reuses the worker's read-only PP adapter; secrets travel on stdin. func CommandProbe(python, script string) func(context.Context, Credentials) Observation { return func(ctx context.Context, c Credentials) Observation { ctx, cancel := context.WithTimeout(ctx, 45*time.Second) defer cancel() raw, _ := json.Marshal(c) command := exec.CommandContext(ctx, python, script) command.Stdin = bytes.NewReader(raw) command.Env = []string{"PATH=" + os.Getenv("PATH"), "PYTHONUNBUFFERED=1"} out, err := command.Output() if err != nil || len(out) > 8192 { return Observation{State: "unavailable", Message: "PP 检查服务暂不可用,请重试"} } var o Observation if json.Unmarshal(out, &o) != nil { return Observation{State: "unavailable", Message: "PP 检查结果不可识别"} } return o } }