From 4e1f8fbbad05fed7762dd085370734d70bcdad83 Mon Sep 17 00:00:00 2001 From: Fred Lotter Date: Thu, 31 Aug 2023 18:37:48 +0200 Subject: [PATCH] feat(daemon): daemon access for API extensions The following PR provided Pebble derived projects to extend the supplied daemon HTTP API handlers. https://github.com/canonical/pebble/pull/265 However, currently such a handler cannot access the daemon, even though we added a daemon method to also expose the Overlord. func v1PostDevice( *daemon.Command, req *http.Request, _ *daemon.UserState) daemon.Response { : // Cannot access c.d (daemon is private) ovld := c.d.Overlord() : } This PR adds c.Daemon() to allow access inside externally defined HTTP API handlers. --- internals/daemon/daemon.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internals/daemon/daemon.go b/internals/daemon/daemon.go index 75ba84ee..15517549 100644 --- a/internals/daemon/daemon.go +++ b/internals/daemon/daemon.go @@ -225,6 +225,10 @@ func (d *Daemon) Overlord() *overlord.Overlord { return d.overlord } +func (c *Command) Daemon() *Daemon { + return c.d +} + func (c *Command) ServeHTTP(w http.ResponseWriter, r *http.Request) { st := c.d.state st.Lock()