Package: irmacl-async
IRMA is an asynchronous and customizable analysis system for suspicious files.
This repository is a subproject of IRMA and contains the source code for IRMA
API client.Irmacl-async requirespython 3.6+and an IRMA server withAPI version 3.
The exact expected version is defined inAAPI.IRMA_VERSION.InstallationFrom the sources, clone the repository and run$pipinstall.Or with pip just run$pipinstallirmacl-asyncConfigurationIrmacl-async configuration is done with aConfigobject that should be
given toAAPIat initialisation. The details of expected configuration is
available withhelp(Config). AConfigobject can be initialized from an
irma.yml file, which is a yaml file containing the parameters of aConfigobject. All parameters are optional.api_endpoint:"https://172.16.1.30/api/v3"verify:trueca:/etc/irma/ca.crtcert:/etc/irma/client.crtkey:/etc/irma/client.keysubmitter:kiosksubmitter_id:kiosk-D205irma.yml is searched in these locations in following order:environment variableIRMA_CONFcurrent directoryuser home directoryglobal directory/etc/irmaOnce you set up a working irma.yml settings file, you could run tests on your
running IRMA server:$pythonsetup.pytestUsageIrmacl-async is an asynchronous library. It is meant to ease the development of
python code that communicates with an IRMA server.Hello world>>>importasyncio>>>fromirmacl_asyncimportAAPI>>>>>>asyncdefmain():...asyncwithAAPI()asapi:...resp=awaitapi.about()...print(resp['version'])...>>>loop=asyncio.get_event_loop()>>>loop.run_until_complete(main())v2.2.3-20-g06a29b45Themaincoroutine just prints the version of the IRMA server counterpart.
There is few things to notice in this example.First, an async context pattern must be opened to create a session and perform
requests. Moreover, AAPI will check the version of IRMA and prints a warning if
it mismatches the expected one (apicheck=Falseto prevent this behavior).
Irmacl-async usesaiohttp.ClientSessionin backend, you can setAAPI().sessionmanually at your own risks but it is not recommenced.Second,api.aboutdoes not return a result but aFuturethat needs to
be awaited before being able to get its result.Finally, themaincoroutine cannot just be called as a regular function but
needs to be awaited from another coroutine or run into an event loop.Basic usage>>>importasyncio>>>frompathlibimportPath>>>fromirmacl_asyncimportAAPI>>>>>>asyncdefscandir(directory):...files=(pforpindirectory.iterdir()ifp.is_file())...asyncwithAAPI()asapi:...scan=awaitapi.scans.scan(files,linger=True)...res=awaitAAPI.fetchall(api.scans.results,scan=scan)...files=[api.files.get(fe.file)forfeinres]...returnawaitasyncio.gather(*files)...>>>loop=asyncio.get_event_loop()>>>d=Path("irmacl_async/tests/functionals/samples")>>>loop.run_until_complete(scandir(d))[FileExt.d13ab478-b24e-43a2-a51a-38c10355e929, ...]Thescandircoroutine is a bit more complex and benefits from the
asynchronicity of the irmacl-async library. It scans the contents of a
directory and wait for the result (linger=True). Then, it queries all
results of the scan.api.scans.resultsreturns a page of result, so, use it
with thefetchallhelper to get all pages at once.  Then, for each result
it queries information about the file itself. Instead of aforloop, that
would query the files one at a time, it usesasyncio.gather.  Finally it
waits for every request to be complete and returns the results.ReferencesAAPIEvery method is -or at least should be- fully documented, usehelp(AAPI)orhelp(AAPI().files)to get a exhaustive list of every available method and
their parameters.Objectsirmacl_async makes a heavy use ofirma-sharedto handle deserialisation and
objects construction.CoverageCoverage is available onhttps://irma.doc.qb/irma-shared/coverage. Check the
deployed branch in the title of the page.OtherDocumentationThe full IRMA documentation is availableon Read The Docs Website.Getting helpJoin the #qb_irma channel on irc.freenode.net. Lots of helpful people hang out
there.Contribute to IRMAIRMA is an ambitious project. Make yourself known on the #qb_irma channel on
irc.freenode.net. We will be please to greet you and to find a way to get you
involved in the project.