@@ -56,7 +56,69 @@ def scope(self):
56
56
57
57
class AddSyntheticAttributes (ResponseMicroService ):
58
58
"""
59
- Add synthetic attributes to the responses.
59
+ A class that add generated or synthetic attributes to a response set. Attribute
60
+ generation is done using mustach (http://mustache.github.io) templates. The
61
+ following example configuration illustrates most common features:
62
+
63
+ ```yaml
64
+ module: satosa.micro_services.attribute_generation.AddSyntheticAttributes
65
+ name: AddSyntheticAttributes
66
+ config:
67
+ synthetic_attributes:
68
+ target_provider1:
69
+ requester1:
70
+ eduPersonAffiliation: member;employee
71
+ default:
72
+ default:
73
+ schacHomeOrganization: {{eduPersonPrincipalName.scope}}
74
+ schacHomeOrganizationType: tomfoolery provider
75
+
76
+ ```
77
+
78
+ The use of "" and 'default' is synonymous. Attribute rules are not
79
+ overloaded or inherited. For instance a response from "target_provider1"
80
+ and requester1 in the above config will generate a (static) attribute
81
+ set of 'member' and 'employee' for the eduPersonAffiliation attribute
82
+ and nothing else. Note that synthetic attributes override existing
83
+ attributes if present.
84
+
85
+ *Evaluating and interpreting templates*
86
+
87
+ Attribute values are split on combinations of ';' and newline so that
88
+ a template resulting in the following text:
89
+ ```
90
+ a;
91
+ b;c
92
+ ```
93
+ results in three attribute values: 'a','b' and 'c'. Templates are
94
+ evaluated with a single context that represents the response attributes
95
+ before the microservice is processed. De-referencing the attribute
96
+ name as in '{{name}}' results in a ';'-separated list of all attribute
97
+ values. This notation is useful when you know there is only a single
98
+ attribute value in the set.
99
+
100
+ *Special contexts*
101
+
102
+ For treating the values as a list - eg for interating using mustach,
103
+ use the .values sub-context For instance to synthesize all fist-last
104
+ name combinations do this:
105
+
106
+ ```
107
+ {{#givenName.values}}
108
+ {{#sn.values}}{{givenName}} {{sn}}{{/sn.values}}
109
+ {{/givenName.values}}
110
+ ```
111
+
112
+ Note that the .values sub-context behaves as if it is an iterator
113
+ over single-value context with the same key name as the original
114
+ attribute name.
115
+
116
+ The .scope sub-context evalues to the right-hand part of any @
117
+ sign. This is assumed to be single valued.
118
+
119
+ The .first sub-context evalues to the first value of a context
120
+ which may be safer to use if the attribute is multivalued but
121
+ you don't care which value is used in a template.
60
122
"""
61
123
62
124
def __init__ (self , config , * args , ** kwargs ):
0 commit comments