Skip to content

Commit

Permalink
[FAB-10568] endpoint config refactoring
Browse files Browse the repository at this point in the history
-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>
  • Loading branch information
sudeshrshetty authored and emirsh committed Jun 11, 2018
1 parent 83bfc05 commit 68e4066
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 115 deletions.
18 changes: 0 additions & 18 deletions pkg/common/providers/fab/network.go
Expand Up @@ -14,9 +14,6 @@ import (

// NetworkConfig provides a static definition of endpoint configuration network
type NetworkConfig struct {
Name string
Description string
Version string
Channels map[string]ChannelEndpointConfig
Organizations map[string]OrganizationConfig
Orderers map[string]OrdererConfig
Expand Down Expand Up @@ -91,21 +88,6 @@ type PeerConfig struct {
TLSCACert *x509.Certificate
}

// MatchConfig contains match pattern and substitution pattern
// for pattern matching of network configured hostnames or channel names with static config
type MatchConfig struct {
Pattern string

// these are used for hostname mapping
URLSubstitutionExp string
EventURLSubstitutionExp string
SSLTargetOverrideURLSubstitutionExp string
MappedHost string

// this is used for Name mapping instead of hostname mappings
MappedName string
}

// CertKeyPair contains the private key and certificate
type CertKeyPair struct {
Cert []byte
Expand Down
5 changes: 0 additions & 5 deletions pkg/core/config/endpoint/endpoint.go
Expand Up @@ -65,15 +65,12 @@ type MutualTLSConfig struct {
}

// TLSKeyPair contains the private key and certificate for TLS encryption
//TODO to be removed from here, instead 'TLSKeyCertPair' should be used
//deprecated
type TLSKeyPair struct {
Key TLSConfig
Cert TLSConfig
}

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

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

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

block, _ := pem.Decode(cfg.bytes)
Expand Down
17 changes: 16 additions & 1 deletion pkg/core/config/lookup/lookup_test.go
Expand Up @@ -33,7 +33,7 @@ const orgChannelID = "orgchannel"
var backend *mocks.MockConfigBackend

type testEntityMatchers struct {
matchers map[string][]fab.MatchConfig
matchers map[string][]MatchConfig
}

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

// MatchConfig contains match pattern and substitution pattern
// for pattern matching of network configured hostnames or channel names with static config
type MatchConfig struct {
Pattern string

// these are used for hostname mapping
URLSubstitutionExp string
EventURLSubstitutionExp string
SSLTargetOverrideURLSubstitutionExp string
MappedHost string

// this is used for Name mapping instead of hostname mappings
MappedName string
}

func TestMain(m *testing.M) {
backend = setupCustomBackend("key")
r := m.Run()
Expand Down
109 changes: 109 additions & 0 deletions pkg/fab/api.go
@@ -0,0 +1,109 @@
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package fab

import (
"github.com/hyperledger/fabric-sdk-go/pkg/common/errors/retry"
"github.com/hyperledger/fabric-sdk-go/pkg/core/config/endpoint"
)

//endpointConfigEntity contains endpoint config elements needed by endpointconfig
type endpointConfigEntity struct {
Client ClientConfig
Channels map[string]ChannelEndpointConfig
Organizations map[string]OrganizationConfig
Orderers map[string]OrdererConfig
Peers map[string]PeerConfig
}

//entityMatchers for endpoint configuration
type entityMatchers struct {
matchers map[string][]MatchConfig
}

// ClientConfig provides the definition of the client configuration
type ClientConfig struct {
Organization string
TLSCerts ClientTLSConfig
}

// ClientTLSConfig contains the client TLS configuration
type ClientTLSConfig struct {
//Client TLS information
Client endpoint.TLSKeyPair
}

// OrdererConfig defines an orderer configuration
type OrdererConfig struct {
URL string
GRPCOptions map[string]interface{}
TLSCACerts endpoint.TLSConfig
}

// PeerConfig defines a peer configuration
type PeerConfig struct {
URL string
EventURL string
GRPCOptions map[string]interface{}
TLSCACerts endpoint.TLSConfig
}

// OrganizationConfig provides the definition of an organization in the network
type OrganizationConfig struct {
MSPID string
CryptoPath string
Users map[string]endpoint.TLSKeyPair
Peers []string
CertificateAuthorities []string
}

// ChannelEndpointConfig provides the definition of channels for the network
type ChannelEndpointConfig struct {
// Orderers list of ordering service nodes
Orderers []string
// Peers a list of peer-channels that are part of this organization
// to get the real Peer config object, use the Name field and fetch NetworkConfig.Peers[Name]
Peers map[string]PeerChannelConfig
//Policies list of policies for channel
Policies ChannelPolicies
}

//ChannelPolicies defines list of policies defined for a channel
type ChannelPolicies struct {
//Policy for querying channel block
QueryChannelConfig QueryChannelConfigPolicy
}

//QueryChannelConfigPolicy defines opts for channelConfigBlock
type QueryChannelConfigPolicy struct {
MinResponses int
MaxTargets int
RetryOpts retry.Opts
}

// PeerChannelConfig defines the peer capabilities
type PeerChannelConfig struct {
EndorsingPeer bool
ChaincodeQuery bool
LedgerQuery bool
EventSource bool
}

// MatchConfig contains match pattern and substitution pattern
// for pattern matching of network configured hostnames or channel names with static config
type MatchConfig struct {
Pattern string

// these are used for hostname mapping
URLSubstitutionExp string
EventURLSubstitutionExp string
SSLTargetOverrideURLSubstitutionExp string
MappedHost string

// this is used for Name mapping instead of hostname mappings
MappedName string
}
88 changes: 1 addition & 87 deletions pkg/fab/endpointconfig.go
Expand Up @@ -17,7 +17,6 @@ import (
"time"

"github.com/hyperledger/fabric-sdk-go/pkg/common/errors/multi"
"github.com/hyperledger/fabric-sdk-go/pkg/common/errors/retry"
"github.com/hyperledger/fabric-sdk-go/pkg/common/logging"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
Expand Down Expand Up @@ -104,87 +103,6 @@ type EndpointConfig struct {
channelMatchers map[int]*regexp.Regexp
}

//entityMatchers for endpoint configuration
type entityMatchers struct {
matchers map[string][]fab.MatchConfig
}

//endpointConfigEntity contains endpoint config elements needed by endpointconfig
type endpointConfigEntity struct {
Client clientConfig
Channels map[string]ChannelEndpointConfig
Organizations map[string]OrganizationConfig
Orderers map[string]OrdererConfig
Peers map[string]PeerConfig
}

// ClientConfig provides the definition of the client configuration
type clientConfig struct {
Organization string
TLSCerts clientTLSConfig
}

type clientTLSConfig struct {
//Client TLS information
Client endpoint.TLSKeyPair
}

// OrdererConfig defines an orderer configuration
type OrdererConfig struct {
URL string
GRPCOptions map[string]interface{}
TLSCACerts endpoint.TLSConfig
}

// PeerConfig defines a peer configuration
type PeerConfig struct {
URL string
EventURL string
GRPCOptions map[string]interface{}
TLSCACerts endpoint.TLSConfig
}

// OrganizationConfig provides the definition of an organization in the network
type OrganizationConfig struct {
MSPID string
CryptoPath string
Users map[string]endpoint.TLSKeyPair
Peers []string
CertificateAuthorities []string
}

// ChannelEndpointConfig provides the definition of channels for the network
type ChannelEndpointConfig struct {
// Orderers list of ordering service nodes
Orderers []string
// Peers a list of peer-channels that are part of this organization
// to get the real Peer config object, use the Name field and fetch NetworkConfig.Peers[Name]
Peers map[string]PeerChannelConfig
//Policies list of policies for channel
Policies ChannelPolicies
}

//ChannelPolicies defines list of policies defined for a channel
type ChannelPolicies struct {
//Policy for querying channel block
QueryChannelConfig QueryChannelConfigPolicy
}

//QueryChannelConfigPolicy defines opts for channelConfigBlock
type QueryChannelConfigPolicy struct {
MinResponses int
MaxTargets int
RetryOpts retry.Opts
}

// PeerChannelConfig defines the peer capabilities
type PeerChannelConfig struct {
EndorsingPeer bool
ChaincodeQuery bool
LedgerQuery bool
EventSource bool
}

// Timeout reads timeouts for the given timeout type, if type is not found in the config
// then default is set as per the const value above for the corresponding type
func (c *EndpointConfig) Timeout(tType fab.TimeoutType) time.Duration {
Expand Down Expand Up @@ -380,7 +298,7 @@ func (c *EndpointConfig) TLSClientCerts() []tls.Certificate {
return c.tlsClientCerts
}

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

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

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

networkConfig := fab.NetworkConfig{}

networkConfig.Name = c.backend.GetString("name")
networkConfig.Description = c.backend.GetString("description")
networkConfig.Version = c.backend.GetString("version")

//Channels
networkConfig.Channels = make(map[string]fab.ChannelEndpointConfig)
for chID, chNwCfg := range configEntity.Channels {
Expand Down
16 changes: 14 additions & 2 deletions pkg/msp/identityconfig.go
Expand Up @@ -19,7 +19,6 @@ import (
"io/ioutil"

"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/msp"
"github.com/hyperledger/fabric-sdk-go/pkg/core/config/endpoint"
"github.com/hyperledger/fabric-sdk-go/pkg/core/config/lookup"
Expand Down Expand Up @@ -57,7 +56,7 @@ type IdentityConfig struct {

//entityMatchers for identity configuration
type entityMatchers struct {
matchers map[string][]fab.MatchConfig
matchers map[string][]MatchConfig
}

//identityConfigEntity contains all config definitions needed
Expand Down Expand Up @@ -90,6 +89,19 @@ type CAConfig struct {
CAName string
}

// MatchConfig contains match pattern and substitution pattern
// for pattern matching of network configured hostnames or channel names with static config
type MatchConfig struct {
Pattern string

// these are used for hostname mapping
URLSubstitutionExp string
MappedHost string

// this is used for Name mapping instead of hostname mappings
MappedName string
}

// Client returns the Client config
func (c *IdentityConfig) Client() *msp.ClientConfig {
return c.client
Expand Down
Expand Up @@ -232,8 +232,6 @@ var (
}

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

0 comments on commit 68e4066

Please sign in to comment.