dbus: add GetEnv method for session environment inspection
This commit is contained in:
parent
dd8a31dd8a
commit
935c234ce9
22
main.go
22
main.go
|
|
@ -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"/>
|
||||
|
|
|
|||
Reference in New Issue