How to use the synapse.exc function in synapse

To help you get started, we’ve selected a few synapse examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vertexproject / synapse / synapse / servers / cell.py View on Github external
async def getCell(outp,
                  celldir,
                  ctorpath,
                  httpport,
                  telepath,
                  name=None,
                  ):

    outp.printf(f'Resolving cellpath: {ctorpath}')

    ctor = s_dyndeps.getDynLocal(ctorpath)
    if ctor is None:
        raise s_exc.NoSuchCtor(name=ctorpath,
                               mesg='No Cell ctor found.')

    outp.printf(f'starting cell: {celldir}')

    cell = await ctor.anit(celldir)

    try:

        outp.printf(f'...cell API (telepath): {telepath}')
        await cell.dmon.listen(telepath)

        outp.printf(f'...cell API (https): {httpport}')
        await cell.addHttpsPort(httpport)

        if name:
            outp.printf(f'...cell additional share name: {name}')
github vertexproject / synapse / synapse / axon.py View on Github external
async def _finish(self, keep_going):
        if self.hashing is None:
            # Ignore inocuous calls to finish or finishFile if there weren't any writes.
            return
        if self.finished:
            raise s_exc.AxonUploaderFinished
        if self.uploader is None:
            return
        hashval = self.hashing.digest()
        self.hashing = None
        if await self.item.wants([hashval]) == []:
            await self.uploader.cancelFile()
            return

        if keep_going:
            retn = await self.uploader.finishFile()
            await self.item._executor_nowait(self.item._addloc, self.bsid, hashval)
        else:
            self.finished = True
            retn = await self.uploader.finish()
            if retn[1] is not None and retn[1] != hashval:
                # The BlobStor and the Axon don't agree on the hash?!
github vertexproject / synapse / synapse / cortex.py View on Github external
async def delLayer(self, iden):
        layr = self.layers.get(iden, None)
        if layr is None:
            raise s_exc.NoSuchLayer(iden=iden)

        for view in self.views.values():
            if layr in view.layers:
                raise s_exc.LayerInUse(iden=iden)

        del self.layers[iden]

        await self.hive.pop(('cortex', 'layers', iden))

        # TODO: actually delete the storage for the data
        await layr.fini()
github vertexproject / synapse / synapse / lib / certdir.py View on Github external
Args:
            name (str): The name of the user keypair.
            outp (synapse.lib.output.Output): The output buffer.

        Examples:
            Make the PKC12 object for user "myuser":

                myuserpkcs12 = cdir.genClientCert('myuser')

        Returns:
            OpenSSL.crypto.PKCS12: The PKCS #12 archive.
        '''
        ucert = self.getUserCert(name)
        if not ucert:
            raise s_exc.NoSuchFile('missing User cert')

        cacert = self._loadCertPath(self._getCaPath(ucert))
        if not cacert:
            raise s_exc.NoSuchFile('missing CA cert')

        ukey = self.getUserKey(name)
        if not ukey:
            raise s_exc.NoSuchFile('missing User private key')

        ccert = crypto.PKCS12()
        ccert.set_friendlyname(name.encode('utf-8'))
        ccert.set_ca_certificates([cacert])
        ccert.set_certificate(ucert)
        ccert.set_privatekey(ukey)

        crtpath = self._saveP12To(ccert, 'users', '%s.p12' % name)
github vertexproject / synapse / synapse / lib / lmdbslab.py View on Github external
def status(self, name):

        meta = self.queues.get(name)
        if meta is None:
            mesg = f'No queue named {name}'
            raise s_exc.NoSuchName(mesg=mesg, name=name)

        return {
            'name': name,
            'meta': meta,
            'size': self.sizes.get(name),
            'offs': self.offsets.get(name),
        }
github vertexproject / synapse / synapse / tools / cellauth.py View on Github external
async def main(argv, outprint=None):
    if outprint is None:   # pragma: no cover
        outprint = s_output.OutPut()
    global outp
    outp = outprint

    pars = makeargparser()
    try:
        opts = pars.parse_args(argv)
    except s_exc.ParserExit:
        return -1

    return await opts.func(opts)
github vertexproject / synapse / synapse / axon.py View on Github external
async def clone_and_next():
                    ''' Get the async generator and the first item of that generator '''
                    genr = await blobstor.clone(cur_offset, timeout=CLONE_TIMEOUT, include_contents=False)
                    try:
                        if genr is None:
                            # This shouldn't be possible...
                            return None, None
                        it = genr.__aiter__()
                        first_item = await it.__anext__()
                        return it, first_item
                    except (StopAsyncIteration, s_exc.SynErr):
                        return None, None
github vertexproject / synapse / synapse / lib / stormtypes.py View on Github external
def toprim(valu, path=None):

    if isinstance(valu, (str, tuple, list, dict, int)) or valu is None:
        return valu

    if isinstance(valu, Prim):
        return valu.value()

    if isinstance(valu, s_node.Node):
        return valu.ndef[1]

    mesg = 'Unable to convert object to Storm primitive.'
    raise s_exc.NoSuchType(mesg=mesg, name=valu.__class__.__name__)
github vertexproject / synapse / synapse / cortex.py View on Github external
def addStormCmd(self, ctor):
        '''
        Add a synapse.lib.storm.Cmd class to the cortex.
        '''
        if not s_grammar.isCmdName(ctor.name):
            raise s_exc.BadCmdName(name=ctor.name)

        self.stormcmds[ctor.name] = ctor
github vertexproject / synapse / synapse / lib / snap.py View on Github external
If a props dictionary is provided, it may be mutated during node construction.

        Returns:
            s_node.Node: A Node object. It may return None if the snap is unable to add or lift the node.
        '''

        try:

            fnib = self._getNodeFnib(name, valu)
            retn = await self._addNodeFnib(fnib, props=props)
            return retn

        except asyncio.CancelledError: # pragma: no cover
            raise

        except s_exc.SynErr as e:
            mesg = f'Error adding node: {name} {valu!r} {props!r}'
            mesg = ', '.join((mesg, e.get('mesg', '')))
            info = e.items()
            info.pop('mesg', None)
            await self._raiseOnStrict(e.__class__, mesg, **info)

        except Exception:

            mesg = f'Error adding node: {name} {valu!r} {props!r}'
            logger.exception(mesg)
            if self.strict:
                raise

            return None