Skip to content

Commit d1c0912

Browse files
authored
Ianhelle/warning fixes 2024 02 11 (#752)
* Updates for new AML defaults * AML Tools updates: - removing unneeded functionality - adding warnings for unsupported kernel types * Fixing aml_tools tests for Python version * Adding method to check auth_methods in aml_tools * Fix to prevent queryprovider trying to load non-query yaml * Adding fix for handling of random yaml files reads as query files. * Fix if Azure.auth_methods key does not exist * Creating mypy warning suppressions and fixes. * Two more mypy issues in vtlookupv3 and proc_tree_build_mde
1 parent 63f96f3 commit d1c0912

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+317
-212
lines changed

msticpy/_version.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
"""Version file."""
2-
VERSION = "2.9.0"
2+
3+
VERSION = "2.10.0"

msticpy/analysis/anomalous_sequence/anomalous.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def score_sessions(
6060
raise MsticpyException(f'"{session_column}" should be a column in the `data`')
6161

6262
sessions_df = data.copy()
63-
sessions = sessions_df[session_column].values.tolist()
63+
sessions = sessions_df[session_column].values.tolist() # type: ignore
6464

6565
model = Model(sessions=sessions)
6666
model.train()

msticpy/analysis/anomalous_sequence/sessionize.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import pandas as pd
1212
from pandas.core.dtypes.dtypes import DatetimeTZDtype
1313

14+
# mypy: ignore-errors
15+
1416

1517
def sessionize_data(
1618
data: pd.DataFrame,

msticpy/analysis/eventcluster.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ def plot_cluster( # noqa: C901, MC0001
688688

689689
# pylint: disable=no-member
690690
# Spectral color map does exist
691-
colors = [cm.Spectral(each) for each in np.linspace(0, 1, len(unique_labels))]
691+
colors = [cm.Spectral(each) for each in np.linspace(0, 1, len(unique_labels))] # type: ignore
692692
# Number of clusters in labels, ignoring noise if present.
693693
n_clusters_ = len(set(labels)) - (1 if -1 in labels else 0)
694694
n_noise_ = list(labels).count(-1)
@@ -747,8 +747,8 @@ def plot_cluster( # noqa: C901, MC0001
747747
except IndexError:
748748
pass
749749

750-
plt.xlabel(xlabel)
751-
plt.ylabel(ylabel)
750+
plt.xlabel(xlabel) # type: ignore
751+
plt.ylabel(ylabel) # type: ignore
752752
plt.title(f"Estimated number of clusters: {n_clusters_}")
753753
plt.show()
754754
return plt

msticpy/analysis/outliers.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def plot_outlier_results(
126126

127127
plt.title(plt_title)
128128
# pylint: disable=no-member
129-
plt.contourf(xx, yy, z, cmap=plt.cm.Blues_r)
129+
plt.contourf(xx, yy, z, cmap=plt.cm.Blues_r) # type: ignore
130130

131131
b1 = plt.scatter(x[:, 0], x[:, 1], c="white", s=20, edgecolor="k")
132132
b2 = plt.scatter(x_predict[:, 0], x_predict[:, 1], c="green", s=40, edgecolor="k")
@@ -142,8 +142,8 @@ def plot_outlier_results(
142142

143143
plt.xlim((xp_min_x, xp_max_x))
144144
plt.ylim((xp_min_y, xp_max_y))
145-
plt.xlabel(feature_columns[0])
146-
plt.ylabel(feature_columns[1])
145+
plt.xlabel(feature_columns[0]) # type: ignore
146+
plt.ylabel(feature_columns[1]) # type: ignore
147147

148148
plt.legend(
149149
[b1, b2, c],
@@ -178,7 +178,7 @@ def remove_common_items(data: pd.DataFrame, columns: List[str]) -> pd.DataFrame:
178178
# pylint: disable=cell-var-from-loop
179179
for col in columns:
180180
filtered_df = filtered_df.filter(
181-
lambda x: (x[col].std() == 0 and x[col].count() > 10)
181+
lambda x: (x[col].std() == 0 and x[col].count() > 10) # type: ignore
182182
)
183183

184184
return filtered_df

msticpy/analysis/polling_detection.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,15 @@ def detect_polling(
202202
end = max(ts_col)
203203

204204
if not groupby:
205-
p_value, freq, interval = self._detect_polling_arr(ts_col, start, end)
205+
p_value, freq, interval = self._detect_polling_arr(ts_col, start, end) # type: ignore
206206

207207
self.data["p_value"] = p_value
208208
self.data["dominant_frequency"] = freq
209209
self.data["dominant_interval"] = interval
210210
else:
211211
grouped_results = self.data.groupby(groupby).apply(
212-
lambda x: self._detect_polling_arr(
213-
x[time_column], min(x[time_column]), max(x[time_column])
212+
lambda x: self._detect_polling_arr( # type: ignore
213+
x[time_column], min(x[time_column]), max(x[time_column]) # type: ignore
214214
)
215215
)
216216

msticpy/analysis/syslog_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def create_host_record(
5858
Details of the host data collected
5959
6060
"""
61-
host_entity = Host(src_event=syslog_df.iloc[0])
61+
host_entity = Host(src_event=syslog_df.iloc[0]) # type: ignore
6262
# Produce list of processes on the host that are not
6363
# part of a 'standard' linux distro
6464
_apps = syslog_df["ProcessName"].unique().tolist()
@@ -186,7 +186,7 @@ def cluster_syslog_logons_df(logon_events: pd.DataFrame) -> pd.DataFrame:
186186
if ses_start <= ses_close_time and ses_opened != 0:
187187
ses_opened += 1
188188
continue
189-
if ses_end < ses_start:
189+
if ses_end < ses_start: # type: ignore
190190
ses_closed += 1
191191
continue
192192
users.append(user)

msticpy/analysis/timeseries.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,8 @@ def extract_anomaly_periods(
360360
if not end_period:
361361
# If we're not already in an anomaly period
362362
# create start/end for a new one
363-
start_period = time - pd.Timedelta(period)
364-
end_period = time + pd.Timedelta(period)
363+
start_period = time - pd.Timedelta(period) # type: ignore
364+
end_period = time + pd.Timedelta(period) # type: ignore
365365
periods[start_period] = end_period
366366
elif (time - end_period) <= pd.Timedelta(
367367
period

msticpy/auth/cloud_mappings_offline.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@
4242
"sqlManagement": "https://management.core.windows.net:8443/",
4343
"microsoftGraphResourceId": "https://graph.microsoft.com/",
4444
"appInsightsResourceId": "https://api.applicationinsights.io",
45-
"appInsightsTelemetryChannelResourceId": "https://dc.applicationinsights.azure.com/v2/track",
45+
"appInsightsTelemetryChannelResourceId": (
46+
"https://dc.applicationinsights.azure.com/v2/track"
47+
),
4648
"attestationResourceId": "https://attest.azure.net",
4749
"synapseAnalyticsResourceId": "https://dev.azuresynapse.net",
4850
"logAnalyticsResourceId": "https://api.loganalytics.io",
@@ -81,7 +83,9 @@
8183
"sqlManagement": "https://management.core.usgovcloudapi.net:8443",
8284
"microsoftGraphResourceId": "https://graph.microsoft.us/",
8385
"appInsightsResourceId": "https://api.applicationinsights.us",
84-
"appInsightsTelemetryChannelResourceId": "https://dc.applicationinsights.us/v2/track",
86+
"appInsightsTelemetryChannelResourceId": (
87+
"https://dc.applicationinsights.us/v2/track"
88+
),
8589
"synapseAnalyticsResourceId": "https://dev.azuresynapse.usgovcloudapi.net",
8690
"logAnalyticsResourceId": "https://api.loganalytics.us",
8791
"ossrDbmsResourceId": "https://ossrdbms-aad.database.usgovcloudapi.net",
@@ -117,7 +121,9 @@
117121
"sqlManagement": "https://management.core.chinacloudapi.cn:8443",
118122
"microsoftGraphResourceId": "https://microsoftgraph.chinacloudapi.cn",
119123
"appInsightsResourceId": "https://api.applicationinsights.azure.cn",
120-
"appInsightsTelemetryChannelResourceId": "https://dc.applicationinsights.azure.cn/v2/track",
124+
"appInsightsTelemetryChannelResourceId": (
125+
"https://dc.applicationinsights.azure.cn/v2/track"
126+
),
121127
"synapseAnalyticsResourceId": "https://dev.azuresynapse.azure.cn",
122128
"logAnalyticsResourceId": "https://api.loganalytics.azure.cn",
123129
"ossrDbmsResourceId": "https://ossrdbms-aad.database.chinacloudapi.cn",

msticpy/common/data_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def ensure_df_datetimes(
4242
4343
"""
4444
if not columns:
45-
columns = list(data.filter(regex=".*[Tt]ime.*").columns)
45+
columns = list(data.filter(regex=".*[Tt]ime.*").columns) # type: ignore
4646
if isinstance(columns, str):
4747
columns = [columns]
4848
col_map = {

msticpy/common/pkg_config.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
import contextlib
1616
import numbers
1717
import os
18+
from importlib.resources import path
1819
from importlib.util import find_spec
1920
from pathlib import Path
2021
from typing import Any, Callable, Dict, Optional, Union
2122

2223
import httpx
23-
import pkg_resources
2424
import yaml
2525
from yaml.error import YAMLError
2626

@@ -218,7 +218,7 @@ def _del_config(setting_path: str, settings_dict) -> Any:
218218
return current_value
219219

220220

221-
def _read_config_file(config_file: str) -> Dict[str, Any]:
221+
def _read_config_file(config_file: Union[str, Path]) -> Dict[str, Any]:
222222
"""
223223
Read a yaml config definition file.
224224
@@ -270,10 +270,11 @@ def _override_config(base_config: Dict[str, Any], new_config: Dict[str, Any]):
270270

271271
def _get_default_config():
272272
"""Return the package default config file."""
273-
conf_file = None
273+
config_path = None
274274
package = "msticpy"
275275
try:
276-
conf_file = pkg_resources.resource_filename(package, _CONFIG_FILE)
276+
with path(package, _CONFIG_FILE) as config_path:
277+
return _read_config_file(config_path) if config_path else {}
277278
except ModuleNotFoundError as mod_err:
278279
# if all else fails we try to find the package default config somewhere
279280
# in the package tree - we use the first one we find
@@ -284,8 +285,8 @@ def _get_default_config():
284285
"msticpy package may be corrupted.",
285286
title=f"Package {_CONFIG_FILE} missing.",
286287
) from mod_err
287-
conf_file = next(iter(pkg_root.glob(f"**/{_CONFIG_FILE}")))
288-
return _read_config_file(conf_file) if conf_file else {}
288+
config_path = next(iter(pkg_root.glob(f"**/{_CONFIG_FILE}")))
289+
return _read_config_file(config_path) if config_path else {}
289290

290291

291292
def _get_custom_config():

msticpy/config/ce_azure.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ class CEAzure(CESimpleSettings):
4646
This will override the cloud and its associated Authority and API endpoint URLs.
4747
4848
"""
49+
# fmt: off
4950
_HELP_URI = {
50-
"MSTICPy Package Configuration": (
51-
"https://msticpy.readthedocs.io/en/latest/getting_started/msticpyconfig.html"
52-
)
51+
"MSTICPy Package Configuration":
52+
"https://msticpy.readthedocs.io/en/latest/getting_started/msticpyconfig.html"
5353
}
54+
# fmt: on

msticpy/config/ce_data_providers.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ class CEDataProviders(CEProviders):
2929
"Data Providers": (
3030
"https://msticpy.readthedocs.io/en/latest/" + "DataAcquisition.html"
3131
),
32-
"Spunk": (
33-
"https://msticpy.readthedocs.io/en/latest/data_acquisition/SplunkProvider.html"
34-
),
32+
"Spunk": "https://msticpy.readthedocs.io/en/latest/data_acquisition/SplunkProvider.html",
3533
"Sumologic": (
3634
"https://github.com/microsoft/msticpy/blob/main/docs/notebooks/"
3735
"Sumologic-DataConnector.ipynb"

msticpy/config/ce_provider_base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ def _populate_edit_ctrls(
145145
prov_name=control_name or self._prov_ctrl_name,
146146
mp_controls=self.mp_controls,
147147
conf_path=self._COMP_PATH,
148-
prov_instance_name=self._select_prov_instance_name
149-
if not new_provider
150-
else "",
148+
prov_instance_name=(
149+
self._select_prov_instance_name if not new_provider else ""
150+
),
151151
)
152152
self.edit_frame.children = [self.edit_ctrls]
153153

msticpy/context/azure/azure_data.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -671,9 +671,11 @@ def get_network_details(
671671
id=network_id,
672672
private_ip=ip_addr.private_ip_address,
673673
private_ip_allocation=str(ip_addr.private_ip_allocation_method),
674-
public_ip=ip_addr.public_ip_address.ip_address
675-
if ip_addr.public_ip_address
676-
else None,
674+
public_ip=(
675+
ip_addr.public_ip_address.ip_address
676+
if ip_addr.public_ip_address
677+
else None
678+
),
677679
public_ip_allocation=(
678680
ip_addr.public_ip_address.public_ip_allocation_method
679681
if ip_addr.public_ip_address

msticpy/context/azure/sentinel_core.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,9 @@ def set_default_workspace(
321321
res_id_parts = parse_resource_id(ws_res_id)
322322
self.workspace_config = WorkspaceConfig.from_settings(
323323
{
324-
"WorkspaceName": self._default_workspace
325-
or res_id_parts["workspace_name"],
324+
"WorkspaceName": (
325+
self._default_workspace or res_id_parts["workspace_name"]
326+
),
326327
"SubscriptionId": res_id_parts["subscription_id"],
327328
"ResourceGroup": res_id_parts["resource_group"],
328329
}

msticpy/context/azure/sentinel_dynamic_summary_types.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,9 @@ def from_json(cls, data: Union[Dict[str, Any], str]) -> "DynamicSummary":
265265
) from json_err
266266
for raw_item in raw_content:
267267
summary_item_props = {
268-
_API_TO_CLS_MAP.get(name, name): pd.to_datetime(value)
269-
if name == "eventTimeUTC"
270-
else value
268+
_API_TO_CLS_MAP.get(name, name): (
269+
pd.to_datetime(value) if name == "eventTimeUTC" else value
270+
)
271271
for name, value in raw_item.items()
272272
}
273273
summary_items.append(DynamicSummaryItem(**summary_item_props))
@@ -462,7 +462,8 @@ def _(
462462
self.summary_items.append(
463463
DynamicSummaryItem(
464464
packed_content={
465-
key: _convert_data_types(value) for key, value in row.items()
465+
key: _convert_data_types(value) # type: ignore
466+
for key, value in row.items() # type: ignore
466467
},
467468
**summary_params,
468469
**kwargs, # pass remaining kwargs as summary item properties

msticpy/context/azure/sentinel_ti.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,9 +419,11 @@ def query_indicators(self, **kwargs) -> pd.DataFrame:
419419
def _build_additional_indicator_items(**kwargs) -> dict:
420420
"""Add in additional data items for indicators."""
421421
data_items = {
422-
"validFrom": kwargs["valid_from"].isoformat()
423-
if "valid_from" in kwargs
424-
else datetime.now().isoformat()
422+
"validFrom": (
423+
kwargs["valid_from"].isoformat()
424+
if "valid_from" in kwargs
425+
else datetime.now().isoformat()
426+
)
425427
}
426428
for item, value in kwargs.items():
427429
if item in _INDICATOR_ITEMS:

msticpy/context/azure/sentinel_watchlists.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,12 @@ def add_watchlist_item(
204204
current_df, item_series = current_items_values.align(
205205
pd.Series(new_item), axis=1, copy=False # type: ignore
206206
)
207-
if (current_df == item_series).all(axis=1).any() and overwrite:
207+
if (current_df == item_series).all(axis=1).any() and overwrite: # type: ignore
208208
watchlist_id = current_items[
209209
current_items.isin(list(new_item.values())).any(axis=1)
210210
]["properties.watchlistItemId"].iloc[0]
211211
# If not in watchlist already generate new ID
212-
elif not (current_df == item_series).all(axis=1).any():
212+
elif not (current_df == item_series).all(axis=1).any(): # type: ignore
213213
watchlist_id = str(uuid4())
214214
else:
215215
raise MsticpyUserError(

msticpy/context/contextproviders/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Context Providers sub-package."""
2+
23
from typing import Dict, Tuple
34

45
from ..._version import VERSION

0 commit comments

Comments
 (0)