mirror of
https://github.com/dstotijn/hetty.git
synced 2025-07-01 18:47:29 -04:00
Add search expression support to admin interface
This commit is contained in:
@ -72,7 +72,8 @@ type ComplexityRoot struct {
|
||||
}
|
||||
|
||||
HTTPRequestLogFilter struct {
|
||||
OnlyInScope func(childComplexity int) int
|
||||
OnlyInScope func(childComplexity int) int
|
||||
SearchExpression func(childComplexity int) int
|
||||
}
|
||||
|
||||
HTTPResponseLog struct {
|
||||
@ -249,6 +250,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
|
||||
|
||||
return e.complexity.HTTPRequestLogFilter.OnlyInScope(childComplexity), true
|
||||
|
||||
case "HttpRequestLogFilter.searchExpression":
|
||||
if e.complexity.HTTPRequestLogFilter.SearchExpression == nil {
|
||||
break
|
||||
}
|
||||
|
||||
return e.complexity.HTTPRequestLogFilter.SearchExpression(childComplexity), true
|
||||
|
||||
case "HttpResponseLog.body":
|
||||
if e.complexity.HTTPResponseLog.Body == nil {
|
||||
break
|
||||
@ -579,10 +587,12 @@ type ClearHTTPRequestLogResult {
|
||||
|
||||
input HttpRequestLogFilterInput {
|
||||
onlyInScope: Boolean
|
||||
searchExpression: String
|
||||
}
|
||||
|
||||
type HttpRequestLogFilter {
|
||||
onlyInScope: Boolean!
|
||||
searchExpression: String
|
||||
}
|
||||
|
||||
type Query {
|
||||
@ -1239,6 +1249,38 @@ func (ec *executionContext) _HttpRequestLogFilter_onlyInScope(ctx context.Contex
|
||||
return ec.marshalNBoolean2bool(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) _HttpRequestLogFilter_searchExpression(ctx context.Context, field graphql.CollectedField, obj *HTTPRequestLogFilter) (ret graphql.Marshaler) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
ec.Error(ctx, ec.Recover(ctx, r))
|
||||
ret = graphql.Null
|
||||
}
|
||||
}()
|
||||
fc := &graphql.FieldContext{
|
||||
Object: "HttpRequestLogFilter",
|
||||
Field: field,
|
||||
Args: nil,
|
||||
IsMethod: false,
|
||||
IsResolver: false,
|
||||
}
|
||||
|
||||
ctx = graphql.WithFieldContext(ctx, fc)
|
||||
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
||||
ctx = rctx // use context from middleware stack in children
|
||||
return obj.SearchExpression, nil
|
||||
})
|
||||
if err != nil {
|
||||
ec.Error(ctx, err)
|
||||
return graphql.Null
|
||||
}
|
||||
if resTmp == nil {
|
||||
return graphql.Null
|
||||
}
|
||||
res := resTmp.(*string)
|
||||
fc.Result = res
|
||||
return ec.marshalOString2ᚖstring(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) _HttpResponseLog_requestId(ctx context.Context, field graphql.CollectedField, obj *HTTPResponseLog) (ret graphql.Marshaler) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
@ -3288,6 +3330,14 @@ func (ec *executionContext) unmarshalInputHttpRequestLogFilterInput(ctx context.
|
||||
if err != nil {
|
||||
return it, err
|
||||
}
|
||||
case "searchExpression":
|
||||
var err error
|
||||
|
||||
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("searchExpression"))
|
||||
it.SearchExpression, err = ec.unmarshalOString2ᚖstring(ctx, v)
|
||||
if err != nil {
|
||||
return it, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -3551,6 +3601,8 @@ func (ec *executionContext) _HttpRequestLogFilter(ctx context.Context, sel ast.S
|
||||
if out.Values[i] == graphql.Null {
|
||||
invalids++
|
||||
}
|
||||
case "searchExpression":
|
||||
out.Values[i] = ec._HttpRequestLogFilter_searchExpression(ctx, field, obj)
|
||||
default:
|
||||
panic("unknown field " + strconv.Quote(field.Name))
|
||||
}
|
||||
|
@ -38,11 +38,13 @@ type HTTPRequestLog struct {
|
||||
}
|
||||
|
||||
type HTTPRequestLogFilter struct {
|
||||
OnlyInScope bool `json:"onlyInScope"`
|
||||
OnlyInScope bool `json:"onlyInScope"`
|
||||
SearchExpression *string `json:"searchExpression"`
|
||||
}
|
||||
|
||||
type HTTPRequestLogFilterInput struct {
|
||||
OnlyInScope *bool `json:"onlyInScope"`
|
||||
OnlyInScope *bool `json:"onlyInScope"`
|
||||
SearchExpression *string `json:"searchExpression"`
|
||||
}
|
||||
|
||||
type HTTPResponseLog struct {
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
"github.com/dstotijn/hetty/pkg/proj"
|
||||
"github.com/dstotijn/hetty/pkg/reqlog"
|
||||
"github.com/dstotijn/hetty/pkg/scope"
|
||||
"github.com/dstotijn/hetty/pkg/search"
|
||||
"github.com/vektah/gqlparser/v2/gqlerror"
|
||||
)
|
||||
|
||||
@ -263,15 +264,14 @@ func (r *mutationResolver) SetHTTPRequestLogFilter(
|
||||
ctx context.Context,
|
||||
input *HTTPRequestLogFilterInput,
|
||||
) (*HTTPRequestLogFilter, error) {
|
||||
filter := findRequestsFilterFromInput(input)
|
||||
filter, err := findRequestsFilterFromInput(input)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not parse request log filter: %v", err)
|
||||
}
|
||||
if err := r.RequestLogService.SetRequestLogFilter(ctx, filter); err != nil {
|
||||
return nil, fmt.Errorf("could not set request log filter: %v", err)
|
||||
}
|
||||
|
||||
empty := reqlog.FindRequestsFilter{}
|
||||
if filter == empty {
|
||||
return nil, nil
|
||||
}
|
||||
return findReqFilterToHTTPReqLogFilter(filter), nil
|
||||
}
|
||||
|
||||
@ -297,13 +297,21 @@ func scopeToScopeRules(rules []scope.Rule) []ScopeRule {
|
||||
return scopeRules
|
||||
}
|
||||
|
||||
func findRequestsFilterFromInput(input *HTTPRequestLogFilterInput) (filter reqlog.FindRequestsFilter) {
|
||||
func findRequestsFilterFromInput(input *HTTPRequestLogFilterInput) (filter reqlog.FindRequestsFilter, err error) {
|
||||
if input == nil {
|
||||
return
|
||||
}
|
||||
if input.OnlyInScope != nil {
|
||||
filter.OnlyInScope = *input.OnlyInScope
|
||||
}
|
||||
if input.SearchExpression != nil && *input.SearchExpression != "" {
|
||||
expr, err := search.ParseQuery(*input.SearchExpression)
|
||||
if err != nil {
|
||||
return reqlog.FindRequestsFilter{}, fmt.Errorf("could not parse search query: %v", err)
|
||||
}
|
||||
filter.RawSearchExpr = *input.SearchExpression
|
||||
filter.SearchExpr = expr
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
@ -317,5 +325,9 @@ func findReqFilterToHTTPReqLogFilter(findReqFilter reqlog.FindRequestsFilter) *H
|
||||
OnlyInScope: findReqFilter.OnlyInScope,
|
||||
}
|
||||
|
||||
if findReqFilter.RawSearchExpr != "" {
|
||||
httpReqLogFilter.SearchExpression = &findReqFilter.RawSearchExpr
|
||||
}
|
||||
|
||||
return httpReqLogFilter
|
||||
}
|
||||
|
@ -64,10 +64,12 @@ type ClearHTTPRequestLogResult {
|
||||
|
||||
input HttpRequestLogFilterInput {
|
||||
onlyInScope: Boolean
|
||||
searchExpression: String
|
||||
}
|
||||
|
||||
type HttpRequestLogFilter {
|
||||
onlyInScope: Boolean!
|
||||
searchExpression: String
|
||||
}
|
||||
|
||||
type Query {
|
||||
|
Reference in New Issue
Block a user