Esempio n. 1
0
    def _revModl201709191412(self):
        '''
        Migrate the XREF types to use the propvalu syntax.
        '''
        tick = s_common.now()
        adds = []
        dels = set()

        nforms = set()

        for form in self.core.getModelDict().get('forms'):
            sforms = self.core.getTypeOfs(form)
            if 'xref' in sforms:
                nforms.add(form)

        for ntyp in nforms:
            nodes = self.core.getTufosByProp(ntyp)
            xtyp = '{}:xtype'.format(ntyp)
            xrefp = '{}:xref'.format(ntyp)
            xrefpint = '{}:xref:intval'.format(ntyp)
            xrefpstr = '{}:xref:strval'.format(ntyp)
            xrefprop = '{}:xref:prop'.format(ntyp)
            for node in nodes:
                iden = node[0]
                srcvtype = node[1].get(xtyp)
                if srcvtype is None:
                    # This is expensive node level introspection :(
                    for prop, valu in s_tufo.props(node).items():
                        if prop.startswith('xref:'):
                            form = prop.split('xref:', 1)[1]
                            if self.core.isTufoForm(form):
                                srcvtype = form
                                break
                    if not srcvtype:
                        raise s_common.NoSuchProp(
                            iden=node[0],
                            type=ntyp,
                            mesg=
                            'Unable to find a xref prop which is a form for migrating a '
                            'XREF node.')
                srcprp = '{}:xref:{}'.format(ntyp, srcvtype)
                srcv = node[1].get(srcprp)
                valu, subs = self.core.getPropNorm(xrefp, [srcvtype, srcv])
                adds.append((iden, xrefp, valu, tick))
                adds.append((iden, xrefprop, srcvtype, tick))
                if 'intval' in subs:
                    adds.append((iden, xrefpint, subs.get('intval'), tick))
                else:
                    adds.append((iden, xrefpstr, subs.get('strval'), tick))
                dels.add(srcprp)
                dels.add(xtyp)
        with self.core.getCoreXact():
            self.core.addRows(adds)
            for prop in dels:
                self.core.delRowsByProp(prop)
Esempio n. 2
0
    def getPropFormBase(self, prop):
        '''
        Return a form,base tuple for the name parts of a given property.

        Example:

        Args:
            prop (str): The fully qualified property name

        Returns:
            ((str,str)):  The (form,base) name tuple for the prop.

        '''
        pdef = self.getPropDef(prop)
        if pdef is None:
            raise s_common.NoSuchProp(name=prop)

        return pdef[1].get('form'), pdef[1].get('base')
Esempio n. 3
0
    def reqPropNorm(self, prop, valu, oldval=None):
        '''
        Return a normalized system mode value for the given property. This throws an exception if the property does
        not exist.

        Args:
            prop (str): Property to normalize.
            valu: Input value to normalize.
            oldval: Optional previous version of the value.

        Examples:
            Normalize an IPV4 address::

                valu, subs = model.reqPropNorm('inet:ipv4', '1.2.3.4')
                # valu = 16909060

            Normalize a DNS A record::

                valu, subs = model.reqPropNorm('inet:dns:a', 'woot.com/1.2.3.4')
                # valu = 'woot.com/1.2.3.4'
                # subs['fqdn'] = 'woot.com'
                # subs['fqdn:domain'] = 'com'
                # subs['fqdn:host'] = 'woot'
                # subs['ipv4'] = 16909060

        Notes:
            This is similar to the getPropNorm() function, however it throws an exception on a missing property
            instead of returning the valu to the caller.

        Returns:
            tuple: A tuple of two items. The first item is the system normalized valu, as an integer or string. The
                   second item is a dictionary of subproperties for the input.

        Raises:
            NoSuchProp: If the requested property is not part of the data model.
        '''
        dtype = self.getPropType(prop)
        if dtype is None:
            raise s_common.NoSuchProp(mesg='Prop does not exist.',
                                      prop=prop,
                                      valu=valu)

        return dtype.norm(valu, oldval=oldval)