Skip to content

Commit

Permalink
fix: discourage authToken usage and link to updated docs (#325)
Browse files Browse the repository at this point in the history
* fix: discourage `authToken` usage and link to updated docs

* chore: add changelog entry

* refactor: update the auth.token missing value comment in sentry.properties

* fix: clean up authToken warnings

* chore: rebuild plugin
  • Loading branch information
byCedric authored Mar 15, 2023
1 parent 699b6f7 commit 459a822
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 18 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 7 additions & 8 deletions plugin/build/withSentry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `# 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) {
Expand All @@ -39,17 +39,16 @@ 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;
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);
Expand All @@ -58,7 +57,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);
6 changes: 4 additions & 2 deletions plugin/src/__tests__/getSentryProperties-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
`
);
Expand All @@ -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
`
);
Expand All @@ -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
`
);
});
Expand All @@ -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
`
);
});
Expand Down
24 changes: 16 additions & 8 deletions plugin/src/withSentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`;

Expand All @@ -55,28 +55,36 @@ 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);
}

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(
', '
)} from app.json. Builds will fall back to environment variables. Refer to @sentry/react-native docs for how to configure this.`;
WarningAggregator.addWarningAndroid('sentry-expo', warningMessage);
WarningAggregator.addWarningIOS('sentry-expo', warningMessage);
}

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}
`;
}

Expand Down

0 comments on commit 459a822

Please sign in to comment.