fix(webui): bind task requester to authenticated principal
This commit is contained in:
1 parent
4217a50874
commit
cbc4cf309d
7 files changed
+157
-124
No files matched your search
@@ -14,6 +14,7 @@ import (
|
||||
"google.golang.org/grpc/status"
|
||||
|
||||
controlpb "github.com/samcharles93/archie-core/internal/contracts/controlplane/v1"
|
||||
"github.com/samcharles93/archie-core/internal/domain/access"
|
||||
"github.com/samcharles93/archie-core/internal/domain/org"
|
||||
"github.com/samcharles93/archie-core/internal/domain/workflow"
|
||||
"github.com/samcharles93/archie-core/internal/domain/workflow/task"
|
||||
@@ -50,7 +51,6 @@ func (s *Server) handleWorkflows(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
type workRequest struct {
|
||||
Identity string `json:"identity"`
|
||||
Repository string `json:"repository"`
|
||||
Workflow string `json:"workflow"`
|
||||
Title string `json:"title"`
|
||||
@@ -70,6 +70,11 @@ func (s *Server) handleWorkRequest(w http.ResponseWriter, r *http.Request) {
|
||||
if !s.authorizeTaskMutation(w, r) {
|
||||
return
|
||||
}
|
||||
principal, ok := access.PrincipalFromContext(r.Context())
|
||||
if !ok || principal.IdentityID == "" {
|
||||
http.Error(w, "authenticated requester required", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
r.Body = http.MaxBytesReader(w, r.Body, 32<<10)
|
||||
var request workRequest
|
||||
decoder := json.NewDecoder(r.Body)
|
||||
@@ -86,13 +91,12 @@ func (s *Server) handleWorkRequest(w http.ResponseWriter, r *http.Request) {
|
||||
http.Error(w, "invalid work request", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
request.Identity = strings.TrimSpace(request.Identity)
|
||||
request.Repository = strings.TrimSpace(request.Repository)
|
||||
request.Workflow = strings.TrimSpace(request.Workflow)
|
||||
request.Title = strings.TrimSpace(request.Title)
|
||||
request.Instructions = strings.TrimSpace(request.Instructions)
|
||||
if request.Identity == "" || request.Workflow == "" || request.Title == "" || request.Instructions == "" {
|
||||
http.Error(w, "identity, workflow, title, and instructions are required", http.StatusBadRequest)
|
||||
if request.Workflow == "" || request.Title == "" || request.Instructions == "" {
|
||||
http.Error(w, "workflow, title, and instructions are required", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if utf8.RuneCountInString(request.Title) > 80 {
|
||||
@@ -113,7 +117,7 @@ func (s *Server) handleWorkRequest(w http.ResponseWriter, r *http.Request) {
|
||||
http.Error(w, err.Error(), status)
|
||||
return
|
||||
}
|
||||
created, err := s.Store.EnqueueChatTask(r.Context(), owner, repo, request.Title, request.Instructions, request.Workflow, request.Identity, "", request.Draft, request.Inputs)
|
||||
created, err := s.Store.EnqueueChatTask(r.Context(), owner, repo, request.Title, request.Instructions, request.Workflow, string(principal.IdentityID), "", request.Draft, request.Inputs)
|
||||
if err != nil {
|
||||
s.logf("work request enqueue failed", "err", err)
|
||||
http.Error(w, "work request rejected", http.StatusBadRequest)
|
||||
|
||||
Reference in new issue
Block a user