Skip to content

Commit 5682760

Browse files
authored
[hma] Switch to pytx copy of HMA interfaces (#1965)
1 parent f8953b5 commit 5682760

15 files changed

Lines changed: 151 additions & 553 deletions

File tree

hasher-matcher-actioner/src/OpenMediaMatch/app.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525

2626
from threatexchange.exchanges import auth
2727

28-
from OpenMediaMatch.storage import interface
28+
from threatexchange.storage.interfaces import SignalExchangeAPIConfig
29+
from OpenMediaMatch.storage.interface import IFlaskUnifiedStore
2930
from OpenMediaMatch.storage.postgres.impl import DefaultOMMStore
3031
from OpenMediaMatch.background_tasks import (
3132
build_index,
@@ -171,7 +172,7 @@ def create_app() -> OpenAPI:
171172
app.config["STORAGE_IFACE_INSTANCE"] = DefaultOMMStore()
172173
storage = app.config["STORAGE_IFACE_INSTANCE"]
173174
assert isinstance(
174-
storage, interface.IUnifiedStore
175+
storage, IFlaskUnifiedStore
175176
), "STORAGE_IFACE_INSTANCE is not an instance of IUnifiedStore"
176177

177178
_setup_task_logging(app.logger)
@@ -335,7 +336,7 @@ def build_indices():
335336
)
336337
@click.option("--unset", is_flag=True, help="clear credentials")
337338
def set_credentials(
338-
api_name: interface.SignalExchangeAPIConfig, from_str: str | None, unset: bool
339+
api_name: SignalExchangeAPIConfig, from_str: str | None, unset: bool
339340
) -> None:
340341
"""
341342
Persist credentials for apis.

hasher-matcher-actioner/src/OpenMediaMatch/background_tasks/build_index.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from OpenMediaMatch.background_tasks.development import get_apscheduler
1010
from OpenMediaMatch.persistence import get_storage
11-
from OpenMediaMatch.storage.interface import (
11+
from threatexchange.storage.interfaces import (
1212
ISignalTypeIndexStore,
1313
ISignalTypeConfigStore,
1414
IBankStore,

hasher-matcher-actioner/src/OpenMediaMatch/background_tasks/fetcher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
from OpenMediaMatch.background_tasks.development import get_apscheduler
1717
from OpenMediaMatch.persistence import get_storage
18-
from OpenMediaMatch.storage.interface import ISignalExchangeStore
18+
from threatexchange.storage.interfaces import ISignalExchangeStore
1919
from threatexchange.storage.interfaces import SignalTypeConfig
2020
from OpenMediaMatch.utils.time_utils import duration_to_human_str
2121

hasher-matcher-actioner/src/OpenMediaMatch/blueprints/curation.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@
2222
from OpenMediaMatch import persistence
2323
from OpenMediaMatch.utils import flask_utils
2424
from OpenMediaMatch.utils.exchange_schema import exchange_api_schema
25-
import OpenMediaMatch.storage.interface as iface
25+
from threatexchange.storage.interfaces import (
26+
BankConfig as StoreBankConfig,
27+
SignalTypeIndexBuildCheckpoint,
28+
)
29+
from OpenMediaMatch.storage.interface import BankContentConfig
2630
from OpenMediaMatch.blueprints import hashing
2731
from OpenMediaMatch.schemas.curation import (
2832
BankConfig,
@@ -108,8 +112,8 @@ def bank_create(body: BankCreateRequest):
108112
return jsonify(bank_create_impl(body.name, enabled_ratio)), 201
109113

110114

111-
def bank_create_impl(name: str, enabled_ratio: float = 1.0) -> iface.BankConfig:
112-
bank = iface.BankConfig(name=name, matching_enabled_ratio=enabled_ratio)
115+
def bank_create_impl(name: str, enabled_ratio: float = 1.0) -> StoreBankConfig:
116+
bank = StoreBankConfig(name=name, matching_enabled_ratio=enabled_ratio)
113117
try:
114118
persistence.get_storage().bank_update(bank, create=True)
115119
except ValueError as e:
@@ -356,7 +360,7 @@ def bank_add_content(path: BankPathParams):
356360

357361

358362
def _bank_add_signals(
359-
bank: iface.BankConfig,
363+
bank: StoreBankConfig,
360364
signal_type_to_signal_str: dict[str, str],
361365
metadata: t.Optional[BankedContentMetadata],
362366
note: t.Optional[str] = None,
@@ -383,9 +387,9 @@ def _bank_add_signals(
383387
if not user_metadata:
384388
user_metadata = None
385389

386-
content_config = iface.BankContentConfig(
390+
content_config = BankContentConfig(
387391
id=0,
388-
disable_until_ts=iface.BankContentConfig.ENABLED,
392+
disable_until_ts=BankContentConfig.ENABLED,
389393
collab_metadata={},
390394
original_media_uri=None,
391395
bank=bank,
@@ -855,9 +859,9 @@ def signal_type_index_status() -> dict[str, dict[str, t.Any]]:
855859
config.signal_type,
856860
)
857861
if tar is None:
858-
tar = iface.SignalTypeIndexBuildCheckpoint.get_empty()
862+
tar = SignalTypeIndexBuildCheckpoint.get_empty()
859863
if last is None:
860-
last = iface.SignalTypeIndexBuildCheckpoint.get_empty()
864+
last = SignalTypeIndexBuildCheckpoint.get_empty()
861865
ret[name] = {
862866
"db_size": tar.total_hash_count,
863867
"index_size": last.total_hash_count,

hasher-matcher-actioner/src/OpenMediaMatch/blueprints/matching.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@
2929
)
3030

3131
from OpenMediaMatch.background_tasks.development import get_apscheduler
32-
from OpenMediaMatch.storage import interface
32+
from threatexchange.storage.interfaces import (
33+
SignalTypeIndexBuildCheckpoint,
34+
ISignalTypeConfigStore,
35+
)
36+
from OpenMediaMatch.storage.interface import IFlaskUnifiedStore
3337
from OpenMediaMatch.blueprints import hashing
3438
from OpenMediaMatch.utils.flask_utils import (
3539
api_error_handler,
@@ -68,7 +72,7 @@ class MatchWithDistancePayload(t.TypedDict):
6872
class _SignalIndexInMemoryCache:
6973
signal_type: t.Type[SignalType]
7074
index: SignalTypeIndex[int]
71-
checkpoint: interface.SignalTypeIndexBuildCheckpoint
75+
checkpoint: SignalTypeIndexBuildCheckpoint
7276
last_check_ts: float
7377
sec_old_before_stale: int
7478

@@ -93,12 +97,12 @@ def get_initial(
9397
return cls(
9498
signal_type,
9599
signal_type.get_index_cls().build([]),
96-
interface.SignalTypeIndexBuildCheckpoint.get_empty(),
100+
SignalTypeIndexBuildCheckpoint.get_empty(),
97101
0,
98102
sec_old_before_stale,
99103
)
100104

101-
def reload_if_needed(self, store: interface.IUnifiedStore) -> None:
105+
def reload_if_needed(self, store: IFlaskUnifiedStore) -> None:
102106
now = time.time()
103107
# There's a race condition here, but it's unclear if we should solve it
104108
curr_checkpoint = store.get_last_index_build_checkpoint(self.signal_type)
@@ -255,7 +259,7 @@ def _checkpoint_timestamp_to_str(checkpoint: int) -> str:
255259

256260

257261
def _validate_and_transform_signal_type(
258-
signal_type_name: str, storage: interface.ISignalTypeConfigStore
262+
signal_type_name: str, storage: ISignalTypeConfigStore
259263
) -> type[SignalType]:
260264
"""
261265
Accepts a signal type name and returns the corresponding signal type class,

hasher-matcher-actioner/src/OpenMediaMatch/persistence.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818

1919
from flask import current_app
2020

21-
from OpenMediaMatch.storage.interface import IUnifiedStore
21+
from OpenMediaMatch.storage.interface import IFlaskUnifiedStore
2222

2323

24-
def get_storage() -> IUnifiedStore:
24+
def get_storage() -> IFlaskUnifiedStore:
2525
"""
2626
Get the storage interface for the current app flask instance
2727
2828
Holdover from earlier development, maybe remove someday.
2929
"""
30-
return t.cast(IUnifiedStore, current_app.config["STORAGE_IFACE_INSTANCE"])
30+
return t.cast(IFlaskUnifiedStore, current_app.config["STORAGE_IFACE_INSTANCE"])

0 commit comments

Comments
 (0)