summaryrefslogtreecommitdiff
path: root/src/saml2/tools/mdexport.py
blob: 80633f7dd210589ed8174b66c5449285a1bedccc (plain)
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
#!/usr/bin/env python
import argparse

from saml2 import md
from saml2 import saml
from saml2 import xmldsig
from saml2 import xmlenc
from saml2.attribute_converter import ac_factory
from saml2.httpbase import HTTPBase
from saml2.mdstore import MetaDataExtern
from saml2.mdstore import MetaDataFile
from saml2.mdstore import load_extensions
from saml2.sigver import SecurityContext
from saml2.sigver import _get_xmlsec_cryptobackend


__author__ = "rolandh"

"""
A script that imports and verifies metadata and then dumps it in a basic
dictionary format.
"""


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("-t", dest="type")
    parser.add_argument("-u", dest="url")
    parser.add_argument("-c", dest="cert")
    parser.add_argument("-a", dest="attrsmap")
    parser.add_argument("-o", dest="output")
    parser.add_argument("-x", dest="xmlsec")
    parser.add_argument(dest="item")
    args = parser.parse_args()

    metad = None

    if args.type == "local":
        metad = MetaDataFile(args.item, args.item)
    elif args.type == "external":
        ATTRCONV = ac_factory(args.attrsmap)
        httpc = HTTPBase()
        crypto = _get_xmlsec_cryptobackend(args.xmlsec)
        sc = SecurityContext(crypto)
        metad = MetaDataExtern(ATTRCONV, args.url, sc, cert=args.cert, http=httpc)

    if metad is not None:
        metad.load()
        txt = metad.dumps()
        if args.output:
            f = open(args.output, "w")
            f.write(txt)
            f.close()
        else:
            print(txt)


if __name__ == "__main__":
    main()