diff --git a/aries_cloudagent/admin/server.py b/aries_cloudagent/admin/server.py index 6d84de327d..c7ab79334d 100644 --- a/aries_cloudagent/admin/server.py +++ b/aries_cloudagent/admin/server.py @@ -370,6 +370,7 @@ async def check_multitenant_authorization(request: web.Request, handler): and not is_server_path and not is_unprotected_path(path) and not base_limited_access_path + and not (request.method == "OPTIONS") # CORS fix ): raise web.HTTPUnauthorized() diff --git a/aries_cloudagent/config/argparse.py b/aries_cloudagent/config/argparse.py index 6822f72c2f..d19bff39c6 100644 --- a/aries_cloudagent/config/argparse.py +++ b/aries_cloudagent/config/argparse.py @@ -74,7 +74,8 @@ def create_argument_parser(*, prog: str = None): def load_argument_groups(parser: ArgumentParser, *groups: Type[ArgumentGroup]): - """Log a set of argument groups into a parser. + """ + Log a set of argument groups into a parser. Returns: A callable to convert loaded arguments into a settings dictionary @@ -872,32 +873,56 @@ def get_settings(self, args: Namespace) -> dict: if args.no_ledger: settings["ledger.disabled"] = True else: - configured = False + single_configured = False + multi_configured = False + update_pool_name = False if args.genesis_url: settings["ledger.genesis_url"] = args.genesis_url - configured = True + single_configured = True elif args.genesis_file: settings["ledger.genesis_file"] = args.genesis_file - configured = True + single_configured = True elif args.genesis_transactions: settings["ledger.genesis_transactions"] = args.genesis_transactions - configured = True + single_configured = True if args.genesis_transactions_list: with open(args.genesis_transactions_list, "r") as stream: txn_config_list = yaml.safe_load(stream) ledger_config_list = [] for txn_config in txn_config_list: ledger_config_list.append(txn_config) + if "is_write" in txn_config and txn_config["is_write"]: + if "genesis_url" in txn_config: + settings["ledger.genesis_url"] = txn_config[ + "genesis_url" + ] + elif "genesis_file" in txn_config: + settings["ledger.genesis_file"] = txn_config[ + "genesis_file" + ] + elif "genesis_transactions" in txn_config: + settings["ledger.genesis_transactions"] = txn_config[ + "genesis_transactions" + ] + else: + raise ArgsParseError( + "No genesis information provided for write ledger" + ) + if "id" in txn_config: + settings["ledger.pool_name"] = txn_config["id"] + update_pool_name = True settings["ledger.ledger_config_list"] = ledger_config_list - configured = True - if not configured: + multi_configured = True + if not (single_configured or multi_configured): raise ArgsParseError( "One of --genesis-url --genesis-file, --genesis-transactions " "or --genesis-transactions-list must be specified (unless " "--no-ledger is specified to explicitly configure aca-py to" " run with no ledger)." ) - if args.ledger_pool_name: + if single_configured and multi_configured: + raise ArgsParseError("Cannot configure both single- and multi-ledger.") + if args.ledger_pool_name and not update_pool_name: settings["ledger.pool_name"] = args.ledger_pool_name if args.ledger_keepalive: settings["ledger.keepalive"] = args.ledger_keepalive diff --git a/aries_cloudagent/core/conductor.py b/aries_cloudagent/core/conductor.py index c24862a4e9..9dfe8f8ab2 100644 --- a/aries_cloudagent/core/conductor.py +++ b/aries_cloudagent/core/conductor.py @@ -28,7 +28,7 @@ from ..config.wallet import wallet_config from ..core.profile import Profile from ..indy.verifier import IndyVerifier -from ..ledger.base import BaseLedger + from ..ledger.error import LedgerConfigError, LedgerTransactionError from ..ledger.multiple_ledger.base_manager import ( BaseMultipleLedgerManager, @@ -144,7 +144,6 @@ async def setup(self): self.root_profile.BACKEND_NAME == "askar" and ledger.BACKEND_NAME == "indy-vdr" ): - context.injector.bind_instance(BaseLedger, ledger) context.injector.bind_provider( IndyVerifier, ClassProvider( @@ -156,7 +155,6 @@ async def setup(self): self.root_profile.BACKEND_NAME == "indy" and ledger.BACKEND_NAME == "indy" ): - context.injector.bind_instance(BaseLedger, ledger) context.injector.bind_provider( IndyVerifier, ClassProvider( diff --git a/demo/features/0586-sign-transaction.feature b/demo/features/0586-sign-transaction.feature index 1a66ef69ab..261800926d 100644 --- a/demo/features/0586-sign-transaction.feature +++ b/demo/features/0586-sign-transaction.feature @@ -25,6 +25,7 @@ Feature: RFC 0586 Aries sign (endorse) transactions functions | --mediation | --mediation | driverslicense | | --multitenant | --multitenant | driverslicense | | --mediation --multitenant | --mediation --multitenant | driverslicense | + | --multitenant --multi-ledger | --multitenant --multi-ledger | driverslicense | @T001.1-RFC0586 @GHA diff --git a/demo/features/taa-txn-author-acceptance.feature b/demo/features/taa-txn-author-acceptance.feature index 55d5790227..ac8274c1ec 100644 --- a/demo/features/taa-txn-author-acceptance.feature +++ b/demo/features/taa-txn-author-acceptance.feature @@ -17,6 +17,8 @@ Feature: TAA Transaction Author Agreement related tests | --taa-accept | driverslicense | | --taa-accept --multitenant | driverslicense | | --taa-accept --revocation | driverslicense | + | --taa-accept --multi-ledger | driverslicense | + | --taa-accept --multitenant --multi-ledger | driverslicense | @T001a-TAA @taa_required Scenario Outline: accept the ledger TAA and write to the ledger via endorser diff --git a/demo/multi_ledger_config.yml b/demo/multi_ledger_config.yml index 3290f50d5e..2c423b8d51 100644 --- a/demo/multi_ledger_config.yml +++ b/demo/multi_ledger_config.yml @@ -1,5 +1,9 @@ +#- id: local +# is_production: true +# genesis_url: 'http://$LEDGER_HOST:9000/genesis' - id: bcorvinTest is_production: true + is_write: true genesis_url: 'http://test.bcovrin.vonx.io/genesis' - id: greenlightTest is_production: true diff --git a/demo/multi_ledger_config_bdd.yml b/demo/multi_ledger_config_bdd.yml new file mode 100644 index 0000000000..14f7919fe1 --- /dev/null +++ b/demo/multi_ledger_config_bdd.yml @@ -0,0 +1,11 @@ +- id: local + is_production: true + is_write: true + genesis_url: 'http://$LEDGER_HOST:9000/genesis' +- id: bcorvinTest + is_production: true +# is_write: true + genesis_url: 'http://test.bcovrin.vonx.io/genesis' +- id: greenlightTest + is_production: true + genesis_url: 'http://dev.greenlight.bcovrin.vonx.io/genesis' diff --git a/demo/runners/agent_container.py b/demo/runners/agent_container.py index a7ee7745ab..87b9ac203c 100644 --- a/demo/runners/agent_container.py +++ b/demo/runners/agent_container.py @@ -1274,9 +1274,11 @@ async def create_agent_with_args(args, ident: str = None): ) multi_ledger_config_path = None + genesis = None if "multi_ledger" in args and args.multi_ledger: multi_ledger_config_path = "./demo/multi_ledger_config.yml" - genesis = await default_genesis_txns() + else: + genesis = await default_genesis_txns() if not genesis and not multi_ledger_config_path: print("Error retrieving ledger genesis transactions") sys.exit(1) diff --git a/demo/runners/support/agent.py b/demo/runners/support/agent.py index 8398df1279..1ec42565dc 100644 --- a/demo/runners/support/agent.py +++ b/demo/runners/support/agent.py @@ -213,6 +213,7 @@ def __init__( self.agency_wallet_did = self.did self.agency_wallet_key = self.wallet_key + self.multi_write_ledger_url = None if self.genesis_txn_list: updated_config_list = [] with open(self.genesis_txn_list, "r") as stream: @@ -225,6 +226,10 @@ def __init__( "$LEDGER_HOST", str(self.external_host) ) updated_config_list.append(config) + if "is_write" in config and config["is_write"]: + self.multi_write_ledger_url = config["genesis_url"].replace( + "/genesis", "" + ) with open(self.genesis_txn_list, "w") as file: documents = yaml.dump(updated_config_list, file) @@ -479,7 +484,10 @@ async def register_did( # if registering a did for issuing indy credentials, publish the did on the ledger self.log(f"Registering {self.ident} ...") if not ledger_url: - ledger_url = LEDGER_URL + if self.multi_write_ledger_url: + ledger_url = self.multi_write_ledger_url + else: + ledger_url = LEDGER_URL if not ledger_url: ledger_url = f"http://{self.external_host}:9000" data = {"alias": alias or self.ident} @@ -501,6 +509,7 @@ async def register_did( await asyncio.sleep(3.0) nym_info = data else: + log_msg("using ledger: " + ledger_url + "/register") resp = await self.client_session.post( ledger_url + "/register", json=data ) diff --git a/docker/Dockerfile.bdd b/docker/Dockerfile.bdd index cacf38b6aa..d2e6c2098a 100644 --- a/docker/Dockerfile.bdd +++ b/docker/Dockerfile.bdd @@ -4,5 +4,6 @@ FROM faber-alice-demo RUN pip3 install --no-cache-dir -r demo/requirements.behave.txt WORKDIR ./demo +ADD demo/multi_ledger_config_bdd.yml ./demo/multi_ledger_config.yml RUN chmod a+w . ENTRYPOINT ["behave"]