-
Notifications
You must be signed in to change notification settings - Fork 138
Expand file tree
/
Copy pathcontext.py
More file actions
93 lines (76 loc) · 2.49 KB
/
context.py
File metadata and controls
93 lines (76 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
from warnings import warn as _warn
from satosa.exception import SATOSAError
class SATOSABadContextError(SATOSAError):
"""
Raise this exception if validating the Context and failing.
"""
pass
class Context(object):
"""
Holds methods for sharing proxy data through the current request
"""
KEY_METADATA_STORE = 'metadata_store'
KEY_TARGET_ENTITYID = 'target_entity_id'
KEY_FORCE_AUTHN = 'force_authn'
KEY_MEMORIZED_IDP = 'memorized_idp'
KEY_AUTHN_CONTEXT_CLASS_REF = 'authn_context_class_ref'
KEY_TARGET_AUTHN_CONTEXT_CLASS_REF = 'target_authn_context_class_ref'
def __init__(self):
self._path = None
self.request = None
self.request_uri = None
self.request_method = None
self.qs_params = None
self.server = None
self.http_headers = None
self.cookie = None
self.request_authorization = None
self.target_backend = None
self.target_frontend = None
self.target_micro_service = None
# This dict is a data carrier between frontend and backend modules.
self.internal_data = {}
self.state = None
@property
def KEY_BACKEND_METADATA_STORE(self):
msg = "'{old_key}' is deprecated; use '{new_key}' instead.".format(
old_key="KEY_BACKEND_METADATA_STORE", new_key="KEY_METADATA_STORE"
)
_warn(msg, DeprecationWarning)
return Context.KEY_METADATA_STORE
@property
def path(self):
"""
Get the path
:rtype: str
:return: context path
"""
return self._path
@path.setter
def path(self, p):
"""
Inserts a path to the context.
This path is striped by the base_url, so for example:
A path BASE_URL/ENDPOINT_URL, would be inserted as only ENDPOINT_URL
https://localhost:8092/sso/redirect -> sso/redirect
:type p: str
:param p: A path to an endpoint.
:return: None
"""
if not p:
raise ValueError("path can't be set to None")
elif p.startswith('/'):
raise ValueError("path can't start with '/'")
self._path = p
def decorate(self, key, value):
"""
Add information to the context
"""
self.internal_data[key] = value
return self
def get_decoration(self, key):
"""
Retrieve information from the context
"""
value = self.internal_data.get(key)
return value