Skip to content

Commit

Permalink
pr fix: Expose daemon.api
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-rodriguez committed Jul 31, 2023
1 parent 8704de8 commit 98186fe
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
6 changes: 1 addition & 5 deletions internals/daemon/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/canonical/pebble/internals/overlord/state"
)

var api = []*Command{{
var Api = []*Command{{
// See daemon.go:canAccess for details how the access is controlled.
Path: "/v1/system-info",
GuestOK: true,
Expand Down Expand Up @@ -117,7 +117,3 @@ func v1SystemInfo(c *Command, r *http.Request, _ *UserState) Response {
}
return SyncResponse(result)
}

func Register(c *Command) {
api = append(api, c)
}
2 changes: 1 addition & 1 deletion internals/daemon/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (s *apiSuite) daemon(c *check.C) *Daemon {
}

func apiCmd(path string) *Command {
for _, cmd := range api {
for _, cmd := range Api {
if cmd.Path == path {
return cmd
}
Expand Down
7 changes: 5 additions & 2 deletions internals/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ type Daemon struct {
mu sync.Mutex
}

// XXX Placeholder for now.
// UserState represents the state of an authenticated API user.
//
// The struct is currently empty as the behaviors haven't been implemented
// yet.
type UserState struct{}

// A ResponseFunc handles one of the individual verbs for a method
Expand Down Expand Up @@ -402,7 +405,7 @@ func (d *Daemon) SetDegradedMode(err error) {
func (d *Daemon) addRoutes() {
d.router = mux.NewRouter()

for _, c := range api {
for _, c := range Api {
c.d = d
if c.PathPrefix == "" {
d.router.Handle(c.Path, c).Name(c.Path)
Expand Down
8 changes: 4 additions & 4 deletions internals/daemon/daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (s *daemonSuite) TestRegisterCommand(c *C) {
GuestOK: true,
GET: getCallback,
}
Register(&command)
Api = append(Api, &command)

d := s.newDaemon(c)
d.Init()
Expand Down Expand Up @@ -421,16 +421,16 @@ func (s *daemonSuite) TestSuperAccess(c *check.C) {
func (s *daemonSuite) TestAddRoutes(c *check.C) {
d := s.newDaemon(c)

expected := make([]string, len(api))
for i, v := range api {
expected := make([]string, len(Api))
for i, v := range Api {
if v.PathPrefix != "" {
expected[i] = v.PathPrefix
continue
}
expected[i] = v.Path
}

got := make([]string, 0, len(api))
got := make([]string, 0, len(Api))
c.Assert(d.router.Walk(func(route *mux.Route, router *mux.Router, ancestors []*mux.Route) error {
got = append(got, route.GetName())
return nil
Expand Down

0 comments on commit 98186fe

Please sign in to comment.