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

feat: add multitenancy example #97

Merged
merged 1 commit into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
repos:
- repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
rev: v2.2.0
rev: v9.16.0
hooks:
- id: commitlint
stages: [commit-msg]
Expand Down
62 changes: 62 additions & 0 deletions examples/multitenancy/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
version: "3"
services:
agency:
image: ghcr.io/hyperledger/aries-cloudagent-python:py3.9-0.11.0
ports:
- "3001:3001"
command: >
start
--label Agency
--inbound-transport http 0.0.0.0 3000
--outbound-transport http
--endpoint http://agency:3000
--admin 0.0.0.0 3001
--admin-insecure-mode
--tails-server-base-url http://tails:6543
--genesis-url https://raw.githubusercontent.com/Indicio-tech/indicio-network/main/genesis_files/pool_transactions_testnet_genesis
--wallet-type askar
--wallet-name agency
--wallet-key insecure
--auto-provision
--multitenant
--multitenant-admin
--jwt-secret insecure
--multitenancy-config wallet_type=askar-profile key_derivation_method=RAW
--log-level debug
--debug-webhooks
healthcheck:
test: curl -s -o /dev/null -w '%{http_code}' "http://localhost:3001/status/live" | grep "200" > /dev/null
start_period: 30s
interval: 7s
timeout: 5s
retries: 5
depends_on:
tails:
condition: service_started

example:
container_name: controller
build:
context: ../..
environment:
- AGENCY=http://agency:3001
volumes:
- ./example.py:/usr/src/app/example.py:ro,z
command: python -m example
depends_on:
agency:
condition: service_healthy

tails:
image: ghcr.io/bcgov/tails-server:latest
ports:
- 6543:6543
environment:
- GENESIS_URL=https://raw.githubusercontent.com/Indicio-tech/indicio-network/main/genesis_files/pool_transactions_testnet_genesis
command: >
tails-server
--host 0.0.0.0
--port 6543
--storage-path /tmp/tails-files
--log-level INFO

81 changes: 81 additions & 0 deletions examples/multitenancy/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
"""Minimal reproducible example script.

This script is for you to use to reproduce a bug or demonstrate a feature.
"""

import asyncio
from os import getenv

from acapy_controller import Controller
from acapy_controller.logging import logging_to_stdout
from acapy_controller.models import CreateWalletResponse
from acapy_controller.protocols import (
didexchange,
indy_anoncred_credential_artifacts,
indy_anoncred_onboard,
indy_issue_credential_v2,
indy_present_proof_v2,
)

AGENCY = getenv("AGENCY", "http://agency:3001")


async def main():
"""Test Controller protocols."""
async with Controller(base_url=AGENCY) as agency:
alice = await agency.post(
"/multitenancy/wallet",
json={
"label": "Alice",
"wallet_type": "askar",
},
response=CreateWalletResponse,
)
bob = await agency.post(
"/multitenancy/wallet",
json={
"label": "Bob",
"wallet_type": "askar",
},
response=CreateWalletResponse,
)

async with Controller(
base_url=AGENCY, wallet_id=alice.wallet_id, subwallet_token=alice.token
) as alice, Controller(
base_url=AGENCY, wallet_id=bob.wallet_id, subwallet_token=bob.token
) as bob:
# Issuance prep
await indy_anoncred_onboard(alice)
_, cred_def = await indy_anoncred_credential_artifacts(
alice,
["firstname", "lastname"],
support_revocation=True,
)

# Connecting
alice_conn, bob_conn = await didexchange(alice, bob)

# Issue a credential
await indy_issue_credential_v2(
alice,
bob,
alice_conn.connection_id,
bob_conn.connection_id,
cred_def.credential_definition_id,
{"firstname": "Bob", "lastname": "Builder"},
)

# Present the the credential's attributes
await indy_present_proof_v2(
bob,
alice,
bob_conn.connection_id,
alice_conn.connection_id,
requested_attributes=[{"name": "firstname"}],
)


if __name__ == "__main__":
logging_to_stdout()
asyncio.run(main())