Skip to content

Commit

Permalink
fixup! feat(glimps): add view token to analysis result
Browse files Browse the repository at this point in the history
  • Loading branch information
glimps-glv committed Nov 18, 2024
1 parent f7d04c4 commit 25d44f3
Show file tree
Hide file tree
Showing 13 changed files with 169 additions and 262 deletions.
9 changes: 5 additions & 4 deletions Glimps/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Waitfor action : submit a file to Glimps detect and wit for analysis to finish
- Get status action : get Glimps detect profile status
- export submission : export analysis result in a given format and layout
- Waitfor action: submit a file to GLIMPS detect and wait for analysis to finish
- Get status action: get GLIMPS detect profile status
- Export submission: export analysis result in a given format and layout

### Changed

- use Glimps py-gdetect client to perform actions
- Upgrade sekoia-automation-sdk
- Use GLIMPS py-gdetect client to perform actions

## 2024-05-28 - 1.13.0

Expand Down
4 changes: 2 additions & 2 deletions Glimps/glimps/base.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from sekoia_automation.action import Action
from gdetect import Client, GDetectError
from functools import cached_property
from glimps.models import GlimpsModule
from glimps.models import GLIMPSModule


class GLIMPSAction(Action):
module: GlimpsModule
module: GLIMPSModule

@cached_property
def gdetect_client(self):
Expand Down
8 changes: 4 additions & 4 deletions Glimps/glimps/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
from typing_extensions import TypedDict, NotRequired


class GlimpsConfiguration(BaseModel):
class GLIMPSConfiguration(BaseModel):
api_key: str = Field(..., secret=True, description="Glimps detect token")
base_url: str = Field(..., description="Glimps detect url")


class GlimpsModule(Module):
configuration: GlimpsConfiguration
class GLIMPSModule(Module):
configuration: GLIMPSConfiguration


class SubmitArgument(BaseModel):
Expand Down Expand Up @@ -100,7 +100,7 @@ class AnalysisDetails(BaseModel):
special_status_code: int = Field(
description="special error code, 0 means no special case"
)
uuid: str = Field(description="Unique analysis identifier")
uuid: str = Field(description="unique analysis identifier")
sha256: str = Field(description="string hex encoded input file SHA256")
sha1: str = Field(description="string hex encoded input file SHA1")
md5: str = Field(description="string hex encoded input file MD5")
Expand Down
4 changes: 2 additions & 2 deletions Glimps/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from glimps.models import GlimpsModule
from glimps.models import GLIMPSModule

from glimps.get_status_action import GetStatus
from glimps.submit_file_to_be_analysed_action import WaitForFile
Expand All @@ -9,7 +9,7 @@


if __name__ == "__main__":
module = GlimpsModule()
module = GLIMPSModule()
module.register(GetStatus, "GetStatus")
module.register(WaitForFile, "WaitForFile")
module.register(ExportSubmission, "ExportSubmission")
Expand Down
2 changes: 1 addition & 1 deletion Glimps/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"description": "[Glimps](https://www.glimps.fr/) offers a DeepLearning solution to detect, analyze and classify malwares. It enables faster responses during incidents with a detailed understanding of the threat",
"version": "1.14.0",
"configuration": {
"title": "GlimpsConfiguration",
"title": "GLIMPSConfiguration",
"type": "object",
"properties": {
"api_key": {
Expand Down
262 changes: 79 additions & 183 deletions Glimps/poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Glimps/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ authors = []

[tool.poetry.dependencies]
python = ">=3.10,<3.12"
sekoia-automation-sdk = "^1.13.0"
sekoia-automation-sdk = "^1.17.0"
tenacity = "*"
gdetect = "^0.7.0"
gdetect = "^0.8.0"

[tool.poetry.dev-dependencies]
pytest = "*"
Expand Down
8 changes: 4 additions & 4 deletions Glimps/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from glimps.retrieve_analysis_action import RetrieveAnalysis
from glimps.search_analysis_by_sha256_action import SearchPreviousAnalysis
from glimps.submit_file_to_be_analysed_action import WaitForFile
from glimps.models import GlimpsConfiguration
from glimps.models import GLIMPSConfiguration


@pytest.fixture(scope="session")
Expand All @@ -30,7 +30,7 @@ def symphony_storage():
@pytest.fixture(scope="session")
def set_up_retrieve_analysis_action(token):
action = RetrieveAnalysis()
action.module.configuration = GlimpsConfiguration(
action.module.configuration = GLIMPSConfiguration(
api_key=token, base_url="https://gmalware.ggp.glimps.re"
)
return action
Expand All @@ -39,7 +39,7 @@ def set_up_retrieve_analysis_action(token):
@pytest.fixture(scope="session")
def set_up_search_analysis_action(token):
action = SearchPreviousAnalysis()
action.module.configuration = GlimpsConfiguration(
action.module.configuration = GLIMPSConfiguration(
api_key=token, base_url="https://gmalware.ggp.glimps.re"
)
return action
Expand All @@ -48,7 +48,7 @@ def set_up_search_analysis_action(token):
@pytest.fixture(scope="session")
def set_up_wait_for_action(token, symphony_storage):
action = WaitForFile(data_path=symphony_storage)
action.module.configuration = GlimpsConfiguration(
action.module.configuration = GLIMPSConfiguration(
api_key=token, base_url="https://gmalware.ggp.glimps.re"
)
return action
Expand Down
76 changes: 39 additions & 37 deletions Glimps/tests/test_export.py
Original file line number Diff line number Diff line change
@@ -1,54 +1,56 @@
import pytest
from glimps.models import (
GlimpsConfiguration,
GLIMPSConfiguration,
ExportSubmissionArguments,
)
from glimps.export_action import ExportSubmission
from unittest.mock import patch
from gdetect import GDetectError
from pydantic.error_wrappers import ValidationError
# import os
# from glimps.submit_file_to_be_analysed_action import (
# WaitForFile,
# WaitForResultArgument,
# AnalysisResponse,
# )
import os
from glimps.submit_file_to_be_analysed_action import (
WaitForFile,
WaitForResultArgument,
AnalysisResponse,
)

test_base_url = "https://gmalware.ggp.glimps.re"


# NB: GGP lite version doesn't yet allow to export result analysis
# @pytest.mark.skipif("'GLIMPS_API_KEY' not in os.environ.keys()")
# def test_integration_get_status(add_file_to_storage):
# symphony_storage, file, _ = add_file_to_storage
# module_configuration = GlimpsConfiguration(
# api_key=os.environ["GLIMPS_API_KEY"],
# base_url=test_base_url,
# )

# prepare = WaitForFile(data_path=symphony_storage)
# prepare.module.configuration = module_configuration

# arguments = WaitForResultArgument(file_name=file)
# response: AnalysisResponse = prepare.run(arguments)
# assert response is not None
# assert response.get("analysis").get("status") is True
# assert response.get("analysis").get("uuid") != ""

# action = ExportSubmission()
# action.module.configuration = module_configuration
# args = ExportSubmissionArguments(
# uuid=response.get("analysis").get("uuid"), format="csv", layout="en"
# )

# response: bytes = action.run(args)
# assert response is not None
# assert response.decode("utf-8") != ""
@pytest.mark.skipif(
"{'GLIMPS_API_KEY', 'GLIMPS_API_URL'}.issubset(os.environ.keys()) == False"
)
def test_integration_get_export(add_file_to_storage):
symphony_storage, file, _ = add_file_to_storage
module_configuration = GLIMPSConfiguration(
api_key=os.environ["GLIMPS_API_KEY"],
base_url=os.environ["GLIMPS_API_URL"],
)

prepare = WaitForFile(data_path=symphony_storage)
prepare.module.configuration = module_configuration

arguments = WaitForResultArgument(file_name=file)
response: AnalysisResponse = prepare.run(arguments)
assert response is not None
assert response.get("analysis").get("status") is True
assert response.get("analysis").get("uuid") != ""

action = ExportSubmission()
action.module.configuration = module_configuration
args = ExportSubmissionArguments(
uuid=response.get("analysis").get("uuid"), format="csv", layout="en"
)

response: bytes = action.run(args)
assert response is not None
assert response.decode("utf-8") != ""


def test_export_succeed(token):
action = ExportSubmission()
action.module.configuration = GlimpsConfiguration(
action.module.configuration = GLIMPSConfiguration(
api_key=token, base_url=test_base_url
)
uuid = "1da0cb84-c5cc-4832-8882-4a7e9df11ed2"
Expand All @@ -64,7 +66,7 @@ def test_export_succeed(token):

def test_export_error(token):
action = ExportSubmission()
action.module.configuration = GlimpsConfiguration(
action.module.configuration = GLIMPSConfiguration(
api_key=token, base_url=test_base_url
)
uuid = "1da0cb84-c5cc-4832-8882-4a7e9df11ed2"
Expand All @@ -78,7 +80,7 @@ def test_export_error(token):

def test_export_bad_format(token):
action = ExportSubmission()
action.module.configuration = GlimpsConfiguration(
action.module.configuration = GLIMPSConfiguration(
api_key=token, base_url=test_base_url
)
uuid = "1da0cb84-c5cc-4832-8882-4a7e9df11ed2"
Expand All @@ -88,7 +90,7 @@ def test_export_bad_format(token):

def test_export_bad_layout(token):
action = ExportSubmission()
action.module.configuration = GlimpsConfiguration(
action.module.configuration = GLIMPSConfiguration(
api_key=token, base_url=test_base_url
)
uuid = "1da0cb84-c5cc-4832-8882-4a7e9df11ed2"
Expand Down
12 changes: 7 additions & 5 deletions Glimps/tests/test_get_status.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import pytest
import os
import json
from glimps.models import GlimpsConfiguration, ProfileStatus
from glimps.models import GLIMPSConfiguration, ProfileStatus
from glimps.get_status_action import GetStatus
from unittest.mock import patch
import requests


@pytest.mark.skipif("'GLIMPS_API_KEY' not in os.environ.keys()")
@pytest.mark.skipif(
"{'GLIMPS_API_KEY', 'GLIMPS_API_URL'}.issubset(os.environ.keys()) == False"
)
def test_integration_get_status():
action = GetStatus()
action.module.configuration = GlimpsConfiguration(
action.module.configuration = GLIMPSConfiguration(
api_key=os.environ["GLIMPS_API_KEY"], base_url="https://gmalware.ggp.glimps.re"
)

Expand All @@ -21,7 +23,7 @@ def test_integration_get_status():

def test_get_status_error(token):
action = GetStatus()
action.module.configuration = GlimpsConfiguration(
action.module.configuration = GLIMPSConfiguration(
api_key=token, base_url="https://gmalware.ggp.glimps.re"
)

Expand All @@ -40,7 +42,7 @@ def test_get_status_error(token):

def test_get_status_ok(token):
action = GetStatus()
action.module.configuration = GlimpsConfiguration(
action.module.configuration = GLIMPSConfiguration(
api_key=token, base_url="https://gmalware.ggp.glimps.re"
)

Expand Down
10 changes: 6 additions & 4 deletions Glimps/tests/test_retrieve_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@
SubmitArgument,
SubmitResponse,
AnalysisResponse,
GlimpsConfiguration,
GLIMPSConfiguration,
GetAnalysisByUUIDArgument,
)
from gdetect import BadUUIDError


@pytest.mark.skipif("'GLIMPS_API_KEY' not in os.environ.keys()")
@pytest.mark.skipif(
"{'GLIMPS_API_KEY', 'GLIMPS_API_URL'}.issubset(os.environ.keys()) == False"
)
def test_integration_retrieve_analysis(add_file_to_storage):
symphony_storage, file, _ = add_file_to_storage
module_configuration = GlimpsConfiguration(
module_configuration = GLIMPSConfiguration(
api_key=os.environ["GLIMPS_API_KEY"],
base_url="https://gmalware.ggp.glimps.re",
base_url=os.environ["GLIMPS_API_URL"],
)
prepare = SubmitFile(data_path=symphony_storage)
prepare.module.configuration = module_configuration
Expand Down
10 changes: 6 additions & 4 deletions Glimps/tests/test_search_analysis_by_sha256.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@
SubmitArgument,
SubmitResponse,
AnalysisResponse,
GlimpsConfiguration,
GLIMPSConfiguration,
SearchAnalysisBySha256Argument,
)
from gdetect import BadSHA256Error


@pytest.mark.skipif("'GLIMPS_API_KEY' not in os.environ.keys()")
@pytest.mark.skipif(
"{'GLIMPS_API_KEY', 'GLIMPS_API_URL'}.issubset(os.environ.keys()) == False"
)
def test_integration_search_analysis(add_file_to_storage):
symphony_storage, file, sha256 = add_file_to_storage
module_configuration = GlimpsConfiguration(
api_key=os.environ["GLIMPS_API_KEY"], base_url="https://gmalware.ggp.glimps.re"
module_configuration = GLIMPSConfiguration(
api_key=os.environ["GLIMPS_API_KEY"], base_url=os.environ["GLIMPS_API_URL"]
)
prepare = SubmitFile(data_path=symphony_storage)
prepare.module.configuration = module_configuration
Expand Down
Loading

0 comments on commit 25d44f3

Please sign in to comment.