Skip to content

Commit 657cff1

Browse files
committed
Fix
1 parent 83dca98 commit 657cff1

File tree

1 file changed

+36
-21
lines changed

1 file changed

+36
-21
lines changed

server/src/handlers/http.rs

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,19 @@ pub fn configure_routes(cfg: &mut web::ServiceConfig) {
141141
.route(
142142
web::put()
143143
.to(logstream::put_stream)
144-
.auth_stream(Action::CreateStream),
144+
.authorize_for_stream(Action::CreateStream),
145145
)
146146
// POST "/logstream/{logstream}" ==> Post logs to given log stream
147-
.route(web::post().to(ingest::post_event))
147+
.route(
148+
web::post()
149+
.to(ingest::post_event)
150+
.authorize_for_stream(Action::Ingest),
151+
)
148152
// DELETE "/logstream/{logstream}" ==> Delete log stream
149153
.route(
150154
web::delete()
151155
.to(logstream::delete)
152-
.auth_stream(Action::DeleteStream),
156+
.authorize_for_stream(Action::DeleteStream),
153157
)
154158
.app_data(web::PayloadConfig::default().limit(MAX_EVENT_PAYLOAD_SIZE)),
155159
)
@@ -159,29 +163,29 @@ pub fn configure_routes(cfg: &mut web::ServiceConfig) {
159163
.route(
160164
web::put()
161165
.to(logstream::put_alert)
162-
.auth_stream(Action::PutAlert),
166+
.authorize_for_stream(Action::PutAlert),
163167
)
164168
// GET "/logstream/{logstream}/alert" ==> Get alert for given log stream
165169
.route(
166170
web::get()
167171
.to(logstream::get_alert)
168-
.auth_stream(Action::GetAlert),
172+
.authorize_for_stream(Action::GetAlert),
169173
),
170174
)
171175
.service(
172176
// GET "/logstream/{logstream}/schema" ==> Get schema for given log stream
173177
web::resource("/schema").route(
174178
web::get()
175179
.to(logstream::schema)
176-
.auth_stream(Action::GetSchema),
180+
.authorize_for_stream(Action::GetSchema),
177181
),
178182
)
179183
.service(
180184
// GET "/logstream/{logstream}/stats" ==> Get stats for given log stream
181185
web::resource("/stats").route(
182186
web::get()
183187
.to(logstream::get_stats)
184-
.auth_stream(Action::GetStats),
188+
.authorize_for_stream(Action::GetStats),
185189
),
186190
)
187191
.service(
@@ -190,13 +194,13 @@ pub fn configure_routes(cfg: &mut web::ServiceConfig) {
190194
.route(
191195
web::put()
192196
.to(logstream::put_retention)
193-
.auth_stream(Action::PutRetention),
197+
.authorize_for_stream(Action::PutRetention),
194198
)
195199
// GET "/logstream/{logstream}/retention" ==> Get retention for given logstream
196200
.route(
197201
web::get()
198202
.to(logstream::get_retention)
199-
.auth_stream(Action::GetRetention),
203+
.authorize_for_stream(Action::GetRetention),
200204
),
201205
);
202206

@@ -205,15 +209,19 @@ pub fn configure_routes(cfg: &mut web::ServiceConfig) {
205209
.service(
206210
web::resource("/{username}")
207211
// PUT /user/{username} => Create a new user
208-
.route(web::put().to(rbac::put_user).auth(Action::PutUser))
212+
.route(web::put().to(rbac::put_user).authorize(Action::PutUser))
209213
// DELETE /user/{username} => Delete a user
210-
.route(web::delete().to(rbac::delete_user).auth(Action::DeleteUser))
211-
.route(web::put().to(rbac::put_roles).auth(Action::PutUser)),
214+
.route(
215+
web::delete()
216+
.to(rbac::delete_user)
217+
.authorize(Action::DeleteUser),
218+
)
219+
.route(web::put().to(rbac::put_roles).authorize(Action::PutUser)),
212220
)
213221
.service(
214222
web::resource("/{username}/roles")
215223
// PUT /user/{username}/roles => Put roles for user
216-
.route(web::put().to(rbac::put_roles).auth(Action::PutRoles)),
224+
.route(web::put().to(rbac::put_roles).authorize(Action::PutRoles)),
217225
)
218226
.wrap_fn(|req, srv| {
219227
// The credentials set in the env vars (P_USERNAME & P_PASSWORD) are treated
@@ -236,13 +244,20 @@ pub fn configure_routes(cfg: &mut web::ServiceConfig) {
236244
web::scope(&base_path())
237245
// POST "/query" ==> Get results of the SQL query passed in request body
238246
.service(
239-
web::resource("/query")
240-
.route(web::post().to(query::query).auth_stream(Action::Query)),
247+
web::resource("/query").route(
248+
web::post()
249+
.to(query::query)
250+
.authorize_for_stream(Action::Query),
251+
),
241252
)
242253
// POST "/ingest" ==> Post logs to given log stream based on header
243254
.service(
244255
web::resource("/ingest")
245-
.route(web::post().to(ingest::ingest).auth(Action::Ingest))
256+
.route(
257+
web::post()
258+
.to(ingest::ingest)
259+
.authorize_for_stream(Action::Ingest),
260+
)
246261
.app_data(web::PayloadConfig::default().limit(MAX_EVENT_PAYLOAD_SIZE)),
247262
)
248263
// GET "/liveness" ==> Liveness check as per https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#define-a-liveness-command
@@ -254,7 +269,7 @@ pub fn configure_routes(cfg: &mut web::ServiceConfig) {
254269
.service(
255270
// GET "/logstream" ==> Get list of all Log Streams on the server
256271
web::resource("")
257-
.route(web::get().to(logstream::list).auth(Action::ListStream)),
272+
.route(web::get().to(logstream::list).authorize(Action::ListStream)),
258273
)
259274
.service(
260275
// logstream API
@@ -277,19 +292,19 @@ pub fn metrics_path() -> String {
277292
}
278293

279294
trait RouteExt {
280-
fn auth(self, action: Action) -> Self;
281-
fn auth_stream(self, action: Action) -> Self;
295+
fn authorize(self, action: Action) -> Self;
296+
fn authorize_for_stream(self, action: Action) -> Self;
282297
}
283298

284299
impl RouteExt for Route {
285-
fn auth(self, action: Action) -> Self {
300+
fn authorize(self, action: Action) -> Self {
286301
self.wrap(Authorization {
287302
action,
288303
stream: false,
289304
})
290305
}
291306

292-
fn auth_stream(self, action: Action) -> Self {
307+
fn authorize_for_stream(self, action: Action) -> Self {
293308
self.wrap(Authorization {
294309
action,
295310
stream: true,

0 commit comments

Comments
 (0)