"""ows-sound-recordings connections.""" import config from src.common.connectors import ows_sound_recordings def post_rule(obj_type, batched_updates): """Upsert fingerprint rules.""" json = {} for update in batched_updates: obj_id = update['obj_id'] rules = update['rules'] json_rules = [] for rule in rules: for territory in rule['territories']: json_rules.append( { 'territory': territory, 'policy': rule['policy'], 'service': rule['service'], 'start': rule['start'], 'end': None } ) json[obj_id] = json_rules response = ows_sound_recordings.call( verb='POST', path=f'/{obj_type}/bulk/rules', app_name=config.APPLICATION_NAME, environment=config.ENVIRONMENT, extra_args={ 'json': json, 'params': {'services': ','.join(config.SUPPORTED_SERVICES)}, }, headers={ 'Orchard-Identity-Id': config.ADMIN_IDENTITY_ID, 'Orchard-Profile-Id': config.ADMIN_PROFILE_ID, 'Orchard-Profile-Type': config.ADMIN_PROFILE_TYPE, }, retry_codes=[ 408, 502, 503, 504 ] ) return response.json()