synapse.tools package

Subpackages

Submodules

synapse.tools.apikey module

async synapse.tools.apikey.main(argv, outp=<synapse.lib.output.OutPut object>)[source]
synapse.tools.apikey.printkey(outp, info, apikey=None)[source]

synapse.tools.autodoc module

class synapse.tools.autodoc.DocHelp(ctors, types, forms, props, univs)[source]

Bases: object

Helper to pre-compute all doc strings hierarchically

async synapse.tools.autodoc.docConfdefs(ctor)[source]
async synapse.tools.autodoc.docModel(outp, core)[source]
async synapse.tools.autodoc.docStormTypes()[source]
async synapse.tools.autodoc.docStormpkg(pkgpath)[source]
async synapse.tools.autodoc.docStormsvc(ctor)[source]
synapse.tools.autodoc.has_popts_data(props)[source]
synapse.tools.autodoc.lookupedgesforform(form: str, edges: List[Tuple[Tuple[str | None, str, str | None], Dict[str, str]]]) Dict[str, List[Tuple[Tuple[str | None, str, str | None], Dict[str, str]]]][source]
async synapse.tools.autodoc.main(argv, outp=None)[source]
synapse.tools.autodoc.makeargparser()[source]
synapse.tools.autodoc.processCtors(rst, dochelp, ctors)[source]
Parameters:
Returns:

None

synapse.tools.autodoc.processFormsProps(rst, dochelp, forms, univ_names, alledges)[source]
async synapse.tools.autodoc.processStormCmds(rst, pkgname, commands)[source]
Parameters:
  • rst (RstHelp)

  • pkgname (str)

  • commands (list)

Returns:

None

async synapse.tools.autodoc.processStormModules(rst, pkgname, modules)[source]
synapse.tools.autodoc.processTypes(rst, dochelp, types)[source]
Parameters:
Returns:

None

synapse.tools.autodoc.processUnivs(rst, dochelp, univs)[source]

synapse.tools.axon2axon module

async synapse.tools.axon2axon.main(argv, outp=<synapse.lib.output.OutPut object>)[source]

synapse.tools.backup module

synapse.tools.backup.backup(srcdir, dstdir, skipdirs=None)[source]

Create a backup of a Synapse application.

Parameters:
  • srcdir (str) – Path to the directory to backup.

  • dstdir (str) – Path to backup target directory.

  • skipdirs (list or None) – Optional list of relative directory name glob patterns to exclude from the backup.

Note

Running this method from the same process as a running user of the directory may lead to a segmentation fault

synapse.tools.backup.backup_lmdb(env: Environment, dstdir: str, txn=None)[source]
synapse.tools.backup.capturelmdbs(srcdir, skipdirs=None, onlydirs=None)[source]

A context manager that opens all the lmdb files under a srcdir and makes a read transaction. All transactions are aborted and environments closed when the context is exited.

Yields:

Dict[str, Tuple[lmdb.Environment, lmdb.Transaction]] – Maps path to environment, transaction

synapse.tools.backup.main(argv)[source]
synapse.tools.backup.parse_args(argv)[source]
synapse.tools.backup.txnbackup(lmdbinfo, srcdir, dstdir, skipdirs=None)[source]

Create a backup of a Synapse application under a (hopefully consistent) set of transactions.

Parameters:
  • lmdbinfo (Dict[str, Tuple[lmdb.Environment, lmdb.Transaction]]) – Maps of path to environment, transaction

  • srcdir (str) – Path to the directory to backup.

  • dstdir (str) – Path to backup target directory.

  • skipdirs (list or None) – Optional list of relative directory name glob patterns to exclude from the backup.

Note

Running this method from the same process as a running user of the directory may lead to a segmentation fault

synapse.tools.cellauth module

async synapse.tools.cellauth.handleList(opts)[source]
async synapse.tools.cellauth.handleModify(opts)[source]
async synapse.tools.cellauth.main(argv, outprint=None)[source]
synapse.tools.cellauth.makeargparser()[source]
async synapse.tools.cellauth.printuser(user, details=False, cell=None)[source]
synapse.tools.cellauth.reprrule(rule)[source]

synapse.tools.changelog module

class synapse.tools.changelog.ModelDiffer(current_model: dict, reference_model: dict)[source]

Bases: object

diffModl(outp: OutPut) dict | None[source]
async synapse.tools.changelog.format(opts: Namespace, outp: OutPut)[source]
async synapse.tools.changelog.gen(opts: Namespace, outp: OutPut)[source]
async synapse.tools.changelog.main(argv, outp=None)[source]
synapse.tools.changelog.makeargparser()[source]
async synapse.tools.changelog.model(opts: Namespace, outp: OutPut)[source]

synapse.tools.cmdr module

async synapse.tools.cmdr.main(argv)[source]
async synapse.tools.cmdr.runcmdr(argv, item)[source]

synapse.tools.csvtool module

async synapse.tools.csvtool.main(argv, outp=<synapse.lib.output.OutPut object>)[source]
synapse.tools.csvtool.makeargparser(outp)[source]
async synapse.tools.csvtool.runCsvExport(opts, outp, text, stormopts)[source]
async synapse.tools.csvtool.runCsvImport(opts, outp, text, stormopts)[source]

synapse.tools.easycert module

synapse.tools.easycert.main(argv, outp=None)[source]

synapse.tools.feed module

async synapse.tools.feed.addFeedData(core, outp, feedformat, debug=False, *paths, chunksize=1000, offset=0, viewiden=None)[source]
synapse.tools.feed.getItems(*paths)[source]
async synapse.tools.feed.main(argv, outp=None)[source]
synapse.tools.feed.makeargparser()[source]

synapse.tools.genpkg module

synapse.tools.genpkg.getStormStr(fn)[source]
synapse.tools.genpkg.loadOpticFiles(pkgdef, path)[source]
synapse.tools.genpkg.loadOpticWorkflows(pkgdef, path)[source]
synapse.tools.genpkg.loadPkgProto(path, opticdir=None, no_docs=False, readonly=False)[source]

Get a Storm Package definition from disk.

Parameters:
  • path (str) – Path to the package .yaml file on disk.

  • opticdir (str) – Path to optional Optic module code to add to the Storm Package.

  • no_docs (bool) – If true, omit inline documentation content if it is not present on disk.

  • readonly (bool) – If set, open files in read-only mode. If files are missing, that will raise a NoSuchFile exception.

Returns:

A Storm package definition.

Return type:

dict

async synapse.tools.genpkg.main(argv, outp=<synapse.lib.output.OutPut object>)[source]
synapse.tools.genpkg.tryLoadPkgProto(fp, opticdir=None, readonly=False)[source]

Try to get a Storm Package prototype from disk with or without inline documentation.

Parameters:
  • fp (str) – Path to the package .yaml file on disk.

  • opticdir (str) – Path to optional Optic module code to add to the Storm Package.

  • readonly (bool) – If set, open files in read-only mode. If files are missing, that will raise a NoSuchFile exception.

Returns:

A Storm package definition.

Return type:

dict

synapse.tools.guid module

synapse.tools.guid.main(argv, outp=None)[source]

synapse.tools.healthcheck module

synapse.tools.healthcheck.format_component(e, mesg: str) dict[source]
async synapse.tools.healthcheck.main(argv, outp=<synapse.lib.output.OutPut object>)[source]
synapse.tools.healthcheck.makeargparser()[source]
synapse.tools.healthcheck.serialize(ret)[source]

synapse.tools.json2mpk module

synapse.tools.json2mpk.getArgParser()[source]
synapse.tools.json2mpk.main(argv, outp=None)[source]

synapse.tools.livebackup module

async synapse.tools.livebackup.main(argv, outp=<synapse.lib.output.OutPut object>)[source]

synapse.tools.modrole module

async synapse.tools.modrole.main(argv, outp=<synapse.lib.output.OutPut object>)[source]
synapse.tools.modrole.printrole(role, outp)[source]

synapse.tools.moduser module

async synapse.tools.moduser.main(argv, outp=<synapse.lib.output.OutPut object>)[source]
synapse.tools.moduser.printuser(user, outp)[source]

synapse.tools.promote module

async synapse.tools.promote.main(argv, outp=<synapse.lib.output.OutPut object>)[source]

synapse.tools.pullfile module

async synapse.tools.pullfile.main(argv, outp=None)[source]
synapse.tools.pullfile.setup()[source]

synapse.tools.pushfile module

async synapse.tools.pushfile.main(argv, outp=None)[source]
synapse.tools.pushfile.makeargparser()[source]

synapse.tools.reload module

synapse.tools.reload.getArgParser()[source]
async synapse.tools.reload.main(argv, outp=<synapse.lib.output.OutPut object>)[source]

synapse.tools.rstorm module

async synapse.tools.rstorm.main(argv, outp=<synapse.lib.output.OutPut object>)[source]

synapse.tools.snapshot module

async synapse.tools.snapshot.main(argv, outp=<synapse.lib.output.OutPut object>)[source]

synapse.tools.storm module

class synapse.tools.storm.ExportCmd(cli, **opts)[source]

Bases: StormCliCmd

Export the results of a storm query into a nodes file.

Example

// Export nodes to a file !export dnsa.nodes { inet:fqdn#mynodes -> inet:dns:a }

// Export nodes to a file and only include specific tags !export fqdn.nodes { inet:fqdn#mynodes } –include-tags footag

getArgParser()[source]
async runCmdOpts(opts)[source]

Perform the command actions. Must be implemented by Cmd implementers.

Parameters:

opts (dict) – Options dictionary.

class synapse.tools.storm.HelpCmd(cli, **opts)[source]

Bases: CmdHelp

List interpreter extended commands and display help output.

Example

!help foocmd

class synapse.tools.storm.PullFileCmd(cli, **opts)[source]

Bases: StormCliCmd

Download a file by sha256 and store it locally.

Example

!pullfile c00adfcc316f8b00772cdbce2505b9ea539d74f42861801eceb1017a44344ed3 /path/to/savefile

getArgParser()[source]
async runCmdOpts(opts)[source]

Perform the command actions. Must be implemented by Cmd implementers.

Parameters:

opts (dict) – Options dictionary.

class synapse.tools.storm.PushFileCmd(cli, **opts)[source]

Bases: StormCliCmd

Upload a file and create a file:bytes node.

Example

!pushfile /path/to/file

getArgParser()[source]
async runCmdOpts(opts)[source]

Perform the command actions. Must be implemented by Cmd implementers.

Parameters:

opts (dict) – Options dictionary.

class synapse.tools.storm.QuitCmd(cli, **opts)[source]

Bases: CmdQuit

Quit the current command line interpreter.

Example

!quit

class synapse.tools.storm.RunFileCmd(cli, **opts)[source]

Bases: StormCliCmd

Run a local storm file.

Example

!runfile /path/to/file.storm

getArgParser()[source]
async runCmdOpts(opts)[source]

Perform the command actions. Must be implemented by Cmd implementers.

Parameters:

opts (dict) – Options dictionary.

class synapse.tools.storm.StormCli[source]

Bases: Cli

async handleErr(mesg)[source]
histfile = 'storm_history'
initCmdClasses()[source]
printf(mesg, addnl=True, color=None)[source]
async runCmdLine(line, opts=None)[source]

Run a single command line.

Parameters:

line (str) – Line to execute.

Examples

Execute the ‘woot’ command with the ‘help’ switch:

await cli.runCmdLine(‘woot –help’)

Returns:

Arbitrary data from the cmd class.

Return type:

object

async storm(text, opts=None)[source]
class synapse.tools.storm.StormCliCmd(cli, **opts)[source]

Bases: Cmd

getArgParser()[source]
getCmdOpts(text)[source]

Use the _cmd_syntax def to split/parse/normalize the cmd line.

Parameters:

text (str) – Command to process.

Notes

This is implemented independent of argparse (et al) due to the need for syntax aware argument splitting. Also, allows different split per command type

Returns:

An opts dictionary.

Return type:

dict

class synapse.tools.storm.StormCompleter(cli)[source]

Bases: Completer

get_completions(document, complete_event)[source]

This should be a generator that yields Completion instances.

If the generation of completions is something expensive (that takes a lot of time), consider wrapping this Completer class in a ThreadedCompleter. In that case, the completer algorithm runs in a background thread and completions will be displayed as soon as they arrive.

Parameters:
  • documentDocument instance.

  • complete_eventCompleteEvent instance.

async get_completions_async(document, complete_event)[source]

Asynchronous generator for completions. (Probably, you won’t have to override this.)

Asynchronous generator of Completion objects.

async load()[source]
synapse.tools.storm.cmplgenr(*genrs, prefix='')[source]

Iterate over all the generators/iterators passed in as args and return Completions from them. If prefix is specified, make sure the current item in the generator starts with the prefix value.

synapse.tools.storm.getArgParser()[source]
async synapse.tools.storm.main(argv, outp=<synapse.lib.output.OutPut object>)[source]