From 6630cddd9cb875284d4dc952718ee5913ab4e458 Mon Sep 17 00:00:00 2001 From: Cedric van Putten Date: Wed, 15 Mar 2023 12:36:13 +0100 Subject: [PATCH 1/5] fix: discourage `authToken` usage and link to updated docs --- plugin/build/withSentry.js | 4 ++++ plugin/src/withSentry.ts | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/plugin/build/withSentry.js b/plugin/build/withSentry.js index e4ed201..6d75cf2 100644 --- a/plugin/build/withSentry.js +++ b/plugin/build/withSentry.js @@ -39,6 +39,10 @@ function getSentryProperties(config) { config_plugins_1.WarningAggregator.addWarningIOS('sentry-expo', 'No Sentry config found in app.json, builds will fall back to environment variables. Refer to @sentry/react-native docs for how to configure this.'); return ''; } + if (sentryHook.config?.authToken) { + config_plugins_1.WarningAggregator.addWarningAndroid('sentry-expo', 'Sentry `authToken` found in app.json. Avoid committing this value to your repository, configure it through `SENTRY_AUTH_TOKEN` environment variable instead. See: https://docs.expo.dev/guides/using-sentry/#app-configuration'); + config_plugins_1.WarningAggregator.addWarningIOS('sentry-expo', 'Sentry `authToken` found in app.json. Avoid committing this value to your repository, configure it through `SENTRY_AUTH_TOKEN` environment variable instead. See: https://docs.expo.dev/guides/using-sentry/#app-configuration'); + } return buildSentryPropertiesString(sentryHook.config); } exports.getSentryProperties = getSentryProperties; diff --git a/plugin/src/withSentry.ts b/plugin/src/withSentry.ts index 365650f..461f29d 100644 --- a/plugin/src/withSentry.ts +++ b/plugin/src/withSentry.ts @@ -55,6 +55,17 @@ export function getSentryProperties(config: ExpoConfig): string | null { return ''; } + if (sentryHook.config?.authToken) { + WarningAggregator.addWarningAndroid( + 'sentry-expo', + 'Sentry `authToken` found in app.json. Avoid committing this value to your repository, configure it through `SENTRY_AUTH_TOKEN` environment variable instead. See: https://docs.expo.dev/guides/using-sentry/#app-configuration' + ); + WarningAggregator.addWarningIOS( + 'sentry-expo', + 'Sentry `authToken` found in app.json. Avoid committing this value to your repository, configure it through `SENTRY_AUTH_TOKEN` environment variable instead. See: https://docs.expo.dev/guides/using-sentry/#app-configuration' + ); + } + return buildSentryPropertiesString(sentryHook.config); } From 0c24e22e127e4dbc66d7675fdee3dbc7f5c2cc27 Mon Sep 17 00:00:00 2001 From: Cedric van Putten Date: Wed, 15 Mar 2023 12:39:25 +0100 Subject: [PATCH 2/5] chore: add changelog entry --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb7eed7..8bbf6d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ ### ๐Ÿ› Bug fixes +- Discourage configuring `authToken` and point to `SENTRY_AUTH_TOKEN` and docs. ([#325](https://github.com/expo/sentry-expo/pull/325) by [@byCedric](https://github.com/byCedric)) + ### ๐Ÿงน Chores ## [6.1.0](https://github.com/expo/sentry-expo/releases/tag/v6.1.0) - 2023-03-04 From 4f3bc605a6d0a19c5bebc96d69f16d7ea59f9c30 Mon Sep 17 00:00:00 2001 From: Cedric van Putten Date: Wed, 15 Mar 2023 13:32:04 +0100 Subject: [PATCH 3/5] refactor: update the auth.token missing value comment in sentry.properties --- plugin/build/withSentry.js | 4 ++-- plugin/src/__tests__/getSentryProperties-test.ts | 6 ++++-- plugin/src/withSentry.ts | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/plugin/build/withSentry.js b/plugin/build/withSentry.js index 6d75cf2..b88f477 100644 --- a/plugin/build/withSentry.js +++ b/plugin/build/withSentry.js @@ -23,7 +23,7 @@ const withSentry = (config) => { } return config; }; -const missingAuthTokenMessage = `# no auth.token found, falling back to SENTRY_AUTH_TOKEN environment variable`; +const missingAuthTokenMessage = `# Configured through SENTRY_AUTH_TOKEN environment variable`; const missingProjectMessage = `# no project found, falling back to SENTRY_PROJECT environment variable`; const missingOrgMessage = `# no org found, falling back to SENTRY_ORG environment variable`; function getSentryProperties(config) { @@ -62,7 +62,7 @@ function buildSentryPropertiesString(sentryHookConfig) { return `defaults.url=${url} ${organization ? `defaults.org=${organization}` : missingOrgMessage} ${project ? `defaults.project=${project}` : missingProjectMessage} -${authToken ? `auth.token=${authToken}` : missingAuthTokenMessage} +${authToken ? `# Configure this value through \`SENTRY_AUTH_TOKEN\` environment variable instead. See:https://docs.expo.dev/guides/using-sentry/#app-configuration\nauth.token=${authToken}` : missingAuthTokenMessage} `; } exports.default = (0, config_plugins_1.createRunOncePlugin)(withSentry, pkg.name, pkg.version); diff --git a/plugin/src/__tests__/getSentryProperties-test.ts b/plugin/src/__tests__/getSentryProperties-test.ts index dba4f01..f366838 100644 --- a/plugin/src/__tests__/getSentryProperties-test.ts +++ b/plugin/src/__tests__/getSentryProperties-test.ts @@ -155,6 +155,7 @@ describe('Get Sentry properties from app config', () => { `defaults.url=https://sentry.io/ defaults.org=test-org defaults.project=myProjectName +# Configure this value through \`SENTRY_AUTH_TOKEN\` environment variable instead. See:https://docs.expo.dev/guides/using-sentry/#app-configuration auth.token=123-abc ` ); @@ -170,6 +171,7 @@ auth.token=123-abc `defaults.url=https://sentry.io/ defaults.org=test-org defaults.project=myProjectName +# Configure this value through \`SENTRY_AUTH_TOKEN\` environment variable instead. See:https://docs.expo.dev/guides/using-sentry/#app-configuration auth.token=123-abc ` ); @@ -180,7 +182,7 @@ auth.token=123-abc `defaults.url=some-url # no org found, falling back to SENTRY_ORG environment variable # no project found, falling back to SENTRY_PROJECT environment variable -# no auth.token found, falling back to SENTRY_AUTH_TOKEN environment variable +# auth.token is configured through SENTRY_AUTH_TOKEN environment variable ` ); }); @@ -190,7 +192,7 @@ auth.token=123-abc `defaults.url=some-url # no org found, falling back to SENTRY_ORG environment variable # no project found, falling back to SENTRY_PROJECT environment variable -# no auth.token found, falling back to SENTRY_AUTH_TOKEN environment variable +# auth.token is configured through SENTRY_AUTH_TOKEN environment variable ` ); }); diff --git a/plugin/src/withSentry.ts b/plugin/src/withSentry.ts index 461f29d..d469646 100644 --- a/plugin/src/withSentry.ts +++ b/plugin/src/withSentry.ts @@ -30,7 +30,7 @@ const withSentry: ConfigPlugin = (config) => { return config; }; -const missingAuthTokenMessage = `# no auth.token found, falling back to SENTRY_AUTH_TOKEN environment variable`; +const missingAuthTokenMessage = `# auth.token is configured through SENTRY_AUTH_TOKEN environment variable`; const missingProjectMessage = `# no project found, falling back to SENTRY_PROJECT environment variable`; const missingOrgMessage = `# no org found, falling back to SENTRY_ORG environment variable`; @@ -87,7 +87,7 @@ function buildSentryPropertiesString(sentryHookConfig: PublishHook['config']) { return `defaults.url=${url} ${organization ? `defaults.org=${organization}` : missingOrgMessage} ${project ? `defaults.project=${project}` : missingProjectMessage} -${authToken ? `auth.token=${authToken}` : missingAuthTokenMessage} +${authToken ? `# Configure this value through \`SENTRY_AUTH_TOKEN\` environment variable instead. See:https://docs.expo.dev/guides/using-sentry/#app-configuration\nauth.token=${authToken}` : missingAuthTokenMessage} `; } From e1ce56a2c5b9214c2de16fa00d60765268915bd1 Mon Sep 17 00:00:00 2001 From: Cedric van Putten Date: Wed, 15 Mar 2023 13:43:18 +0100 Subject: [PATCH 4/5] fix: clean up authToken warnings --- plugin/src/withSentry.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/plugin/src/withSentry.ts b/plugin/src/withSentry.ts index d469646..2d3626a 100644 --- a/plugin/src/withSentry.ts +++ b/plugin/src/withSentry.ts @@ -71,12 +71,8 @@ export function getSentryProperties(config: ExpoConfig): string | null { function buildSentryPropertiesString(sentryHookConfig: PublishHook['config']) { const { organization, project, authToken, url = 'https://sentry.io/' } = sentryHookConfig ?? {}; - const missingProperties = ['organization', 'project', 'authToken'].filter((each) => { - if (!sentryHookConfig?.hasOwnProperty(each)) { - return true - } - return false - }); + const missingProperties = ['organization', 'project'].filter((each) => !sentryHookConfig?.hasOwnProperty(each)); + if (missingProperties.length) { const warningMessage = `Missing Sentry configuration properties: ${missingProperties.join( ', ' @@ -84,6 +80,7 @@ function buildSentryPropertiesString(sentryHookConfig: PublishHook['config']) { WarningAggregator.addWarningAndroid('sentry-expo', warningMessage); WarningAggregator.addWarningIOS('sentry-expo', warningMessage); } + return `defaults.url=${url} ${organization ? `defaults.org=${organization}` : missingOrgMessage} ${project ? `defaults.project=${project}` : missingProjectMessage} From bc69f0df5c4874340e621a9d25fc83a772d1ab98 Mon Sep 17 00:00:00 2001 From: Cedric van Putten Date: Wed, 15 Mar 2023 13:45:02 +0100 Subject: [PATCH 5/5] chore: rebuild plugin --- plugin/build/withSentry.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/plugin/build/withSentry.js b/plugin/build/withSentry.js index b88f477..07a0684 100644 --- a/plugin/build/withSentry.js +++ b/plugin/build/withSentry.js @@ -23,7 +23,7 @@ const withSentry = (config) => { } return config; }; -const missingAuthTokenMessage = `# Configured through SENTRY_AUTH_TOKEN environment variable`; +const missingAuthTokenMessage = `# auth.token is configured through SENTRY_AUTH_TOKEN environment variable`; const missingProjectMessage = `# no project found, falling back to SENTRY_PROJECT environment variable`; const missingOrgMessage = `# no org found, falling back to SENTRY_ORG environment variable`; function getSentryProperties(config) { @@ -48,12 +48,7 @@ function getSentryProperties(config) { exports.getSentryProperties = getSentryProperties; function buildSentryPropertiesString(sentryHookConfig) { const { organization, project, authToken, url = 'https://sentry.io/' } = sentryHookConfig ?? {}; - const missingProperties = ['organization', 'project', 'authToken'].filter((each) => { - if (!sentryHookConfig?.hasOwnProperty(each)) { - return true; - } - return false; - }); + const missingProperties = ['organization', 'project'].filter((each) => !sentryHookConfig?.hasOwnProperty(each)); if (missingProperties.length) { const warningMessage = `Missing Sentry configuration properties: ${missingProperties.join(', ')} from app.json. Builds will fall back to environment variables. Refer to @sentry/react-native docs for how to configure this.`; config_plugins_1.WarningAggregator.addWarningAndroid('sentry-expo', warningMessage);