@@ -11,8 +11,8 @@ import (
11
11
"time"
12
12
13
13
"github.com/containers/selinuxd/pkg/datastore"
14
+ "github.com/go-chi/chi/v5"
14
15
"github.com/go-logr/logr"
15
- "github.com/gorilla/mux"
16
16
)
17
17
18
18
const (
@@ -53,7 +53,7 @@ func initStatusServer(cfg StatusServerConfig, ds datastore.ReadOnlyDataStore, l
53
53
}
54
54
55
55
func (ss * statusServer ) Serve (readychan <- chan bool ) error {
56
- r := mux .NewRouter ()
56
+ r := chi .NewRouter ()
57
57
ss .initializeRoutes (r )
58
58
59
59
server := & http.Server {
@@ -75,25 +75,16 @@ func (ss *statusServer) waitForReady(readychan <-chan bool) {
75
75
ss .l .Info ("Status Server got READY signal" )
76
76
}
77
77
78
- func (ss * statusServer ) initializeRoutes (r * mux .Router ) {
78
+ func (ss * statusServer ) initializeRoutes (r chi .Router ) {
79
79
// /policies/
80
- s := r .PathPrefix ("/policies" ).Subrouter ()
81
- s .HandleFunc ("/" , ss .listPoliciesHandler ).
82
- Methods ("GET" )
83
- s .HandleFunc ("/" , ss .catchAllNotGetHandler )
84
- // IMPORTANT(jaosorior): We should better restrict what characters
85
- // does this handler accept
86
- s .HandleFunc ("/{policy}" , ss .getPolicyStatusHandler ).
87
- Methods ("GET" )
88
- s .HandleFunc ("/{policy}" , ss .catchAllNotGetHandler )
89
-
90
- // /policies -- without the trailing /
91
- r .HandleFunc ("/policies" , ss .listPoliciesHandler ).
92
- Methods ("GET" )
93
- r .HandleFunc ("/policies" , ss .catchAllNotGetHandler )
94
- r .HandleFunc ("/ready" , ss .readyStatusHandler )
95
- r .HandleFunc ("/ready/" , ss .readyStatusHandler )
96
- r .HandleFunc ("/" , ss .catchAllHandler )
80
+ r .Route ("/policies" , func (r chi.Router ) {
81
+ r .Get ("/" , ss .listPoliciesHandler )
82
+ r .Get ("/{policy}" , ss .getPolicyStatusHandler )
83
+ })
84
+
85
+ r .Get ("/ready" , ss .readyStatusHandler )
86
+ r .Get ("/ready/" , ss .readyStatusHandler )
87
+ r .Get ("/" , ss .catchAllHandler )
97
88
98
89
if ss .cfg .EnableProfiling {
99
90
r .HandleFunc ("/debug/pprof/" , pprof .Index )
@@ -125,8 +116,7 @@ func (ss *statusServer) listPoliciesHandler(w http.ResponseWriter, r *http.Reque
125
116
}
126
117
127
118
func (ss * statusServer ) getPolicyStatusHandler (w http.ResponseWriter , r * http.Request ) {
128
- vars := mux .Vars (r )
129
- policy := vars ["policy" ]
119
+ policy := chi .URLParam (r , "policy" )
130
120
status , err := ss .ds .Get (policy )
131
121
if errors .Is (err , datastore .ErrPolicyNotFound ) {
132
122
http .Error (w , "couldn't find requested policy" , http .StatusNotFound )
@@ -159,10 +149,6 @@ func (ss *statusServer) catchAllHandler(w http.ResponseWriter, r *http.Request)
159
149
http .Error (w , "Invalid path" , http .StatusBadRequest )
160
150
}
161
151
162
- func (ss * statusServer ) catchAllNotGetHandler (w http.ResponseWriter , r * http.Request ) {
163
- http .Error (w , "Only GET is allowed" , http .StatusBadRequest )
164
- }
165
-
166
152
func createSocket (path string , uid , gid int ) (net.Listener , error ) {
167
153
if err := os .RemoveAll (path ); err != nil {
168
154
return nil , fmt .Errorf ("cannot remove old socket: %w" , err )
0 commit comments