4 # Copyright (c) 2017 Inocybe Technologies and others. All rights reserved.
6 # This program and the accompanying materials are made available under the
7 # terms of the Eclipse Public License v1.0 which accompanies this distribution,
8 # and is available at http://www.eclipse.org/legal/epl-v10.html
12 # convert-shiro-ini-to-rest-payload.py
14 # Used to help ease upgrades. In ODL Nitrogen, AAA related application config
15 # is now done via the datastore. This allows a more cohesive experience in
16 # line with the rest of the controller architecture. More information about
17 # this can be found here:
19 # https://bugs.opendaylight.org/show_bug.cgi?id=7793
21 # This program assumes a correctly formatted shiro.ini file. No extra checks
22 # are done on shiro.ini.
25 import sys, ConfigParser
26 from xml.etree.ElementTree import Element, SubElement, tostring
27 from xml.dom import minidom
30 SHIRO_CONFIGURATION = "shiro-configuration"
31 NS = "urn:opendaylight:aaa:app:config"
35 def convert(filename):
37 convert shiro.ini to a XML based representation
39 config = ConfigParser.ConfigParser()
40 config.optionxform = str
42 root = Element(SHIRO_CONFIGURATION)
43 root.attrib['xmlns'] = NS
44 for section in config.sections():
45 if MAIN_SECTION in section or URLS_SECTION in section:
46 for item in config.items(section):
47 child = SubElement(root, section)
48 k = SubElement(child, "pair-key")
50 v = SubElement(child, "pair-value")
56 print "> python convert-shiro-ini-to-rest <filename>"
58 if __name__ == '__main__':
60 filename = sys.argv[1]
61 et = convert(filename)
62 xmlstr = minidom.parseString(tostring(et)).toprettyxml(indent=" ")