Beispiel #1
0
async def destroy(
        api_token_id: int,
        api_token_repo: ApiTokenRepo = Depends(ApiTokenRepo()),
        token: TokenPayload = Depends(ScopedTo("api-token:destroy")),
):
    messages = [{"text": "Deactivation Succesful", "type": "success"}]
    if not api_token_repo.exists(api_token_id):
        return BaseResponse(messages=messages)
    api_token_repo.deactivate(api_token_id)
    return BaseResponse(messages=messages)
Beispiel #2
0
async def sensitive(
        api_token_id: int,
        api_token_repo: ApiTokenRepo = Depends(ApiTokenRepo()),
        token: TokenPayload = Depends(ScopedTo("api-token:read")),
        includes: List[str] = Query(None),
):
    # TODO: require stronger scope
    if not api_token_repo.exists(api_token_id):
        raise HTTPException(404, detail="Not found")
    api_token = (api_token_repo.loads("dns_server").set_data_model(
        SensitiveApiTokenData).includes(includes).data())
    return SensitiveApiTokenResponse(api_token=api_token)