|
31 | 31 | from pyff.samlmd import (
|
32 | 32 | annotate_entity,
|
33 | 33 | discojson_sp_t,
|
| 34 | + discojson_sp_attr_t, |
34 | 35 | discojson_t,
|
35 | 36 | entitiesdescriptor,
|
36 | 37 | find_in_document,
|
@@ -731,7 +732,7 @@ def select(req: Plumbing.Request, *opts):
|
731 | 732 | Select a set of EntityDescriptor elements as the working document.
|
732 | 733 |
|
733 | 734 | :param req: The request
|
734 |
| - :param opts: Options - used for select alias |
| 735 | + :param opts: Options - see Options below |
735 | 736 | :return: returns the result of the operation as a working document
|
736 | 737 |
|
737 | 738 | Select picks and expands elements (with optional filtering) from the active repository you setup using calls
|
@@ -778,25 +779,60 @@ def select(req: Plumbing.Request, *opts):
|
778 | 779 | would terminate the plumbing at select if there are no SPs in the local repository. This is useful in
|
779 | 780 | combination with fork for handling multiple cases in your plumbings.
|
780 | 781 |
|
781 |
| - The 'as' keyword allows a select to be stored as an alias in the local repository. For instance |
| 782 | + Options are put directly after "select". E.g: |
782 | 783 |
|
783 | 784 | .. code-block:: yaml
|
784 | 785 |
|
785 |
| - - select as /foo-2.0: "!//md:EntityDescriptor[md:IDPSSODescriptor]" |
| 786 | + - select as /foo-2.0 dedup True: "!//md:EntityDescriptor[md:IDPSSODescriptor]" |
786 | 787 |
|
787 |
| - would allow you to use /foo-2.0.json to refer to the JSON-version of all IdPs in the current repository. |
788 |
| - Note that you should not include an extension in your "as foo-bla-something" since that would make your |
789 |
| - alias invisible for anything except the corresponding mime type. |
| 788 | + **Options** |
| 789 | + Defaults are marked with (*) |
| 790 | + - as <name> : The 'as' keyword allows a select to be stored as an alias in the local repository. For instance |
| 791 | +
|
| 792 | + .. code-block:: yaml |
| 793 | +
|
| 794 | + - select as /foo-2.0: "!//md:EntityDescriptor[md:IDPSSODescriptor]" |
| 795 | +
|
| 796 | + would allow you to use /foo-2.0.json to refer to the JSON-version of all IdPs in the current repository. |
| 797 | + Note that you should not include an extension in your "as foo-bla-something" since that would make your |
| 798 | + alias invisible for anything except the corresponding mime type. |
| 799 | +
|
| 800 | + - dedup <True*|False> : Whether to deduplicate the results by entityID. |
| 801 | +
|
| 802 | + Note: When select is used after a load pipe with more than one source, if dedup is set to True |
| 803 | + and there are entity properties that may differ from one source to another, these will be squashed |
| 804 | + rather than merged. |
790 | 805 | """
|
| 806 | + opt_names = ('as', 'dedup') |
| 807 | + if len(opts) % 2 == 0: |
| 808 | + _opts = dict(list(zip(opts[::2], opts[1::2]))) |
| 809 | + else: |
| 810 | + _opts = {} |
| 811 | + for i in range(0, len(opts), 2): |
| 812 | + if opts[i] in opt_names: |
| 813 | + _opts[opts[i]] = opts[i + 1] |
| 814 | + else: |
| 815 | + _opts['as'] = opts[i] |
| 816 | + if i + 1 < len(opts): |
| 817 | + more_opts = opts[i + 1:] |
| 818 | + _opts.update(dict(list(zip(more_opts[::2], more_opts[1::2])))) |
| 819 | + break |
| 820 | + |
| 821 | + _opts.setdefault('dedup', "True") |
| 822 | + _opts.setdefault('name', req.plumbing.id) |
| 823 | + _opts['dedup'] = bool(str2bool(_opts['dedup'])) |
| 824 | + |
791 | 825 | args = _select_args(req)
|
792 |
| - name = req.plumbing.id |
| 826 | + name = _opts['name'] |
| 827 | + dedup = _opts['dedup'] |
| 828 | + |
793 | 829 | if len(opts) > 0:
|
794 | 830 | if opts[0] != 'as' and len(opts) == 1:
|
795 | 831 | name = opts[0]
|
796 | 832 | if opts[0] == 'as' and len(opts) == 2:
|
797 | 833 | name = opts[1]
|
798 | 834 |
|
799 |
| - entities = resolve_entities(args, lookup_fn=req.md.store.select) |
| 835 | + entities = resolve_entities(args, lookup_fn=req.md.store.select, dedup=dedup) |
800 | 836 |
|
801 | 837 | if req.state.get('match', None): # TODO - allow this to be passed in via normal arguments
|
802 | 838 |
|
@@ -1044,6 +1080,36 @@ def _discojson_sp(req, *opts):
|
1044 | 1080 | return json.dumps(res)
|
1045 | 1081 |
|
1046 | 1082 |
|
| 1083 | +@pipe(name='discojson_sp_attr') |
| 1084 | +def _discojson_sp_attr(req, *opts): |
| 1085 | + """ |
| 1086 | +
|
| 1087 | + Return a json representation of the trust information |
| 1088 | +
|
| 1089 | + .. code-block:: yaml |
| 1090 | + discojson_sp_attr: |
| 1091 | +
|
| 1092 | + SP Entities can carry trust information as a base64 encoded json blob |
| 1093 | + as an entity attribute with name `https://refeds.org/entity-selection-profile`. |
| 1094 | + The schema of this json is the same as the one produced above from XML |
| 1095 | + with the pipe `discojson_sp`, and published at: |
| 1096 | +
|
| 1097 | + https://github.com/TheIdentitySelector/thiss-mdq/blob/master/trustinfo.schema.json |
| 1098 | +
|
| 1099 | + :param req: The request |
| 1100 | + :param opts: Options (unusued) |
| 1101 | + :return: returns a JSON doc |
| 1102 | +
|
| 1103 | + """ |
| 1104 | + |
| 1105 | + if req.t is None: |
| 1106 | + raise PipeException("Your pipeline is missing a select statement.") |
| 1107 | + |
| 1108 | + res = discojson_sp_attr_t(req) |
| 1109 | + |
| 1110 | + return json.dumps(res) |
| 1111 | + |
| 1112 | + |
1047 | 1113 | @pipe
|
1048 | 1114 | def sign(req: Plumbing.Request, *_opts):
|
1049 | 1115 | """
|
|
0 commit comments