Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move rules into rules package and other smaller code cleanups #54

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"fmt"
"github.com/ardanlabs/conf/v3"
"github.com/ldebruijn/graphql-protect/internal/app/config"
"github.com/ldebruijn/graphql-protect/internal/business/block_field_suggestions"
"github.com/ldebruijn/graphql-protect/internal/business/persisted_operations"
"github.com/ldebruijn/graphql-protect/internal/business/protect"
"github.com/ldebruijn/graphql-protect/internal/business/rules/block_field_suggestions"
"github.com/ldebruijn/graphql-protect/internal/business/schema"
"github.com/ldebruijn/graphql-protect/internal/http/middleware"
"github.com/ldebruijn/graphql-protect/internal/http/proxy"
Expand Down Expand Up @@ -114,7 +114,7 @@ func run(log *slog.Logger, cfg *config.Config, shutdown chan os.Signal) error {

mux := http.NewServeMux()

mid := ProtectMiddlewareChain(log)
mid := protectMiddlewareChain(log)

mux.Handle("/metrics", promhttp.Handler())
mux.Handle("/internal/healthz/readiness", readiness.NewReadinessHandler())
Expand Down Expand Up @@ -158,7 +158,7 @@ func run(log *slog.Logger, cfg *config.Config, shutdown chan os.Signal) error {
return nil
}

func ProtectMiddlewareChain(log *slog.Logger) func(next http.Handler) http.Handler {
func protectMiddlewareChain(log *slog.Logger) func(next http.Handler) http.Handler {
rec := middleware.Recover(log)
httpInstrumentation := middleware.RequestMetricMiddleware()

Expand Down
12 changes: 6 additions & 6 deletions internal/app/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import (
"fmt"
"github.com/ardanlabs/conf/v3"
"github.com/ardanlabs/conf/v3/yaml"
"github.com/ldebruijn/graphql-protect/internal/business/aliases"
"github.com/ldebruijn/graphql-protect/internal/business/batch"
"github.com/ldebruijn/graphql-protect/internal/business/block_field_suggestions"
"github.com/ldebruijn/graphql-protect/internal/business/enforce_post"
"github.com/ldebruijn/graphql-protect/internal/business/max_depth"
"github.com/ldebruijn/graphql-protect/internal/business/persisted_operations"
"github.com/ldebruijn/graphql-protect/internal/business/rules/aliases"
"github.com/ldebruijn/graphql-protect/internal/business/rules/batch"
"github.com/ldebruijn/graphql-protect/internal/business/rules/block_field_suggestions"
"github.com/ldebruijn/graphql-protect/internal/business/rules/enforce_post"
"github.com/ldebruijn/graphql-protect/internal/business/rules/max_depth"
"github.com/ldebruijn/graphql-protect/internal/business/rules/tokens"
"github.com/ldebruijn/graphql-protect/internal/business/schema"
"github.com/ldebruijn/graphql-protect/internal/business/tokens"
"github.com/ldebruijn/graphql-protect/internal/http/proxy"
"os"
"time"
Expand Down
12 changes: 6 additions & 6 deletions internal/app/config/config_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package config

import (
"github.com/ldebruijn/graphql-protect/internal/business/aliases"
"github.com/ldebruijn/graphql-protect/internal/business/batch"
"github.com/ldebruijn/graphql-protect/internal/business/block_field_suggestions"
"github.com/ldebruijn/graphql-protect/internal/business/enforce_post"
"github.com/ldebruijn/graphql-protect/internal/business/max_depth"
"github.com/ldebruijn/graphql-protect/internal/business/persisted_operations"
"github.com/ldebruijn/graphql-protect/internal/business/rules/aliases"
"github.com/ldebruijn/graphql-protect/internal/business/rules/batch"
"github.com/ldebruijn/graphql-protect/internal/business/rules/block_field_suggestions"
"github.com/ldebruijn/graphql-protect/internal/business/rules/enforce_post"
"github.com/ldebruijn/graphql-protect/internal/business/rules/max_depth"
"github.com/ldebruijn/graphql-protect/internal/business/rules/tokens"
"github.com/ldebruijn/graphql-protect/internal/business/schema"
"github.com/ldebruijn/graphql-protect/internal/business/tokens"
"github.com/ldebruijn/graphql-protect/internal/http/proxy"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3"
Expand Down
21 changes: 9 additions & 12 deletions internal/business/protect/protect.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import (
"encoding/json"
"errors"
"github.com/ldebruijn/graphql-protect/internal/app/config"
"github.com/ldebruijn/graphql-protect/internal/business/aliases"
"github.com/ldebruijn/graphql-protect/internal/business/batch"
"github.com/ldebruijn/graphql-protect/internal/business/enforce_post"
"github.com/ldebruijn/graphql-protect/internal/business/gql"
"github.com/ldebruijn/graphql-protect/internal/business/max_depth"
"github.com/ldebruijn/graphql-protect/internal/business/persisted_operations"
"github.com/ldebruijn/graphql-protect/internal/business/rules/aliases"
"github.com/ldebruijn/graphql-protect/internal/business/rules/batch"
"github.com/ldebruijn/graphql-protect/internal/business/rules/enforce_post"
"github.com/ldebruijn/graphql-protect/internal/business/rules/max_depth"
"github.com/ldebruijn/graphql-protect/internal/business/rules/tokens"
"github.com/ldebruijn/graphql-protect/internal/business/schema"
"github.com/ldebruijn/graphql-protect/internal/business/tokens"
"github.com/vektah/gqlparser/v2/ast"
"github.com/vektah/gqlparser/v2/gqlerror"
"github.com/vektah/gqlparser/v2/parser"
Expand Down Expand Up @@ -104,13 +104,10 @@ func (p *GraphQLProtect) validateRequest(r *http.Request) gqlerror.List {
return errs
}

// only process the rest if no error yet
if err == nil {
for _, data := range payload {
validationErrors := p.validateQuery(data)
if len(validationErrors) > 0 {
errs = append(errs, validationErrors...)
}
for _, data := range payload {
validationErrors := p.validateQuery(data)
if len(validationErrors) > 0 {
errs = append(errs, validationErrors...)
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/http/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package proxy
import (
"bytes"
"encoding/json"
"github.com/ldebruijn/graphql-protect/internal/business/block_field_suggestions"
"github.com/ldebruijn/graphql-protect/internal/business/rules/block_field_suggestions"
"io"
"net"
"net/http"
Expand Down
2 changes: 1 addition & 1 deletion internal/http/proxy/proxy_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package proxy

import (
"github.com/ldebruijn/graphql-protect/internal/business/block_field_suggestions"
"github.com/ldebruijn/graphql-protect/internal/business/rules/block_field_suggestions"
"github.com/stretchr/testify/assert"
"io"
"net/http"
Expand Down
Loading