Skip to content

Commit 783672a

Browse files
vsilentCopilot
andcommitted
feat(dockerhub): add POST /dockerhub/events analytics endpoint
The stack builder UI (ServiceDockerhub.jsx) fires POST requests to /api/builder/dockerhub/events to log autocomplete interactions. The Next.js proxy forwards them to stacker at POST /dockerhub/events, but no such route existed — Casbin denied it with 403. - Add log_event handler: accepts {event, payload} JSON body, logs via tracing at DEBUG level, returns 204 No Content (fire-and-forget) - Register in startup.rs under /dockerhub scope - Add Casbin migration granting group_user and group_admin POST access Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent f7b639a commit 783672a

4 files changed

Lines changed: 24 additions & 2 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
DELETE FROM public.casbin_rule
2+
WHERE ptype = 'p' AND v1 = '/dockerhub/events' AND v2 = 'POST';
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-- Allow authenticated users to post DockerHub autocomplete analytics events
2+
INSERT INTO public.casbin_rule (ptype, v0, v1, v2, v3, v4, v5)
3+
VALUES ('p', 'group_user', '/dockerhub/events', 'POST', '', '', '')
4+
ON CONFLICT DO NOTHING;
5+
6+
INSERT INTO public.casbin_rule (ptype, v0, v1, v2, v3, v4, v5)
7+
VALUES ('p', 'group_admin', '/dockerhub/events', 'POST', '', '', '')
8+
ON CONFLICT DO NOTHING;

src/routes/dockerhub/mod.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ use std::sync::Arc;
22

33
use crate::connectors::{DockerHubConnector, NamespaceSummary, RepositorySummary, TagSummary};
44
use crate::helpers::JsonResponse;
5-
use actix_web::{get, web, Error, Responder};
5+
use actix_web::{get, post, web, Error, HttpResponse, Responder};
66
use serde::Deserialize;
7+
use serde_json::Value;
78

89
#[derive(Deserialize, Debug)]
910
pub struct AutocompleteQuery {
@@ -86,6 +87,16 @@ pub async fn list_tags(
8687
.map_err(Error::from)
8788
}
8889

90+
/// Receive a DockerHub autocomplete analytics event from the stack builder UI.
91+
/// The payload is `{event: string, payload: any}` — logged and discarded.
92+
/// Returns 204 No Content so the browser's fire-and-forget fetch succeeds.
93+
#[tracing::instrument(name = "dockerhub_log_event", skip(body))]
94+
#[post("/events")]
95+
pub async fn log_event(body: web::Json<Value>) -> HttpResponse {
96+
tracing::debug!(event = ?body, "dockerhub autocomplete event received");
97+
HttpResponse::NoContent().finish()
98+
}
99+
89100
#[cfg(test)]
90101
mod tests {
91102
use super::*;

src/startup.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ pub async fn run(
158158
web::scope("/dockerhub")
159159
.service(crate::routes::dockerhub::search_namespaces)
160160
.service(crate::routes::dockerhub::list_repositories)
161-
.service(crate::routes::dockerhub::list_tags),
161+
.service(crate::routes::dockerhub::list_tags)
162+
.service(crate::routes::dockerhub::log_event),
162163
)
163164
.service(
164165
web::scope("/admin")

0 commit comments

Comments
 (0)