(updates, analyst)
return result
Update the TAXII Server config in the DB.

    :return dictionary
Update the TAXII Server config in the DB.
Update the TAXII Server config in the DB .
def update_taxii_server_config(updates, analyst):
    """
    Update the TAXII Server config in the DB.

    :return dictionary
    """
    result = {'success': False}
    service = CRITsService.objects(name='taxii_service').first()
    servers = service.config.taxii_servers
    if 'remove_server' in updates:
        try:
            del servers[updates['remove_server']]
        except:
            pass
    elif 'remove_feed' in updates:
        try:
            srv_name = updates.get('srv_name')
            sdict = service.to_dict()
            servers = sdict['config']['taxii_servers']
            del servers[srv_name]['feeds'][updates['remove_feed']]
            service.config.taxii_servers = servers
        except:
            pass
    elif 'edit_feed' in updates:
        if not updates['edit_feed']:
            result['success'] = False
            return result
        data = servers[updates['srv_name']]['feeds'][updates['edit_feed']]
        hostname = servers[updates['srv_name']].get('hostname', '')
        last = taxii.Taxii.get_last(hostname + ':' + data['feedname'])
        if last:
            data['last_poll'] = str(pytz.utc.localize(last.end)).split('+')[0]
        else:
            data['last_poll'] = "No Record of Previous Poll"
        result.update(data)
        result['fid'] = updates['edit_feed']
        result['success'] = True
        return result
    elif updates:
        # Get the class that implements this service.
        from . import TAXIIClient
        taxii_class = TAXIIClient()
        try:
            if 'servername' in updates:
                taxii_class.parse_server_config(updates)
                name = updates.pop('servername', None)
                cur_sname = updates.pop('cur_sname', None)
                if not cur_sname:
                    cur_sname = name

                try:
                    if 'feeds' in servers.get(cur_sname, {}):
                        updates['feeds'] = servers[cur_sname]['feeds']
                    else:
                        updates['feeds'] = {}

                    # Remove existing if changing servername
                    if cur_sname and cur_sname != name:
                        del servers[cur_sname]

                    servers[name] = updates
                except AttributeError:
                    servers = {}
                    servers[name] = updates
            elif 'feedname' in updates:
                taxii_class.parse_feed_config(updates)
                srv_name = updates.pop('srv_name', None)
                fid = updates.pop('fid', None)

                sdict = service.to_dict()
                servers = sdict['config']['taxii_servers']

                try:
                    feeds = servers[srv_name]['feeds']
                    if not fid:
                        fid = len(feeds)
                        while str(fid) in feeds:
                            fid += 1
                    feeds[str(fid)] = updates
                    servers[srv_name]['feeds'] = feeds
                except (KeyError, TypeError):
                    if not isinstance(servers, dict):
                        servers = {}
                    servers[srv_name] = {'feeds': {'0': updates}}

                service.config.taxii_servers = servers
        except ServiceConfigError as e:
            result['error'] = str(e)
            return result

    try:
        service.save(username=analyst)
    except ValidationError, e:
        result['message'] = e
        return result

    if 'remove_server' in updates:
        service.reload()
        choices = ''
        for choice in service.config.taxii_servers:
            choices += '<option value="%s">%s</option>' % (choice, choice)
        result['html'] = choices
    elif 'remove_feed' in updates or 'subID' in updates:
        service.reload()
        choices = ''
        feeds = service.config.taxii_servers[srv_name]['feeds']
        html = '<option value="%s">%s</option>'
        for choice in feeds:
            choices += html % (choice,
                               feeds[choice]['feedname'])
        result['html'] = choices

    result['success'] = True
    return result
def update_taxii_server_config ( updates , analyst ) : result = { 'success' : False } service = CRITsService . objects ( name = 'taxii_service' ) . first ( ) servers = service . config . taxii_servers if 'remove_server' in updates : try : del servers [ updates [ 'remove_server' ] ] except : pass elif 'remove_feed' in updates : try : srv_name = updates . get ( 'srv_name' ) sdict = service . to_dict ( ) servers = sdict [ 'config' ] [ 'taxii_servers' ] del servers [ srv_name ] [ 'feeds' ] [ updates [ 'remove_feed' ] ] service . config . taxii_servers = servers except : pass elif 'edit_feed' in updates : if not updates [ 'edit_feed' ] : result [ 'success' ] = False return result data = servers [ updates [ 'srv_name' ] ] [ 'feeds' ] [ updates [ 'edit_feed' ] ] hostname = servers [ updates [ 'srv_name' ] ] . get ( 'hostname' , '' ) last = taxii . Taxii . get_last ( hostname + ':' + data [ 'feedname' ] ) if last : data [ 'last_poll' ] = str ( pytz . utc . localize ( last . end ) ) . split ( '+' ) [ 0 ] else : data [ 'last_poll' ] = "No Record of Previous Poll" result . update ( data ) result [ 'fid' ] = updates [ 'edit_feed' ] result [ 'success' ] = True return result elif updates : # Get the class that implements this service. from . import TAXIIClient taxii_class = TAXIIClient ( ) try : if 'servername' in updates : taxii_class . parse_server_config ( updates ) name = updates . pop ( 'servername' , None ) cur_sname = updates . pop ( 'cur_sname' , None ) if not cur_sname : cur_sname = name try : if 'feeds' in servers . get ( cur_sname , { } ) : updates [ 'feeds' ] = servers [ cur_sname ] [ 'feeds' ] else : updates [ 'feeds' ] = { } # Remove existing if changing servername if cur_sname and cur_sname != name : del servers [ cur_sname ] servers [ name ] = updates except AttributeError : servers = { } servers [ name ] = updates elif 'feedname' in updates : taxii_class . parse_feed_config ( updates ) srv_name = updates . pop ( 'srv_name' , None ) fid = updates . pop ( 'fid' , None ) sdict = service . to_dict ( ) servers = sdict [ 'config' ] [ 'taxii_servers' ] try : feeds = servers [ srv_name ] [ 'feeds' ] if not fid : fid = len ( feeds ) while str ( fid ) in feeds : fid += 1 feeds [ str ( fid ) ] = updates servers [ srv_name ] [ 'feeds' ] = feeds except ( KeyError , TypeError ) : if not isinstance ( servers , dict ) : servers = { } servers [ srv_name ] = { 'feeds' : { '0' : updates } } service . config . taxii_servers = servers except ServiceConfigError as e : result [ 'error' ] = str ( e ) return result try : service . save ( username = analyst ) except ValidationError , e : result [ 'message' ] = e return result if 'remove_server' in updates : service . reload ( ) choices = '' for choice in service . config . taxii_servers : choices += '<option value="%s">%s</option>' % ( choice , choice ) result [ 'html' ] = choices elif 'remove_feed' in updates or 'subID' in updates : service . reload ( ) choices = '' feeds = service . config . taxii_servers [ srv_name ] [ 'feeds' ] html = '<option value="%s">%s</option>' for choice in feeds : choices += html % ( choice , feeds [ choice ] [ 'feedname' ] ) result [ 'html' ] = choices result [ 'success' ] = True return result