Skip to content

Commit 5686d1d

Browse files
feat: add config view command
1 parent b922c60 commit 5686d1d

File tree

5 files changed

+89
-0
lines changed

5 files changed

+89
-0
lines changed

cmd/config/root.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright © 2025 Ory Corp
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package config
5+
6+
import (
7+
"github.com/spf13/cobra"
8+
9+
"github.com/ory/kratos/driver"
10+
"github.com/ory/x/configx"
11+
)
12+
13+
func NewConfigCmd() *cobra.Command {
14+
c := &cobra.Command{
15+
Use: "config",
16+
}
17+
configx.RegisterFlags(c.PersistentFlags())
18+
return c
19+
}
20+
21+
func RegisterCommandRecursive(parent *cobra.Command, dOpts []driver.RegistryOption) {
22+
c := NewConfigCmd()
23+
parent.AddCommand(c)
24+
c.AddCommand(NewConfigViewCmd(dOpts))
25+
}

cmd/config/view.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright © 2025 Ory Corp
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package config
5+
6+
import (
7+
"fmt"
8+
9+
"github.com/spf13/cobra"
10+
11+
"github.com/ory/kratos/driver"
12+
"github.com/ory/kratos/driver/config"
13+
"github.com/ory/x/configx"
14+
"github.com/ory/x/contextx"
15+
"github.com/ory/x/logrusx"
16+
)
17+
18+
func NewConfigViewCmd(dOpts []driver.RegistryOption) *cobra.Command {
19+
c := &cobra.Command{
20+
Use: "view",
21+
RunE: func(cmd *cobra.Command, args []string) error {
22+
l := logrusx.New("Ory Kratos", config.Version)
23+
config, err := config.New(
24+
cmd.Context(),
25+
l,
26+
cmd.ErrOrStderr(),
27+
&contextx.Default{},
28+
configx.WithFlags(cmd.Flags()),
29+
configx.SkipValidation(),
30+
configx.WithContext(cmd.Context()),
31+
)
32+
if err != nil {
33+
return err
34+
}
35+
36+
out, err := config.View(cmd.Context())
37+
if err != nil {
38+
return err
39+
}
40+
41+
fmt.Printf("%s\n", out)
42+
43+
return nil
44+
},
45+
}
46+
47+
return c
48+
}

cmd/root.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/spf13/cobra"
1212

1313
"github.com/ory/kratos/cmd/cleanup"
14+
configCmd "github.com/ory/kratos/cmd/config"
1415
"github.com/ory/kratos/cmd/courier"
1516
"github.com/ory/kratos/cmd/hashers"
1617
"github.com/ory/kratos/cmd/identities"
@@ -31,6 +32,7 @@ func NewRootCmd(driverOpts ...driver.RegistryOption) (cmd *cobra.Command) {
3132
}
3233
cmdx.EnableUsageTemplating(cmd)
3334

35+
configCmd.RegisterCommandRecursive(cmd, driverOpts)
3436
courier.RegisterCommandRecursive(cmd, driverOpts)
3537
cmd.AddCommand(identities.NewGetCmd())
3638
cmd.AddCommand(identities.NewDeleteCmd())

driver/config/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,10 @@ func (p *Config) validateIdentitySchemas(ctx context.Context) error {
492492
return nil
493493
}
494494

495+
func (p *Config) View(ctx context.Context) ([]byte, error) {
496+
return p.GetProvider(ctx).View()
497+
}
498+
495499
func (p *Config) formatJsonErrors(schema []byte, err error) {
496500
_, _ = fmt.Fprintln(p.stdOutOrErr, "")
497501
jsonschemax.FormatValidationErrorForCLI(p.stdOutOrErr, schema, err)

oryx/configx/provider.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616

1717
"github.com/inhies/go-bytesize"
1818
"github.com/knadh/koanf/parsers/json"
19+
"github.com/knadh/koanf/parsers/yaml"
1920
"github.com/knadh/koanf/providers/posflag"
2021
"github.com/knadh/koanf/v2"
2122
"github.com/pkg/errors"
@@ -534,6 +535,15 @@ func (p *Provider) PrintHumanReadableValidationErrors(w io.Writer, err error) {
534535
p.printHumanReadableValidationErrors(p.Koanf, w, err)
535536
}
536537

538+
func (p *Provider) View() ([]byte, error) {
539+
out, err := p.Koanf.Marshal(yaml.Parser())
540+
if err != nil {
541+
return nil, fmt.Errorf("Unable to marshal configuration: %w", err)
542+
}
543+
544+
return out, nil
545+
}
546+
537547
func (p *Provider) printHumanReadableValidationErrors(k *koanf.Koanf, w io.Writer, err error) {
538548
if err == nil {
539549
return

0 commit comments

Comments
 (0)