Skip to content

Commit 9690d27

Browse files
authored
feat: create new helper which enables passing in of a key manager (#109)
1 parent 62dd952 commit 9690d27

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

server/api.go

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,12 @@ func combine(f, g func(http.HandlerFunc) http.HandlerFunc) func(http.HandlerFunc
5555
}
5656
}
5757

58-
// GetRouter creates the mux router that serves knox routes.
59-
// All routes are declared in this file. Each handler itself takes in the db and
60-
// auth provider interfaces and returns a handler that the is processed through
61-
// the API Middleware.
62-
func GetRouter(
58+
// GetRouterFromKeyManager creates the mux router that serves knox routes from a key manager
59+
func GetRouterFromKeyManager(
6360
cryptor keydb.Cryptor,
64-
db keydb.DB,
61+
keyManager KeyManager,
6562
decorators [](func(http.HandlerFunc) http.HandlerFunc),
6663
additionalRoutes []Route) (*mux.Router, error) {
67-
6864
existingRouteIds := map[string]Route{}
6965
existingRouteMethodAndPaths := map[string]map[string]Route{}
7066
allRoutes := append(routes[:], additionalRoutes[:]...)
@@ -103,16 +99,28 @@ func GetRouter(
10399
decorator = combine(decorators[j], decorator)
104100
}
105101

106-
m := NewKeyManager(cryptor, db)
107-
108-
r.NotFoundHandler = setupRoute("404", m)(decorator(WriteErr(errF(knox.NotFoundCode, ""))))
102+
r.NotFoundHandler = setupRoute("404", keyManager)(decorator(WriteErr(errF(knox.NotFoundCode, ""))))
109103

110104
for _, route := range allRoutes {
111-
addRoute(r, route, decorator, m)
105+
addRoute(r, route, decorator, keyManager)
112106
}
113107
return r, nil
114108
}
115109

110+
// GetRouter creates the mux router that serves knox routes.
111+
// All routes are declared in this file. Each handler itself takes in the db and
112+
// auth provider interfaces and returns a handler that the is processed through
113+
// the API Middleware.
114+
func GetRouter(
115+
cryptor keydb.Cryptor,
116+
db keydb.DB,
117+
decorators [](func(http.HandlerFunc) http.HandlerFunc),
118+
additionalRoutes []Route) (*mux.Router, error) {
119+
m := NewKeyManager(cryptor, db)
120+
121+
return GetRouterFromKeyManager(cryptor, m, decorators, additionalRoutes)
122+
}
123+
116124
func addRoute(
117125
router *mux.Router,
118126
route Route,

0 commit comments

Comments
 (0)