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
Expand Up @@ -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()

Expand Down
32 changes: 26 additions & 6 deletions aries_cloudagent/config/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -872,31 +872,51 @@ 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
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
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 single_configured and multi_configured:
raise ArgsParseError("Cannot configure both single- and multi-ledger.")
if args.ledger_pool_name:
shaangill025 marked this conversation as resolved.
Show resolved Hide resolved
settings["ledger.pool_name"] = args.ledger_pool_name
if args.ledger_keepalive:
Expand Down
7 changes: 4 additions & 3 deletions aries_cloudagent/core/conductor.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
from ..config.wallet import wallet_config
from ..core.profile import Profile
from ..indy.verifier import IndyVerifier
from ..ledger.base import BaseLedger

# from ..ledger.base import BaseLedger
from ..ledger.error import LedgerConfigError, LedgerTransactionError
from ..ledger.multiple_ledger.base_manager import (
BaseMultipleLedgerManager,
Expand Down Expand Up @@ -144,7 +145,7 @@ 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_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(
Expand All @@ -156,7 +157,7 @@ async def setup(self):
self.root_profile.BACKEND_NAME == "indy"
and ledger.BACKEND_NAME == "indy"
):
context.injector.bind_instance(BaseLedger, ledger)
# context.injector.bind_instance(BaseLedger, ledger)
context.injector.bind_provider(
IndyVerifier,
ClassProvider(
Expand Down
1 change: 1 addition & 0 deletions demo/features/0586-sign-transaction.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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
Expand Down
4 changes: 3 additions & 1 deletion demo/runners/agent_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 10 additions & 1 deletion demo/runners/support/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)

Expand Down Expand Up @@ -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}
Expand All @@ -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
)
Expand Down
1 change: 1 addition & 0 deletions docker/Dockerfile.bdd
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ FROM faber-alice-demo
RUN pip3 install --no-cache-dir -r demo/requirements.behave.txt

WORKDIR ./demo
ADD demo ./demo
RUN chmod a+w .
ENTRYPOINT ["behave"]