def composer_connection(opts, verbose=False): peer_namespace = get_namespace(opts, opts['peers']['msp']) ord_namespace = get_namespace(opts, opts['orderers']['msp']) # TODO: This could be a single function peer_ca = opts['peers']['ca'] peer_ca_msp = opts['cas'][peer_ca]['msp'] ingress_urls = ingress_read(peer_ca + '-hlf-ca', namespace=peer_namespace, verbose=verbose) peer_ca_url = ingress_urls[0] try: cm_read(opts['composer']['secret_connection'], peer_namespace, verbose=verbose) except ApiException: # Set up connection.json # TODO: Improve json_ct to work directly with opts structure cm_data = { 'connection.json': json_ct(opts['peers']['names'], opts['orderers']['names'], [ peer + '-hlf-peer.{ns}.svc.cluster.local'.format(ns=peer_namespace) for peer in opts['peers']['names'] ], [ orderer + '-hlf-ord.{ns}.svc.cluster.local'.format(ns=ord_namespace) for orderer in opts['orderers']['names'] ], peer_ca, peer_ca_url, 'AidTech', None, peer_ca_msp, opts['peers']['channel_name']) } cm_create(peer_namespace, opts['composer']['secret_connection'], cm_data)
def test_json_ct(self, mock_define_orderers, mock_define_peers): mock_define_peers.side_effect = [({ 'peer0.an-org.a-domain.com': { 'chaincodeQuery': True, 'endorsingPeer': True, 'eventSource': True, 'ledgerQuery': True } }, { 'peer0.an-org.a-domain.com': { 'url': 'grpc://peer0.local-cluster:7051', 'eventUrl': 'grpc://peer0.local-cluster:7053' } })] mock_define_orderers.side_effect = [{ 'ord0.a-domain.com': { 'url': 'grpc://ord0.local-cluster:7050' } }] res = json_ct(['peer0'], ['ord0'], ['peer0.local-cluster'], ['ord0.local-cluster'], 'a-ca', 'a-ca.a-domain.com', 'an-org', 'a-domain.com', 'AnMSP', 'a-channel') mock_define_peers.assert_called_once_with(['peer0'], ['peer0.local-cluster'], 'an-org', 'a-domain.com') mock_define_orderers.assert_called_once_with(['ord0'], ['ord0.local-cluster'], 'a-domain.com') assert isinstance(res, str)
def composer_connection(opts, verbose=False): """Composer connection setup. This creates a ConfigMap on K8S with the Hyperledger Composer connection. Args: opts (dict): Nephos options dict. verbose (bool): Verbosity. False by default. """ peer_namespace = get_namespace(opts, opts["peers"]["msp"]) # TODO: This could be a single function peer_msp = opts["peers"]["msp"] peer_ca = opts["msps"][peer_msp]["ca"] ca_namespace = opts["cas"][peer_ca]["namespace"] ingress_urls = ingress_read(peer_ca + "-hlf-ca", namespace=ca_namespace) peer_ca_url = ingress_urls[0] try: cm_read(opts["composer"]["secret_connection"], peer_namespace) except ApiException: # Set up connection.json # TODO: Improve json_ct to work entirely with opts structure cm_data = { "connection.json": json_ct( opts, peer_ca, peer_ca_url, "AidTech", None, peer_msp, opts["peers"]["channel_name"], ) } cm_create(cm_data, opts["composer"]["secret_connection"], peer_namespace)
def test_json_ct(self, mock_define_orderers, mock_define_peers): mock_define_peers.side_effect = [( { "peer0.an-org.a-domain.com": { "chaincodeQuery": True, "endorsingPeer": True, "eventSource": True, "ledgerQuery": True, } }, { "peer0.an-org.a-domain.com": { "url": "grpc://peer0-hlf-peer.peer-namespace.svc.cluster.local:7051", "eventUrl": "grpc://peer0-hlf-peer.peer-namespace.svc.cluster.local:7053", } }, )] mock_define_orderers.side_effect = [{ "ord0.a-domain.com": { "url": "grpc://ord0-hlf-ord.orderer-namespace.svc.cluster.local:7050" } }] res = json_ct( self.OPTS, "a-ca", "a-ca.a-domain.com", "an-org", "a-domain.com", "AnMSP", "a-channel", ) mock_define_peers.assert_called_once_with( ["peer0"], ["peer0-hlf-peer.peer-namespace.svc.cluster.local"], "an-org", "a-domain.com", ) mock_define_orderers.assert_called_once_with( ["ord0"], ["ord0-hlf-ord.ord-namespace.svc.cluster.local"], "a-domain.com") assert isinstance(res, str)