Exemple #1
0
    await asyncio.sleep(0.1)

    if not terminated:
        os._exit(1)


if __name__ == "__main__":
    import argparse

    parser = argparse.ArgumentParser(description="Runs an Acme demo agent.")
    parser.add_argument(
        "-p",
        "--port",
        type=int,
        default=8040,
        metavar=("<port>"),
        help="Choose the starting port number to listen on",
    )
    parser.add_argument("--timing",
                        action="store_true",
                        help="Enable timing information")
    args = parser.parse_args()

    check_requires(args)

    try:
        asyncio.get_event_loop().run_until_complete(
            main(args.port, args.timing))
    except KeyboardInterrupt:
        os._exit(1)
async def create_agent_with_args(args, ident: str = None):
    if ("did_exchange" in args and args.did_exchange) and args.mediation:
        raise Exception(
            "DID-Exchange connection protocol is not (yet) compatible with mediation"
        )

    check_requires(args)

    if "revocation" in args and args.revocation:
        tails_server_base_url = args.tails_server_base_url or os.getenv(
            "PUBLIC_TAILS_URL"
        )
    else:
        tails_server_base_url = None

    arg_file = args.arg_file or os.getenv("ACAPY_ARG_FILE")
    arg_file_dict = {}
    if arg_file:
        with open(arg_file) as f:
            arg_file_dict = yaml.safe_load(f)

    # if we don't have a tails server url then guess it
    if ("revocation" in args and args.revocation) and not tails_server_base_url:
        # assume we're running in docker
        tails_server_base_url = (
            "http://" + (os.getenv("DOCKERHOST") or "host.docker.internal") + ":6543"
        )

    if ("revocation" in args and args.revocation) and not tails_server_base_url:
        raise Exception(
            "If revocation is enabled, --tails-server-base-url must be provided"
        )

    genesis = await default_genesis_txns()
    if not genesis:
        print("Error retrieving ledger genesis transactions")
        sys.exit(1)

    agent_ident = ident if ident else (args.ident if "ident" in args else "Aries")

    if "aip" in args:
        aip = int(args.aip)
        if aip not in [
            10,
            20,
        ]:
            raise Exception("Invalid value for aip, should be 10 or 20")
    else:
        aip = 20

    if "cred_type" in args and args.cred_type != CRED_FORMAT_INDY:
        public_did = None
        aip = 20
    elif "cred_type" in args and args.cred_type == CRED_FORMAT_INDY:
        public_did = True
    else:
        public_did = args.public_did if "public_did" in args else None

    cred_type = args.cred_type if "cred_type" in args else None
    log_msg(
        f"Initializing demo agent {agent_ident} with AIP {aip} and credential type {cred_type}"
    )

    agent = AgentContainer(
        genesis,
        agent_ident + ".agent",
        args.port,
        no_auto=args.no_auto,
        revocation=args.revocation if "revocation" in args else False,
        tails_server_base_url=tails_server_base_url,
        show_timing=args.timing,
        multitenant=args.multitenant,
        mediation=args.mediation,
        cred_type=cred_type,
        use_did_exchange=args.did_exchange if ("did_exchange" in args) else (aip == 20),
        wallet_type=arg_file_dict.get("wallet-type") or args.wallet_type,
        public_did=public_did,
        seed="random" if public_did else None,
        arg_file=arg_file,
        aip=aip,
        endorser_role=args.endorser_role,
    )

    return agent