Skip to content

Commit

Permalink
sf metadata support added
Browse files Browse the repository at this point in the history
  • Loading branch information
leobrada committed Jan 17, 2022
1 parent 56a7717 commit a332e59
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
7 changes: 1 addition & 6 deletions internal/app/authorization/authorization.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ const (
requestEndpoint = "/v1/authorization"
)

type authoResponse struct {
Allow bool `json:"allow"`
SFC []string `json:"sfc"`
}

// Sends an auhtorization request to the PEP for to the passed client resource access request
// Step 1: Extracts all needed authorization metadata from the passed client request
func PerformAuthorization(sysLogger *logger.Logger, clientReq *http.Request, cpm *metadata.CpMetadata) error {
Expand All @@ -47,7 +42,7 @@ func PerformAuthorization(sysLogger *logger.Logger, clientReq *http.Request, cpm
}

// Decode json body received from PDP (pdpResp)
var authoResp authoResponse
var authoResp metadata.AuthoResponse
err = json.NewDecoder(pdpResp.Body).Decode(&authoResp)
if err != nil {
return fmt.Errorf("unable to parse json answer from PDP: %w", err)
Expand Down
14 changes: 12 additions & 2 deletions internal/app/metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
// during processing inside the PEP.
package metadata

type AuthoResponse struct {
Allow bool `json:"allow"`
SFC []Sf `json:"sfc"`
}

type Sf struct {
Name string `json:"name"`
Md string `json:"md"`
}

// The struct CpMetadata is for storing several meta data for a client
// request. The struct can be passed across the PEP, such that several
// components can collect different information in here.
Expand All @@ -16,7 +26,7 @@ type CpMetadata struct {
RequestToday string
FailedToday string
Location string
SFC []string
SFC []Sf
SFP []struct {
Name string
URL string
Expand All @@ -36,7 +46,7 @@ func (cpm *CpMetadata) ClearMetadata() {
cpm.RequestToday = ""
cpm.FailedToday = ""
cpm.Location = ""
cpm.SFC = []string{}
cpm.SFC = []Sf{}
cpm.SFP = []struct {
Name string
URL string
Expand Down
12 changes: 11 additions & 1 deletion internal/app/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ func addHSTSHeader(w http.ResponseWriter) {
w.Header().Add("Strict-Transport-Security", "max-age=63072000; includeSubDomains")
}

func prepareSfMdHeader(req *http.Request, cpm *metadata.CpMetadata) {
for _, sf := range cpm.SFC {
switch sf.Name {
case "logger":
req.Header.Set("Logger_MD", sf.Md)
}
}
}

// ServeHTTP gets called if a request receives the PEP. The function implements
// the PEP's main routine: It performs basic authentication, authorization with
// help of the PEP, transformation from SFCs into SFPs with help of the SFP
Expand Down Expand Up @@ -161,7 +170,8 @@ func (router *Router) ServeHTTP(w http.ResponseWriter, req *http.Request) {
// identify next hop, find its config and set nextHopURL and cert respectively
nextHop := md.SFP[0]
// TODO: make this dynamic later
req.Header.Set("Sfloggerlevel", "16383")
prepareSfMdHeader(req, md)
fmt.Printf("LoGGER MD Header: %s\n", req.Header.Values("Logger_MD"))

router.sysLogger.Debugf("router: ServeHTTP(): next hop: %s", nextHop)

Expand Down
2 changes: 1 addition & 1 deletion internal/app/sfp_logic/sfp_logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func prepareSFPRequest(req *http.Request, cpm *metadata.CpMetadata) {
// send SFC as a query parameter
q := req.URL.Query()
for _, sf := range cpm.SFC {
q.Add("sfc", sf)
q.Add("sfc", sf.Name)
}
req.URL.RawQuery = q.Encode()

Expand Down

0 comments on commit a332e59

Please sign in to comment.