mirror of
https://github.com/pomerium/pomerium.git
synced 2025-07-06 19:38:09 +02:00
use strings.Cut, add unit tests
This commit is contained in:
parent
9cf8207cd8
commit
21b79405cd
4 changed files with 183 additions and 35 deletions
|
@ -152,6 +152,8 @@ func populateLogEvent(
|
|||
hdrs map[string]string,
|
||||
impersonateDetails *impersonateDetails,
|
||||
) *zerolog.Event {
|
||||
path, query, _ := strings.Cut(in.GetAttributes().GetRequest().GetHttp().GetPath(), "?")
|
||||
|
||||
switch field {
|
||||
case log.AuthorizeLogFieldCheckRequestID:
|
||||
return evt.Str(string(field), hdrs["X-Request-Id"])
|
||||
|
@ -179,9 +181,9 @@ func populateLogEvent(
|
|||
case log.AuthorizeLogFieldMethod:
|
||||
return evt.Str(string(field), in.GetAttributes().GetRequest().GetHttp().GetMethod())
|
||||
case log.AuthorizeLogFieldPath:
|
||||
return evt.Str(string(field), stripQueryString(in.GetAttributes().GetRequest().GetHttp().GetPath()))
|
||||
return evt.Str(string(field), path)
|
||||
case log.AuthorizeLogFieldQuery:
|
||||
return evt.Str(string(field), getQueryString(in.GetAttributes().GetRequest().GetHttp().GetPath()))
|
||||
return evt.Str(string(field), query)
|
||||
case log.AuthorizeLogFieldRequestID:
|
||||
return evt.Str(string(field), requestid.FromContext(ctx))
|
||||
case log.AuthorizeLogFieldServiceAccountID:
|
||||
|
@ -200,17 +202,3 @@ func populateLogEvent(
|
|||
return evt
|
||||
}
|
||||
}
|
||||
|
||||
func getQueryString(str string) string {
|
||||
if idx := strings.Index(str, "?"); idx != -1 {
|
||||
return str[idx+1:]
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func stripQueryString(str string) string {
|
||||
if idx := strings.Index(str, "?"); idx != -1 {
|
||||
str = str[:idx]
|
||||
}
|
||||
return str
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue