dbus: add GetEnv method for session environment inspection

This commit is contained in:
Levi Neely 2026-07-18 15:27:05 +02:00
parent dd8a31dd8a
commit 935c234ce9
1 changed files with 22 additions and 0 deletions

22
main.go
View File

@ -439,6 +439,24 @@ func (m *SessionManager) GetCost(sessionID string) (string, *dbus.Error) {
return sess.core.Cost(), nil
}
func (m *SessionManager) GetEnv(sessionID string) (string, *dbus.Error) {
m.mu.RLock()
_, ok := m.sessions[sessionID]
m.mu.RUnlock()
if !ok {
return "", dbus.MakeFailedError(fmt.Errorf("session not found: %s", sessionID))
}
var sb strings.Builder
fmt.Fprintf(&sb, "OLLIE_SESSION_ID=%s\n", sessionID)
for _, e := range os.Environ() {
if strings.HasPrefix(e, "OLLIE_") && !strings.HasPrefix(e, "OLLIE_SESSION_ID=") {
sb.WriteString(e)
sb.WriteByte('\n')
}
}
return sb.String(), nil
}
// --- Config ---
func (m *SessionManager) GetConfig(sessionID string) (string, *dbus.Error) {
@ -1262,6 +1280,10 @@ const introspectXML = `<node>
<arg name="session_id" type="s" direction="in"/>
<arg name="cost" type="s" direction="out"/>
</method>
<method name="GetEnv">
<arg name="session_id" type="s" direction="in"/>
<arg name="env" type="s" direction="out"/>
</method>
<method name="GetConfig">
<arg name="session_id" type="s" direction="in"/>
<arg name="config" type="s" direction="out"/>