Sorry to revive such an old thread, but thought I would chime in with how I did this sort of thing with via Python scripts and SaltStack.
Note: Sentry automatically creates a DSN when a Project
model is saved so I had to delete that an re-create it later with a known DSN.
Note 2: I’ve installed sentry in /opt
, if you install via pip
I expect the location will be different.
#The Scripts
###create_project.py
import sys
from sentry.runner import configure
configure()
from sentry.models import Project, ProjectKey
project_id = sys.argv[1]
project_name = sys.argv[2]
slug = project_name.lower()
p = Project.objects.create(id=project_id, name=project_name, public=False, slug=slug, team_id=1, organization_id=1)
ProjectKey.objects.get(project=p).delete()
###create_projectkey.py
import sys
from sentry.runner import configure
configure()
from sentry.models import Project, ProjectKey
project_name = sys.argv[1]
slug = project_name.lower()
public_key = sys.argv[2]
secret_key = sys.argv[3]
p = Project.objects.get(slug=slug)
ProjectKey.objects.create(project=p, public_key=public_key, secret_key=secret_key, roles=1)
#The Salt
foo-project:
cmd.run:
- name: SENTRY_CONF=/etc/sentry /opt/sentry/bin/python /etc/sentry/scripts/create_project.py 2 Foo
- unless: echo "from sentry.models import Project; print Project.objects.get(name='Foo')" | SENTRY_CONF=/etc/sentry sentry shell | grep -q -i Foo
Then a similar state for the create_projectkey.py command:
...
- name: SENTRY_CONF=/etc/sentry /opt/sentry/bin/python /etc/sentry/scripts/create_projectkey.py Foo FooPublicKey FooSecretKey
- unless: echo "from sentry.models import ProjectKey; print ProjectKey.objects.get(project__name='Foo').project.name" | SENTRY_CONF=/etc/sentry sentry shell | grep -q -i Foo
Users are simpler, you can just execute straight through sentry
CLI:
- name: SENTRY_CONF=/etc/sentry sentry createuser --email admin --password admin --superuser --no-input
- unless: echo "from django.contrib.auth import get_user_model; print get_user_model().objects.all()" | SENTRY_CONF=/etc/sentry sentry shell | grep -q -i admin
Of course executing these states assumes you’ve already put the Python scripts in place. I put them in /etc/sentry/scripts
.