Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 132e90c

Browse files
committedMar 15, 2025·
add control peer rest api
Signed-off-by: Fedor Partanskiy <[email protected]>
1 parent 4f14163 commit 132e90c

File tree

84 files changed

+25320
-51
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+25320
-51
lines changed
 

‎core/peer/config.go

+29
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,26 @@ type Config struct {
219219
// interact with fabric networks
220220

221221
GatewayOptions gatewayconfig.Options
222+
223+
// ----- Rest api config -----
224+
RestAPI RestAPI
225+
}
226+
227+
// RestAPI configures the rest endpoint for the peer.
228+
type RestAPI struct {
229+
ListenAddress string
230+
TLS TLS
231+
}
232+
233+
// TLS contains configuration for TLS connections.
234+
type TLS struct {
235+
Enabled bool
236+
PrivateKey string
237+
Certificate string
238+
RootCAs []string
239+
ClientAuthRequired bool
240+
ClientRootCAs []string
241+
TLSHandshakeTimeShift time.Duration
222242
}
223243

224244
// GlobalConfig obtains a set of configuration from viper, build and returns
@@ -331,6 +351,15 @@ func (c *Config) load() error {
331351
c.DockerKey = config.GetPath("vm.docker.tls.key.file")
332352
c.DockerCA = config.GetPath("vm.docker.tls.ca.file")
333353

354+
c.RestAPI.ListenAddress = viper.GetString("RestAPI.ListenAddress")
355+
c.RestAPI.TLS.Enabled = viper.GetBool("RestAPI.TLS.Enabled")
356+
c.RestAPI.TLS.Certificate = config.GetPath("RestAPI.TLS.Certificate")
357+
c.RestAPI.TLS.PrivateKey = config.GetPath("RestAPI.TLS.PrivateKey")
358+
c.RestAPI.TLS.ClientAuthRequired = viper.GetBool("RestAPI.TLS.ClientAuthRequired")
359+
for _, rca := range viper.GetStringSlice("RestAPI.TLS.ClientRootCAs") {
360+
c.RestAPI.TLS.ClientRootCAs = append(c.RestAPI.TLS.ClientRootCAs, config.TranslatePath(configDir, rca))
361+
}
362+
334363
return nil
335364
}
336365

‎core/peer/config_test.go

+21
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,13 @@ func TestGlobalConfig(t *testing.T) {
305305
viper.Set("metrics.statsd.writeInterval", "10s")
306306
viper.Set("metrics.statsd.prefix", "testPrefix")
307307

308+
viper.Set("RestAPI.ListenAddress", "127.0.0.1:9444")
309+
viper.Set("RestAPI.TLS.Enabled", false)
310+
viper.Set("RestAPI.TLS.Certificate", "test/tls/cert/file")
311+
viper.Set("RestAPI.TLS.PrivateKey", "test/tls/key/file")
312+
viper.Set("RestAPI.TLS.ClientAuthRequired", false)
313+
viper.Set("RestAPI.TLS.ClientRootCAs", []string{"relative/file1", "/absolute/file2"})
314+
308315
viper.Set("chaincode.pull", false)
309316
viper.Set("chaincode.externalBuilders", &[]ExternalBuilder{
310317
{
@@ -385,6 +392,20 @@ func TestGlobalConfig(t *testing.T) {
385392
BroadcastTimeout: 10 * time.Second,
386393
DialTimeout: 60 * time.Second,
387394
},
395+
RestAPI: RestAPI{
396+
ListenAddress: "127.0.0.1:9444",
397+
TLS: TLS{
398+
Enabled: false,
399+
PrivateKey: filepath.Join(cwd, "test/tls/key/file"),
400+
Certificate: filepath.Join(cwd, "test/tls/cert/file"),
401+
RootCAs: nil,
402+
ClientAuthRequired: false,
403+
ClientRootCAs: []string{
404+
filepath.Join(cwd, "relative", "file1"),
405+
"/absolute/file2",
406+
},
407+
},
408+
},
388409
}
389410

390411
require.Equal(t, coreConfig, expectedConfig)

0 commit comments

Comments
 (0)
Please sign in to comment.