Exemplo n.º 1
0
async def show(
        api_token_id: int,
        api_token_repo: ApiTokenRepo = Depends(ApiTokenRepo()),
        token: TokenPayload = Depends(ScopedTo("api-token:read")),
        includes: List[str] = Query(None),
):

    includes = only(includes, ["dns_server", "http_server"], values=True)

    if (not api_token_repo.loads(includes).strict().includes(includes).exists(
            api_token_id)):
        raise HTTPException(404, detail="Not found")
    api_token = api_token_repo.data()
    return ApiTokenResponse(api_token=api_token)
Exemplo n.º 2
0
def create_or_get_api_token_for_all_nodes(
    token: TokenPayload,
    api_token_repo: ApiTokenRepo,
    dns_server: DnsServer,
    http_server: HttpServer,
) -> ApiTokenData:
    scopes = token.scopes

    if not api_token_repo.exists(token=token.token):
        api_token_repo.clear()
        logger.info(
            "[email protected] - Saving api token from auth token for all nodes")
        return api_token_repo.create(
            dict(
                token=token.token,
                scopes=" ".join(scopes),
                dns_server_id=dns_server.id,
                http_server_id=http_server.id,
                expires_at=datetime.utcfromtimestamp(float(token.exp)),
            )).data()
    else:
        logger.info("[email protected] - token already exists in database")
        return api_token_repo.data()