Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 33 additions & 7 deletions src/sentry/integrations/vercel/integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,31 +232,57 @@ def update_organization_config(self, data):
)

env_var_map = {
"SENTRY_ORG": {"type": "encrypted", "value": sentry_project.organization.slug},
"SENTRY_PROJECT": {"type": "encrypted", "value": sentry_project.slug},
dsn_env_name: {"type": "encrypted", "value": sentry_project_dsn},
"SENTRY_ORG": {
"type": "encrypted",
"value": sentry_project.organization.slug,
"target": ["production", "preview"],
},
"SENTRY_PROJECT": {
"type": "encrypted",
"value": sentry_project.slug,
"target": ["production", "preview"],
},
dsn_env_name: {
"type": "encrypted",
"value": sentry_project_dsn,
"target": [
"production",
"preview",
"development", # The DSN is the only value that makes sense to have available locally via Vercel CLI's `vercel dev` command
],
},
"SENTRY_AUTH_TOKEN": {
"type": "encrypted",
"value": sentry_auth_token,
"target": ["production", "preview"],
},
"VERCEL_GIT_COMMIT_SHA": {
"type": "system",
"value": "VERCEL_GIT_COMMIT_SHA",
"target": ["production", "preview"],
},
"VERCEL_GIT_COMMIT_SHA": {"type": "system", "value": "VERCEL_GIT_COMMIT_SHA"},
}

for env_var, details in env_var_map.items():
self.create_env_var(
vercel_client, vercel_project_id, env_var, details["value"], details["type"]
vercel_client,
vercel_project_id,
env_var,
details["value"],
details["type"],
details["target"],
)
config.update(data)
self.org_integration = integration_service.update_organization_integration(
org_integration_id=self.org_integration.id,
config=config,
)

def create_env_var(self, client, vercel_project_id, key, value, type):
def create_env_var(self, client, vercel_project_id, key, value, type, target):
data = {
"key": key,
"value": value,
"target": ["production"],
"target": target,
"type": type,
}
try:
Expand Down
92 changes: 70 additions & 22 deletions tests/sentry/integrations/vercel/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,35 @@ def test_update_organization_config(self):
sentry_auth_token = SentryAppInstallationToken.objects.get_token(org.id, "vercel")

env_var_map = {
"SENTRY_ORG": {"type": "encrypted", "value": org.slug},
"SENTRY_PROJECT": {"type": "encrypted", "value": self.project.slug},
"SENTRY_DSN": {"type": "encrypted", "value": enabled_dsn},
"SENTRY_AUTH_TOKEN": {"type": "encrypted", "value": sentry_auth_token},
"VERCEL_GIT_COMMIT_SHA": {"type": "system", "value": "VERCEL_GIT_COMMIT_SHA"},
"SENTRY_ORG": {
"type": "encrypted",
"value": org.slug,
"target": ["production", "preview"],
},
"SENTRY_PROJECT": {
"type": "encrypted",
"value": self.project.slug,
"target": ["production", "preview"],
},
"SENTRY_DSN": {
"type": "encrypted",
"value": enabled_dsn,
"target": [
"production",
"preview",
"development",
],
},
"SENTRY_AUTH_TOKEN": {
"type": "encrypted",
"value": sentry_auth_token,
"target": ["production", "preview"],
},
"VERCEL_GIT_COMMIT_SHA": {
"type": "system",
"value": "VERCEL_GIT_COMMIT_SHA",
"target": ["production", "preview"],
},
}

# mock get_project API call
Expand All @@ -169,7 +193,7 @@ def test_update_organization_config(self):
json={
"key": env_var,
"value": details["value"],
"target": ["production"],
"target": details["target"],
"type": details["type"],
},
)
Expand All @@ -192,30 +216,30 @@ def test_update_organization_config(self):
req_params = json.loads(responses.calls[5].request.body)
assert req_params["key"] == "SENTRY_ORG"
assert req_params["value"] == org.slug
assert req_params["target"] == ["production"]
assert req_params["target"] == ["production", "preview"]
assert req_params["type"] == "encrypted"

req_params = json.loads(responses.calls[6].request.body)
assert req_params["key"] == "SENTRY_PROJECT"
assert req_params["value"] == self.project.slug
assert req_params["target"] == ["production"]
assert req_params["target"] == ["production", "preview"]
assert req_params["type"] == "encrypted"

req_params = json.loads(responses.calls[7].request.body)
assert req_params["key"] == "NEXT_PUBLIC_SENTRY_DSN"
assert req_params["value"] == enabled_dsn
assert req_params["target"] == ["production"]
assert req_params["target"] == ["production", "preview", "development"]
assert req_params["type"] == "encrypted"

req_params = json.loads(responses.calls[8].request.body)
assert req_params["key"] == "SENTRY_AUTH_TOKEN"
assert req_params["target"] == ["production"]
assert req_params["target"] == ["production", "preview"]
assert req_params["type"] == "encrypted"

req_params = json.loads(responses.calls[9].request.body)
assert req_params["key"] == "VERCEL_GIT_COMMIT_SHA"
assert req_params["value"] == "VERCEL_GIT_COMMIT_SHA"
assert req_params["target"] == ["production"]
assert req_params["target"] == ["production", "preview"]
assert req_params["type"] == "system"

@responses.activate
Expand All @@ -233,11 +257,35 @@ def test_update_org_config_vars_exist(self):
sentry_auth_token = SentryAppInstallationToken.objects.get_token(org.id, "vercel")

env_var_map = {
"SENTRY_ORG": {"type": "encrypted", "value": org.slug},
"SENTRY_PROJECT": {"type": "encrypted", "value": self.project.slug},
"SENTRY_DSN": {"type": "encrypted", "value": enabled_dsn},
"SENTRY_AUTH_TOKEN": {"type": "secret", "value": sentry_auth_token},
"VERCEL_GIT_COMMIT_SHA": {"type": "system", "value": "VERCEL_GIT_COMMIT_SHA"},
"SENTRY_ORG": {
"type": "encrypted",
"value": org.slug,
"target": ["production", "preview"],
},
"SENTRY_PROJECT": {
"type": "encrypted",
"value": self.project.slug,
"target": ["production", "preview"],
},
"SENTRY_DSN": {
"type": "encrypted",
"value": enabled_dsn,
"target": [
"production",
"preview",
"development",
],
},
"SENTRY_AUTH_TOKEN": {
"type": "encrypted",
"value": sentry_auth_token,
"target": ["production", "preview"],
},
"VERCEL_GIT_COMMIT_SHA": {
"type": "system",
"value": "VERCEL_GIT_COMMIT_SHA",
"target": ["production", "preview"],
},
}

# mock get_project API call
Expand Down Expand Up @@ -270,7 +318,7 @@ def test_update_org_config_vars_exist(self):
json={
"key": env_var,
"value": details["value"],
"target": ["production"],
"target": details["target"],
"type": details["type"],
},
)
Expand All @@ -292,30 +340,30 @@ def test_update_org_config_vars_exist(self):
req_params = json.loads(responses.calls[5].request.body)
assert req_params["key"] == "SENTRY_ORG"
assert req_params["value"] == org.slug
assert req_params["target"] == ["production"]
assert req_params["target"] == ["production", "preview"]
assert req_params["type"] == "encrypted"

req_params = json.loads(responses.calls[8].request.body)
assert req_params["key"] == "SENTRY_PROJECT"
assert req_params["value"] == self.project.slug
assert req_params["target"] == ["production"]
assert req_params["target"] == ["production", "preview"]
assert req_params["type"] == "encrypted"

req_params = json.loads(responses.calls[11].request.body)
assert req_params["key"] == "SENTRY_DSN"
assert req_params["value"] == enabled_dsn
assert req_params["target"] == ["production"]
assert req_params["target"] == ["production", "preview", "development"]
assert req_params["type"] == "encrypted"

req_params = json.loads(responses.calls[14].request.body)
assert req_params["key"] == "SENTRY_AUTH_TOKEN"
assert req_params["target"] == ["production"]
assert req_params["target"] == ["production", "preview"]
assert req_params["type"] == "encrypted"

req_params = json.loads(responses.calls[17].request.body)
assert req_params["key"] == "VERCEL_GIT_COMMIT_SHA"
assert req_params["value"] == "VERCEL_GIT_COMMIT_SHA"
assert req_params["target"] == ["production"]
assert req_params["target"] == ["production", "preview"]
assert req_params["type"] == "system"

@responses.activate
Expand Down