def delete_dataset(key=None) -> DeleteDatasetResponse: """ Delete dataset """ config = ThreatExchangeConfig.getx(str(key)) hmaconfig.delete_config(config) return DeleteDatasetResponse(response="The privacy group is deleted")
def test_delete(self): a_config = config.HMAConfig("a") config.create_config(a_config) self.assertEqual({c.name for c in config.HMAConfig.get_all()}, {"a"}) config.delete_config(a_config) self.assertEqual({c.name for c in config.HMAConfig.get_all()}, set()) self.assertEqual(None, config.HMAConfig.get("a"))
def update_dataset(request: UpdateDatasetRequest) -> Dataset: """ Update dataset values: fetcher_active, write_back, and matcher_active. """ config = ThreatExchangeConfig.getx(str(request.privacy_group_id)) config.fetcher_active = request.fetcher_active config.write_back = request.write_back config.matcher_active = request.matcher_active updated_config = hmaconfig.update_config(config).__dict__ updated_config["privacy_group_id"] = updated_config["name"] additional_config = AdditionalMatchSettingsConfig.get( str(request.privacy_group_id)) if request.pdq_match_threshold: if additional_config: additional_config.pdq_match_threshold = int( request.pdq_match_threshold) hmaconfig.update_config(additional_config) else: additional_config = AdditionalMatchSettingsConfig( str(request.privacy_group_id), int(request.pdq_match_threshold)) hmaconfig.create_config(additional_config) elif additional_config: # pdq_match_threshold was set and now should be removed hmaconfig.delete_config(additional_config) return Dataset.from_dict(updated_config)
def delete_match_settings(key=None, ) -> MatchSettingsUpdateResponse: """ Delete a match settings config for a given privacy_group_id """ if config := AdditionalMatchSettingsConfig.get(str(key)): hmaconfig.delete_config(config) return MatchSettingsUpdateResponse( f"match_settings deleted for pg_id {key}")
def test_get_all(self): @dataclass class GetAllConfig(config.HMAConfig): a: int = 1 b: str = "a" c: t.List[str] = field(default_factory=list) configs_to_make = [ GetAllConfig("a", a=2), GetAllConfig("b", b="b"), GetAllConfig("c", c=["a", "b", "c"]), ] made_configs = [] self.assertCountEqual(made_configs, GetAllConfig.get_all()) for c in configs_to_make: config.create_config(c) made_configs.append(c) self.assertCountEqual(made_configs, GetAllConfig.get_all()) config.delete_config(made_configs[-1]) made_configs = made_configs[:-1] self.assertCountEqual(made_configs, GetAllConfig.get_all())