Ejemplo n.º 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)
Ejemplo n.º 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),
):

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

    # 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(includes).set_data_model(
        SensitiveApiTokenData).includes(includes).data())
    return SensitiveApiTokenResponse(api_token=api_token)
Ejemplo n.º 3
0
def create_or_get_api_token_for_dns_server(
        token: TokenPayload, api_token_repo: ApiTokenRepo,
        dns_server: DnsServer) -> 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 dns node")
        return api_token_repo.create(
            dict(
                token=token.token,
                scopes=" ".join(scopes),
                dns_server=dns_server,
                expires_at=datetime.utcfromtimestamp(float(token.exp)),
            )).data()
    else:
        logger.info("[email protected] - token already exists in database")
        return api_token_repo.loads("dns_server").includes("dns_server").data()