Skip to content

Commit

Permalink
feat: add config version schema (#608)
Browse files Browse the repository at this point in the history
closes #590
  • Loading branch information
zepatrik committed Aug 4, 2020
1 parent 61341e1 commit d218662
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 1 deletion.
15 changes: 15 additions & 0 deletions .schema/config.schema.json
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-]+)*))?$"
},
"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
@@ -0,0 +1,22 @@
{
"$id": "https://github.com/ory/kratos/.schema/versions.config.schema.json",
"$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": [
{
"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
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
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
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)
}

0 comments on commit d218662

Please sign in to comment.