Skip to content

Commit 55fa30c

Browse files
author
Rebecka Gulliksson
committed
Add microservice plugin for adding static attributes to responses.
1 parent 2e77f75 commit 55fa30c

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import os
2+
3+
import yaml
4+
5+
from satosa.internal_data import DataConverter
6+
from satosa.micro_service.service_base import ResponseMicroService
7+
8+
9+
class AddStaticAttributes(ResponseMicroService):
10+
"""
11+
Add static attributes to the responses.
12+
13+
The path to the file describing the mapping (as YAML) of static attributes must be specified
14+
with the environment variable 'SATOSA_STATIC_ATTRIBUTES'.
15+
"""
16+
def __init__(self, internal_attributes):
17+
super(AddStaticAttributes, self).__init__()
18+
self.data_converter = DataConverter(internal_attributes)
19+
20+
mapping_file = os.environ.get("SATOSA_STATIC_ATTRIBUTES")
21+
if not mapping_file:
22+
raise ValueError("Could not find file containing mapping of static attributes.")
23+
24+
with open(mapping_file) as f:
25+
self.static_attributes = yaml.safe_load(f)
26+
27+
def process(self, context, data):
28+
all_attributes = data.get_attributes()
29+
all_attributes.update(self.data_converter.to_internal("saml", self.static_attributes))
30+
data.add_attributes(all_attributes)
31+
return data

0 commit comments

Comments
 (0)