Skip to content

Commit a453237

Browse files
replaced class Config by ConfigDict
1 parent 5abb8e0 commit a453237

File tree

8 files changed

+28
-44
lines changed

8 files changed

+28
-44
lines changed

contentctl/actions/detection_testing/infrastructures/DetectionTestingInfrastructure.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from shutil import copyfile
1515
from typing import Union, Optional
1616

17-
from pydantic import BaseModel, PrivateAttr, Field, dataclasses
17+
from pydantic import ConfigDict, BaseModel, PrivateAttr, Field, dataclasses
1818
import requests # type: ignore
1919
import splunklib.client as client # type: ignore
2020
from splunklib.binding import HTTPError # type: ignore
@@ -49,9 +49,7 @@ class SetupTestGroupResults(BaseModel):
4949
success: bool = True
5050
duration: float = 0
5151
start_time: float
52-
53-
class Config:
54-
arbitrary_types_allowed = True
52+
model_config = ConfigDict(arbitrary_types_allowed=True)
5553

5654

5755
class CleanupTestGroupResults(BaseModel):
@@ -86,9 +84,7 @@ class DetectionTestingInfrastructure(BaseModel, abc.ABC):
8684
_conn: client.Service = PrivateAttr()
8785
pbar: tqdm.tqdm = None
8886
start_time: Optional[float] = None
89-
90-
class Config:
91-
arbitrary_types_allowed = True
87+
model_config = ConfigDict(arbitrary_types_allowed=True)
9288

9389
def __init__(self, **data):
9490
super().__init__(**data)

contentctl/actions/detection_testing/views/DetectionTestingViewWeb.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import jinja2
88
import webbrowser
99
from threading import Thread
10+
from pydantic import ConfigDict
1011

1112
DEFAULT_WEB_UI_PORT = 7999
1213

@@ -100,9 +101,7 @@ def log_exception(*args, **kwargs):
100101
class DetectionTestingViewWeb(DetectionTestingView):
101102
bottleApp: Bottle = Bottle()
102103
server: SimpleWebServer = SimpleWebServer(host="0.0.0.0", port=DEFAULT_WEB_UI_PORT)
103-
104-
class Config:
105-
arbitrary_types_allowed = True
104+
model_config = ConfigDict(arbitrary_types_allowed=True)
106105

107106
def setup(self):
108107
self.bottleApp.route("/", callback=self.showStatus)

contentctl/enrichments/cve_enrichment.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import shelve
66
import time
77
from typing import Annotated, Any, Union, TYPE_CHECKING
8-
from pydantic import BaseModel,Field, computed_field
8+
from pydantic import ConfigDict, BaseModel,Field, computed_field
99
from decimal import Decimal
1010
from requests.exceptions import ReadTimeout
1111

@@ -33,12 +33,8 @@ class CveEnrichment(BaseModel):
3333
use_enrichment: bool = True
3434
cve_api_obj: Union[CVESearch,None] = None
3535

36-
37-
class Config:
38-
# Arbitrary_types are allowed to let us use the CVESearch Object
39-
arbitrary_types_allowed = True
40-
frozen = True
41-
36+
# Arbitrary_types are allowed to let us use the CVESearch Object
37+
model_config = ConfigDict(arbitrary_types_allowed=True, frozen=True)
4238

4339
@staticmethod
4440
def getCveEnrichment(config:validate, timeout_seconds:int=10, force_disable_enrichment:bool=True)->CveEnrichment:

contentctl/objects/base_test_result.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import Union, Any
22
from enum import Enum
33

4-
from pydantic import BaseModel
4+
from pydantic import ConfigDict, BaseModel
55
from splunklib.data import Record
66

77
from contentctl.helper.utils import Utils
@@ -51,12 +51,9 @@ class BaseTestResult(BaseModel):
5151

5252
# The Splunk endpoint URL
5353
sid_link: Union[None, str] = None
54-
55-
class Config:
56-
validate_assignment = True
57-
58-
# Needed to allow for embedding of Exceptions in the model
59-
arbitrary_types_allowed = True
54+
55+
# Needed to allow for embedding of Exceptions in the model
56+
model_config = ConfigDict(validate_assignment=True, arbitrary_types_allowed=True)
6057

6158
@property
6259
def passed(self) -> bool:

contentctl/objects/correlation_search.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from typing import Union, Optional, Any
55
from enum import Enum
66

7-
from pydantic import BaseModel, validator, Field, PrivateAttr
7+
from pydantic import ConfigDict, BaseModel, computed_field, Field, PrivateAttr
88
from splunklib.results import JSONResultsReader, Message # type: ignore
99
from splunklib.binding import HTTPError, ResponseReader # type: ignore
1010
import splunklib.client as splunklib # type: ignore
@@ -177,10 +177,9 @@ class PbarData(BaseModel):
177177
pbar: tqdm
178178
fq_test_name: str
179179
start_time: float
180-
181-
class Config:
182-
# needed to support the tqdm type
183-
arbitrary_types_allowed = True
180+
181+
# needed to support the tqdm type
182+
model_config = ConfigDict(arbitrary_types_allowed=True)
184183

185184

186185
class CorrelationSearch(BaseModel):
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pydantic import BaseModel
1+
from pydantic import ConfigDict, BaseModel
22

33
from contentctl.objects.detection import Detection
44

@@ -10,11 +10,10 @@ class NotableEvent(BaseModel):
1010

1111
# The search ID that found that generated this risk event
1212
orig_sid: str
13-
14-
class Config:
15-
# Allowing fields that aren't explicitly defined to be passed since some of the risk event's
16-
# fields vary depending on the SPL which generated them
17-
extra = 'allow'
13+
14+
# Allowing fields that aren't explicitly defined to be passed since some of the risk event's
15+
# fields vary depending on the SPL which generated them
16+
model_config = ConfigDict(extra='allow')
1817

1918
def validate_against_detection(self, detection: Detection) -> None:
2019
raise NotImplementedError()

contentctl/objects/risk_event.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import re
22
from typing import Union, Optional
33

4-
from pydantic import BaseModel, Field, PrivateAttr, field_validator
4+
from pydantic import ConfigDict, BaseModel, Field, PrivateAttr, field_validator
55

66
from contentctl.objects.errors import ValidationFailed
77
from contentctl.objects.detection import Detection
@@ -61,11 +61,10 @@ class RiskEvent(BaseModel):
6161

6262
# Private attribute caching the observable this RiskEvent is mapped to
6363
_matched_observable: Optional[Observable] = PrivateAttr(default=None)
64-
65-
class Config:
66-
# Allowing fields that aren't explicitly defined to be passed since some of the risk event's
67-
# fields vary depending on the SPL which generated them
68-
extra = "allow"
64+
65+
# Allowing fields that aren't explicitly defined to be passed since some of the risk event's
66+
# fields vary depending on the SPL which generated them
67+
model_config = ConfigDict(extra="allow")
6968

7069
@field_validator("annotations_mitre_attack", "analyticstories", mode="before")
7170
@classmethod

contentctl/objects/ssa_detection.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import string
44
import requests
55
import time
6-
from pydantic import BaseModel, validator, root_validator
6+
from pydantic import ConfigDict, BaseModel, validator, root_validator
77
from dataclasses import dataclass
88
from datetime import datetime
99
from typing import Union
@@ -59,8 +59,7 @@ class SSADetection(BaseModel):
5959
# raise ValueError('name is longer then 67 chars: ' + v)
6060
# return v
6161

62-
class Config:
63-
use_enum_values = True
62+
model_config = ConfigDict(use_enum_values=True)
6463

6564
'''
6665
@validator("name")

0 commit comments

Comments
 (0)