Skip to content

Commit 5594cae

Browse files
committed
chore(decom): Block post/put methods
1 parent 1dea7ae commit 5594cae

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
**NOTE** As of August 31, the Launch (provisioning) service is no longer supported. You can use individual clouds in order to Launch an image.
2+
13
# provisioning-backend
24

35
Provisioning backend service for cloud.redhat.com
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package middleware
2+
3+
import (
4+
"net/http"
5+
6+
"github.com/RHEnVision/provisioning-backend/internal/config"
7+
)
8+
9+
func BlockWriteOperationsMiddleware(next http.Handler) http.Handler {
10+
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
11+
isProd := config.InProdClowder()
12+
isStage := config.InStageClowder()
13+
14+
if (isProd || isStage) && (r.Method == "POST" || r.Method == "PUT") {
15+
w.Header().Set("Content-Type", "application/json")
16+
w.WriteHeader(http.StatusNotImplemented)
17+
_, _ = w.Write([]byte(`{"msg": "Write operations are not available in this environment, service is decommissioned"}`))
18+
return
19+
}
20+
21+
next.ServeHTTP(w, r)
22+
})
23+
}

internal/routes/all_routes.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ func MountAPI(r *chi.Mux) {
8686
})
8787

8888
r.Route("/pubkeys", func(r chi.Router) {
89-
r.With(middleware.EnforcePermissions("pubkey", "write")).Post("/", s.CreatePubkey)
89+
r.With(middleware.BlockWriteOperationsMiddleware).With(middleware.EnforcePermissions("pubkey", "write")).Post("/", s.CreatePubkey)
9090
r.With(middleware.EnforcePermissions("pubkey", "read")).With(middleware.Pagination).Get("/", s.ListPubkeys)
91-
r.Post("/", s.CreatePubkey)
91+
r.With(middleware.BlockWriteOperationsMiddleware).Post("/", s.CreatePubkey)
9292
r.Route("/{ID}", func(r chi.Router) {
9393
r.With(middleware.EnforcePermissions("pubkey", "read")).Get("/", s.GetPubkey)
9494
r.With(middleware.EnforcePermissions("pubkey", "write")).Delete("/", s.DeletePubkey)
@@ -102,7 +102,7 @@ func MountAPI(r *chi.Mux) {
102102
r.Route("/{TYPE}", func(r chi.Router) {
103103
// additional permission checks are in the service functions
104104
r.With(middleware.EnforcePermissions("reservation", "read")).Get("/{ID}", s.GetReservationDetail)
105-
r.With(middleware.EnforcePermissions("reservation", "write")).Post("/", s.CreateReservation)
105+
r.With(middleware.BlockWriteOperationsMiddleware).With(middleware.EnforcePermissions("reservation", "write")).Post("/", s.CreateReservation)
106106
})
107107
// Generic reservation detail request (no details provided)
108108
r.With(middleware.EnforcePermissions("reservation", "read")).Get("/{ID}", s.GetReservationDetail)
@@ -111,7 +111,7 @@ func MountAPI(r *chi.Mux) {
111111
// Endpoint used by sources background checker (no permissions needed)
112112
r.Route("/availability_status", func(r chi.Router) {
113113
r.Route("/sources", func(r chi.Router) {
114-
r.Post("/", s.AvailabilityStatus)
114+
r.With(middleware.BlockWriteOperationsMiddleware).Post("/", s.AvailabilityStatus)
115115
})
116116
})
117117

0 commit comments

Comments
 (0)