Skip to content

Commit 0999270

Browse files
committed
Remove all usage of use_enum_values.
However, this has not received any testing yet.
1 parent 8f24494 commit 0999270

File tree

7 files changed

+20
-42
lines changed

7 files changed

+20
-42
lines changed

contentctl/objects/abstract_security_content_objects/detection_abstract.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@
5555
}
5656

5757

58-
# TODO (#266): disable the use_enum_values configuration
5958
class Detection_Abstract(SecurityContentObject):
60-
model_config = ConfigDict(use_enum_values=True)
6159
name:str = Field(...,max_length=CONTENTCTL_MAX_SEARCH_NAME_LENGTH)
6260
#contentType: SecurityContentType = SecurityContentType.detections
6361
type: AnalyticsType = Field(...)
@@ -210,7 +208,7 @@ def adjust_tests_and_groups(self) -> None:
210208
# https://docs.pydantic.dev/latest/api/config/#pydantic.config.ConfigDict.populate_by_name
211209

212210
# Skip tests for non-production detections
213-
if self.status != DetectionStatus.production.value: # type: ignore
211+
if self.status != DetectionStatus.production.value:
214212
self.skip_all_tests(f"TEST SKIPPED: Detection is non-production ({self.status})")
215213

216214
# Skip tests for detecton types like Correlation which are not supported via contentctl

contentctl/objects/abstract_security_content_objects/security_content_object_abstract.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@
3131
NO_FILE_NAME = "NO_FILE_NAME"
3232

3333

34-
# TODO (#266): disable the use_enum_values configuration
3534
class SecurityContentObject_Abstract(BaseModel, abc.ABC):
36-
model_config = ConfigDict(use_enum_values=True,validate_default=True)
35+
model_config = ConfigDict(validate_default=True)
3736

3837
name: str = Field(...,max_length=99)
3938
author: str = Field(...,max_length=255)

contentctl/objects/config.py

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@
3333
SPLUNKBASE_URL = "https://splunkbase.splunk.com/app/{uid}/release/{version}/download"
3434

3535

36-
# TODO (#266): disable the use_enum_values configuration
3736
class App_Base(BaseModel,ABC):
38-
model_config = ConfigDict(use_enum_values=True,validate_default=True, arbitrary_types_allowed=True)
37+
model_config = ConfigDict(validate_default=True, arbitrary_types_allowed=True)
3938
uid: Optional[int] = Field(default=None)
4039
title: str = Field(description="Human-readable name used by the app. This can have special characters.")
4140
appid: Optional[APPID_TYPE]= Field(default=None,description="Internal name used by your app. "
@@ -59,9 +58,8 @@ def ensureAppPathExists(self, config:test, stage_file:bool=False):
5958
config.getLocalAppDir().mkdir(parents=True)
6059

6160

62-
# TODO (#266): disable the use_enum_values configuration
6361
class TestApp(App_Base):
64-
model_config = ConfigDict(use_enum_values=True,validate_default=True, arbitrary_types_allowed=True)
62+
model_config = ConfigDict(validate_default=True, arbitrary_types_allowed=True)
6563
hardcoded_path: Optional[Union[FilePath,HttpUrl]] = Field(default=None, description="This may be a relative or absolute link to a file OR an HTTP URL linking to your app.")
6664

6765

@@ -99,9 +97,8 @@ def getApp(self, config:test,stage_file:bool=False)->str:
9997
return str(destination)
10098

10199

102-
# TODO (#266): disable the use_enum_values configuration
103100
class CustomApp(App_Base):
104-
model_config = ConfigDict(use_enum_values=True,validate_default=True, arbitrary_types_allowed=True)
101+
model_config = ConfigDict(validate_default=True, arbitrary_types_allowed=True)
105102
# Fields required for app.conf based on
106103
# https://docs.splunk.com/Documentation/Splunk/9.0.4/Admin/Appconf
107104
uid: int = Field(ge=2, lt=100000, default_factory=lambda:random.randint(20000,100000))
@@ -159,9 +156,8 @@ def getApp(self, config:test, stage_file=True)->str:
159156
verbose_print=True)
160157
return str(destination)
161158

162-
# TODO (#266): disable the use_enum_values configuration
163159
class Config_Base(BaseModel):
164-
model_config = ConfigDict(use_enum_values=True,validate_default=True, arbitrary_types_allowed=True)
160+
model_config = ConfigDict(validate_default=True, arbitrary_types_allowed=True)
165161

166162
path: DirectoryPath = Field(default=DirectoryPath("."), description="The root of your app.")
167163
app:CustomApp = Field(default_factory=CustomApp)
@@ -175,7 +171,7 @@ def serialize_path(path: DirectoryPath)->str:
175171
return str(path)
176172

177173
class init(Config_Base):
178-
model_config = ConfigDict(use_enum_values=True,validate_default=True, arbitrary_types_allowed=True)
174+
model_config = ConfigDict(validate_default=True, arbitrary_types_allowed=True)
179175
bare: bool = Field(default=False, description="contentctl normally provides some some example content "
180176
"(macros, stories, data_sources, and/or analytic stories). This option disables "
181177
"initialization with that additional contnet. Note that even if --bare is used, it "
@@ -184,9 +180,8 @@ class init(Config_Base):
184180
"the deployment/ directory (since it is not yet easily customizable).")
185181

186182

187-
# TODO (#266): disable the use_enum_values configuration
188183
class validate(Config_Base):
189-
model_config = ConfigDict(use_enum_values=True,validate_default=True, arbitrary_types_allowed=True)
184+
model_config = ConfigDict(validate_default=True, arbitrary_types_allowed=True)
190185
enrichments: bool = Field(default=False, description="Enable MITRE, APP, and CVE Enrichments. "\
191186
"This is useful when outputting a release build "\
192187
"and validating these values, but should otherwise "\
@@ -241,9 +236,8 @@ def getReportingPath(self)->pathlib.Path:
241236
return self.path/"reporting/"
242237

243238

244-
# TODO (#266): disable the use_enum_values configuration
245239
class build(validate):
246-
model_config = ConfigDict(use_enum_values=True,validate_default=True, arbitrary_types_allowed=True)
240+
model_config = ConfigDict(validate_default=True, arbitrary_types_allowed=True)
247241
build_path: DirectoryPath = Field(default=DirectoryPath("dist/"), title="Target path for all build outputs")
248242

249243
@field_serializer('build_path',when_used='always')
@@ -395,17 +389,15 @@ class new(Config_Base):
395389
type: NewContentType = Field(default=NewContentType.detection, description="Specify the type of content you would like to create.")
396390

397391

398-
# TODO (#266): disable the use_enum_values configuration
399392
class deploy_acs(inspect):
400-
model_config = ConfigDict(use_enum_values=True,validate_default=False, arbitrary_types_allowed=True)
393+
model_config = ConfigDict(validate_default=False, arbitrary_types_allowed=True)
401394
#ignore linter error
402395
splunk_cloud_jwt_token: str = Field(exclude=True, description="Splunk JWT used for performing ACS operations on a Splunk Cloud Instance")
403396
splunk_cloud_stack: str = Field(description="The name of your Splunk Cloud Stack")
404397

405398

406-
# TODO (#266): disable the use_enum_values configuration
407399
class Infrastructure(BaseModel):
408-
model_config = ConfigDict(use_enum_values=True,validate_default=True, arbitrary_types_allowed=True)
400+
model_config = ConfigDict(validate_default=True, arbitrary_types_allowed=True)
409401
splunk_app_username:str = Field(default="admin", description="Username for logging in to your Splunk Server")
410402
splunk_app_password:str = Field(exclude=True, default="password", description="Password for logging in to your Splunk Server.")
411403
instance_address:str = Field(..., description="Address of your splunk server.")
@@ -415,15 +407,13 @@ class Infrastructure(BaseModel):
415407
instance_name: str = Field(...)
416408

417409

418-
# TODO (#266): disable the use_enum_values configuration
419410
class Container(Infrastructure):
420-
model_config = ConfigDict(use_enum_values=True,validate_default=True, arbitrary_types_allowed=True)
411+
model_config = ConfigDict(validate_default=True, arbitrary_types_allowed=True)
421412
instance_address:str = Field(default="localhost", description="Address of your splunk server.")
422413

423414

424-
# TODO (#266): disable the use_enum_values configuration
425415
class ContainerSettings(BaseModel):
426-
model_config = ConfigDict(use_enum_values=True,validate_default=True, arbitrary_types_allowed=True)
416+
model_config = ConfigDict(validate_default=True, arbitrary_types_allowed=True)
427417
leave_running: bool = Field(default=True, description="Leave container running after it is first "
428418
"set up to speed up subsequent test runs.")
429419
num_containers: PositiveInt = Field(default=1, description="Number of containers to start in parallel. "
@@ -447,15 +437,13 @@ class All(BaseModel):
447437
pass
448438

449439

450-
# TODO (#266): disable the use_enum_values configuration
451440
class Changes(BaseModel):
452-
model_config = ConfigDict(use_enum_values=True,validate_default=True, arbitrary_types_allowed=True)
441+
model_config = ConfigDict(validate_default=True, arbitrary_types_allowed=True)
453442
target_branch:str = Field(...,description="The target branch to diff against. Note that this includes uncommitted changes in the working directory as well.")
454443

455444

456-
# TODO (#266): disable the use_enum_values configuration
457445
class Selected(BaseModel):
458-
model_config = ConfigDict(use_enum_values=True,validate_default=True, arbitrary_types_allowed=True)
446+
model_config = ConfigDict(validate_default=True, arbitrary_types_allowed=True)
459447
files:List[FilePath] = Field(...,description="List of detection files to test, separated by spaces.")
460448

461449
@field_serializer('files',when_used='always')
@@ -826,9 +814,8 @@ def getModeName(self)->str:
826814
return DetectionTestingMode.selected.value
827815

828816

829-
# TODO (#266): disable the use_enum_values configuration
830817
class test(test_common):
831-
model_config = ConfigDict(use_enum_values=True,validate_default=True, arbitrary_types_allowed=True)
818+
model_config = ConfigDict(validate_default=True, arbitrary_types_allowed=True)
832819
container_settings:ContainerSettings = ContainerSettings()
833820
test_instances: List[Container] = Field([], exclude = True, validate_default=True)
834821
splunk_api_username: Optional[str] = Field(default=None, exclude = True,description="Splunk API username used for running appinspect or installating apps from Splunkbase")
@@ -893,9 +880,8 @@ def getAppFilePath(self):
893880
TEST_ARGS_ENV = "CONTENTCTL_TEST_INFRASTRUCTURES"
894881

895882

896-
# TODO (#266): disable the use_enum_values configuration
897883
class test_servers(test_common):
898-
model_config = ConfigDict(use_enum_values=True,validate_default=True, arbitrary_types_allowed=True)
884+
model_config = ConfigDict(validate_default=True, arbitrary_types_allowed=True)
899885
test_instances:List[Infrastructure] = Field([],description="Test against one or more preconfigured servers.", validate_default=True)
900886
server_info:Optional[str] = Field(None, validate_default=True, description='String of pre-configured servers to use for testing. The list MUST be in the format:\n'
901887
'address,username,web_ui_port,hec_port,api_port;address_2,username_2,web_ui_port_2,hec_port_2,api_port_2'

contentctl/objects/detection_tags.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,9 @@
3535
from contentctl.objects.atomic import AtomicEnrichment, AtomicTest
3636
from contentctl.objects.annotated_types import MITRE_ATTACK_ID_TYPE, CVE_TYPE
3737

38-
# TODO (#266): disable the use_enum_values configuration
3938
class DetectionTags(BaseModel):
4039
# detection spec
41-
model_config = ConfigDict(use_enum_values=True, validate_default=False)
40+
model_config = ConfigDict(validate_default=False)
4241
analytic_story: list[Story] = Field(...)
4342
asset_type: AssetType = Field(...)
4443

contentctl/objects/investigation.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
)
1313
from contentctl.objects.config import CustomApp
1414

15-
# TODO (#266): disable the use_enum_values configuration
1615
class Investigation(SecurityContentObject):
17-
model_config = ConfigDict(use_enum_values=True,validate_default=False)
16+
model_config = ConfigDict(validate_default=False)
1817
type: str = Field(...,pattern="^Investigation$")
1918
datamodel: list[DataModel] = Field(...)
2019
name:str = Field(...,max_length=CONTENTCTL_MAX_SEARCH_NAME_LENGTH)

contentctl/objects/mitre_attack_enrichment.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,7 @@ def standardize_contributors(cls, contributors:list[str] | None) -> list[str]:
8383
return []
8484
return contributors
8585

86-
# TODO (#266): disable the use_enum_values configuration
8786
class MitreAttackEnrichment(BaseModel):
88-
ConfigDict(use_enum_values=True)
8987
mitre_attack_id: MITRE_ATTACK_ID_TYPE = Field(...)
9088
mitre_attack_technique: str = Field(...)
9189
mitre_attack_tactics: List[MitreTactics] = Field(...)

contentctl/objects/story_tags.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ class StoryUseCase(str,Enum):
1818
OTHER = "Other"
1919

2020

21-
# TODO (#266): disable the use_enum_values configuration
2221
class StoryTags(BaseModel):
23-
model_config = ConfigDict(extra='forbid', use_enum_values=True)
22+
model_config = ConfigDict(extra='forbid')
2423
category: List[StoryCategory] = Field(...,min_length=1)
2524
product: List[SecurityContentProductName] = Field(...,min_length=1)
2625
usecase: StoryUseCase = Field(...)

0 commit comments

Comments
 (0)