Make update of block possible

This commit is contained in:
moanos [he/him] 2023-01-09 12:01:39 +01:00
parent 1197228650
commit 7f3154f515
2 changed files with 5 additions and 3 deletions

6
cli.py
View File

@ -21,14 +21,14 @@ def load_local_blocklist(filename: str) -> [Instance]:
return instances return instances
def blocklist_json_to_instances(blocklist_json): def blocklist_json_to_instances(blocklist_json: str):
instances = [] instances = []
for i in blocklist_json: for i in blocklist_json:
instances.append(Instance(i)) instances.append(Instance(i))
return instances return instances
def load_remote_blocklist(server, token): def load_remote_blocklist(server: str, token: str):
headers = { headers = {
f'Authorization': f'Bearer {token}', f'Authorization': f'Bearer {token}',
} }
@ -68,5 +68,7 @@ def cli():
diffs = Instance.list_diffs(local_blocklist, remote_blocklist) diffs = Instance.list_diffs(local_blocklist, remote_blocklist)
Instance.apply_blocks_from_diff(diffs, args.server, args.token) Instance.apply_blocks_from_diff(diffs, args.server, args.token)
if __name__ == "__main__": if __name__ == "__main__":
logging.basicConfig(level=logging.DEBUG)
cli() cli()

View File

@ -69,7 +69,7 @@ class Instance:
if block_id is None: if block_id is None:
response = requests.post(f'https://{server}/api/v1/admin/domain_blocks', data=data, headers=headers) response = requests.post(f'https://{server}/api/v1/admin/domain_blocks', data=data, headers=headers)
else: else:
response = requests.post(f'https://{server}/api/v1/admin/domain_blocks/{block_id}', data=data, headers=headers) response = requests.put(f'https://{server}/api/v1/admin/domain_blocks/{block_id}', data=data, headers=headers)
if response.status_code != 200: if response.status_code != 200:
raise ConnectionError(f"Could not apply block ({response.status_code}: {response.reason})") raise ConnectionError(f"Could not apply block ({response.status_code}: {response.reason})")