Skip to content

Commit

Permalink
Merge pull request #77 from intezer/feature/docs
Browse files Browse the repository at this point in the history
docs: add documentation to some classes
  • Loading branch information
davidt99 authored Feb 22, 2023
2 parents d1b4ad1 + 8d2fd6a commit ae8bbdb
Show file tree
Hide file tree
Showing 21 changed files with 481 additions and 92 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
![PyPI](https://img.shields.io/pypi/v/intezer_sdk)
![Build](https://github.com/intezer/analyze-python-sdk/actions/workflows/test.yml/badge.svg)
# Intezer SDK

Basic SDK for Intezer Analyze API 2.0

[View full API documentation](https://analyze.intezer.com/api/docs/documentation) (Notice - You must be logged in to Intezer Analyze to access the documentation)
The SDK wraps Intezer Analyze API 2.0 ([View full API documentation](https://analyze.intezer.com/api-docs.html))

Currently, the following options are available in the SDK:

Expand All @@ -29,7 +28,7 @@ pip install intezer-sdk
### Set global api key
Before using the SDK functionality we should set the api key:
```python
api.set_global_api('<api_key>')
api.set_global_api('<api_key>')
```

### Analyze By File
Expand Down Expand Up @@ -142,7 +141,7 @@ index_id = index.index_id

### Get Latest File Analysis
```python
analysis = get_latest_analysis(file_hash: <file_sha256>)
analysis = FileAnalysis.from_latest_hash_analysis(file_hash: <file_sha256>)
result = analysis.result()
```

Expand Down
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
34 changes: 34 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = 'Intezer Python SDK'
copyright = '2023, Intezer'
author = 'Intezer'

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.autosummary',
# 'sphinx.ext.viewcode',
# 'sphinx.ext.napoleon'
]

templates_path = ['_templates']
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']

import os
import sys
sys.path.insert(0, os.path.abspath('..'))

# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = 'sphinx_rtd_theme'
html_static_path = ['_static']
45 changes: 45 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
.. Intezer Python SDK documentation master file, created by
sphinx-quickstart on Wed Feb 8 13:33:44 2023.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to Intezer Python SDK's documentation!
==============================================


GitHub (code repository, issues): https://github.com/intezer//analyze-python-sdk

PyPI (installable, stable distributions): https://pypi.org/project/intezer-sdk. You can install Injector using pip::

pip install intezer-sdk

Intezer SDK works with CPython 3.6+ .

The SDK wraps Intezer Analyze API 2.0 (`View full API documentation <https://analyze.intezer.com/api-docs.html>`_)

Setup
#####
Intezer works with global api configuration configured with and API key

.. code-block:: python
api.set_global_api('<api_key>')
Basic Usage
===========


.. toctree::
:maxdepth: 2
:caption: Contents:

modules



Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
128 changes: 128 additions & 0 deletions docs/intezer_sdk.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
intezer\_sdk package
====================

Submodules
----------

intezer\_sdk.account module
-------------------------------------

.. automodule:: intezer_sdk.account
:members:
:undoc-members:
:show-inheritance:

intezer\_sdk.analyses\_history module
-------------------------------------

.. automodule:: intezer_sdk.analyses_history
:members:
:undoc-members:
:show-inheritance:
:exclude-members: generate_analyses_history_filter

intezer\_sdk.analyses\_results module
-------------------------------------

.. automodule:: intezer_sdk.analyses_results
:members:
:undoc-members:
:show-inheritance:

intezer\_sdk.analysis module
----------------------------

.. automodule:: intezer_sdk.analysis
:members:
:undoc-members:
:show-inheritance:
:exclude-members: get_url_analysis_by_id, get_latest_analysis, get_file_analysis_by_id, get_analysis_by_id

intezer\_sdk.api module
-----------------------

.. automodule:: intezer_sdk.api
:members:
:undoc-members:
:show-inheritance:
:exclude-members: IntezerApi, raise_for_status

intezer\_sdk.base\_analysis module
----------------------------------

.. automodule:: intezer_sdk.base_analysis
:members:
:undoc-members:
:show-inheritance:

intezer\_sdk.consts module
--------------------------

.. automodule:: intezer_sdk.consts
:members:
:undoc-members:
:show-inheritance:

intezer\_sdk.endpoint\_analysis module
--------------------------------------

.. automodule:: intezer_sdk.endpoint_analysis
:members:
:undoc-members:
:show-inheritance:

intezer\_sdk.errors module
--------------------------

.. automodule:: intezer_sdk.errors
:members:
:undoc-members:
:show-inheritance:

intezer\_sdk.family module
--------------------------

.. automodule:: intezer_sdk.family
:members:
:undoc-members:
:show-inheritance:

intezer\_sdk.index module
-------------------------

.. automodule:: intezer_sdk.index
:members:
:undoc-members:
:show-inheritance:

intezer\_sdk.operation module
-----------------------------

.. automodule:: intezer_sdk.operation
:members:
:undoc-members:
:show-inheritance:

intezer\_sdk.sub\_analysis module
---------------------------------

.. automodule:: intezer_sdk.sub_analysis
:members:
:undoc-members:
:show-inheritance:

intezer\_sdk.util module
------------------------

.. automodule:: intezer_sdk.util
:members:
:undoc-members:
:show-inheritance:

Module contents
---------------

.. automodule:: intezer_sdk
:members:
:undoc-members:
:show-inheritance:
35 changes: 35 additions & 0 deletions docs/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=.
set BUILDDIR=_build

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.https://www.sphinx-doc.org/
exit /b 1
)

if "%1" == "" goto help

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
7 changes: 7 additions & 0 deletions docs/modules.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
intezer_sdk
===========

.. toctree::
:maxdepth: 4

intezer_sdk
2 changes: 2 additions & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sphinx
sphinx-rtd-theme
1 change: 1 addition & 0 deletions examples/sentinel_one_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,4 @@ def query_threats(next_time_query: Optional[datetime.datetime]):
else:
print('error: the following arguments are required: subcommand')
sys.exit(1)

11 changes: 5 additions & 6 deletions intezer_sdk/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,17 +290,16 @@ def get_string_related_samples_by_id(self,

return response.json()['result_url']

def get_url_result(self, url: str) -> Optional[Response]:
def get_url_result(self, url: str) -> dict:
response = self.api.request_with_refresh_expired_access_token('GET', url)

raise_for_status(response)
result = response.json()

response_json = response.json()
if 'error' in result:
raise errors.IntezerError(f'response error: {result["error"]}')

if 'error' in response_json:
raise errors.IntezerError(f'response error: {response_json["error"]}')

return response
return result

def download_file_by_sha256(self, sha256: str, path: str = None, output_stream: IO = None) -> None:
if not path and not output_stream:
Expand Down
28 changes: 28 additions & 0 deletions intezer_sdk/_operation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import datetime
from typing import Dict
from typing import Optional
from typing import Union

from intezer_sdk._api import IntezerApi
from intezer_sdk.operation import Operation


def handle_operation(operations: Dict[str, Operation],
api: IntezerApi,
operation: str,
result_url: str,
wait: Union[bool, int],
wait_timeout: Optional[datetime.timedelta]) -> Operation:
if operation not in operations:
operations[operation] = Operation(result_url, operation, api=api.api)

if wait:
if isinstance(wait, bool):
operations[operation].wait_for_completion(sleep_before_first_check=True,
wait_timeout=wait_timeout)
else:
operations[operation].wait_for_completion(wait,
sleep_before_first_check=True,
wait_timeout=wait_timeout)

return operations[operation]
Loading

0 comments on commit ae8bbdb

Please sign in to comment.