appconnect_cli.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/usr/bin/env sentry exec
  2. """Dumb CLI to experiment with our App Store Connect functionality.
  3. It contains several useful tools to manipulate the database during development. Exactly
  4. what it does can be easily changed based on new needs though, nothing is set in stone.
  5. Most actions assume you have only one App Store Connect source and will simply pick the
  6. first one found.
  7. """
  8. import sys
  9. from pprint import pprint
  10. from sentry.lang.native.appconnect import SYMBOL_SOURCES_PROP_NAME
  11. from sentry.models import AppConnectBuild, Project
  12. from sentry.tasks import app_store_connect
  13. from sentry.utils import json
  14. PROJECT_ID = 2
  15. def main(argv):
  16. if argv[0] == "dump-cfg":
  17. # Dumps the symbolSource configuration as stored in the project option.
  18. project = Project.objects.get(pk=PROJECT_ID)
  19. raw_config = project.get_option(SYMBOL_SOURCES_PROP_NAME, default="[]")
  20. config = json.loads(raw_config)
  21. pprint(config)
  22. elif argv[0] == "dsyms":
  23. # Start the dsym_download task for first config found (needs running workers).
  24. config = appconnect_config()
  25. app_store_connect.dsym_download(PROJECT_ID, config["id"])
  26. elif argv[0] == "zip":
  27. # "Uploads" DIFs into sentry from a zipfile passed as argument.
  28. project = Project.objects.get(pk=PROJECT_ID)
  29. app_store_connect.create_difs_from_dsyms_zip(argv[1], project)
  30. elif argv[0] == "dump-db":
  31. # Dumps (part of) the AppConnectBuild table.
  32. for build in AppConnectBuild.objects.all():
  33. print( # noqa: S002
  34. f"{build!r} app_id={build.app_id} bundle_id={build.bundle_id} platform={build.platform} version={build.bundle_short_version} build={build.bundle_version} fetched={build.fetched}"
  35. )
  36. elif argv[0] == "reset-fetched":
  37. # Resets the fetched state of the AppConnectBuild table, so dsym_download task will
  38. # process the entries again.
  39. for build in AppConnectBuild.objects.all():
  40. build.fetched = False
  41. build.save()
  42. elif argv[0] == "task":
  43. # Manually trigger the dsym_download task right now (needs running workers).
  44. config = appconnect_config()
  45. app_store_connect.dsym_download.apply_async(
  46. kwargs={"project_id": PROJECT_ID, "config_id": config["id"]}
  47. )
  48. else:
  49. raise ValueError("Unknown command")
  50. def appconnect_config():
  51. project = Project.objects.get(pk=PROJECT_ID)
  52. raw_config = project.get_option(SYMBOL_SOURCES_PROP_NAME, default="[]")
  53. symbol_sources = json.loads(raw_config)
  54. for config in symbol_sources:
  55. if config["type"] == "appStoreConnect":
  56. return config
  57. else:
  58. raise KeyError("appStoreConnect config not found")
  59. if __name__ == "__main__":
  60. if sys.argv[2].startswith("--project="):
  61. project_arg = sys.argv.pop(2)
  62. PROJECT_ID = int(project_arg[10:])
  63. main(sys.argv[2:])