Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Commit 68e4066

Browse files
sudeshrshettyemirsh
authored andcommitted
[FAB-10568] endpoint config refactoring
-remove Network config Name,Description,Version -some minor cleanup Change-Id: Ic74766271e63e39556423418afa6f237575e30fd Signed-off-by: Sudesh Shetty <sudesh.shetty@securekey.com> Signed-off-by: Emir Heidinger <emir.heidinger@securekey.com>
1 parent 83bfc05 commit 68e4066

File tree

7 files changed

+140
-115
lines changed

7 files changed

+140
-115
lines changed

pkg/common/providers/fab/network.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ import (
1414

1515
// NetworkConfig provides a static definition of endpoint configuration network
1616
type NetworkConfig struct {
17-
Name string
18-
Description string
19-
Version string
2017
Channels map[string]ChannelEndpointConfig
2118
Organizations map[string]OrganizationConfig
2219
Orderers map[string]OrdererConfig
@@ -91,21 +88,6 @@ type PeerConfig struct {
9188
TLSCACert *x509.Certificate
9289
}
9390

94-
// MatchConfig contains match pattern and substitution pattern
95-
// for pattern matching of network configured hostnames or channel names with static config
96-
type MatchConfig struct {
97-
Pattern string
98-
99-
// these are used for hostname mapping
100-
URLSubstitutionExp string
101-
EventURLSubstitutionExp string
102-
SSLTargetOverrideURLSubstitutionExp string
103-
MappedHost string
104-
105-
// this is used for Name mapping instead of hostname mappings
106-
MappedName string
107-
}
108-
10991
// CertKeyPair contains the private key and certificate
11092
type CertKeyPair struct {
11193
Cert []byte

pkg/core/config/endpoint/endpoint.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,12 @@ type MutualTLSConfig struct {
6565
}
6666

6767
// TLSKeyPair contains the private key and certificate for TLS encryption
68-
//TODO to be removed from here, instead 'TLSKeyCertPair' should be used
69-
//deprecated
7068
type TLSKeyPair struct {
7169
Key TLSConfig
7270
Cert TLSConfig
7371
}
7472

7573
// TLSConfig TLS configuration used in the sdk's configs.
76-
//deprecated
7774
type TLSConfig struct {
7875
// the following two fields are interchangeable.
7976
// If Path is available, then it will be used to load the cert
@@ -94,7 +91,6 @@ func (cfg *TLSConfig) Bytes() []byte {
9491

9592
//LoadBytes preloads bytes from Pem/Path
9693
//Pem takes precedence over Path
97-
//TODO to be removed since separate TLSConfig should only be used in parsing
9894
func (cfg *TLSConfig) LoadBytes() error {
9995
var err error
10096
if cfg.Pem != "" {
@@ -109,7 +105,6 @@ func (cfg *TLSConfig) LoadBytes() error {
109105
}
110106

111107
// TLSCert returns the tls certificate as a *x509.Certificate by loading it either from the embedded Pem or Path
112-
//TODO to be removed since separate TLSConfig should only be used in parsing
113108
func (cfg *TLSConfig) TLSCert() (*x509.Certificate, bool, error) {
114109

115110
block, _ := pem.Decode(cfg.bytes)

pkg/core/config/lookup/lookup_test.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const orgChannelID = "orgchannel"
3333
var backend *mocks.MockConfigBackend
3434

3535
type testEntityMatchers struct {
36-
matchers map[string][]fab.MatchConfig
36+
matchers map[string][]MatchConfig
3737
}
3838

3939
// networkConfig matches all network config elements
@@ -49,6 +49,21 @@ type networkConfig struct {
4949
CertificateAuthorities map[string]msp.CAConfig
5050
}
5151

52+
// MatchConfig contains match pattern and substitution pattern
53+
// for pattern matching of network configured hostnames or channel names with static config
54+
type MatchConfig struct {
55+
Pattern string
56+
57+
// these are used for hostname mapping
58+
URLSubstitutionExp string
59+
EventURLSubstitutionExp string
60+
SSLTargetOverrideURLSubstitutionExp string
61+
MappedHost string
62+
63+
// this is used for Name mapping instead of hostname mappings
64+
MappedName string
65+
}
66+
5267
func TestMain(m *testing.M) {
5368
backend = setupCustomBackend("key")
5469
r := m.Run()

pkg/fab/api.go

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
Copyright SecureKey Technologies Inc. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package fab
8+
9+
import (
10+
"github.com/hyperledger/fabric-sdk-go/pkg/common/errors/retry"
11+
"github.com/hyperledger/fabric-sdk-go/pkg/core/config/endpoint"
12+
)
13+
14+
//endpointConfigEntity contains endpoint config elements needed by endpointconfig
15+
type endpointConfigEntity struct {
16+
Client ClientConfig
17+
Channels map[string]ChannelEndpointConfig
18+
Organizations map[string]OrganizationConfig
19+
Orderers map[string]OrdererConfig
20+
Peers map[string]PeerConfig
21+
}
22+
23+
//entityMatchers for endpoint configuration
24+
type entityMatchers struct {
25+
matchers map[string][]MatchConfig
26+
}
27+
28+
// ClientConfig provides the definition of the client configuration
29+
type ClientConfig struct {
30+
Organization string
31+
TLSCerts ClientTLSConfig
32+
}
33+
34+
// ClientTLSConfig contains the client TLS configuration
35+
type ClientTLSConfig struct {
36+
//Client TLS information
37+
Client endpoint.TLSKeyPair
38+
}
39+
40+
// OrdererConfig defines an orderer configuration
41+
type OrdererConfig struct {
42+
URL string
43+
GRPCOptions map[string]interface{}
44+
TLSCACerts endpoint.TLSConfig
45+
}
46+
47+
// PeerConfig defines a peer configuration
48+
type PeerConfig struct {
49+
URL string
50+
EventURL string
51+
GRPCOptions map[string]interface{}
52+
TLSCACerts endpoint.TLSConfig
53+
}
54+
55+
// OrganizationConfig provides the definition of an organization in the network
56+
type OrganizationConfig struct {
57+
MSPID string
58+
CryptoPath string
59+
Users map[string]endpoint.TLSKeyPair
60+
Peers []string
61+
CertificateAuthorities []string
62+
}
63+
64+
// ChannelEndpointConfig provides the definition of channels for the network
65+
type ChannelEndpointConfig struct {
66+
// Orderers list of ordering service nodes
67+
Orderers []string
68+
// Peers a list of peer-channels that are part of this organization
69+
// to get the real Peer config object, use the Name field and fetch NetworkConfig.Peers[Name]
70+
Peers map[string]PeerChannelConfig
71+
//Policies list of policies for channel
72+
Policies ChannelPolicies
73+
}
74+
75+
//ChannelPolicies defines list of policies defined for a channel
76+
type ChannelPolicies struct {
77+
//Policy for querying channel block
78+
QueryChannelConfig QueryChannelConfigPolicy
79+
}
80+
81+
//QueryChannelConfigPolicy defines opts for channelConfigBlock
82+
type QueryChannelConfigPolicy struct {
83+
MinResponses int
84+
MaxTargets int
85+
RetryOpts retry.Opts
86+
}
87+
88+
// PeerChannelConfig defines the peer capabilities
89+
type PeerChannelConfig struct {
90+
EndorsingPeer bool
91+
ChaincodeQuery bool
92+
LedgerQuery bool
93+
EventSource bool
94+
}
95+
96+
// MatchConfig contains match pattern and substitution pattern
97+
// for pattern matching of network configured hostnames or channel names with static config
98+
type MatchConfig struct {
99+
Pattern string
100+
101+
// these are used for hostname mapping
102+
URLSubstitutionExp string
103+
EventURLSubstitutionExp string
104+
SSLTargetOverrideURLSubstitutionExp string
105+
MappedHost string
106+
107+
// this is used for Name mapping instead of hostname mappings
108+
MappedName string
109+
}

pkg/fab/endpointconfig.go

Lines changed: 1 addition & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"time"
1818

1919
"github.com/hyperledger/fabric-sdk-go/pkg/common/errors/multi"
20-
"github.com/hyperledger/fabric-sdk-go/pkg/common/errors/retry"
2120
"github.com/hyperledger/fabric-sdk-go/pkg/common/logging"
2221
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
2322
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
@@ -104,87 +103,6 @@ type EndpointConfig struct {
104103
channelMatchers map[int]*regexp.Regexp
105104
}
106105

107-
//entityMatchers for endpoint configuration
108-
type entityMatchers struct {
109-
matchers map[string][]fab.MatchConfig
110-
}
111-
112-
//endpointConfigEntity contains endpoint config elements needed by endpointconfig
113-
type endpointConfigEntity struct {
114-
Client clientConfig
115-
Channels map[string]ChannelEndpointConfig
116-
Organizations map[string]OrganizationConfig
117-
Orderers map[string]OrdererConfig
118-
Peers map[string]PeerConfig
119-
}
120-
121-
// ClientConfig provides the definition of the client configuration
122-
type clientConfig struct {
123-
Organization string
124-
TLSCerts clientTLSConfig
125-
}
126-
127-
type clientTLSConfig struct {
128-
//Client TLS information
129-
Client endpoint.TLSKeyPair
130-
}
131-
132-
// OrdererConfig defines an orderer configuration
133-
type OrdererConfig struct {
134-
URL string
135-
GRPCOptions map[string]interface{}
136-
TLSCACerts endpoint.TLSConfig
137-
}
138-
139-
// PeerConfig defines a peer configuration
140-
type PeerConfig struct {
141-
URL string
142-
EventURL string
143-
GRPCOptions map[string]interface{}
144-
TLSCACerts endpoint.TLSConfig
145-
}
146-
147-
// OrganizationConfig provides the definition of an organization in the network
148-
type OrganizationConfig struct {
149-
MSPID string
150-
CryptoPath string
151-
Users map[string]endpoint.TLSKeyPair
152-
Peers []string
153-
CertificateAuthorities []string
154-
}
155-
156-
// ChannelEndpointConfig provides the definition of channels for the network
157-
type ChannelEndpointConfig struct {
158-
// Orderers list of ordering service nodes
159-
Orderers []string
160-
// Peers a list of peer-channels that are part of this organization
161-
// to get the real Peer config object, use the Name field and fetch NetworkConfig.Peers[Name]
162-
Peers map[string]PeerChannelConfig
163-
//Policies list of policies for channel
164-
Policies ChannelPolicies
165-
}
166-
167-
//ChannelPolicies defines list of policies defined for a channel
168-
type ChannelPolicies struct {
169-
//Policy for querying channel block
170-
QueryChannelConfig QueryChannelConfigPolicy
171-
}
172-
173-
//QueryChannelConfigPolicy defines opts for channelConfigBlock
174-
type QueryChannelConfigPolicy struct {
175-
MinResponses int
176-
MaxTargets int
177-
RetryOpts retry.Opts
178-
}
179-
180-
// PeerChannelConfig defines the peer capabilities
181-
type PeerChannelConfig struct {
182-
EndorsingPeer bool
183-
ChaincodeQuery bool
184-
LedgerQuery bool
185-
EventSource bool
186-
}
187-
188106
// Timeout reads timeouts for the given timeout type, if type is not found in the config
189107
// then default is set as per the const value above for the corresponding type
190108
func (c *EndpointConfig) Timeout(tType fab.TimeoutType) time.Duration {
@@ -380,7 +298,7 @@ func (c *EndpointConfig) TLSClientCerts() []tls.Certificate {
380298
return c.tlsClientCerts
381299
}
382300

383-
func (c *EndpointConfig) loadPrivateKeyFromConfig(clientConfig *clientConfig, clientCerts tls.Certificate, cb []byte) ([]tls.Certificate, error) {
301+
func (c *EndpointConfig) loadPrivateKeyFromConfig(clientConfig *ClientConfig, clientCerts tls.Certificate, cb []byte) ([]tls.Certificate, error) {
384302

385303
kb := clientConfig.TLSCerts.Client.Key.Bytes()
386304

@@ -598,10 +516,6 @@ func (c *EndpointConfig) loadNetworkConfig(configEntity *endpointConfigEntity) e
598516

599517
networkConfig := fab.NetworkConfig{}
600518

601-
networkConfig.Name = c.backend.GetString("name")
602-
networkConfig.Description = c.backend.GetString("description")
603-
networkConfig.Version = c.backend.GetString("version")
604-
605519
//Channels
606520
networkConfig.Channels = make(map[string]fab.ChannelEndpointConfig)
607521
for chID, chNwCfg := range configEntity.Channels {

pkg/msp/identityconfig.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"io/ioutil"
2020

2121
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
22-
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
2322
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/msp"
2423
"github.com/hyperledger/fabric-sdk-go/pkg/core/config/endpoint"
2524
"github.com/hyperledger/fabric-sdk-go/pkg/core/config/lookup"
@@ -57,7 +56,7 @@ type IdentityConfig struct {
5756

5857
//entityMatchers for identity configuration
5958
type entityMatchers struct {
60-
matchers map[string][]fab.MatchConfig
59+
matchers map[string][]MatchConfig
6160
}
6261

6362
//identityConfigEntity contains all config definitions needed
@@ -90,6 +89,19 @@ type CAConfig struct {
9089
CAName string
9190
}
9291

92+
// MatchConfig contains match pattern and substitution pattern
93+
// for pattern matching of network configured hostnames or channel names with static config
94+
type MatchConfig struct {
95+
Pattern string
96+
97+
// these are used for hostname mapping
98+
URLSubstitutionExp string
99+
MappedHost string
100+
101+
// this is used for Name mapping instead of hostname mappings
102+
MappedName string
103+
}
104+
93105
// Client returns the Client config
94106
func (c *IdentityConfig) Client() *msp.ClientConfig {
95107
return c.client

test/integration/e2e/configless/endpointconfig_override_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,6 @@ var (
232232
}
233233

234234
networkConfig = fab.NetworkConfig{
235-
Name: "config-overridden network",
236-
Description: "This config structure is an example of overriding the sdk config by injecting interfaces instead of using a config file",
237235
Channels: channelsConfig,
238236
Organizations: orgsConfig,
239237
Orderers: newOrderersConfig(),

0 commit comments

Comments
 (0)