Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
25 changes: 25 additions & 0 deletions cmd/config/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright © 2025 Ory Corp
// SPDX-License-Identifier: Apache-2.0

package config

import (
"github.com/spf13/cobra"

"github.com/ory/kratos/driver"
"github.com/ory/x/configx"
)

func NewConfigCmd() *cobra.Command {
c := &cobra.Command{
Use: "config",
}
configx.RegisterFlags(c.PersistentFlags())
return c
}

func RegisterCommandRecursive(parent *cobra.Command, dOpts []driver.RegistryOption) {
c := NewConfigCmd()
parent.AddCommand(c)
c.AddCommand(NewConfigViewCmd(dOpts))
}
48 changes: 48 additions & 0 deletions cmd/config/view.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright © 2025 Ory Corp
// SPDX-License-Identifier: Apache-2.0

package config

import (
"fmt"

"github.com/spf13/cobra"

"github.com/ory/kratos/driver"
"github.com/ory/kratos/driver/config"
"github.com/ory/x/configx"
"github.com/ory/x/contextx"
"github.com/ory/x/logrusx"
)

func NewConfigViewCmd(dOpts []driver.RegistryOption) *cobra.Command {
c := &cobra.Command{
Use: "view",
RunE: func(cmd *cobra.Command, args []string) error {
l := logrusx.New("Ory Kratos", config.Version)
config, err := config.New(
cmd.Context(),
l,
cmd.ErrOrStderr(),
&contextx.Default{},
configx.WithFlags(cmd.Flags()),
configx.SkipValidation(),
configx.WithContext(cmd.Context()),
)
if err != nil {
return err
}

out, err := config.View(cmd.Context())
if err != nil {
return err
}

fmt.Printf("%s\n", out)

return nil
},
}

return c
}
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/spf13/cobra"

"github.com/ory/kratos/cmd/cleanup"
configCmd "github.com/ory/kratos/cmd/config"
"github.com/ory/kratos/cmd/courier"
"github.com/ory/kratos/cmd/hashers"
"github.com/ory/kratos/cmd/identities"
Expand All @@ -31,6 +32,7 @@ func NewRootCmd(driverOpts ...driver.RegistryOption) (cmd *cobra.Command) {
}
cmdx.EnableUsageTemplating(cmd)

configCmd.RegisterCommandRecursive(cmd, driverOpts)
courier.RegisterCommandRecursive(cmd, driverOpts)
cmd.AddCommand(identities.NewGetCmd())
cmd.AddCommand(identities.NewDeleteCmd())
Expand Down
4 changes: 4 additions & 0 deletions driver/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,10 @@ func (p *Config) validateIdentitySchemas(ctx context.Context) error {
return nil
}

func (p *Config) View(ctx context.Context) ([]byte, error) {
return p.GetProvider(ctx).View()
}

func (p *Config) formatJsonErrors(schema []byte, err error) {
_, _ = fmt.Fprintln(p.stdOutOrErr, "")
jsonschemax.FormatValidationErrorForCLI(p.stdOutOrErr, schema, err)
Expand Down
10 changes: 10 additions & 0 deletions oryx/configx/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

"github.com/inhies/go-bytesize"
"github.com/knadh/koanf/parsers/json"
"github.com/knadh/koanf/parsers/yaml"
"github.com/knadh/koanf/providers/posflag"
"github.com/knadh/koanf/v2"
"github.com/pkg/errors"
Expand Down Expand Up @@ -534,6 +535,15 @@ func (p *Provider) PrintHumanReadableValidationErrors(w io.Writer, err error) {
p.printHumanReadableValidationErrors(p.Koanf, w, err)
}

func (p *Provider) View() ([]byte, error) {
out, err := p.Koanf.Marshal(yaml.Parser())
if err != nil {
return nil, fmt.Errorf("Unable to marshal configuration: %w", err)
}

return out, nil
}

func (p *Provider) printHumanReadableValidationErrors(k *koanf.Koanf, w io.Writer, err error) {
if err == nil {
return
Expand Down
Loading