Skip to content

Commit

Permalink
feat(config): Add output function
Browse files Browse the repository at this point in the history
  • Loading branch information
ldebruijn committed Sep 8, 2024
1 parent 62d5252 commit 7620f5f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
5 changes: 2 additions & 3 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"
"flag"
"fmt"
"github.com/ardanlabs/conf/v3"
"github.com/ldebruijn/graphql-protect/internal/app/config"
"github.com/ldebruijn/graphql-protect/internal/app/log"
"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -61,8 +60,8 @@ func startup(action string, path string) error {
return err
}
}
cfgAsString, _ := conf.String(cfg)
log2.Println(cfgAsString)
log2.Println("Configuration:")
log2.Println(cfg)

logger := log.NewLogger(cfg.Log)
logger.Info("Starting Protect", "version", build)
Expand Down
20 changes: 16 additions & 4 deletions internal/app/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/ldebruijn/graphql-protect/internal/http/proxy"
y "gopkg.in/yaml.v3"
"os"
"time"
)

var ErrConfigFileNotFound = errors.New("config file could not be found, defaults applied")
Expand All @@ -26,8 +25,8 @@ type Config struct {
Schema schema.Config `yaml:"schema"`
Target proxy.Config `yaml:"target"`
PersistedOperations persistedoperations.Config `yaml:"persisted_operations"`
ObfuscateValidationErrors bool `conf:"default:false" yaml:"obfuscate_validation_errors"`
ObfuscateUpstreamErrors bool `conf:"default:true" yaml:"obfuscate_upstream_errors"`
ObfuscateValidationErrors bool `yaml:"obfuscate_validation_errors"`
ObfuscateUpstreamErrors bool `yaml:"obfuscate_upstream_errors"`
BlockFieldSuggestions block_field_suggestions.Config `yaml:"block_field_suggestions"`
MaxTokens tokens.Config `yaml:"max_tokens"`
MaxAliases aliases.Config `yaml:"max_aliases"`
Expand All @@ -36,9 +35,22 @@ type Config struct {
MaxBatch batch.Config `yaml:"max_batch"`
AccessLogging accesslogging.Config `yaml:"access_logging"`
Log log.Config `yaml:"log"`
LogGraphqlErrors bool `conf:"default:false" yaml:"log_graphql_errors"`
LogGraphqlErrors bool `yaml:"log_graphql_errors"`
}

func (c Config) String() string {
marshal, err := y.Marshal(c)
if err != nil {
return ""
}

return string(marshal)
}

// NewConfig initializes the runtime configuration.
// It uses defaults, and applies any user overrides to it
// If no configuration file can be found, the defaults will be returned the ErrConfigFileNotFound error
// if the configuration file can be found, but cannot be unmarshalled, an error will be returned
func NewConfig(configPath string) (*Config, error) {
cfg := defaults()

Expand Down

0 comments on commit 7620f5f

Please sign in to comment.