Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
 def test_cm_read(self, mock_api, mock_pretty_print):
     mock_api.read_namespaced_config_map.side_effect = [
         ConfigMap({"a_key": "a_value"})
     ]
     cm_read("a_configmap", "a-namespace")
     mock_api.read_namespaced_config_map.assert_called_once_with(
         name="a_configmap", namespace="a-namespace")
     mock_pretty_print.assert_called_once_with('{"a_key": "a_value"}')
Ejemplo n.º 4
0
 def test_cm_read_verbose(self, mock_api, mock_pretty_print):
     mock_api.read_namespaced_config_map.side_effect = [
         ConfigMap({'a_key': 'a_value'})
     ]
     cm_read('a_configmap', 'a-namespace', verbose=True)
     mock_api.read_namespaced_config_map.assert_called_once_with(
         name='a_configmap', namespace='a-namespace')
     mock_pretty_print.assert_called_once_with('{"a_key": "a_value"}')
Ejemplo n.º 5
0
 def test_cm_read(self, mock_api, mock_pretty_print):
     cm_read("a_configmap", "a-namespace")
     mock_api.read_namespaced_config_map.assert_called_once_with(
         name="a_configmap", namespace="a-namespace"
     )
     mock_pretty_print.assert_not_called()
Ejemplo n.º 6
0
 def test_cm_read(self, mock_api, mock_pretty_print):
     cm_read('a_configmap', 'a-namespace')
     mock_api.read_namespaced_config_map.assert_called_once_with(
         name='a_configmap', namespace='a-namespace')
     mock_pretty_print.assert_not_called()