Skip to content

feat: add a config.schema.json and validate the configuration against it#1733

Merged
aeneasr merged 29 commits intomasterfrom
add-config-schema
Apr 6, 2020
Merged

feat: add a config.schema.json and validate the configuration against it#1733
aeneasr merged 29 commits intomasterfrom
add-config-schema

Conversation

@zepatrik
Copy link
Copy Markdown
Member

@zepatrik zepatrik commented Feb 18, 2020

Related issue

closes #1729

Proposed changes

Checklist

  • I have read the contributing guidelines
  • I have read the security policy
  • I confirm that this pull request does not address a security vulnerability. If this pull request addresses a security
    vulnerability, I confirm that I got green light (please contact [email protected]) from the maintainers to push the changes.
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation within the code base (if appropriate)
  • I have documented my changes in the developer guide (if appropriate)

Further comments

@zepatrik
Copy link
Copy Markdown
Member Author

As I found out it is not possible with jsonschema to have nil as a default value. It's the same problem as with "const": null but there it is solved by wrapping the value with a slice. So we will have to set some defaults in config.schema.json that are currently set in the code (e.g. like this one). viperx will automatically set the default viper value to either the default value from the schema or the default value for the type. This means an array type with "minItems" that is not set will not pass validation. @aeneasr

@aeneasr
Copy link
Copy Markdown
Member

aeneasr commented Feb 24, 2020

That is not a good idea, especially with secrets. Let’s nit do that please and figure out another way to tackle this. If no secret is set, then it should not pass validation, right? If it should pass, then minItems should not be 1

@aeneasr
Copy link
Copy Markdown
Member

aeneasr commented Mar 14, 2020

@zepatrik what's the status of this? Will you continue working on it?

# Conflicts:
#	client/sql_migration_files.go
#	consent/sql_migration_files.go
#	go.mod
#	go.sum
#	jwk/sql_migration_files.go
#	oauth2/sql_migration_files.go
# Conflicts:
#	cmd/server/handler.go
#	go.mod
@zepatrik zepatrik marked this pull request as ready for review March 25, 2020 10:50
@zepatrik zepatrik requested a review from aeneasr March 25, 2020 10:50
@zepatrik
Copy link
Copy Markdown
Member Author

latest schema changes needed as workaround for ory/x#131

# Conflicts:
#	driver/configuration/provider_viper_test.go
#	go.mod
#	go.sum
var schemas = packr.New("schemas", "../../docs")

// LoggerWithValidationErrorFields adds all validation errors as fields to the logger.
func LoggerWithValidationErrorFields(l logrus.FieldLogger, err error) logrus.FieldLogger {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this not provided by the X package?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping @zepatrik

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

zepatrik and others added 9 commits April 1, 2020 15:00
# Conflicts:
#	cmd/server/handler.go
#	docs/api.swagger.json
#	driver/configuration/provider_viper_test.go
#	go.mod
#	go.sum
#	internal/httpclient/models/consent_request.go
#	internal/httpclient/models/health_status.go
#	internal/httpclient/models/json_web_key_set_generator_request.go
#	internal/httpclient/models/login_request.go
#	internal/httpclient/models/o_auth2_client.go
#	internal/httpclient/models/oauth2_token_response.go
#	internal/httpclient/models/open_id_connect_context.go
#	internal/httpclient/models/well_known.go
@zepatrik zepatrik requested a review from aeneasr April 4, 2020 16:03
@aeneasr aeneasr merged commit 631cefd into master Apr 6, 2020
@aeneasr aeneasr deleted the add-config-schema branch April 6, 2020 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Validate configuration using JSON Schema and support config hot reloading

2 participants