...

Source file src/edge-infra.dev/pkg/edge/auth-proxy/handlers/session_user_edge_role.go

Documentation: edge-infra.dev/pkg/edge/auth-proxy/handlers

     1  package handlers
     2  
     3  import (
     4  	"net/http"
     5  	"slices"
     6  
     7  	"github.com/gin-gonic/gin"
     8  
     9  	"edge-infra.dev/pkg/edge/auth-proxy/utils"
    10  )
    11  
    12  // SessionUSerEdgeRole handler that updates the session roles with most recent fetched BSL one
    13  func (h ProxyHandler) SessionUserEdgeRole(req *http.Request, body []byte) (*http.Request, []byte, error) {
    14  	respBody, err := utils.GetGraphqlResponse(body)
    15  	if err != nil {
    16  		h.log.Error(err, "failed to unmarshal client response")
    17  		h.c.JSON(http.StatusInternalServerError, gin.H{"message": "Internal Server Error"})
    18  		return req, body, err
    19  	}
    20  	var resp struct{ SessionUserEdgeRole []string }
    21  	if err := utils.Unpack(respBody.Data, &resp); err != nil {
    22  		h.log.Error(err, "failed to unpack response")
    23  		h.c.JSON(http.StatusInternalServerError, gin.H{"message": "Internal Server Error"})
    24  		return req, body, err
    25  	}
    26  
    27  	sessionRoles := h.session.Get("roles").([]string)
    28  
    29  	if !slices.Equal(resp.SessionUserEdgeRole, sessionRoles) && len(resp.SessionUserEdgeRole) > 0 {
    30  		h.session.Set("roles", resp.SessionUserEdgeRole)
    31  	}
    32  	return req, body, h.session.Save()
    33  }
    34  

View as plain text