Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-ledger/Multi-tenant issues #2022

Merged
merged 12 commits into from
Nov 24, 2022
1 change: 1 addition & 0 deletions aries_cloudagent/admin/server.py
Original file line number Diff line number Diff line change
@@ -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()

41 changes: 33 additions & 8 deletions aries_cloudagent/config/argparse.py
Original file line number Diff line number Diff line change
@@ -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
shaangill025 marked this conversation as resolved.
Show resolved Hide resolved
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"]:
shaangill025 marked this conversation as resolved.
Show resolved Hide resolved
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"
)
shaangill025 marked this conversation as resolved.
Show resolved Hide resolved
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
4 changes: 1 addition & 3 deletions aries_cloudagent/core/conductor.py
Original file line number Diff line number Diff line change
@@ -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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me, it is working even with context.injector.bind_instance(BaseLedger, ledger) included.

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(
1 change: 1 addition & 0 deletions demo/features/0586-sign-transaction.feature
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions demo/features/taa-txn-author-acceptance.feature
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions demo/multi_ledger_config.yml
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions demo/multi_ledger_config_bdd.yml
Original file line number Diff line number Diff line change
@@ -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'
4 changes: 3 additions & 1 deletion demo/runners/agent_container.py
Original file line number Diff line number Diff line change
@@ -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)
11 changes: 10 additions & 1 deletion demo/runners/support/agent.py
Original file line number Diff line number Diff line change
@@ -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
)
1 change: 1 addition & 0 deletions docker/Dockerfile.bdd
Original file line number Diff line number Diff line change
@@ -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"]