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

feat: config versions meta schema #608

Merged
merged 5 commits into from
Aug 4, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
15 changes: 15 additions & 0 deletions .schema/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
"title": "ORY Kratos Configuration",
"type": "object",
"definitions": {
"version": {
"type": "string",
"description": "SemVer according to https://semver.org/ prefixed with `v` as in our releases.",
"pattern": "^v(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$"
zepatrik marked this conversation as resolved.
Show resolved Hide resolved
},
"defaultReturnTo": {
"title": "Redirect browsers to set URL per default",
"description": "ORY Kratos redirects to this URL per default on completion of self-service flows and other browser interaction. Read this [article for more information on browser redirects](https://www.ory.sh/kratos/docs/concepts/browser-redirect-flow-completion).",
Expand Down Expand Up @@ -898,6 +903,16 @@
"additionalProperties": false
}
}
},
"version": {
"allOf": [
{
"title": "The kratos version this config is written for."
},
{
"$ref": "#/definitions/version"
}
]
}
},
"allOf": [
Expand Down
22 changes: 22 additions & 0 deletions .schema/version.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"$id": "https://github.com/ory/kratos/.schema/versions.config.schema.json",
"$schema": "http://json-schema.org/draft-07/schema#",
zepatrik marked this conversation as resolved.
Show resolved Hide resolved
"title": "All Versions for ORY Kratos Configuration",
"type": "object",
"oneOf": [
{
"allOf": [
{
"properties": {
"version": {
"const": "v0.4.6-alpha.1"
}
}
},
{
"$ref": "https://raw.githubusercontent.com/ory/kratos/v0.4.6-alpha.1/.schema/config.schema.json"
}
]
}
]
}
14 changes: 13 additions & 1 deletion cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"os"
"strconv"

"github.com/ory/kratos/driver/configuration"

"github.com/ory/x/viperx"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -48,7 +50,17 @@ DON'T DO THIS IN PRODUCTION!
}

x.WatchAndValidateViper(logger)
daemon.ServeAll(driver.MustNewDefaultDriver(logger, BuildVersion, BuildTime, BuildGitHash, dev))(cmd, args)
d := driver.MustNewDefaultDriver(logger, BuildVersion, BuildTime, BuildGitHash, dev)

configVersion := d.Configuration().ConfigVersion()
if configVersion == configuration.UnknownVersion {
d.Logger().Warn("The config has no version specified. Add the version to improve your development experience.")
} else if BuildVersion != "" &&
configVersion != BuildVersion {
d.Logger().Warnf("Config version is '%s' but kratos runs on version '%s'", configVersion, BuildVersion)
}

daemon.ServeAll(d)(cmd, args)
},
}

Expand Down
2 changes: 2 additions & 0 deletions driver/configuration/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,6 @@ type Provider interface {
TracingServiceName() string
TracingProvider() string
TracingJaegerConfig() *tracing.JaegerConfig

ConfigVersion() string
}
8 changes: 8 additions & 0 deletions driver/configuration/provider_viper.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ const DefaultBrowserReturnURL = "default_browser_return_url"

const DefaultSQLiteMemoryDSN = "sqlite://:memory:?_fk=true"

const UnknownVersion = "unknown version"

const (
ViperKeyDSN = "dsn"

Expand Down Expand Up @@ -101,6 +103,8 @@ const (
ViperKeyHasherArgon2ConfigParallelism = "hashers.argon2.parallelism"
ViperKeyHasherArgon2ConfigSaltLength = "hashers.argon2.salt_length"
ViperKeyHasherArgon2ConfigKeyLength = "hashers.argon2.key_length"

ViperKeyVersion = "version"
)

func HookStrategyKey(key, strategy string) string {
Expand Down Expand Up @@ -534,3 +538,7 @@ func (p *ViperProvider) selfServiceReturnTo(key string, strategy string) *url.UR
}
return redir
}

func (p *ViperProvider) ConfigVersion() string {
return viperx.GetString(p.l, ViperKeyVersion, UnknownVersion)
}