-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
daemon: allowing adding external http handlers #265
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved, but note we should change Api -> API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Just one detail needs to be fixed on the test.
Gustavo reviewed & approved, pending comment fix and conflict resolved |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, but still has issues. :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
The following PR provided Pebble derived projects to extend the supplied daemon HTTP API handlers. canonical#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.
The following PR provided Pebble derived projects to extend the supplied daemon HTTP API handlers. #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.
#265 provides the ability for the daemon REST API to be extended by appending new handlers to the API list. For example, the following new reboot command can be added now: // requestReboot asks the daemon to gracefully shut down the system // and issue a reboot. func requestReboot(d *daemon.Daemon) daemon.Response { d.HandleRestart(restart.RestartSystem) result := deviceResult{} return daemon.SyncResponse(result) } Note that SyncResponse was already public, which allows the code above to work. Following this patch, we can now reply with a suitable error response: : switch(...) { case reboot: requestReboot(...) default: return daemon.ErrorResponse(http.StatusBadRequest,"invalid media type %q", mediaType) { :
This PR turns the daemon API into an exported variable.
External tools depending on pebble may append to the variable to extend the daemon API, see snippet below.