From 7c5b741937ccb9f3b1a9369e3fb215af6861a29a Mon Sep 17 00:00:00 2001 From: Maciej Borzecki Date: Thu, 26 Sep 2024 10:54:42 +0200 Subject: [PATCH] cmd/snap/debug-api: option to choose access through /run/snapd-snap.socket Add an option to choose access through the dedicated snap socket. Signed-off-by: Maciej Borzecki --- cmd/snap/cmd_debug_api.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/cmd/snap/cmd_debug_api.go b/cmd/snap/cmd_debug_api.go index 2f107635e10..b2fb7016634 100644 --- a/cmd/snap/cmd_debug_api.go +++ b/cmd/snap/cmd_debug_api.go @@ -28,6 +28,7 @@ import ( "strings" "github.com/jessevdk/go-flags" + "github.com/snapcore/snapd/dirs" "github.com/snapcore/snapd/logger" ) @@ -49,6 +50,8 @@ $ echo '{"action": "refresh"}' | snap debug api -X POST \ type cmdDebugAPI struct { clientMixin + SnapSocket bool `long:"snap-socket"` + Headers []string `short:"H" long:"header"` Method string `short:"X" long:"request"` Fail bool `long:"fail"` @@ -67,13 +70,19 @@ func init() { func() flags.Commander { return &cmdDebugAPI{} }, map[string]string{ - "header": "Set header (can be repeated multiple times), header kind and value are separated with ': '", - "request": "HTTP method to use (defaults to GET)", - "fail": "Fail on request errors", + "header": "Set header (can be repeated multiple times), header kind and value are separated with ': '", + "request": "HTTP method to use (defaults to GET)", + "fail": "Fail on request errors", + "snap-socket": "Use snap access socket", }, nil) } func (x *cmdDebugAPI) Execute(args []string) error { + if x.SnapSocket { + ClientConfig.Socket = dirs.SnapSocket + x.setClient(mkClient()) + } + method := x.Method switch method { case "GET", "POST", "PUT":