Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

D assistant take 2 #355

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c65e501
progress towards d assistant. not working yet
pyth0n1c Jan 23, 2025
c6503b8
Merge branch 'main' into d_assistant_take_2
pyth0n1c Jan 23, 2025
4283eb2
progress towards deprecation assistant,
pyth0n1c Jan 24, 2025
5258a6a
Merge branch 'main' into d_assistant_take_2
pyth0n1c Jan 29, 2025
c942cca
more progress on
pyth0n1c Jan 29, 2025
c5067ee
Huge cleanup around object construction
pyth0n1c Feb 3, 2025
4dc2a01
Merge branch 'main' into d_assistant_take_2
pyth0n1c Feb 14, 2025
ebbc02f
cleanup director. add containing folder
pyth0n1c Feb 17, 2025
5f5f43c
Merge branch 'main' into d_assistant_take_2
pyth0n1c Feb 22, 2025
28af8e8
clean up the director a bit
pyth0n1c Feb 24, 2025
1448eb0
remove duplcate line at
pyth0n1c Feb 25, 2025
9acf456
A number of improvements and restructuring of
pyth0n1c Feb 26, 2025
a378482
fix deprecation file name
pyth0n1c Feb 26, 2025
bfdc941
Merge branch 'main' into d_assistant_take_2
pyth0n1c Feb 26, 2025
c37084c
More deprecation progress
pyth0n1c Mar 4, 2025
fd86570
more deprecation progress
pyth0n1c Mar 6, 2025
1565de2
Merge branch 'main' into d_assistant_take_2
pyth0n1c Mar 10, 2025
697910e
We are now generating a deprecation CSV in
pyth0n1c Mar 10, 2025
68e1d32
More progress on writing deprecation CSV to
pyth0n1c Mar 10, 2025
d488456
progress on exceptions for content
pyth0n1c Mar 10, 2025
12152cd
better deprecation failure error strings
pyth0n1c Mar 10, 2025
a70c3e7
roll back status removed and remove
pyth0n1c Mar 17, 2025
f64095c
Don't try to populate Investigations
pyth0n1c Mar 18, 2025
e6bce99
Many changes to meet new structure/naming
pyth0n1c Mar 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 25 additions & 9 deletions contentctl/actions/build.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import datetime
import json
import pathlib
import shutil

import uuid
from dataclasses import dataclass

from contentctl.input.director import DirectorOutputDto
from contentctl.objects.config import build
from contentctl.objects.lookup import CSVLookup, Lookup_Type
from contentctl.output.api_json_output import ApiJsonOutput
from contentctl.output.conf_output import ConfOutput
from contentctl.output.conf_writer import ConfWriter
from contentctl.output.api_json_output import ApiJsonOutput
from contentctl.output.data_source_writer import DataSourceWriter
from contentctl.objects.lookup import CSVLookup, Lookup_Type
import pathlib
import json
import datetime
import uuid

from contentctl.objects.config import build


@dataclass(frozen=True)
@@ -46,9 +44,27 @@
/ "data_sources.csv"
)

if input_dto.director_output_dto.deprecation_documentation is not None:
input_dto.director_output_dto.deprecation_documentation.writeDeprecationCSV(
input_dto.config.app,
input_dto.config.getBuildDir() / "deprecation_info.csv",
)

deprecation_lookup_fake_yml_path = (

Check failure on line 53 in contentctl/actions/build.py

GitHub Actions / lint

Ruff (F841)

contentctl/actions/build.py:53:13: F841 Local variable `deprecation_lookup_fake_yml_path` is assigned to but never used
input_dto.config.getPackageDirectoryPath()
/ "lookups"
/ "deprecated_content.yml"
)

DataSourceWriter.writeDataSourceCsv(
input_dto.director_output_dto.data_sources, data_sources_lookup_csv_path
)
deprecation_lookup_csv_path = (

Check failure on line 62 in contentctl/actions/build.py

GitHub Actions / lint

Ruff (F841)

contentctl/actions/build.py:62:13: F841 Local variable `deprecation_lookup_csv_path` is assigned to but never used
input_dto.config.getPackageDirectoryPath()
/ "lookups"
/ "deprecated_content.csv"
)

input_dto.director_output_dto.addContentToDictMappings(
CSVLookup.model_construct(
name="data_sources",
11 changes: 6 additions & 5 deletions contentctl/actions/validate.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import pathlib

from contentctl.input.director import Director, DirectorOutputDto
from contentctl.objects.config import validate
from contentctl.enrichments.attack_enrichment import AttackEnrichment
from contentctl.enrichments.cve_enrichment import CveEnrichment
from contentctl.objects.atomic import AtomicEnrichment
from contentctl.objects.lookup import FileBackedLookup
from contentctl.helper.splunk_app import SplunkApp
from contentctl.helper.utils import Utils
from contentctl.input.director import Director, DirectorOutputDto
from contentctl.objects.atomic import AtomicEnrichment
from contentctl.objects.config import validate
from contentctl.objects.data_source import DataSource
from contentctl.helper.splunk_app import SplunkApp
from contentctl.objects.lookup import FileBackedLookup


class Validate:
@@ -27,6 +27,7 @@ def execute(self, input_dto: validate) -> DirectorOutputDto:
[],
[],
[],
[],
)

director = Director(director_output_dto)
35 changes: 15 additions & 20 deletions contentctl/helper/utils.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,34 @@
import os
import git
import shutil
import requests
import pathlib
import random
import shutil
import string
from math import ceil
from timeit import default_timer
import pathlib
from typing import TYPE_CHECKING, Tuple, Union

from typing import Union, Tuple
import git
import requests
import tqdm
from math import ceil

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from contentctl.objects.security_content_object import SecurityContentObject
from contentctl.objects.security_content_object import SecurityContentObject

from contentctl.objects.security_content_object import SecurityContentObject

TOTAL_BYTES = 0
ALWAYS_PULL = True


class Utils:
@staticmethod
def get_all_yml_files_from_directory(path: str) -> list[pathlib.Path]:
listOfFiles: list[pathlib.Path] = []
base_path = pathlib.Path(path)
if not base_path.exists():
return listOfFiles
for dirpath, dirnames, filenames in os.walk(path):
for file in filenames:
if file.endswith(".yml"):
listOfFiles.append(pathlib.Path(os.path.join(dirpath, file)))
def get_all_yml_files_from_directory(path: pathlib.Path) -> list[pathlib.Path]:
if not path.exists():
raise FileNotFoundError(
f"Trying to find content files in the directory {path}, but it does not exist. "
"It is not mandatory to have content in this directory, but it must exist"
)

return sorted(listOfFiles)
return sorted(pathlib.Path(yml_path) for yml_path in path.glob("**/*.yml"))

@staticmethod
def get_security_content_files_from_directory(
@@ -490,3 +484,4 @@ def getPercent(numerator: float, denominator: float, decimal_places: int) -> str
ratio = numerator / denominator
percent = ratio * 100
return Utils.getFixedWidth(percent, decimal_places) + "%"
return Utils.getFixedWidth(percent, decimal_places) + "%"
Loading