Exemplo n.º 1
0
def parseFromFile(args):
    """
    Parse a local policy file to execute
    
    @type  args: list of objects
    @param args: list of input arguments
    """
    test = args.test
    debug = args.verbose
    policypath = args.path
    config = ConfigLoader(args.config)
    setLoggingSystem(config, debug)
    # get the policy schema path
    schemapath = config.SectionMap('Schemas')['policies']
    logger.info('Getting the policy schema via file %s', policypath)
    # get the user account mapping
    mapFilename = config.SectionMap('AccountMapping')['file']
    usermap = loadUserMap(mapFilename)
    # load the policy schema
    pParser = PolicyParser(None, test, 'PolicyManager', debug)
    xmlSchemaDoc = pParser.parseXmlSchema(None, [schemapath])
    # load the policy doc and validate it
    pParser.parseFromFile(policypath, xmlSchemaDoc)
    # execute the policy as a B2SAFE workflow
    runPolicy(pParser.policy, usermap, test, 'PolicyManager', debug)
Exemplo n.º 2
0
def queryDpm(args, config, begin_date=None, end_date=None):

    #load properties from configuration
    username = config.SectionMap('DpmServer')['username']
    password = config.SectionMap('DpmServer')['password']
    server = config.SectionMap('DpmServer')['hostname']
    url = '%s://%s%s?community_id=%s&center_id=%s' % \
          (config.SectionMap('DpmServer')['scheme'],
           config.SectionMap('DpmServer')['hostname'],
           config.SectionMap('DpmServer')['path'],
           config.SectionMap('Community')['id'],
           config.SectionMap('Center')['id'])

    #apply parameters
    if not begin_date is None:
        url += '&begin_date=%s' % begin_date
    if not end_date is None:
        url += '&end_date=%s' % end_date

    #start interaction with DPM server
    logger.info('Listing policies [%s]' % url)
    authinfo = urllib2.HTTPPasswordMgrWithDefaultRealm()
    authinfo.add_password(None, server, username, password)
    handler = urllib2.HTTPBasicAuthHandler(authinfo)
    myopener = urllib2.build_opener(handler)
    opened = urllib2.install_opener(myopener)
    response = urllib2.urlopen(url)

    json_data = response.read()

    if json_data is None:
        logger.info('No response found')
    else:
        _json = json.loads(json_data)
        logger.info('Found %d policies' % (len(_json)))
        for entry in _json:
            url = str(entry[0])
            ts = entry[1]
            checksum_value = str(entry[2])
            checksum_algo = str(entry[3])

            if not url.endswith('.html'):
                logger.info('Processing policy: %s [%s, %s, %s]', url, ts, 
                            checksum_value, checksum_algo)
                pParser = PolicyParser(None, args.test, 'PolicyManager', args.verbose)
                xmlSchemaDoc = pParser.parseXmlSchema(args.schemaurl, args.schemapath)
                pParser.parseFromUrl(url, xmlSchemaDoc, checksum_algo, checksum_value)
                if not pParser.policy is None:
                    mapFilename = config.SectionMap('AccountMapping')['file']
                    usermap = loadUserMap(mapFilename)
                    runPolicy(pParser.policy, usermap, args.test, 'PolicyManager', args.verbose)
            else:
                logger.error('invalid policy location [%s]', url)
Exemplo n.º 3
0
def queryDpm(args, config):
    """ Download the policies from the DB and execute the related B2SAFE workflow

    @type  args:       list of objects
    @param args:       The list of input parameters
    @type  config:     ConfigLoader object
    @param config:     It contains the configuration parameters
    """
    debug = args.verbose
    # manage the checksum verification
    chk_veri = False
    chk_verify = config.SectionMap('Integrity')['checksum_verify']
    if chk_verify.lower() == 'true':
        chk_veri = True
    # load the policy schema path/url
    policySchemaUrl = None
    policySchema = config.SectionMap('Schemas')['policies']
    if policySchema.startswith('http://'):
        policySchemaUrl = policySchema
    # get the list of policies matching the input criteria
    conn = ServerConnector(args.config, args.test, "PolicyManager", debug)
    policy_files = getInfoPolicies(args,logger)
    if policy_files is not None:
        for url in policy_files:
            logger.info('Processing policy: %s', url)
            # load the XML policy schema
            pParser = PolicyParser(None, args.test, 'PolicyManager', debug)
            policySchemaDoc = pParser.parseXmlSchema([policySchemaUrl], 
                                                     [policySchema])
            if chk_veri:
                # get the id from the policy on the DB
                policyId = conn.getDocumentByUrl(url, '//*:policy/@uniqueid/data()')
                # get the status doc from the DB for the checksum
                status, doc = conn.getStatus(policyId)
                # parse the policy and validate against schema and checksum
                errMsg = pParser.parseFromUrl(url, policySchemaDoc, conn, 
                         status[staNs+':policy'][staNs+':checksum']['@method'],
                         status[staNs+':policy'][staNs+':checksum']['#text'])
            else:
                # parse the policy and validate against schema
                errMsg = pParser.parseFromUrl(url, policySchemaDoc, conn)
            if errMsg is not None:
                print 'ERROR: ' + errMsg
                exit(1)            
            if pParser.policy is not None:
                # load user mapping
                mapFilename = config.SectionMap('AccountMapping')['file']
                usermap = loadUserMap(mapFilename)
                # schedule the policy
                runPolicy(pParser.policy, usermap, args.test, 'PolicyManager',
                          debug)
Exemplo n.º 4
0
def parseFromFile(args):
    """
    Parse a local policy file to execute
    """
    test = args.test
    debug = args.verbose
    policypath = args.path
    schemapath = args.schemapath
    config = ConfigLoader(args.config)
    setLoggingSystem(config, debug)
    logger.info('Getting the policies via file %s', policypath)
    mapFilename = config.SectionMap('AccountMapping')['file']
    usermap = loadUserMap(mapFilename)  
    pParser = PolicyParser(None, test, 'PolicyManager', debug)
    xmlSchemaDoc = pParser.parseXmlSchema(None, schemapath)
    pParser.parseFromFile(policypath, xmlSchemaDoc)
    runPolicy(pParser.policy, usermap, test, 'PolicyManager', debug)
Exemplo n.º 5
0
def loadDefaultPolicy():
    parser = PolicyParser()
    policy = parser.parsePolicy("../data/map01.policy")
    return policy