示例#1
0
    def rows(self, name, offs, size, timeout=None):
        '''
        Retrive raw rows from a section of the named CryoTank.

        Args:
            name (str): The name of the remote CryoTank.
            offs (int): The offset to begin the row retrieval from.
            size (int): The number of records to retrieve.
            timeout (int): Request timeout.

        Notes:
            This returns msgpack encoded records. It is the callers
            responsibility to decode them.

        Yields:
            (int, bytes): (indx, bytes) tuples for the rows in range.
        '''
        mesg = ('cryo:rows', {'name': name, 'offs': offs, 'size': size})
        with self.sess.task(mesg, timeout=timeout) as chan:

            ok, retn = chan.next(timeout=timeout)
            s_common.reqok(ok, retn)

            for bloc in chan.rxwind(timeout=timeout):
                for item in bloc:
                    yield item
示例#2
0
文件: neuron.py 项目: thpatel/synapse
 def genCellAuth(self, name, timeout=None):
     '''
     Generate a new cell auth file.
     '''
     mesg = ('cell:init', {'name': name})
     ok, retn = self.sess.call(mesg, timeout=timeout)
     return s_common.reqok(ok, retn)
示例#3
0
文件: axon.py 项目: TrentNow/synapse
    def bytes(self, buid, timeout=None):
        '''
        Yield bytes for the given buid.

        Args:
            buid (bytes): The buid hash.
            timeout (int): The network timeout in seconds.

        Yields:
            bytes: Chunks of bytes for the given buid.
        '''
        mesg = ('blob:load', {'buid': buid})
        with self.sess.task(mesg, timeout=timeout) as chan:
            ok, retn = chan.next(timeout=timeout)
            s_common.reqok(ok, retn)
            for byts in chan.rxwind(timeout=timeout):
                yield byts
示例#4
0
文件: axon.py 项目: TrentNow/synapse
    def metrics(self, offs=0, timeout=None):
        '''
        Yield metrics rows beginning at an offset.

        Args:
            offs (int): The offset to begin at.
            timeout (int): The network timeout in seconds.

        Yields:
            ((int, dict)): A tuple of offset and metrics information.
        '''
        mesg = ('axon:metrics', {'offs': offs})
        with self.sess.task(mesg, timeout=timeout) as chan:

            ok, retn = chan.next(timeout=timeout)
            s_common.reqok(ok, retn)

            for bloc in chan.rxwind(timeout=timeout):
                for item in bloc:
                    yield item
示例#5
0
文件: axon.py 项目: TrentNow/synapse
    def metrics(self, offs=0, timeout=None):
        '''
        Get metrics for a given blob.

        Args:
            offs (int): Offset to start collecting metrics from.
            timeout (int): The network timeout in seconds.

        Yields:
            ((int, dict)): A tuple of offset and metrics information.
        '''
        mesg = ('blob:metrics', {'offs': offs})
        with self.sess.task(mesg, timeout=timeout) as chan:

            ok, retn = chan.next(timeout=timeout)
            s_common.reqok(ok, retn)

            for bloc in chan.rxwind(timeout=timeout):
                for item in bloc:
                    yield item
示例#6
0
    def metrics(self, name, offs, size=None, timeout=None):
        '''
        Carve a slice of metrics data from the named CryoTank.

        Args:
            name (str): The name of the remote CryoTank.
            offs (int): The index offset.
            timeout (int): Request timeout

        Returns:
            tuple: A tuple containing metrics tufos for the named CryoTank.
        '''
        mesg = ('cryo:metrics', {'name': name, 'offs': offs, 'size': size})
        with self.sess.task(mesg, timeout=timeout) as chan:

            ok, retn = chan.next(timeout=timeout)
            s_common.reqok(ok, retn)

            for bloc in chan.rxwind(timeout=timeout):
                for item in bloc:
                    yield item
示例#7
0
    def list(self, timeout=None):
        '''
        Get a list of the remote CryoTanks.

        Args:
            timeout (int): Request timeout

        Returns:
            tuple: A tuple containing name, info tufos for the remote CryoTanks.
        '''
        ok, retn = self.sess.call(('cryo:list', {}), timeout=timeout)
        return s_common.reqok(ok, retn)
示例#8
0
文件: axon.py 项目: TrentNow/synapse
    def bytes(self, sha256, timeout=None):
        '''
        Yield bytes for the given SHA256.

        Args:
            sha256 (str): The SHA256 hash bytes.
            timeout (int): The network timeout in seconds.

        Yields:
            bytes: Bytes of the file requested.

        Raises:
            RetnErr: If the file requested does not exist.
        '''
        mesg = ('axon:bytes', {'sha256': sha256})
        with self.sess.task(mesg, timeout=timeout) as chan:

            ok, retn = chan.next(timeout=timeout)
            s_common.reqok(ok, retn)

            for byts in chan.rxwind(timeout=timeout):
                yield byts
示例#9
0
文件: axon.py 项目: TrentNow/synapse
    def upload(self, genr, timeout=None):
        '''
        Upload a large file using a generator.

        Args:
            genr (generator): Yields file bytes chunks.
            timeout (int): The network timeout in seconds.

        Returns:
            bytes: The sha256 digest of the file received, in bytes.
        '''
        mesg = ('axon:upload', {})

        with self.sess.task(mesg, timeout=timeout) as chan:

            ok, retn = chan.next(timeout=timeout)
            s_common.reqok(ok, retn)

            chan.txwind(genr, 10, timeout=timeout)

            ok, retn = chan.next(timeout=timeout)
            return s_common.reqok(ok, retn)
示例#10
0
文件: axon.py 项目: TrentNow/synapse
    def stat(self, timeout=None):
        '''
        Return the stat dictionary for the Axon.

        Args:
            timeout (int): The network timeout in seconds.

        Returns:
            dict: The stat dictionary.
        '''
        mesg = ('axon:stat', {})
        ok, retn = self.sess.call(mesg, timeout=timeout)
        return s_common.reqok(ok, retn)
示例#11
0
    def slice(self, name, offs, size, timeout=None):
        '''
        Slice and return a section from the named CryoTank.

        Args:
            name (str): The name of the remote CryoTank.
            offs (int): The offset to begin the slice.
            size (int): The number of records to slice.
            timeout (int): Request timeout

        Yields:
            (int, obj): (indx, item) tuples for the sliced range.
        '''
        mesg = ('cryo:slice', {'name': name, 'offs': offs, 'size': size})
        with self.sess.task(mesg, timeout=timeout) as chan:

            ok, retn = chan.next(timeout=timeout)
            s_common.reqok(ok, retn)

            for bloc in chan.rxwind(timeout=timeout):
                for item in bloc:
                    yield item
示例#12
0
文件: axon.py 项目: TrentNow/synapse
    def wants(self, hashes, timeout=None):
        '''
        Filter and return a list of hashes that the axon wants.

        Args:
            hashes (list): A list of SHA256 bytes.
            timeout (int): The network timeout in seconds.

        Returns:
            tuple: A tuple containg hashes the axon wants.
        '''
        mesg = ('axon:wants', {'hashes': hashes})
        ok, retn = self.sess.call(mesg, timeout=timeout)
        return s_common.reqok(ok, retn)
示例#13
0
文件: axon.py 项目: TrentNow/synapse
    def save(self, files, timeout=None):
        '''
        Save a list of files to the axon.

        Args:
            files ([bytes]): A list of files as bytes blobs.
            timeout (int): The network timeout in seconds.

        Returns:
            int: The number of files saved.
        '''
        mesg = ('axon:save', {'files': files})
        ok, retn = self.sess.call(mesg, timeout=timeout)
        return s_common.reqok(ok, retn)
示例#14
0
    def init(self, name, conf=None, timeout=None):
        '''
        Create a new named Cryotank.

        Args:
            name (str): Name of the Cryotank to make.
            conf (dict): Additional configable options for the Cryotank.
            timeout (int): Request timeout

        Returns:
            True if the tank was created, False if the tank existed or
            there was an error during CryoTank creation.
        '''
        mesg = ('cryo:init', {'name': name, 'conf': conf})
        ok, retn = self.sess.call(mesg, timeout=timeout)
        return s_common.reqok(ok, retn)
示例#15
0
文件: axon.py 项目: TrentNow/synapse
    def locs(self, sha256, timeout=None):
        '''
        Get the Blob hostname and buid pairs for a given sha256.

        Args:
            sha256 (bytes): Sha256 to look up.
            timeout (int): The network timeout in seconds.

        Returns:
            tuple: A tuple of (blob, buid) tuples.

        Raises:
            RetnErr: If the file requested does not exist.
        '''
        mesg = ('axon:locs', {'sha256': sha256})
        ok, retn = self.sess.call(mesg, timeout=timeout)
        return s_common.reqok(ok, retn)
示例#16
0
    def runCmdOpts(self, opts):
        core = self.getCmdItem()  # type: s_auth.AuthMixin

        act = opts.pop('act')
        typ = opts.pop('type')
        name = opts.pop('name', None)
        astub = 'auth:add'
        dstub = 'auth:del'

        # Form our mesg
        if act == 'get':
            if name:
                mesg = s_tufo.tufo('auth:req:%s' % typ,
                                   **{self.typmap.get(typ): name})
            else:
                mesg = ('auth:get:%s' % self.getmap.get(typ),
                        {})
        elif act == 'add':
            mesg = self.getMsg(astub, name, typ, opts)
        elif act == 'del':
            mesg = self.getMsg(dstub, name, typ, opts)
        else:  # pragma: no cover
            raise s_exc.BadSyntaxError(mesg='Unknown action provided',
                                       act=act)

        # Execute remote call
        isok, retn = core.authReact(mesg)
        retn = s_common.reqok(isok, retn)

        # Format output
        if opts.get('json'):
            outp = json.dumps(retn, indent=2, sort_keys=True)
        else:
            width, _ = shutil.get_terminal_size((120, 24))
            if width == 0:
                # In CI we may not have a tty available.
                width = 120
            outp = pprint.pformat(retn, width=width)
        self.printf(outp)
        return retn
示例#17
0
    def getSslCore(self, conf=None, configure_roles=False):
        dconf = {
            'auth:admin': 'root@localhost',
            'auth:en': 1,
        }
        if conf:
            conf.update(dconf)
        conf = dconf

        amesgs = (
            ('auth:add:user', {
                'user': '******'
            }),
            ('auth:add:role', {
                'role': 'creator'
            }),
            ('auth:add:rrule', {
                'role': 'creator',
                'rule': ('node:add', {
                    'form': '*'
                })
            }),
            ('auth:add:rrule', {
                'role': 'creator',
                'rule': ('node:tag:add', {
                    'tag': '*'
                })
            }),
            ('auth:add:rrule', {
                'role': 'creator',
                'rule': ('node:prop:set', {
                    'form': '*',
                    'prop': '*'
                })
            }),
            ('auth:add:role', {
                'role': 'deleter'
            }),
            ('auth:add:rrule', {
                'role': 'deleter',
                'rule': ('node:del', {
                    'form': '*'
                })
            }),
            ('auth:add:rrule', {
                'role': 'deleter',
                'rule': ('node:del', {
                    'form': '*'
                })
            }),
            ('auth:add:rrule', {
                'role': 'deleter',
                'rule': ('node:tag:del', {
                    'tag': '*'
                })
            }),
            ('auth:add:rrule', {
                'role': 'deleter',
                'rule': ('node:prop:set', {
                    'form': '*',
                    'prop': '*'
                })
            }),
            ('auth:add:urole', {
                'user': '******',
                'role': 'creator'
            }),
            ('auth:add:urole', {
                'user': '******',
                'role': 'deleter'
            }),
        )

        with self.getDirCore(conf=conf) as core:
            s_scope.set('syn:core', core)
            dirn = s_scope.get('dirn')
            writeCerts(dirn)
            cafile = os.path.join(dirn, 'ca.crt')
            keyfile = os.path.join(dirn, 'server.key')
            certfile = os.path.join(dirn, 'server.crt')
            userkey = os.path.join(dirn, 'user.key')
            usercrt = os.path.join(dirn, 'user.crt')
            rootkey = os.path.join(dirn, 'root.key')
            rootcrt = os.path.join(dirn, 'root.crt')
            with s_daemon.Daemon() as dmon:
                s_scope.set('syn:dmon', dmon)
                dmon.share('core', core)
                link = dmon.listen(
                    'ssl://*****:*****@localhost/core'
                user_prox = s_telepath.openurl(
                    url,
                    port=port,
                    cafile=cafile,
                    keyfile=userkey,
                    certfile=usercrt)  # type: s_cores_common.CoreApi
                root_prox = s_telepath.openurl(
                    url,
                    port=port,
                    cafile=cafile,
                    keyfile=rootkey,
                    certfile=rootcrt)  # type: s_cores_common.CoreApi

                if configure_roles:
                    for mesg in amesgs:
                        isok, retn = root_prox.authReact(mesg)
                        s_common.reqok(isok, retn)

                try:
                    yield user_prox, root_prox
                finally:
                    user_prox.fini()
                    root_prox.fini()