forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
interfaces.go
66 lines (52 loc) · 1.99 KB
/
interfaces.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package osinserver
import (
"net/http"
"github.com/RangelReale/osin"
)
// mux is an object that can register http handlers.
type Mux interface {
Handle(pattern string, handler http.Handler)
HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))
}
// AuthorizeHandler populates an AuthorizeRequest or handles the request itself
type AuthorizeHandler interface {
// HandleAuthorize populates an AuthorizeRequest (typically the Authorized and UserData fields)
// and returns false, or writes the response itself and returns true.
HandleAuthorize(ar *osin.AuthorizeRequest, w http.ResponseWriter) (handled bool, err error)
}
type AuthorizeHandlerFunc func(ar *osin.AuthorizeRequest, w http.ResponseWriter) (bool, error)
func (f AuthorizeHandlerFunc) HandleAuthorize(ar *osin.AuthorizeRequest, w http.ResponseWriter) (bool, error) {
return f(ar, w)
}
type AuthorizeHandlers []AuthorizeHandler
func (all AuthorizeHandlers) HandleAuthorize(ar *osin.AuthorizeRequest, w http.ResponseWriter) (bool, error) {
for _, h := range all {
if handled, err := h.HandleAuthorize(ar, w); handled || err != nil {
return handled, err
}
}
return false, nil
}
// AccessHandler populates an AccessRequest
type AccessHandler interface {
// HandleAccess populates an AccessRequest (typically the Authorized and UserData fields)
HandleAccess(ar *osin.AccessRequest, w http.ResponseWriter) error
}
type AccessHandlerFunc func(ar *osin.AccessRequest, w http.ResponseWriter) error
func (f AccessHandlerFunc) HandleAccess(ar *osin.AccessRequest, w http.ResponseWriter) error {
return f(ar, w)
}
type AccessHandlers []AccessHandler
func (all AccessHandlers) HandleAccess(ar *osin.AccessRequest, w http.ResponseWriter) error {
for _, h := range all {
if err := h.HandleAccess(ar, w); err != nil {
return err
}
}
return nil
}
// ErrorHandler writes an error response
type ErrorHandler interface {
// HandleError writes an error response
HandleError(err error, w http.ResponseWriter, req *http.Request)
}