Skip to content

Commit

Permalink
feat(authorization): use github.com/Scalingo/go-plugins-helpers/sdk
Browse files Browse the repository at this point in the history
… rather than upstream one
  • Loading branch information
EtienneM committed Feb 11, 2025
1 parent 20ecfc1 commit 41f69b8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
12 changes: 8 additions & 4 deletions authorization/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import (
"encoding/pem"
"net/http"

"github.com/docker/go-plugins-helpers/sdk"
"github.com/sirupsen/logrus"

"github.com/Scalingo/go-plugins-helpers/sdk"
)

const (
Expand Down Expand Up @@ -107,8 +109,8 @@ type Handler struct {
}

// NewHandler initializes the request handler with a plugin implementation.
func NewHandler(plugin Plugin) *Handler {
h := &Handler{plugin, sdk.NewHandler(manifest)}
func NewHandler(logger logrus.FieldLogger, plugin Plugin) *Handler {
h := &Handler{plugin, sdk.NewHandler(logger, manifest)}
h.initMux()
return h
}
Expand All @@ -126,7 +128,7 @@ func (h *Handler) initMux() {
type actionHandler func(Request) Response

func (h *Handler) handle(name string, actionCall actionHandler) {
h.HandleFunc(name, func(w http.ResponseWriter, r *http.Request) {
h.HandleFunc(name, func(w http.ResponseWriter, r *http.Request, _ map[string]string) error {
var (
req Request
d = json.NewDecoder(r.Body)
Expand All @@ -139,5 +141,7 @@ func (h *Handler) handle(name string, actionCall actionHandler) {
res := actionCall(req)

sdk.EncodeResponse(w, res, res.Err != "")

return nil
})
}
4 changes: 3 additions & 1 deletion authorization/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (

"github.com/docker/go-plugins-helpers/sdk"
"github.com/stretchr/testify/require"

"github.com/Scalingo/go-utils/logger"
)

type TestPlugin struct {
Expand Down Expand Up @@ -215,7 +217,7 @@ func callURL(url string) {

func TestMain(m *testing.M) {
d := &TestPlugin{}
h := NewHandler(d)
h := NewHandler(logger.Default(), d)
go func() {
err := h.ServeTCP("test", "localhost:32456", "", nil)
if err != nil {
Expand Down

0 comments on commit 41f69b8

Please sign in to comment.