Skip to content

Commit

Permalink
Changes con job uid retreival
Browse files Browse the repository at this point in the history
  • Loading branch information
catttam committed Oct 1, 2024
1 parent 9211206 commit 82b6fc0
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions pkg/handlers/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package handlers

import (
"context"
"encoding/json"
"fmt"
"io"
"log"
Expand Down Expand Up @@ -95,7 +96,16 @@ func MakeJobHandler(cfg *types.Config, kubeClientset *kubernetes.Clientset, back
c.Status(http.StatusUnauthorized)
return
}
} else {
}

// Get the event from request body
eventBytes, err := io.ReadAll(c.Request.Body)
if err != nil {
c.String(http.StatusInternalServerError, err.Error())
return
}

if len(rawToken) != tokenLength {
oidcManager, _ := auth.NewOIDCManager(cfg.OIDCIssuer, cfg.OIDCSubject, cfg.OIDCGroups)

if !oidcManager.IsAuthorised(rawToken) {
Expand All @@ -115,22 +125,19 @@ func MakeJobHandler(cfg *types.Config, kubeClientset *kubernetes.Clientset, back
return
}

ui, err := oidcManager.GetUserInfo(rawToken)
if err != nil {
// Extract user UID from MinIO event
// TODO check if is MinIO event
var decoded map[string]interface{}
if err := json.Unmarshal(eventBytes, &decoded); err != nil {
c.String(http.StatusInternalServerError, err.Error())
return
}
uid := ui.Subject
c.Set("uidOrigin", uid)
c.Next()
records := decoded["Records"].([]interface{})
r := records[0].(map[string]interface{})

}

// Get the event from request body
eventBytes, err := io.ReadAll(c.Request.Body)
if err != nil {
c.String(http.StatusInternalServerError, err.Error())
return
eventInfo := r["requestParameters"].(map[string]interface{})
c.Set("uidOrigin", eventInfo["principalId"])
c.Next()
}

// Initialize event envVar and args var
Expand Down

0 comments on commit 82b6fc0

Please sign in to comment.