From 672794c7bf4b1b29417bc7235a340fb69673bd37 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Sun, 16 Apr 2023 13:34:41 +0200 Subject: [PATCH 1/3] feat(vercel-integration): Create environment variables for all Vercel deployment environments --- src/sentry/integrations/vercel/integration.py | 2 +- .../integrations/vercel/test_integration.py | 24 +++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/sentry/integrations/vercel/integration.py b/src/sentry/integrations/vercel/integration.py index 22524178255397..d8ae1393dbafb4 100644 --- a/src/sentry/integrations/vercel/integration.py +++ b/src/sentry/integrations/vercel/integration.py @@ -256,7 +256,7 @@ def create_env_var(self, client, vercel_project_id, key, value, type): data = { "key": key, "value": value, - "target": ["production"], + "target": ["production", "preview", "development"], "type": type, } try: diff --git a/tests/sentry/integrations/vercel/test_integration.py b/tests/sentry/integrations/vercel/test_integration.py index aa9d600acb2e17..0caebe063d0b0d 100644 --- a/tests/sentry/integrations/vercel/test_integration.py +++ b/tests/sentry/integrations/vercel/test_integration.py @@ -169,7 +169,7 @@ def test_update_organization_config(self): json={ "key": env_var, "value": details["value"], - "target": ["production"], + "target": ["production", "preview", "development"], "type": details["type"], }, ) @@ -192,30 +192,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", "development"] 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", "development"] 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", "development"] 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", "development"] assert req_params["type"] == "system" @responses.activate @@ -270,7 +270,7 @@ def test_update_org_config_vars_exist(self): json={ "key": env_var, "value": details["value"], - "target": ["production"], + "target": ["production", "preview", "development"], "type": details["type"], }, ) @@ -292,30 +292,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", "development"] 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", "development"] 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", "development"] 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", "development"] assert req_params["type"] == "system" @responses.activate From d4f7487cf64a97bad3f91510c42531cdce40bb83 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Sun, 16 Apr 2023 15:16:56 +0200 Subject: [PATCH 2/3] Only have DSN in dev env --- src/sentry/integrations/vercel/integration.py | 40 +++++++++++--- .../integrations/vercel/test_integration.py | 52 ++++++++++++++----- 2 files changed, 71 insertions(+), 21 deletions(-) diff --git a/src/sentry/integrations/vercel/integration.py b/src/sentry/integrations/vercel/integration.py index d8ae1393dbafb4..1f376d5abd51f9 100644 --- a/src/sentry/integrations/vercel/integration.py +++ b/src/sentry/integrations/vercel/integration.py @@ -232,19 +232,45 @@ 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}, + 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_ORG": { + "type": "encrypted", + "value": sentry_project.organization.slug, + "target": ["production", "preview"], + }, + "SENTRY_PROJECT": { + "type": "encrypted", + "value": sentry_project.slug, + "target": ["production", "preview"], + }, "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( @@ -252,11 +278,11 @@ def update_organization_config(self, data): 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", "preview", "development"], + "target": target, "type": type, } try: diff --git a/tests/sentry/integrations/vercel/test_integration.py b/tests/sentry/integrations/vercel/test_integration.py index 0caebe063d0b0d..375143c0f51750 100644 --- a/tests/sentry/integrations/vercel/test_integration.py +++ b/tests/sentry/integrations/vercel/test_integration.py @@ -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_DSN": { + "type": "encrypted", + "value": enabled_dsn, + "target": [ + "production", + "preview", + "development", + ], + }, + "SENTRY_ORG": { + "type": "encrypted", + "value": org.slug, + "target": ["production", "preview"], + }, + "SENTRY_PROJECT": { + "type": "encrypted", + "value": self.project.slug, + "target": ["production", "preview"], + }, + "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 @@ -169,7 +193,7 @@ def test_update_organization_config(self): json={ "key": env_var, "value": details["value"], - "target": ["production", "preview", "development"], + "target": details["target"], "type": details["type"], }, ) @@ -192,13 +216,13 @@ 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", "preview", "development"] + 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", "preview", "development"] + assert req_params["target"] == ["production", "preview"] assert req_params["type"] == "encrypted" req_params = json.loads(responses.calls[7].request.body) @@ -209,13 +233,13 @@ def test_update_organization_config(self): req_params = json.loads(responses.calls[8].request.body) assert req_params["key"] == "SENTRY_AUTH_TOKEN" - assert req_params["target"] == ["production", "preview", "development"] + 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", "preview", "development"] + assert req_params["target"] == ["production", "preview"] assert req_params["type"] == "system" @responses.activate @@ -292,13 +316,13 @@ 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", "preview", "development"] + 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", "preview", "development"] + assert req_params["target"] == ["production", "preview"] assert req_params["type"] == "encrypted" req_params = json.loads(responses.calls[11].request.body) @@ -309,13 +333,13 @@ def test_update_org_config_vars_exist(self): req_params = json.loads(responses.calls[14].request.body) assert req_params["key"] == "SENTRY_AUTH_TOKEN" - assert req_params["target"] == ["production", "preview", "development"] + 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", "preview", "development"] + assert req_params["target"] == ["production", "preview"] assert req_params["type"] == "system" @responses.activate From 928e9513248c98eb5f0739aae0af4e70c368e43d Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Sun, 16 Apr 2023 18:29:29 +0200 Subject: [PATCH 3/3] Fix tests --- src/sentry/integrations/vercel/integration.py | 18 +++---- .../integrations/vercel/test_integration.py | 54 +++++++++++++------ 2 files changed, 48 insertions(+), 24 deletions(-) diff --git a/src/sentry/integrations/vercel/integration.py b/src/sentry/integrations/vercel/integration.py index 1f376d5abd51f9..5a4fcaf346ecc8 100644 --- a/src/sentry/integrations/vercel/integration.py +++ b/src/sentry/integrations/vercel/integration.py @@ -232,15 +232,6 @@ def update_organization_config(self, data): ) env_var_map = { - 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_ORG": { "type": "encrypted", "value": sentry_project.organization.slug, @@ -251,6 +242,15 @@ def update_organization_config(self, data): "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, diff --git a/tests/sentry/integrations/vercel/test_integration.py b/tests/sentry/integrations/vercel/test_integration.py index 375143c0f51750..7a0f56132cfcb8 100644 --- a/tests/sentry/integrations/vercel/test_integration.py +++ b/tests/sentry/integrations/vercel/test_integration.py @@ -147,15 +147,6 @@ def test_update_organization_config(self): sentry_auth_token = SentryAppInstallationToken.objects.get_token(org.id, "vercel") env_var_map = { - "SENTRY_DSN": { - "type": "encrypted", - "value": enabled_dsn, - "target": [ - "production", - "preview", - "development", - ], - }, "SENTRY_ORG": { "type": "encrypted", "value": org.slug, @@ -166,6 +157,15 @@ def test_update_organization_config(self): "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, @@ -257,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 @@ -294,7 +318,7 @@ def test_update_org_config_vars_exist(self): json={ "key": env_var, "value": details["value"], - "target": ["production", "preview", "development"], + "target": details["target"], "type": details["type"], }, )