Remove 'kind' idea from send_json util

we only support one kind: files.
(in the past it was useful to send-to-self already uploaded items,
but this idea is never used in practice, and the whole idea of having to supply a
'kind' on the cmdline is confusing)
This commit is contained in:
Klaas van Schelven
2025-08-24 21:03:35 +02:00
parent c38ca8c58a
commit f0d3667121

View File

@@ -15,8 +15,6 @@ from compat.dsn import get_store_url, get_envelope_url, get_header_value
from bugsink.streams import compress_with_zlib, WBITS_PARAM_FOR_GZIP, WBITS_PARAM_FOR_DEFLATE from bugsink.streams import compress_with_zlib, WBITS_PARAM_FOR_GZIP, WBITS_PARAM_FOR_DEFLATE
from bugsink.utils import nc_rnd from bugsink.utils import nc_rnd
from projects.models import Project
class Command(BaseCommand): class Command(BaseCommand):
help = "Send raw events to a sentry-compatible server; events can be sources from the filesystem or your DB." help = "Send raw events to a sentry-compatible server; events can be sources from the filesystem or your DB."
@@ -35,8 +33,7 @@ class Command(BaseCommand):
"--x-forwarded-for", action="store", "--x-forwarded-for", action="store",
help="Set the X-Forwarded-For header to test whether your setup is properly ignoring it") help="Set the X-Forwarded-For header to test whether your setup is properly ignoring it")
parser.add_argument("--sent-at", action="store", default=None, help="Set the sent_at header to this value") parser.add_argument("--sent-at", action="store", default=None, help="Set the sent_at header to this value")
parser.add_argument("kind", action="store", help="The kind of object (filename, project, issue, event)") parser.add_argument("filenames", nargs="+")
parser.add_argument("identifiers", nargs="+")
def is_valid(self, data, identifier): def is_valid(self, data, identifier):
# In our (private) samples we often have this "_meta" field. I can't (quickly) find any documentation for it, # In our (private) samples we often have this "_meta" field. I can't (quickly) find any documentation for it,
@@ -75,35 +72,19 @@ class Command(BaseCommand):
successfully_sent = [] successfully_sent = []
kind = options["kind"] for json_filename in options["filenames"]:
with open(json_filename) as f:
print("considering", json_filename)
try:
data = json.loads(f.read())
except Exception as e:
self.stderr.write("%s %s %s" % ("Not JSON", json_filename, str(e)))
continue
if kind == "filename": if self.send_to_server(dsn, options, json_filename, data, use_envelope, compress):
for json_filename in options["identifiers"]: successfully_sent.append(json_filename)
with open(json_filename) as f:
print("considering", json_filename)
try:
data = json.loads(f.read())
except Exception as e:
self.stderr.write("%s %s %s" % ("Not JSON", json_filename, str(e)))
continue
if self.send_to_server(dsn, options, json_filename, data, use_envelope, compress): print("Successfuly sent to server:")
successfully_sent.append(json_filename)
elif kind == "project":
for project_id in options["identifiers"]:
print("considering", project_id)
project = Project.objects.get(pk=project_id)
for event in project.event_set.all():
data = event.get_parsed_data()
if self.send_to_server(dsn, options, str(event.id), data, use_envelope, compress):
successfully_sent.append(event.id)
else:
self.stderr.write("Unknown kind of data %s" % kind)
exit(1)
print("Successfuly sent to server")
for filename in successfully_sent: for filename in successfully_sent:
print(filename) print(filename)