Skip to content

Commit 8650cce

Browse files
added mtls support for fxconfig namespace list (#39)
Signed-off-by: Marcus Brandenburger <bur@zurich.ibm.com>
1 parent e9a537d commit 8650cce

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

tools/fxconfig/cmd/namespace/list.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,46 @@ package namespace
99
import (
1010
"io"
1111

12+
"github.com/hyperledger/fabric-x-common/cmd/common/comm"
13+
1214
"github.com/spf13/cobra"
1315
)
1416

15-
type listFunc func(out io.Writer, endpoint, cacert string) error
17+
type listFunc func(out io.Writer, endpoint string, tlsConfig comm.Config) error
1618

1719
func newListCommand(listFunc listFunc) *cobra.Command {
1820
// this is our default query service endpoint
1921
endpoint := "localhost:7001"
20-
cacert := ""
22+
var tlsConfig comm.Config
2123

2224
cmd := &cobra.Command{
2325
Use: "list",
2426
Short: "List installed Namespaces",
2527
Long: "",
2628
RunE: func(cmd *cobra.Command, _ []string) error {
27-
return listFunc(cmd.OutOrStdout(), endpoint, cacert)
29+
return listFunc(cmd.OutOrStdout(), endpoint, tlsConfig)
2830
},
2931
}
3032

31-
cmd.PersistentFlags().StringVarP(&cacert,
33+
cmd.PersistentFlags().StringVarP(&tlsConfig.PeerCACertPath,
3234
"cafile",
3335
"",
3436
"",
35-
"Path to file containing PEM-encoded trusted certificate(s) for the committer query service endpoint",
37+
"Path to file containing PEM-encoded trusted certificate(s) for the committer",
3638
)
3739

38-
// TODO: add client crt / key for mTLS support
40+
cmd.PersistentFlags().StringVarP(&tlsConfig.KeyPath,
41+
"keyfile",
42+
"",
43+
"",
44+
"Path to file containing PEM-encoded private key to use for mutual TLS communication with the committer",
45+
)
46+
cmd.PersistentFlags().StringVarP(&tlsConfig.CertPath,
47+
"certfile",
48+
"",
49+
"",
50+
"Path to file containing PEM-encoded public key to use for mutual TLS communication with the committer",
51+
)
3952

4053
cmd.PersistentFlags().StringVar(
4154
&endpoint,

tools/fxconfig/cmd/namespace/list_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"io"
1111
"testing"
1212

13+
"github.com/hyperledger/fabric-x-common/cmd/common/comm"
14+
1315
"github.com/spf13/cobra"
1416
"github.com/stretchr/testify/require"
1517
)
@@ -38,7 +40,7 @@ func setupList(t *testing.T) *cobra.Command {
3840
return rootCmd
3941
}
4042

41-
var fakeList = func(_ io.Writer, _, _ string) error {
43+
var fakeList = func(_ io.Writer, _ string, _ comm.Config) error {
4244
// don't do anything
4345
return nil
4446
}

tools/fxconfig/internal/namespace/list.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ import (
1919
)
2020

2121
// List calls the committer query service and shows all installed namespace policies.
22-
func List(out io.Writer, endpoint, cacert string) error {
23-
cl, err := comm.NewClient(comm.Config{
24-
PeerCACertPath: cacert,
25-
})
22+
func List(out io.Writer, endpoint string, tlsConfig comm.Config) error {
23+
cl, err := comm.NewClient(tlsConfig)
2624
if err != nil {
2725
return fmt.Errorf("cannot get grpc client: %w", err)
2826
}

0 commit comments

Comments
 (0)