Override the private comment
This commit is contained in:
parent
c06f4a9b1a
commit
9ca042ab74
|
@ -77,6 +77,9 @@ blocklist_instance_destinations = [
|
||||||
# merge_threshold_type = 'count'
|
# merge_threshold_type = 'count'
|
||||||
# merge_threshold = 0
|
# merge_threshold = 0
|
||||||
|
|
||||||
|
## set an override private comment
|
||||||
|
# override_private_comment = 'Updated by Fediblockhole'
|
||||||
|
|
||||||
## Set which fields we import
|
## Set which fields we import
|
||||||
## 'domain' and 'severity' are always imported, these are additional
|
## 'domain' and 'severity' are always imported, these are additional
|
||||||
##
|
##
|
||||||
|
|
|
@ -90,7 +90,7 @@ def sync_blocklists(conf: argparse.Namespace):
|
||||||
token = dest['token']
|
token = dest['token']
|
||||||
scheme = dest.get('scheme', 'https')
|
scheme = dest.get('scheme', 'https')
|
||||||
max_followed_severity = BlockSeverity(dest.get('max_followed_severity', 'silence'))
|
max_followed_severity = BlockSeverity(dest.get('max_followed_severity', 'silence'))
|
||||||
push_blocklist(token, target, merged, conf.dryrun, import_fields, max_followed_severity, scheme)
|
push_blocklist(token, target, merged, conf.dryrun, import_fields, max_followed_severity, scheme, conf.override_private_comment)
|
||||||
|
|
||||||
def apply_allowlists(merged: Blocklist, conf: argparse.Namespace, allowlists: dict):
|
def apply_allowlists(merged: Blocklist, conf: argparse.Namespace, allowlists: dict):
|
||||||
"""Apply allowlists
|
"""Apply allowlists
|
||||||
|
@ -560,6 +560,7 @@ def push_blocklist(token: str, host: str, blocklist: list[DomainBlock],
|
||||||
import_fields: list=['domain', 'severity'],
|
import_fields: list=['domain', 'severity'],
|
||||||
max_followed_severity:BlockSeverity=BlockSeverity('silence'),
|
max_followed_severity:BlockSeverity=BlockSeverity('silence'),
|
||||||
scheme: str='https',
|
scheme: str='https',
|
||||||
|
override_private_comment: str=None
|
||||||
):
|
):
|
||||||
"""Push a blocklist to a remote instance.
|
"""Push a blocklist to a remote instance.
|
||||||
|
|
||||||
|
@ -575,6 +576,10 @@ def push_blocklist(token: str, host: str, blocklist: list[DomainBlock],
|
||||||
# Force use of the admin API, and add 'id' to the list of fields
|
# Force use of the admin API, and add 'id' to the list of fields
|
||||||
if 'id' not in import_fields:
|
if 'id' not in import_fields:
|
||||||
import_fields.append('id')
|
import_fields.append('id')
|
||||||
|
|
||||||
|
# if we're overriding the private comment, we need to include it in the import
|
||||||
|
if override_private_comment:
|
||||||
|
import_fields.append('private_comment')
|
||||||
serverblocks = fetch_instance_blocklist(host, token, True, import_fields, scheme)
|
serverblocks = fetch_instance_blocklist(host, token, True, import_fields, scheme)
|
||||||
|
|
||||||
# # Convert serverblocks to a dictionary keyed by domain name
|
# # Convert serverblocks to a dictionary keyed by domain name
|
||||||
|
@ -582,6 +587,10 @@ def push_blocklist(token: str, host: str, blocklist: list[DomainBlock],
|
||||||
|
|
||||||
for newblock in blocklist.values():
|
for newblock in blocklist.values():
|
||||||
|
|
||||||
|
# stamp this record with a private comment
|
||||||
|
if override_private_comment:
|
||||||
|
newblock.private_comment = override_private_comment
|
||||||
|
|
||||||
log.debug(f"Processing block: {newblock}")
|
log.debug(f"Processing block: {newblock}")
|
||||||
if newblock.domain in serverblocks:
|
if newblock.domain in serverblocks:
|
||||||
log.debug(f"Block already exists for {newblock.domain}, checking for differences...")
|
log.debug(f"Block already exists for {newblock.domain}, checking for differences...")
|
||||||
|
@ -742,6 +751,9 @@ def augment_args(args, tomldata: str=None):
|
||||||
if not args.save_intermediate:
|
if not args.save_intermediate:
|
||||||
args.save_intermediate = conf.get('save_intermediate', False)
|
args.save_intermediate = conf.get('save_intermediate', False)
|
||||||
|
|
||||||
|
if not args.override_private_comment:
|
||||||
|
args.override_private_comment = conf.get('override_private_comment', None)
|
||||||
|
|
||||||
if not args.savedir:
|
if not args.savedir:
|
||||||
args.savedir = conf.get('savedir', '/tmp')
|
args.savedir = conf.get('savedir', '/tmp')
|
||||||
|
|
||||||
|
@ -787,6 +799,7 @@ def setup_argparse():
|
||||||
ap.add_argument('-b', '--block-audit-file', dest="blocklist_auditfile", help="Save blocklist auditfile to this location.")
|
ap.add_argument('-b', '--block-audit-file', dest="blocklist_auditfile", help="Save blocklist auditfile to this location.")
|
||||||
ap.add_argument('--merge-threshold', type=int, help="Merge threshold value")
|
ap.add_argument('--merge-threshold', type=int, help="Merge threshold value")
|
||||||
ap.add_argument('--merge-threshold-type', choices=['count', 'pct'], help="Type of merge threshold to use.")
|
ap.add_argument('--merge-threshold-type', choices=['count', 'pct'], help="Type of merge threshold to use.")
|
||||||
|
ap.add_argument('--override-private-comment', dest='override_private_comment', help="Enforces a private comment for all blocks.")
|
||||||
|
|
||||||
ap.add_argument('-I', '--import-field', dest='import_fields', action='append', help="Extra blocklist fields to import.")
|
ap.add_argument('-I', '--import-field', dest='import_fields', action='append', help="Extra blocklist fields to import.")
|
||||||
ap.add_argument('-E', '--export-field', dest='export_fields', action='append', help="Extra blocklist fields to export.")
|
ap.add_argument('-E', '--export-field', dest='export_fields', action='append', help="Extra blocklist fields to export.")
|
||||||
|
|
Loading…
Reference in New Issue