Skip to content

Commit

Permalink
cmd/snap/debug-api: option to choose access through /run/snapd-snap.s…
Browse files Browse the repository at this point in the history
…ocket

Add an option to choose access through the dedicated snap socket.

Signed-off-by: Maciej Borzecki <[email protected]>
  • Loading branch information
bboozzoo committed Oct 7, 2024
1 parent 37eb0a3 commit 2eefa00
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions cmd/snap/cmd_debug_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"strings"

"github.com/jessevdk/go-flags"
"github.com/snapcore/snapd/dirs"
"github.com/snapcore/snapd/logger"
)

Expand All @@ -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"`
Expand All @@ -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":
Expand Down

0 comments on commit 2eefa00

Please sign in to comment.