4 Commits

8 changed files with 52 additions and 37 deletions

View File

@@ -10,7 +10,7 @@ platform:
steps:
- name: build
commands:
- docker build -t gcrkrause/fediverse-blocklist-deploy .
- docker build -t gcrkrause/mastodon-blocklist-deploy .
- name: push
environment:
USERNAME:
@@ -19,7 +19,7 @@ steps:
from_secret: docker-hub-pw
commands:
- docker login -u $USERNAME -p $PASSWORD
- docker push gcrkrause/fediverse-blocklist-deploy
- docker push gcrkrause/mastodon-blocklist-deploy
- docker image prune -a -f
when:
event:

View File

@@ -4,14 +4,14 @@
In order to have a common development environment, its nice to use docker. Its quite easy. To build a new image, simply run
`docker build . -t fediverse_blocklist_deploy`
`docker build . -t mastodon_blocklist_deploy`
Now you can execute any commands using
`docker run --rm fediverse_blocklist_deploy --help`
`docker run --rm mastodon_blocklist_deploy --help`
If you want to avoid building new containers for each change, simply mount your code into the container using
`docker run --rm -v $(pwd):/app fediverse_blocklist_deploy`
`docker run --rm -v $(pwd):/app mastodon_blocklist_deploy`
Please be aware that changes to the package itself require a rebuild anyways.

View File

@@ -4,9 +4,9 @@ ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
COPY pyproject.toml poetry.lock README.md /app/
COPY fediverse_blocklist_deploy /app/fediverse_blocklist_deploy
COPY mastodon_blocklist_deploy /app/mastodon_blocklist_deploy
WORKDIR /app
ENTRYPOINT ["fediverse_blocklist_deploy"]
ENTRYPOINT ["mastodon_blocklist_deploy"]
RUN pip install -e .

View File

@@ -1,11 +1,11 @@
# fediverse-blocklist-deploy
# mastodon-blocklist-deploy
A small tool to deploy blocklist updates to a fediverse server using its API.
A small tool to deploy blocklist updates to a mastodon server using its API.
## Concept
The idea is to maintain a blocklist in a simple structured file in this repository. All changes need to be deployed to
the fediverse server, this is supposed to be automated with Drone CI.
the mastodon server, this is supposed to be automated with Drone CI.
In order to compare the list entries, we can read the whole blocklist
using [the get endpoint](https://docs.joinmastodon.org/methods/admin/domain_blocks/#get). At the same time we read the
@@ -19,22 +19,17 @@ and structured file format. Since Python 3.11 got native support for [toml](http
supports [Array of Tables](https://toml.io/en/v1.0.0#array-of-tables), I'd prefer to use this.
# Supported server types
- [x] Mastodon
- [X] GoToSocial
# Basic usage
##
```
usage: fediverse_blocklist_deploy [-h] [-s SERVER] [-t TOKEN] [-i INPUT_FILE] [-r REMOTE_BLOCKLIST] [-o OUTPUT] [-v] [-n]
usage: mastodon_blocklist_deploy [-h] [-s SERVER] [-t TOKEN] [-i INPUT_FILE] [-r REMOTE_BLOCKLIST] [-o OUTPUT] [-v] [-n]
[--format FORMAT] [--private]
{diff,deploy,export}
Deploy blocklist updates to a fediverse server
Deploy blocklist updates to a mastodon server
positional arguments:
{diff,deploy,export} Either use 'diff' to check the difference between local blockĺist and the blocklist on the server, 'deploy'
@@ -69,7 +64,7 @@ options:
1. **Export the current blocklist from the server**
```
fediverse_blocklist_deploy export -s yourserver -t yourtoken -o blocklist.toml
mastodon_blocklist_deploy export -s yourserver -t yourtoken -o blocklist.toml
```
2. **Manually add something to the blocklist**
@@ -88,12 +83,12 @@ private_comment = "We discussed this after X and Y and now that Z happend we dec
3. **Check the difference between the local and remote blocklist**
```
fediverse_blocklist_deploy diff -s yourserver -t yourtoken -i blocklist.toml
mastodon_blocklist_deploy diff -s yourserver -t yourtoken -i blocklist.toml
```
4. **Apply the local blocklist to the server**
```
fediverse_blocklist_deploy apply -s yourserver -t yourtoken -i blocklist.toml
mastodon_blocklist_deploy apply -s yourserver -t yourtoken -i blocklist.toml
```

View File

@@ -6,8 +6,8 @@ import requests
import os
import toml
from fediverse_blocklist_deploy.models import Instance
from fediverse_blocklist_deploy.helpers import blocklist_to_markdown, blocklist_to_toml, blocklist_to_csv, \
from mastodon_blocklist_deploy.models import Instance
from mastodon_blocklist_deploy.helpers import blocklist_to_markdown, blocklist_to_toml, blocklist_to_csv, \
blocklist_to_json
@@ -65,6 +65,9 @@ def exporter(blocklist, output=None, format: str = "toml", private: bool = False
def merge(input_file, merge_target, format: str = "toml", private: bool = False, overwrite=False):
"""Shows a table in the CLI comparing the local and remote blocklist"""
from rich.table import Table
from rich.console import Console
input_blocklist = load_blocklist_file(input_file)
merge_target_blocklist = load_blocklist_file(merge_target)
for input_instance in input_blocklist:
@@ -73,12 +76,12 @@ def merge(input_file, merge_target, format: str = "toml", private: bool = False,
continue
# Check if there is a domain in the merge target where the input domain is similar
try:
merge_target_instance = [merge_target_instance for merge_target_instance in merge_target if input_instance.domain == merge_target_instance.domain][0]
merge_target_instance = [merge_target_instance for merge_target_instance in merge_target_blocklist if input_instance.domain == merge_target_instance.domain][0]
if not overwrite:
key_input = ""
while key_input not in ("i", "O"):
print(f"Different settings for {input_instance.domain} detected.")
print(f"In the input blocklist the setting is\n{input_instance} whereas it's {merge_target_instance} in the merge target")
Instance.show_diff(input_instance, merge_target_instance)
key_input = input("Keep input (i) or original (o) [i/O]")
elif key_input == "i":
merge_target_blocklist.append(merge_target_instance)
@@ -89,7 +92,7 @@ def merge(input_file, merge_target, format: str = "toml", private: bool = False,
def cli():
parser = argparse.ArgumentParser(description='Deploy blocklist updates to a fediverse server')
parser = argparse.ArgumentParser(description='Deploy blocklist updates to a mastodon server')
parser.add_argument('action', choices=['diff', 'deploy', 'export', 'merge'],
help="Either use 'diff' to check the difference between local blockĺist and the blocklist on "
"the server, 'deploy' to apply the current local blocklist or 'export' to export the remote "
@@ -117,6 +120,8 @@ def cli():
else:
token = os.getenv('MBD_TOKEN')
"""Get a remote blocklist only when necessary"""
if args.action in ["diff", "deploy"]:
"""if there is a remote blocklist provided load this instead of fetching it from a server (for debugging reasons)"""
if args.remote_blocklist:
with open(args.remote_blocklist) as f:

View File

@@ -1,4 +1,4 @@
from fediverse_blocklist_deploy.models import Instance
from mastodon_blocklist_deploy.models import Instance
import toml
import io
import csv

View File

@@ -138,3 +138,18 @@ class Instance:
table.add_row(diff["local"].domain, diff["local"].status_str(), diff["remote"].status_str())
console = Console()
console.print(table)
@staticmethod
def show_diff(instanceA, instanceB, column_names=('Input', 'Original')):
from rich.table import Table
from rich.console import Console
table = Table(title="Differences", expand=True, show_lines=True)
table.add_column("Attribute", style="cyan")
table.add_column(column_names[0], style="green")
table.add_column(column_names[1], style="magenta")
compare_attributes = ["domain", "severity", "obfuscate", "private_comment", "public_comment", "reject_media", "reject_reports"]
for attr in compare_attributes:
table.add_row(attr, str(getattr(instanceA, attr)), str(getattr(instanceB, attr)))
console = Console()
console.print(table)

View File

@@ -1,12 +1,12 @@
[tool.poetry]
name = "fediverse-blocklist-deploy"
name = "mastodon-blocklist-deploy"
version = "0.1.0"
description = "A small tool to deploy blocklist updates to a fediverse server using its API."
description = "A small tool to deploy blocklist updates to a mastodon server using its API."
authors = ["Georg Krause <mail@georg-krause.net>", "Julian-Samuel Gebühr <julian-samuel@gebuehr.net>"]
readme = "README.md"
packages = [{include = "fediverse_blocklist_deploy"}]
packages = [{include = "mastodon_blocklist_deploy"}]
license = "MIT"
keywords = ["fediverse", "blocklist", "fediverse"]
keywords = ["mastodon", "blocklist", "fediverse"]
[tool.poetry.dependencies]
@@ -16,7 +16,7 @@ rich = "^13.0.1"
toml = "^0.10.2"
[tool.poetry.scripts]
fediverse_blocklist_deploy = 'fediverse_blocklist_deploy.cli:cli'
mastodon_blocklist_deploy = 'mastodon_blocklist_deploy.cli:cli'
[build-system]