Skip to content
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

cmd/snap/debug-api: option to choose access through /run/snapd-snap.socket #14540

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
"strings"

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

Expand All @@ -49,6 +50,8 @@
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() 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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is vague, can you clarify that this is using the socket used by snapctl when SNAP_NAME is set?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm but it's using the snap socket only when --snap-socket is passed in the command line, SNAP_NAME is not checked at all

}, nil)
}

func (x *cmdDebugAPI) Execute(args []string) error {
if x.SnapSocket {
ClientConfig.Socket = dirs.SnapSocket
x.setClient(mkClient())
}

Check warning on line 84 in cmd/snap/cmd_debug_api.go

View check run for this annotation

Codecov / codecov/patch

cmd/snap/cmd_debug_api.go#L81-L84

Added lines #L81 - L84 were not covered by tests

method := x.Method
switch method {
case "GET", "POST", "PUT":
Expand Down
Loading