Exemple #1
0
    def post(self):
        """Create a new configuration namespace"""
        self.reqparse.add_argument('namespacePrefix', type=str, required=True)
        self.reqparse.add_argument('name', type=str, required=True)
        self.reqparse.add_argument('sortOrder', type=int, required=True)
        args = self.reqparse.parse_args()

        if self.dbconfig.namespace_exists(args['namespacePrefix']):
            return self.make_response(
                'Namespace {} already exists'.format(args['namespacePrefix']),
                HTTP.CONFLICT)

        ns = ConfigNamespace()

        ns.namespace_prefix = args['namespacePrefix']
        ns.name = args['name']
        ns.sort_order = args['sortOrder']

        db.session.add(ns)
        db.session.commit()

        self.dbconfig.reload_data()
        auditlog(event='configNamespace.create',
                 actor=session['user'].username,
                 data=args)

        return self.make_response('Namespace created', HTTP.CREATED)
Exemple #2
0
 def get_config_namespace(self, prefix, name, sort_order=2):
     nsobj = ConfigNamespace.query.filter(ConfigNamespace.namespace_prefix == prefix).first()
     if not nsobj:
         self.log.info('Adding namespace {}'.format(name))
         nsobj = ConfigNamespace()
         nsobj.namespace_prefix = prefix
         nsobj.name = name
         nsobj.sort_order = sort_order
     return nsobj
Exemple #3
0
def _get_config_namespace(prefix, name, sort_order=2):
    nsobj = db.ConfigNamespace.find_one(
        ConfigNamespace.namespace_prefix == prefix)
    if not nsobj:
        logger.info('Adding namespace {}'.format(name))
        nsobj = ConfigNamespace()
        nsobj.namespace_prefix = prefix
        nsobj.name = name
        nsobj.sort_order = sort_order
    return nsobj
Exemple #4
0
def apply_config(config):
    for nsdata in config:
        ns = ConfigNamespace.get(nsdata['namespacePrefix'])

        # Update existing namespace
        if ns:
            ns.namespace_prefix = nsdata['namespacePrefix']
            ns.name = nsdata['name']
            ns.sort_order = nsdata['sortOrder']

        else:
            ns = ConfigNamespace()
            ns.namespace_prefix = nsdata['namespacePrefix']
            ns.name = nsdata['name']
            ns.sort_order = nsdata['sortOrder']
        db.session.add(ns)

        for itmdata in nsdata['configItems']:
            itm = ConfigItem.get(ns.namespace_prefix, itmdata['key'])

            if itm:
                itm.value = itmdata['value']
                itm.type = itmdata['type']
                itm.description = itmdata['description']
            else:
                itm = ConfigItem()
                itm.namespace_prefix = ns.namespace_prefix
                itm.key = itmdata['key']
                itm.value = itmdata['value']
                itm.description = itmdata['description']

            db.session.add(itm)

    db.session.commit()
Exemple #5
0
    def post(self):
        self.reqparse.add_argument('config', type=str, required=True)
        args = self.reqparse.parse_args()

        try:
            config = json.loads(args['config'], cls=InquisitorJSONDecoder)
            for nsdata in config:
                ns = ConfigNamespace.get(nsdata['namespacePrefix'])

                # Update existing namespace
                if ns:
                    ns.namespace_prefix = nsdata['namespacePrefix']
                    ns.name = nsdata['name']
                    ns.sort_order = nsdata['sortOrder']

                else:
                    ns = ConfigNamespace()
                    ns.namespace_prefix = nsdata['namespacePrefix']
                    ns.name = nsdata['name']
                    ns.sort_order = nsdata['sortOrder']
                db.session.add(ns)

                for itmdata in nsdata['configItems']:
                    itm = ConfigItem.get(ns.namespace_prefix, itmdata['key'])

                    if itm:
                        itm.value = itmdata['value']
                        itm.type = itmdata['type']
                        itm.description = itmdata['description']
                    else:
                        itm = ConfigItem()
                        itm.namespace_prefix = ns.namespace_prefix
                        itm.key = itmdata['key']
                        itm.value = itmdata['value']
                        itm.description = itmdata['description']

                    db.session.add(itm)

            db.session.commit()
            auditlog(event='config.import',
                     actor=session['user'].username,
                     data=config)
            return self.make_response('Configuration imported')
        except Exception as ex:
            self.log.exception('Failed importing configuration data')
            return self.make_response(
                'Error importing configuration data: {}'.format(ex),
                HTTP.SERVER_ERROR)