diff --git a/pkg/common/providers/fab/network.go b/pkg/common/providers/fab/network.go index 26d37d36e3..06d4977f64 100644 --- a/pkg/common/providers/fab/network.go +++ b/pkg/common/providers/fab/network.go @@ -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 @@ -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 diff --git a/pkg/core/config/endpoint/endpoint.go b/pkg/core/config/endpoint/endpoint.go index b5599ab6cc..b79a780592 100644 --- a/pkg/core/config/endpoint/endpoint.go +++ b/pkg/core/config/endpoint/endpoint.go @@ -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 @@ -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 != "" { @@ -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) diff --git a/pkg/core/config/lookup/lookup_test.go b/pkg/core/config/lookup/lookup_test.go index d4823ad5b1..769c73b83e 100644 --- a/pkg/core/config/lookup/lookup_test.go +++ b/pkg/core/config/lookup/lookup_test.go @@ -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 @@ -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() diff --git a/pkg/fab/api.go b/pkg/fab/api.go new file mode 100644 index 0000000000..eb1cbac46f --- /dev/null +++ b/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 +} diff --git a/pkg/fab/endpointconfig.go b/pkg/fab/endpointconfig.go index f88a49097e..4ff15e7ca6 100644 --- a/pkg/fab/endpointconfig.go +++ b/pkg/fab/endpointconfig.go @@ -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" @@ -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 { @@ -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() @@ -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 { diff --git a/pkg/msp/identityconfig.go b/pkg/msp/identityconfig.go index 91119e2cef..e63ccb7ad2 100644 --- a/pkg/msp/identityconfig.go +++ b/pkg/msp/identityconfig.go @@ -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" @@ -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 @@ -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 diff --git a/test/integration/e2e/configless/endpointconfig_override_test.go b/test/integration/e2e/configless/endpointconfig_override_test.go index 6853e6ab79..a13b065c3c 100644 --- a/test/integration/e2e/configless/endpointconfig_override_test.go +++ b/test/integration/e2e/configless/endpointconfig_override_test.go @@ -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(),