Skip to content

Commit

Permalink
Fix max tokens config mapping and reject_on_failure property (#17)
Browse files Browse the repository at this point in the history
the `max_tokens` config in the yaml was ignored due to incorrect mapping
The same applied to '`reject_on_failure`' boolean for both `max_aliases`
and `max_tokens`

---------

Co-authored-by: Rick Bijkerk <[email protected]>
  • Loading branch information
rickbijkerk and Rick Bijkerk authored Jan 10, 2024
1 parent 68ba2fc commit c349c7d
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func middleware(log *slog.Logger, cfg *config.Config, po *persisted_operations.P
httpInstrumentation := HttpInstrumentation()

aliases.NewMaxAliasesRule(cfg.MaxAliases)
tks := tokens.MaxTokens(cfg.Token)
tks := tokens.MaxTokens(cfg.MaxTokens)
vr := ValidationRules(schema, tks)

fn := func(next http.Handler) http.Handler {
Expand Down
4 changes: 2 additions & 2 deletions cmd/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,8 @@ type Product {
}
`,
cfgOverrides: func(cfg *config.Config) *config.Config {
cfg.Token.Enabled = true
cfg.Token.Max = 1
cfg.MaxTokens.Enabled = true
cfg.MaxTokens.Max = 1
return cfg
},
mockResponse: map[string]interface{}{
Expand Down
2 changes: 1 addition & 1 deletion internal/app/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ type Config struct {
//DebugHost string `conf:"default:0.0.0.0:4000"`
}
Schema schema.Config `yaml:"schema"`
Token tokens.Config `yaml:"token"`
Target proxy.Config `yaml:"target"`
PersistedOperations persisted_operations.Config `yaml:"persisted_operations"`
BlockFieldSuggestions block_field_suggestions.Config `yaml:"block_field_suggestions"`
MaxTokens tokens.Config `yaml:"max_tokens"`
MaxAliases aliases.Config `yaml:"max_aliases"`
}

Expand Down
2 changes: 1 addition & 1 deletion internal/business/aliases/aliases.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var resultCounter = prometheus.NewCounterVec(prometheus.CounterOpts{
type Config struct {
Enabled bool `conf:"default:true" yaml:"enabled"`
Max int `conf:"default:15" yaml:"max"`
RejectOnFailure bool `conf:"default:true" yaml:"reject-on-failure"`
RejectOnFailure bool `conf:"default:true" yaml:"reject_on_failure"`
}

func init() {
Expand Down
2 changes: 1 addition & 1 deletion internal/business/tokens/tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var resultCounter = prometheus.NewCounterVec(prometheus.CounterOpts{
type Config struct {
Enabled bool `conf:"default:true" yaml:"enabled"`
Max int `conf:"default:1000" yaml:"max"`
RejectOnFailure bool `conf:"default:true" yaml:"reject-on-failure"`
RejectOnFailure bool `conf:"default:true" yaml:"reject_on_failure"`
}

type MaxTokensRule struct {
Expand Down

0 comments on commit c349c7d

Please sign in to comment.