From 4fc2607f4d4e923ec45e943d4649870a9232cbb1 Mon Sep 17 00:00:00 2001 From: zepatrik Date: Wed, 29 Jul 2020 16:57:11 +0200 Subject: [PATCH 1/3] feat: config versions meta schema --- .schema/config.schema.json | 18 +++++++++++++++++- .schema/versions.config.schema.json | 22 ++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 .schema/versions.config.schema.json diff --git a/.schema/config.schema.json b/.schema/config.schema.json index 84c9df2450f4..beeaae607522 100644 --- a/.schema/config.schema.json +++ b/.schema/config.schema.json @@ -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-]+)*))?$" + }, "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).", @@ -898,6 +903,16 @@ "additionalProperties": false } } + }, + "version": { + "allOf": [ + { + "title": "The kratos version this config is written for." + }, + { + "$ref": "#/definitions/version" + } + ] } }, "allOf": [ @@ -972,7 +987,8 @@ "required": [ "identity", "dsn", - "selfservice" + "selfservice", + "version" ], "additionalProperties": false } diff --git a/.schema/versions.config.schema.json b/.schema/versions.config.schema.json new file mode 100644 index 000000000000..6f5868cd9b24 --- /dev/null +++ b/.schema/versions.config.schema.json @@ -0,0 +1,22 @@ +{ + "$id": "https://github.com/ory/kratos/.schema/versions.config.schema.json", + "$schema": "http://json-schema.org/draft-07/schema#", + "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" + } + ] + } + ] +} From 0f1af32a917ac8ddba193600efa0a7727cf2432e Mon Sep 17 00:00:00 2001 From: zepatrik Date: Mon, 3 Aug 2020 16:10:40 +0200 Subject: [PATCH 2/3] u --- .schema/config.schema.json | 3 +-- ...ions.config.schema.json => version.schema.json} | 0 cmd/serve.go | 14 +++++++++++++- driver/configuration/provider.go | 2 ++ driver/configuration/provider_viper.go | 8 ++++++++ 5 files changed, 24 insertions(+), 3 deletions(-) rename .schema/{versions.config.schema.json => version.schema.json} (100%) diff --git a/.schema/config.schema.json b/.schema/config.schema.json index beeaae607522..7680dd46aa35 100644 --- a/.schema/config.schema.json +++ b/.schema/config.schema.json @@ -987,8 +987,7 @@ "required": [ "identity", "dsn", - "selfservice", - "version" + "selfservice" ], "additionalProperties": false } diff --git a/.schema/versions.config.schema.json b/.schema/version.schema.json similarity index 100% rename from .schema/versions.config.schema.json rename to .schema/version.schema.json diff --git a/cmd/serve.go b/cmd/serve.go index 3a3fa238f389..7d08c1aba145 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -18,6 +18,8 @@ import ( "os" "strconv" + "github.com/ory/kratos/driver/configuration" + "github.com/ory/x/viperx" "github.com/spf13/cobra" @@ -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) }, } diff --git a/driver/configuration/provider.go b/driver/configuration/provider.go index 45ee4d3b0b5e..fa40b3c89a30 100644 --- a/driver/configuration/provider.go +++ b/driver/configuration/provider.go @@ -115,4 +115,6 @@ type Provider interface { TracingServiceName() string TracingProvider() string TracingJaegerConfig() *tracing.JaegerConfig + + ConfigVersion() string } diff --git a/driver/configuration/provider_viper.go b/driver/configuration/provider_viper.go index 8903b7e4659b..aa54adf8ced8 100644 --- a/driver/configuration/provider_viper.go +++ b/driver/configuration/provider_viper.go @@ -36,6 +36,8 @@ const DefaultBrowserReturnURL = "default_browser_return_url" const DefaultSQLiteMemoryDSN = "sqlite://:memory:?_fk=true" +const UnknownVersion = "unknown version" + const ( ViperKeyDSN = "dsn" @@ -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 { @@ -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) +} From d8cbf3bbe57834f740abe5300187385a646397bb Mon Sep 17 00:00:00 2001 From: zepatrik Date: Tue, 4 Aug 2020 12:23:38 +0200 Subject: [PATCH 3/3] change to our meta schema --- .schema/version.schema.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.schema/version.schema.json b/.schema/version.schema.json index 6f5868cd9b24..0aed3f8f78ce 100644 --- a/.schema/version.schema.json +++ b/.schema/version.schema.json @@ -1,6 +1,6 @@ { "$id": "https://github.com/ory/kratos/.schema/versions.config.schema.json", - "$schema": "http://json-schema.org/draft-07/schema#", + "$schema": "https://raw.githubusercontent.com/ory/cli/v0.0.21/.schema/version_meta.schema.json#", "title": "All Versions for ORY Kratos Configuration", "type": "object", "oneOf": [