Skip to content

Commit

Permalink
Merge pull request #316 from bsummers-tc/main
Browse files Browse the repository at this point in the history
API and logging updates
  • Loading branch information
bsummers-tc authored Jul 28, 2023
2 parents 59080c3 + 95897df commit 30dc147
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 12 deletions.
28 changes: 24 additions & 4 deletions release_notes.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
# Release Notes

### 4.0.1

- APP-4055 - [API] Updated v3 gen body to allow 0 and false in body
- APP-4056 - [API] Update Transforms to Support Email Group Type
- APP-4057 - [Logging] Add lock to sensitive filter to fix concurrent update exception

### 4.0.0

- APP-3910 - [TcEx] Updated typing hint to Python 3.11 standards
- APP-3911 - [TcEx] General code enhancement
- APP-3914 - [TcEx] Restructured code for better programming interface
- APP-3918 - [Inputs] Added App type specific models to use in app_inputs.py file in templates
- APP-3925 - [CLI] Split CLI tools into a new project (tcex-cli)

## 3.x

### 3.0.9

- APP-3943 - [API] Update Transforms to Support Email Group Type
- APP-3981 - [API] Updated v3 gen body to allow 0 and false in body
- APP-3972 - [Logging] Add lock to sensitive filter to fix concurrent update exception
- APP-3993 - [KVStore] Added Redis password support

### 3.0.8

- APP-3899 [CLI] Updated error handling on CLI when downloading template files
- APP-3900 [CLI] Updated proxy support for CLI
- APP-3906 [CLI] Don't create requirements.lock file if any errors occurred during tcex deps.
APP-3922 [API] Update TI Transforms to treat event_date field on some group types as a datetime transform.
- APP-3899 - [CLI] Updated error handling on CLI when downloading template files
- APP-3900 - [CLI] Updated proxy support for CLI
- APP-3906 - [CLI] Don't create requirements.lock file if any errors occurred during tcex deps.
APP-3922 - [API] Update TI Transforms to treat event_date field on some group types as a datetime transform.

### 3.0.7

Expand Down
2 changes: 1 addition & 1 deletion tcex/__metadata__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""TcEx Framework Module"""
__license__ = 'Apache-2.0'
__version__ = '4.0.0'
__version__ = '4.0.1'
5 changes: 4 additions & 1 deletion tcex/api/tc/ti_transform/model/transform_model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""TcEx Framework Module"""
"""Model Definition"""
# standard library
from collections.abc import Callable

Expand Down Expand Up @@ -149,6 +149,9 @@ class GroupTransformModel(TiTransformModel, extra=Extra.forbid):
from_addr: MetadataTransformModel | None = Field(None, description='')
score: MetadataTransformModel | None = Field(None, description='')
to_addr: MetadataTransformModel | None = Field(None, description='')
subject: MetadataTransformModel | None = Field(None, description='')
body: MetadataTransformModel | None = Field(None, description='')
header: MetadataTransformModel | None = Field(None, description='')
# event, incident
event_date: DatetimeTransformModel | None = Field(None, description='')
status: MetadataTransformModel | None = Field(None, description='')
Expand Down
5 changes: 4 additions & 1 deletion tcex/api/tc/ti_transform/transform_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,10 @@ def _process_group(self):
self._process_metadata('password', self.transform.password)

if self.transformed_item['type'] == 'Email':
self._process_metadata('body', self.transform.body)
self._process_metadata('from', self.transform.from_addr)
self._process_metadata('header', self.transform.header)
self._process_metadata('subject', self.transform.subject)
self._process_metadata('to', self.transform.to_addr)

if self.transformed_item['type'] in ('Event', 'Incident'):
Expand Down Expand Up @@ -404,7 +407,7 @@ def _process_security_labels(self, labels: list[SecurityLabelTransformModel]):
continue
# strip out None params so that required params are enforced and optional
# params with default values are respected.
self.add_security_label(**self.util.remove_none(kwargs))
self.add_security_label(**kwargs)

def _process_tags(self, tags: list[TagTransformModel]):
"""Process Tag data"""
Expand Down
2 changes: 1 addition & 1 deletion tcex/api/tc/v3/v3_model_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def _calculate_field_inclusion(

# METHOD RULE: If the current method is in the property "methods" list the
# field should be included when available.
if method in property_.get('methods', []) and value:
if method in property_.get('methods', []) and (value or value in [0, False]):
return True

# DEFAULT RULE -> Fields should not be included unless the match a previous rule.
Expand Down
12 changes: 8 additions & 4 deletions tcex/logger/sensitive_filter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""TcEx Framework Module"""
# standard library
import logging
from threading import Lock


class SensitiveFilter(logging.Filter):
Expand All @@ -10,12 +11,14 @@ def __init__(self, name=''):
"""Plug in a new filter to an existing formatter"""
super().__init__(name)
self._sensitive_registry = set()
self._lock = Lock()

def add(self, value: str):
"""Add sensitive value to registry."""
if value:
# don't add empty string
self._sensitive_registry.add(str(value))
with self._lock:
# don't add empty string
self._sensitive_registry.add(str(value))

def filter(self, record: logging.LogRecord) -> bool:
"""Filter the record"""
Expand All @@ -26,6 +29,7 @@ def filter(self, record: logging.LogRecord) -> bool:

def replace(self, obj: str):
"""Replace any sensitive data in the object if its a string"""
for replacement in self._sensitive_registry:
obj = obj.replace(replacement, '***')
with self._lock:
for replacement in self._sensitive_registry:
obj = obj.replace(replacement, '***')
return obj

0 comments on commit 30dc147

Please sign in to comment.