@@ -17,11 +17,13 @@ import (
1717 "github.com/styrainc/opa-control-plane/internal/database"
1818 "github.com/styrainc/opa-control-plane/internal/metrics"
1919 "github.com/styrainc/opa-control-plane/internal/server/types"
20+ "github.com/styrainc/opa-control-plane/internal/service"
2021)
2122
2223type Server struct {
2324 router * http.ServeMux
2425 db * database.Database
26+ svc * service.Service
2527 readyFn func (context.Context ) error
2628}
2729
@@ -48,6 +50,7 @@ func (s *Server) Init() *Server {
4850 s .router .HandleFunc ("PUT /v1/bundles/{bundle}" , authenticationMiddleware (s .db , s .v1BundlesPut ))
4951 s .router .HandleFunc ("GET /v1/bundles/{bundle}" , authenticationMiddleware (s .db , s .v1BundlesGet ))
5052 s .router .HandleFunc ("DELETE /v1/bundles/{bundle}" , authenticationMiddleware (s .db , s .v1BundlesDelete ))
53+ s .router .HandleFunc ("POST /v1/bundles/{bundle}" , authenticationMiddleware (s .db , s .v1BundlesPost ))
5154 s .router .HandleFunc ("GET /v1/stacks" , authenticationMiddleware (s .db , s .v1StacksList ))
5255 s .router .HandleFunc ("PUT /v1/stacks/{stack}" , authenticationMiddleware (s .db , s .v1StacksPut ))
5356 s .router .HandleFunc ("GET /v1/stacks/{stack}" , authenticationMiddleware (s .db , s .v1StacksGet ))
@@ -65,6 +68,11 @@ func (s *Server) WithRouter(router *http.ServeMux) *Server {
6568 return s
6669}
6770
71+ func (s * Server ) WithService (svc * service.Service ) * Server {
72+ s .svc = svc
73+ return s
74+ }
75+
6876func (s * Server ) WithDatabase (db * database.Database ) * Server {
6977 s .db = db
7078 return s
@@ -156,6 +164,24 @@ func (s *Server) v1BundlesGet(w http.ResponseWriter, r *http.Request) {
156164 JSONOK (w , resp , pretty (r ))
157165}
158166
167+ func (s * Server ) v1BundlesPost (w http.ResponseWriter , r * http.Request ) {
168+ ctx := r .Context ()
169+
170+ name , err := url .PathUnescape (r .PathValue ("bundle" ))
171+ if err != nil {
172+ ErrorString (w , http .StatusBadRequest , types .CodeInvalidParameter , err )
173+ return
174+ }
175+
176+ if err := s .svc .Trigger (ctx , s .auth (r ), name ); err != nil {
177+ errorAuto (w , err )
178+ return
179+ }
180+
181+ resp := types.BundlesPostResponseV1 {}
182+ JSONOK (w , resp , pretty (r ))
183+ }
184+
159185func (s * Server ) v1BundlesDelete (w http.ResponseWriter , r * http.Request ) {
160186 ctx := r .Context ()
161187
0 commit comments