Cache Pillar API Object on request object.
This commit is contained in:
@@ -4,7 +4,7 @@ Replacement of the old SystemUtility class.
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
from flask import current_app, session
|
from flask import current_app, session, request
|
||||||
from flask_login import current_user
|
from flask_login import current_user
|
||||||
|
|
||||||
from pillar.sdk import FlaskInternalApi
|
from pillar.sdk import FlaskInternalApi
|
||||||
@@ -35,6 +35,11 @@ def pillar_server_endpoint_static():
|
|||||||
|
|
||||||
|
|
||||||
def pillar_api(token=None):
|
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
|
# Check if current_user is initialized (in order to support manage.py
|
||||||
# scripts and non authenticated server requests).
|
# scripts and non authenticated server requests).
|
||||||
if token is None and current_user and current_user.is_authenticated:
|
if token is None and current_user and current_user.is_authenticated:
|
||||||
@@ -47,6 +52,7 @@ def pillar_api(token=None):
|
|||||||
token=token
|
token=token
|
||||||
)
|
)
|
||||||
|
|
||||||
|
request.pillar_api = api
|
||||||
return api
|
return api
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user