Skip to content

Commit b353b61

Browse files
feature(fxconfig): add config file support (#57)
#### Type of change - New feature - Test update - Documentation update - Breaking change #### Description This PR introduces config file support to fxconfig as described in #58. Note that this PR does not yet introduce MSP-based policies nor the multi-org endorsement flows. These features will come in the next PRs. #### Additional details (Optional) See readme in `tools/fxconfig/docs/README.md #### Related issues - #55 - Resolves #58 Signed-off-by: Marcus Brandenburger <bur@zurich.ibm.com>
1 parent 0a47711 commit b353b61

33 files changed

+2627
-996
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ require (
2222
github.com/hyperledger/fabric-x-committer v0.1.8
2323
github.com/hyperledger/fabric-x-common v0.1.0
2424
github.com/spf13/cobra v1.10.2
25+
github.com/spf13/viper v1.21.0
2526
github.com/stretchr/testify v1.11.1
2627
github.com/testcontainers/testcontainers-go v0.40.0
2728
golang.org/x/text v0.33.0
2829
google.golang.org/protobuf v1.36.11
30+
gopkg.in/yaml.v3 v3.0.1
2931
)
3032

3133
require (
@@ -122,7 +124,6 @@ require (
122124
github.com/spf13/afero v1.15.0 // indirect
123125
github.com/spf13/cast v1.10.0 // indirect
124126
github.com/spf13/pflag v1.0.10 // indirect
125-
github.com/spf13/viper v1.21.0 // indirect
126127
github.com/subosito/gotenv v1.6.0 // indirect
127128
github.com/sykesm/zap-logfmt v0.0.4 // indirect
128129
github.com/tklauser/go-sysconf v0.3.12 // indirect
@@ -150,5 +151,4 @@ require (
150151
google.golang.org/genproto/googleapis/api v0.0.0-20260120221211-b8f7ae30c516 // indirect
151152
google.golang.org/genproto/googleapis/rpc v0.0.0-20260120174246-409b4a993575 // indirect
152153
google.golang.org/grpc v1.78.0 // indirect
153-
gopkg.in/yaml.v3 v3.0.1 // indirect
154154
)

tools/fxconfig/cmd/cmd.go

Lines changed: 0 additions & 26 deletions
This file was deleted.

tools/fxconfig/cmd/config.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
Copyright IBM Corp. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
// Package cmd implements the command-line interface for fxconfig.
8+
// It provides commands for namespace management and configuration handling.
9+
package cmd
10+
11+
import (
12+
"github.com/spf13/cobra"
13+
14+
"github.com/hyperledger/fabric-x/tools/fxconfig/internal/config"
15+
)
16+
17+
// configKeyType is a custom type for context keys to avoid collisions.
18+
type configKeyType string
19+
20+
// configKey is the context key used to store and retrieve configuration.
21+
const configKey configKeyType = "app-config"
22+
23+
// getConfig retrieves the configuration from the command context.
24+
// Panics if the configuration is not found, indicating a programming error.
25+
func getConfig(cmd *cobra.Command) *config.Config {
26+
cfg, ok := cmd.Context().Value(configKey).(*config.Config)
27+
if !ok {
28+
panic("programming error: extracting config from context failed")
29+
}
30+
return cfg
31+
}

tools/fxconfig/cmd/info.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright IBM Corp. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package cmd
8+
9+
import (
10+
"github.com/spf13/cobra"
11+
"gopkg.in/yaml.v3"
12+
)
13+
14+
// NewInfoCommand returns a command that displays the effective configuration.
15+
// The configuration is shown as YAML after applying all overrides from
16+
// flags, environment variables, and config files.
17+
func NewInfoCommand() *cobra.Command {
18+
cmd := &cobra.Command{
19+
Use: "info",
20+
Short: "Display system-wide information",
21+
Long: ``,
22+
RunE: func(cmd *cobra.Command, _ []string) error {
23+
cfg := getConfig(cmd)
24+
25+
out, err := yaml.Marshal(cfg)
26+
if err != nil {
27+
return err
28+
}
29+
30+
cmd.Println(string(out))
31+
return nil
32+
},
33+
}
34+
35+
return cmd
36+
}

tools/fxconfig/cmd/namespace.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
Copyright IBM Corp. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package cmd
8+
9+
import (
10+
"github.com/spf13/cobra"
11+
12+
"github.com/hyperledger/fabric-x/tools/fxconfig/internal/namespace"
13+
)
14+
15+
// NewNamespaceCommand returns the namespace command group.
16+
// This command provides subcommands for namespace lifecycle operations:
17+
// create, update, and list.
18+
func NewNamespaceCommand() *cobra.Command {
19+
cmd := &cobra.Command{
20+
Use: "namespace",
21+
Short: "Perform namespace operations",
22+
Long: "",
23+
}
24+
25+
cmd.AddCommand(
26+
newCreateCommand(namespace.DeployNamespace),
27+
newListCommand(namespace.ListNamespaces),
28+
newUpdateCommand(namespace.DeployNamespace),
29+
)
30+
31+
return cmd
32+
}

tools/fxconfig/cmd/namespace/cmd.go

Lines changed: 0 additions & 87 deletions
This file was deleted.

tools/fxconfig/cmd/namespace/create.go

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
 (0)