Skip to content

Commit

Permalink
Update docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
cl0ete committed Oct 25, 2024
1 parent 87557d6 commit 081d15f
Showing 1 changed file with 103 additions and 12 deletions.
115 changes: 103 additions & 12 deletions app/routes/wallet/dids.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,30 @@
router = APIRouter(prefix="/v1/wallet/dids", tags=["wallet"])


@router.post("", response_model=DID)
@router.post("", response_model=DID, summary="Create Local DID")
async def create_did(
did_create: Optional[DIDCreate] = None,
auth: AcaPyAuth = Depends(acapy_auth_from_header),
):
"""Create Local DID."""
"""
Create Local DID.
---
This endpoint allows you to create a new DID in the wallet.
The `method` parameter is optional and can be set to 'key' or 'sov'.
Request body:
---
DIDCreate:
method: Optional[str]
options: Optional[DIDCreateOptions]
seed: Optional[str]
Response:
---
Returns the created DID.
"""
logger.debug("POST request received: Create DID")

async with client_from_auth(auth) as aries_controller:
Expand All @@ -37,12 +55,19 @@ async def create_did(
return result


@router.get("", response_model=List[DID])
@router.get("", response_model=List[DID], summary="List DIDs")
async def list_dids(
auth: AcaPyAuth = Depends(acapy_auth_from_header),
) -> List[DID]:
"""
Retrieve list of DIDs.
---
This endpoint allows you to retrieve a list of DIDs in the wallet.
Response:
---
Returns a list of DIDs.
"""
logger.debug("GET request received: Retrieve list of DIDs")

Expand All @@ -60,12 +85,20 @@ async def list_dids(
return did_result.results


@router.get("/public", response_model=DID)
@router.get("/public", response_model=DID, summary="Fetch Public DID")
async def get_public_did(
auth: AcaPyAuth = Depends(acapy_auth_from_header),
) -> DID:
"""
Fetch the current public DID.
---
This endpoint allows you to fetch the current public DID.
Response:
---
Returns the public DID.
"""
logger.debug("GET request received: Fetch public DID")

Expand All @@ -82,12 +115,27 @@ async def get_public_did(
return result.result


@router.put("/public", response_model=DID)
@router.put("/public", response_model=DID, summary="Set Public DID")
async def set_public_did(
did: str,
auth: AcaPyAuth = Depends(acapy_auth_from_header),
) -> DID:
"""Set the current public DID."""
"""
Set the current public DID.
---
This endpoint allows you to set the current public DID.
The tenant needs a connection with the endorser to make a did public.
Request body:
---
did: str
Response:
---
Returns the public DID.
"""
logger.debug("PUT request received: Set public DID")

async with client_from_auth(auth) as aries_controller:
Expand All @@ -98,28 +146,57 @@ async def set_public_did(
return result


@router.patch("/{did}/rotate-keypair", status_code=204)
@router.patch("/{did}/rotate-keypair", status_code=204, summary="Rotate Key Pair")
async def rotate_keypair(
did: str,
auth: AcaPyAuth = Depends(acapy_auth_from_header),
) -> None:
"""
Rotate key pair for DID.
---
This endpoint allows you to rotate the key pair for a DID.
Parameters:
---
did: str
Response:
---
204 No Content
"""
bound_logger = logger.bind(body={"did": did})
bound_logger.debug("PATCH request received: Rotate keypair for DID")
async with client_from_auth(auth) as aries_controller:
bound_logger.debug("Rotating keypair")
bound_logger.debug("Rotating key pair")
await handle_acapy_call(
logger=logger, acapy_call=aries_controller.wallet.rotate_keypair, did=did
)

bound_logger.debug("Successfully rotated keypair.")


@router.get("/{did}/endpoint", response_model=DIDEndpoint)
@router.get("/{did}/endpoint", response_model=DIDEndpoint, summary="Get DID Endpoint")
async def get_did_endpoint(
did: str,
auth: AcaPyAuth = Depends(acapy_auth_from_header),
) -> DIDEndpoint:
"""Get DID endpoint."""
"""
Get DID endpoint.
---
This endpoint allows you to fetch the endpoint for a DID.
Parameters:
---
did: str
Response:
---
Returns the endpoint for the DID.
"""
bound_logger = logger.bind(body={"did": did})
bound_logger.debug("GET request received: Get endpoint for DID")
async with client_from_auth(auth) as aries_controller:
Expand All @@ -132,13 +209,27 @@ async def get_did_endpoint(
return result


@router.post("/{did}/endpoint", status_code=204)
@router.post("/{did}/endpoint", status_code=204, summary="Set DID Endpoint")
async def set_did_endpoint(
did: str,
body: SetDidEndpointRequest,
auth: AcaPyAuth = Depends(acapy_auth_from_header),
) -> None:
"""Update Endpoint in wallet and on ledger if posted to it."""
"""
Update Endpoint in wallet and on ledger if posted to it.
---
This endpoint allows you to update the endpoint for a DID.
Parameters:
---
did: str
Request body:
---
SetDidEndpointRequest:
endpoint: str
"""

# "Endpoint" type is for making connections using public indy DIDs
bound_logger = logger.bind(body={"did": did, "body": body})
Expand Down

0 comments on commit 081d15f

Please sign in to comment.