Cache Pillar API Object on request object.

This commit is contained in:
Sybren A. Stüvel 2016-10-12 14:29:47 +02:00
parent 0146b568c0
commit 26aa155b9e

View File

@ -4,7 +4,7 @@ Replacement of the old SystemUtility class.
import os
import logging
from flask import current_app, session
from flask import current_app, session, request
from flask_login import current_user
from pillar.sdk import FlaskInternalApi
@ -35,6 +35,11 @@ def pillar_server_endpoint_static():
def pillar_api(token=None):
# Cache API objects on the request.
api = getattr(request, 'pillar_api', None)
if api is not None:
return api
# Check if current_user is initialized (in order to support manage.py
# scripts and non authenticated server requests).
if token is None and current_user and current_user.is_authenticated:
@ -47,6 +52,7 @@ def pillar_api(token=None):
token=token
)
request.pillar_api = api
return api