Exemple #1
0
def make_certificate(ledger_id: str, crypto_private_key_path: str,
                     message: bytes, output_path: str) -> str:
    """Create certificate."""
    crypto = crypto_registry.make(ledger_id,
                                  private_key_path=crypto_private_key_path)
    signature = crypto.sign_message(message).encode("ascii").hex()
    ensure_dir(os.path.dirname(output_path))
    Path(output_path).write_bytes(signature.encode("ascii"))
    return signature
Exemple #2
0
def build_node(build_dir: str) -> None:
    """Build node placed inside build_dir."""
    with tempfile.TemporaryDirectory() as dirname:
        copy_tree(LIBP2P_NODE_MODULE, dirname)
        err_str = _golang_module_build(dirname)
        if err_str:  # pragma: nocover
            raise Exception(f"Node build failed: {err_str}")
        ensure_dir(build_dir)
        shutil.copy(
            os.path.join(dirname, LIBP2P_NODE_MODULE_NAME),
            os.path.join(build_dir, LIBP2P_NODE_MODULE_NAME),
        )
    print(f"{LIBP2P_NODE_MODULE_NAME} built successfully!")
Exemple #3
0
def test_ensure_dir():
    """Test ensure_dir."""
    dir_name = "test"
    with TemporaryDirectory() as tmpdirname:
        full_path = os.path.join(tmpdirname, dir_name)
        assert not os.path.exists(full_path)
        ensure_dir(full_path)
        assert os.path.exists(full_path)
        file_path = os.path.join(full_path, "file_name")
        with open(file_path, "w"):
            pass

        with pytest.raises(AEAEnforceError):
            ensure_dir(file_path)