diff --git a/cmd/root.go b/cmd/root.go index 799b68c8aa9a..94733c846a96 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -5,6 +5,8 @@ import ( "fmt" "os" + "github.com/ory/kratos/driver/config" + "github.com/ory/kratos/cmd/hashers" "github.com/ory/kratos/cmd/remote" @@ -13,7 +15,6 @@ import ( "github.com/ory/kratos/cmd/jsonnet" "github.com/ory/kratos/cmd/migrate" "github.com/ory/kratos/cmd/serve" - "github.com/ory/kratos/internal/clihelpers" "github.com/ory/x/cmdx" "github.com/spf13/cobra" @@ -45,5 +46,5 @@ func init() { remote.RegisterCommandRecursive(RootCmd) hashers.RegisterCommandRecursive(RootCmd) - RootCmd.AddCommand(cmdx.Version(&clihelpers.BuildVersion, &clihelpers.BuildGitHash, &clihelpers.BuildTime)) + RootCmd.AddCommand(cmdx.Version(&config.Version, &config.Commit, &config.Date)) } diff --git a/cmd/serve/root.go b/cmd/serve/root.go index 56bef206df56..cf55998c0a36 100644 --- a/cmd/serve/root.go +++ b/cmd/serve/root.go @@ -16,7 +16,6 @@ package serve import ( "github.com/ory/kratos/driver/config" - "github.com/ory/kratos/internal/clihelpers" "github.com/ory/x/configx" "github.com/spf13/cobra" @@ -45,9 +44,9 @@ DON'T DO THIS IN PRODUCTION! configVersion := d.Configuration(cmd.Context()).ConfigVersion() if configVersion == config.UnknownVersion { d.Logger().Warn("The config has no version specified. Add the version to improve your development experience.") - } else if clihelpers.BuildVersion != "" && - configVersion != clihelpers.BuildVersion { - d.Logger().Warnf("Config version is '%s' but kratos runs on version '%s'", configVersion, clihelpers.BuildVersion) + } else if config.Version != "" && + configVersion != config.Version { + d.Logger().Warnf("Config version is '%s' but kratos runs on version '%s'", configVersion, config.Version) } daemon.ServeAll(d)(cmd, args) diff --git a/continuity/container.go b/continuity/container.go index a58874e16346..2ef6b1a6ab91 100644 --- a/continuity/container.go +++ b/continuity/container.go @@ -4,7 +4,7 @@ import ( "context" "time" - "github.com/ory/kratos/corp/tablename" + "github.com/ory/kratos/corp" "github.com/gofrs/uuid" "github.com/pkg/errors" @@ -41,7 +41,7 @@ func (c *Container) UTC() *Container { } func (c Container) TableName(ctx context.Context) string { - return tablename.Contextualize(ctx, "continuity_containers") + return corp.ContextualizeTableName(ctx, "continuity_containers") } func NewContainer(name string, o managerOptions) *Container { diff --git a/corp/context.go b/corp/context.go new file mode 100644 index 000000000000..996b2139d96a --- /dev/null +++ b/corp/context.go @@ -0,0 +1,22 @@ +package corp + +import ( + "context" + "net/http" + + "github.com/ory/kratos/driver/config" +) + +func ContextualizeTableName(_ context.Context, name string) string { + return name +} + +func ContextualizeMiddleware(_ context.Context) func(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) { + return func(w http.ResponseWriter, r *http.Request, n http.HandlerFunc) { + n(w, r) + } +} + +func ContextualizeConfig(ctx context.Context, fb config.Provider) config.Provider { + return fb +} diff --git a/corp/go.mod b/corp/go.mod new file mode 100644 index 000000000000..405bb69f66ef --- /dev/null +++ b/corp/go.mod @@ -0,0 +1,7 @@ +module github.com/ory/kratos/corp + +go 1.14 + +replace github.com/ory/kratos => ../ + +require github.com/urfave/negroni v1.0.0 diff --git a/corp/go.sum b/corp/go.sum new file mode 100644 index 000000000000..66076391f5d6 --- /dev/null +++ b/corp/go.sum @@ -0,0 +1,2 @@ +github.com/urfave/negroni v1.0.0 h1:kIimOitoypq34K7TG7DUaJ9kq/N4Ofuwi1sjz0KipXc= +github.com/urfave/negroni v1.0.0/go.mod h1:Meg73S6kFm/4PpbYdq35yYWoCZ9mS/YSx+lKnmiohz4= diff --git a/corp/tablename/context.go b/corp/tablename/context.go deleted file mode 100644 index 96829393f20d..000000000000 --- a/corp/tablename/context.go +++ /dev/null @@ -1,7 +0,0 @@ -package tablename - -import "context" - -func Contextualize(_ context.Context, name string) string { - return name -} diff --git a/corp/tablename/go.mod b/corp/tablename/go.mod deleted file mode 100644 index 28a9c7ce0049..000000000000 --- a/corp/tablename/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module github.com/ory/kratos/corp/tablename - -go 1.14 diff --git a/courier/message.go b/courier/message.go index af081791033e..ccf6443d77ea 100644 --- a/courier/message.go +++ b/courier/message.go @@ -4,7 +4,7 @@ import ( "context" "time" - "github.com/ory/kratos/corp/tablename" + "github.com/ory/kratos/corp" "github.com/gofrs/uuid" ) @@ -37,5 +37,5 @@ type Message struct { } func (m Message) TableName(ctx context.Context) string { - return tablename.Contextualize(ctx, "courier_messages") + return corp.ContextualizeTableName(ctx, "courier_messages") } diff --git a/go.mod b/go.mod index 9da987cd5b7c..e7157bd6f2aa 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ replace gopkg.in/DataDog/dd-trace-go.v1 => gopkg.in/DataDog/dd-trace-go.v1 v1.27 replace github.com/ory/kratos-client-go => ./internal/httpclient // Use the internal name for tablename generation -replace github.com/ory/kratos/corp/tablename => ./corp/tablename +replace github.com/ory/kratos/corp => ./corp require ( github.com/HdrHistogram/hdrhistogram-go v1.0.1 // indirect @@ -61,7 +61,7 @@ require ( github.com/ory/herodot v0.9.0 github.com/ory/jsonschema/v3 v3.0.1 github.com/ory/kratos-client-go v0.0.0-00010101000000-000000000000 - github.com/ory/kratos/corp/tablename v0.0.0-00010101000000-000000000000 + github.com/ory/kratos/corp v0.0.0-00010101000000-000000000000 github.com/ory/mail/v3 v3.0.0 github.com/ory/nosurf v1.2.3 github.com/ory/x v0.0.170 diff --git a/identity/credentials.go b/identity/credentials.go index 4ecc75b87452..79fb02acac90 100644 --- a/identity/credentials.go +++ b/identity/credentials.go @@ -5,7 +5,7 @@ import ( "reflect" "time" - "github.com/ory/kratos/corp/tablename" + "github.com/ory/kratos/corp" "github.com/gofrs/uuid" @@ -90,23 +90,23 @@ type ( ) func (c CredentialsTypeTable) TableName(ctx context.Context) string { - return tablename.Contextualize(ctx, "identity_credential_types") + return corp.ContextualizeTableName(ctx, "identity_credential_types") } func (c CredentialsCollection) TableName(ctx context.Context) string { - return tablename.Contextualize(ctx, "identity_credentials") + return corp.ContextualizeTableName(ctx, "identity_credentials") } func (c Credentials) TableName(ctx context.Context) string { - return tablename.Contextualize(ctx, "identity_credentials") + return corp.ContextualizeTableName(ctx, "identity_credentials") } func (c CredentialIdentifierCollection) TableName(ctx context.Context) string { - return tablename.Contextualize(ctx, "identity_credential_identifiers") + return corp.ContextualizeTableName(ctx, "identity_credential_identifiers") } func (c CredentialIdentifier) TableName(ctx context.Context) string { - return tablename.Contextualize(ctx, "identity_credential_identifiers") + return corp.ContextualizeTableName(ctx, "identity_credential_identifiers") } func CredentialsEqual(a, b map[CredentialsType]Credentials) bool { diff --git a/identity/identity.go b/identity/identity.go index c59f2f101333..59de6246b57f 100644 --- a/identity/identity.go +++ b/identity/identity.go @@ -7,7 +7,7 @@ import ( "sync" "time" - "github.com/ory/kratos/corp/tablename" + "github.com/ory/kratos/corp" "github.com/ory/herodot" "github.com/ory/x/sqlxx" @@ -117,7 +117,7 @@ func (t *Traits) UnmarshalJSON(data []byte) error { } func (i Identity) TableName(ctx context.Context) string { - return tablename.Contextualize(ctx, "identities") + return corp.ContextualizeTableName(ctx, "identities") } func (i *Identity) lock() *sync.RWMutex { diff --git a/identity/identity_recovery.go b/identity/identity_recovery.go index 8479611baa06..b50f6bc183e1 100644 --- a/identity/identity_recovery.go +++ b/identity/identity_recovery.go @@ -4,7 +4,7 @@ import ( "context" "time" - "github.com/ory/kratos/corp/tablename" + "github.com/ory/kratos/corp" "github.com/gofrs/uuid" ) @@ -49,7 +49,7 @@ func (v RecoveryAddressType) HTMLFormInputType() string { } func (a RecoveryAddress) TableName(ctx context.Context) string { - return tablename.Contextualize(ctx, "identity_recovery_addresses") + return corp.ContextualizeTableName(ctx, "identity_recovery_addresses") } func NewRecoveryEmailAddress( diff --git a/identity/identity_verification.go b/identity/identity_verification.go index 2885d2f92d7a..554975d6ab6e 100644 --- a/identity/identity_verification.go +++ b/identity/identity_verification.go @@ -4,7 +4,7 @@ import ( "context" "time" - "github.com/ory/kratos/corp/tablename" + "github.com/ory/kratos/corp" "github.com/gofrs/uuid" @@ -62,7 +62,7 @@ func (v VerifiableAddressType) HTMLFormInputType() string { } func (a VerifiableAddress) TableName(ctx context.Context) string { - return tablename.Contextualize(ctx, "identity_verifiable_addresses") + return corp.ContextualizeTableName(ctx, "identity_verifiable_addresses") } func NewVerifiableEmailAddress(value string, identity uuid.UUID) *VerifiableAddress { diff --git a/internal/clihelpers/helpers.go b/internal/clihelpers/helpers.go index bfceef00cada..870c67a9871f 100644 --- a/internal/clihelpers/helpers.go +++ b/internal/clihelpers/helpers.go @@ -1,11 +1,5 @@ package clihelpers -var ( - BuildVersion = "" - BuildTime = "" - BuildGitHash = "" -) - const ( WarningJQIsComplicated = "We have to admit, this is not easy if you don't speak jq fluently. What about opening an issue and telling us what predefined selectors you want to have? https://github.com/ory/kratos/issues/new/choose" ) diff --git a/selfservice/errorx/error.go b/selfservice/errorx/error.go index f76040c5ce4d..53cabf055f12 100644 --- a/selfservice/errorx/error.go +++ b/selfservice/errorx/error.go @@ -6,7 +6,7 @@ import ( "encoding/json" "time" - "github.com/ory/kratos/corp/tablename" + "github.com/ory/kratos/corp" "github.com/gofrs/uuid" ) @@ -36,5 +36,5 @@ type ErrorContainer struct { } func (e ErrorContainer) TableName(ctx context.Context) string { - return tablename.Contextualize(ctx, "selfservice_errors") + return corp.ContextualizeTableName(ctx, "selfservice_errors") } diff --git a/selfservice/flow/login/flow.go b/selfservice/flow/login/flow.go index ebd4a7d49747..6e704bb7c035 100644 --- a/selfservice/flow/login/flow.go +++ b/selfservice/flow/login/flow.go @@ -6,7 +6,7 @@ import ( "net/url" "time" - "github.com/ory/kratos/corp/tablename" + "github.com/ory/kratos/corp" "github.com/gobuffalo/pop/v5" "github.com/gofrs/uuid" @@ -132,7 +132,7 @@ func (f *Flow) AfterFind(_ *pop.Connection) error { } func (f Flow) TableName(ctx context.Context) string { - return tablename.Contextualize(ctx, "selfservice_login_flows") + return corp.ContextualizeTableName(ctx, "selfservice_login_flows") } func (f *Flow) Valid() error { diff --git a/selfservice/flow/login/flow_method.go b/selfservice/flow/login/flow_method.go index 7a8ea4581f9b..a8db56e258b7 100644 --- a/selfservice/flow/login/flow_method.go +++ b/selfservice/flow/login/flow_method.go @@ -6,7 +6,7 @@ import ( "encoding/json" "time" - "github.com/ory/kratos/corp/tablename" + "github.com/ory/kratos/corp" "github.com/ory/x/sqlxx" @@ -45,13 +45,13 @@ type FlowMethod struct { } func (u FlowMethod) TableName(ctx context.Context) string { - return tablename.Contextualize(ctx, "selfservice_login_flow_methods") + return corp.ContextualizeTableName(ctx, "selfservice_login_flow_methods") } type FlowMethods map[identity.CredentialsType]*FlowMethod func (u FlowMethods) TableName(ctx context.Context) string { - return tablename.Contextualize(ctx, "selfservice_login_flow_methods") + return corp.ContextualizeTableName(ctx, "selfservice_login_flow_methods") } // swagger:ignore diff --git a/selfservice/flow/recovery/flow.go b/selfservice/flow/recovery/flow.go index c0845fbbd345..623fe50e70f8 100644 --- a/selfservice/flow/recovery/flow.go +++ b/selfservice/flow/recovery/flow.go @@ -6,7 +6,7 @@ import ( "net/url" "time" - "github.com/ory/kratos/corp/tablename" + "github.com/ory/kratos/corp" "github.com/gobuffalo/pop/v5" "github.com/gofrs/uuid" @@ -120,7 +120,7 @@ func NewFlow(exp time.Duration, csrf string, r *http.Request, strategies Strateg } func (f Flow) TableName(ctx context.Context) string { - return tablename.Contextualize(ctx, "selfservice_recovery_flows") + return corp.ContextualizeTableName(ctx, "selfservice_recovery_flows") } func (f *Flow) GetID() uuid.UUID { diff --git a/selfservice/flow/recovery/flow_method.go b/selfservice/flow/recovery/flow_method.go index 88095b328edd..1513d768cff9 100644 --- a/selfservice/flow/recovery/flow_method.go +++ b/selfservice/flow/recovery/flow_method.go @@ -6,7 +6,7 @@ import ( "encoding/json" "time" - "github.com/ory/kratos/corp/tablename" + "github.com/ory/kratos/corp" "github.com/ory/x/sqlxx" @@ -44,13 +44,13 @@ type FlowMethod struct { } func (u FlowMethod) TableName(ctx context.Context) string { - return tablename.Contextualize(ctx, "selfservice_recovery_flow_methods") + return corp.ContextualizeTableName(ctx, "selfservice_recovery_flow_methods") } type FlowMethods map[string]*FlowMethod func (u FlowMethods) TableName(ctx context.Context) string { - return tablename.Contextualize(ctx, "selfservice_recovery_flow_methods") + return corp.ContextualizeTableName(ctx, "selfservice_recovery_flow_methods") } // swagger:ignore diff --git a/selfservice/flow/registration/flow.go b/selfservice/flow/registration/flow.go index bd26098076a0..f83572d92287 100644 --- a/selfservice/flow/registration/flow.go +++ b/selfservice/flow/registration/flow.go @@ -6,7 +6,7 @@ import ( "net/url" "time" - "github.com/ory/kratos/corp/tablename" + "github.com/ory/kratos/corp" "github.com/gobuffalo/pop/v5" "github.com/gofrs/uuid" @@ -118,7 +118,7 @@ func (f *Flow) AfterFind(_ *pop.Connection) error { } func (f Flow) TableName(ctx context.Context) string { - return tablename.Contextualize(ctx, "selfservice_registration_flows") + return corp.ContextualizeTableName(ctx, "selfservice_registration_flows") } func (f *Flow) GetID() uuid.UUID { diff --git a/selfservice/flow/registration/flow_method.go b/selfservice/flow/registration/flow_method.go index 6e16de0efe25..a1eddbb8f905 100644 --- a/selfservice/flow/registration/flow_method.go +++ b/selfservice/flow/registration/flow_method.go @@ -6,7 +6,7 @@ import ( "encoding/json" "time" - "github.com/ory/kratos/corp/tablename" + "github.com/ory/kratos/corp" "github.com/ory/x/sqlxx" @@ -45,13 +45,13 @@ type FlowMethod struct { } func (u FlowMethod) TableName(ctx context.Context) string { - return tablename.Contextualize(ctx, "selfservice_registration_flow_methods") + return corp.ContextualizeTableName(ctx, "selfservice_registration_flow_methods") } type FlowMethods map[identity.CredentialsType]*FlowMethod func (u FlowMethods) TableName(ctx context.Context) string { - return tablename.Contextualize(ctx, "selfservice_registration_flow_methods") + return corp.ContextualizeTableName(ctx, "selfservice_registration_flow_methods") } // swagger:ignore diff --git a/selfservice/flow/settings/flow.go b/selfservice/flow/settings/flow.go index dfa45a5b0004..d5e38a323558 100644 --- a/selfservice/flow/settings/flow.go +++ b/selfservice/flow/settings/flow.go @@ -6,7 +6,7 @@ import ( "net/url" "time" - "github.com/ory/kratos/corp/tablename" + "github.com/ory/kratos/corp" "github.com/gobuffalo/pop/v5" "github.com/gofrs/uuid" @@ -137,7 +137,7 @@ func NewFlow(exp time.Duration, r *http.Request, i *identity.Identity, ft flow.T } func (r Flow) TableName(ctx context.Context) string { - return tablename.Contextualize(ctx, "selfservice_settings_flows") + return corp.ContextualizeTableName(ctx, "selfservice_settings_flows") } func (r *Flow) GetID() uuid.UUID { diff --git a/selfservice/flow/settings/flow_method.go b/selfservice/flow/settings/flow_method.go index 67edb44f366f..1d3c14a45b19 100644 --- a/selfservice/flow/settings/flow_method.go +++ b/selfservice/flow/settings/flow_method.go @@ -6,7 +6,7 @@ import ( "encoding/json" "time" - "github.com/ory/kratos/corp/tablename" + "github.com/ory/kratos/corp" "github.com/ory/x/sqlxx" @@ -44,13 +44,13 @@ type FlowMethod struct { } func (u FlowMethod) TableName(ctx context.Context) string { - return tablename.Contextualize(ctx, "selfservice_settings_flow_methods") + return corp.ContextualizeTableName(ctx, "selfservice_settings_flow_methods") } type FlowMethods map[string]*FlowMethod func (u FlowMethods) TableName(ctx context.Context) string { - return tablename.Contextualize(ctx, "selfservice_settings_flow_methods") + return corp.ContextualizeTableName(ctx, "selfservice_settings_flow_methods") } // swagger:ignore diff --git a/selfservice/flow/verification/flow.go b/selfservice/flow/verification/flow.go index 6e142a64dd67..364a2a384542 100644 --- a/selfservice/flow/verification/flow.go +++ b/selfservice/flow/verification/flow.go @@ -6,7 +6,7 @@ import ( "net/url" "time" - "github.com/ory/kratos/corp/tablename" + "github.com/ory/kratos/corp" "github.com/gobuffalo/pop/v5" "github.com/gofrs/uuid" @@ -89,7 +89,7 @@ type Flow struct { } func (f Flow) TableName(ctx context.Context) string { - return tablename.Contextualize(ctx, "selfservice_verification_flows") + return corp.ContextualizeTableName(ctx, "selfservice_verification_flows") } func NewFlow(exp time.Duration, csrf string, r *http.Request, strategies Strategies, ft flow.Type) (*Flow, error) { diff --git a/selfservice/flow/verification/flow_method.go b/selfservice/flow/verification/flow_method.go index d484fd8fd423..e4339ab2d791 100644 --- a/selfservice/flow/verification/flow_method.go +++ b/selfservice/flow/verification/flow_method.go @@ -6,7 +6,7 @@ import ( "encoding/json" "time" - "github.com/ory/kratos/corp/tablename" + "github.com/ory/kratos/corp" "github.com/ory/x/sqlxx" @@ -44,13 +44,13 @@ type FlowMethod struct { } func (u FlowMethod) TableName(ctx context.Context) string { - return tablename.Contextualize(ctx, "selfservice_verification_flow_methods") + return corp.ContextualizeTableName(ctx, "selfservice_verification_flow_methods") } type FlowMethods map[string]*FlowMethod func (u FlowMethods) TableName(ctx context.Context) string { - return tablename.Contextualize(ctx, "selfservice_verification_flow_methods") + return corp.ContextualizeTableName(ctx, "selfservice_verification_flow_methods") } // swagger:ignore diff --git a/selfservice/mfa/questions/identity.go b/selfservice/mfa/questions/identity.go index 0e9edc624468..91635102b94b 100644 --- a/selfservice/mfa/questions/identity.go +++ b/selfservice/mfa/questions/identity.go @@ -4,7 +4,7 @@ import ( "context" "time" - "github.com/ory/kratos/corp/tablename" + "github.com/ory/kratos/corp" "github.com/gofrs/uuid" ) @@ -28,5 +28,5 @@ type ( ) func (a RecoverySecurityAnswers) TableName(ctx context.Context) string { - return tablename.Contextualize(ctx, "identity_recovery_addresses") + return corp.ContextualizeTableName(ctx, "identity_recovery_addresses") } diff --git a/selfservice/strategy/link/token_recovery.go b/selfservice/strategy/link/token_recovery.go index 9cc3595c7310..fc8c265f03e5 100644 --- a/selfservice/strategy/link/token_recovery.go +++ b/selfservice/strategy/link/token_recovery.go @@ -4,7 +4,7 @@ import ( "context" "time" - "github.com/ory/kratos/corp/tablename" + "github.com/ory/kratos/corp" "github.com/gofrs/uuid" errors "github.com/pkg/errors" @@ -50,7 +50,7 @@ type RecoveryToken struct { } func (RecoveryToken) TableName(ctx context.Context) string { - return tablename.Contextualize(ctx, "identity_recovery_tokens") + return corp.ContextualizeTableName(ctx, "identity_recovery_tokens") } func NewSelfServiceRecoveryToken(address *identity.RecoveryAddress, f *recovery.Flow) *RecoveryToken { diff --git a/selfservice/strategy/link/token_verification.go b/selfservice/strategy/link/token_verification.go index 96f837ae8813..42b07e571d69 100644 --- a/selfservice/strategy/link/token_verification.go +++ b/selfservice/strategy/link/token_verification.go @@ -4,7 +4,7 @@ import ( "context" "time" - "github.com/ory/kratos/corp/tablename" + "github.com/ory/kratos/corp" "github.com/gofrs/uuid" "github.com/pkg/errors" @@ -50,7 +50,7 @@ type VerificationToken struct { } func (VerificationToken) TableName(ctx context.Context) string { - return tablename.Contextualize(ctx, "identity_verification_tokens") + return corp.ContextualizeTableName(ctx, "identity_verification_tokens") } func NewSelfServiceVerificationToken(address *identity.VerifiableAddress, f *verification.Flow) *VerificationToken { diff --git a/session/session.go b/session/session.go index 8baa88711709..bcb4d1ac23d9 100644 --- a/session/session.go +++ b/session/session.go @@ -4,7 +4,7 @@ import ( "context" "time" - "github.com/ory/kratos/corp/tablename" + "github.com/ory/kratos/corp" "github.com/gofrs/uuid" @@ -44,7 +44,7 @@ type Session struct { } func (s Session) TableName(ctx context.Context) string { - return tablename.Contextualize(ctx, "sessions") + return corp.ContextualizeTableName(ctx, "sessions") } func NewActiveSession(i *identity.Identity, c interface {