sentry-react-native icon indicating copy to clipboard operation
sentry-react-native copied to clipboard

Getting auth.token from .env

Open fragilehm opened this issue 4 years ago • 4 comments

So right now I have sentry.properties file with auth.token filled in, in order to upload the source map. I understand that we can add this file to .gitignore not to expose the token to the remote repo. But we are using appcenter which also does build the release application so it needs to upload the sentry source map as well, but there is no option to get the auth.token from the specific file which is not in the repo, but we can set the env variables. So I was wondering if we could get the auth.token from .env instead or leave the default to get the variable from the sentry.properties file but in case it is not configured there, get it from .env something like: "--auth-token", sentryProps.get("auth.token") ?: project.env.get("SENTRY_AUTH_TOKEN")

fragilehm avatar Nov 14 '21 13:11 fragilehm

kinda related to https://github.com/getsentry/sentry-react-native/issues/831

marandaneto avatar Nov 15 '21 08:11 marandaneto

ideally, we'd patch https://github.com/getsentry/sentry-react-native/blob/master/sentry.gradle#L108-L124 to not add the args in case they don't have a value, so sentry-cli would be able to read the env. var.

"--auth-token", sentryProps.get("auth.token") ?: project.env.get("SENTRY_AUTH_TOKEN")

would be a solution but sentry-cli already looks up into SENTRY_AUTH_TOKEN in case there's no --auth-token set, so in that case, we should just not add --auth-token if sentryProps.get("auth.token") returns nothing. the same for url (SENTRY_URL), org (SENTRY_ORG) and project (SENTRY_PROJECT)

marandaneto avatar Nov 15 '21 08:11 marandaneto

@marandaneto that sounds much better indeed, any plans on doing that in the near future?

fragilehm avatar Nov 15 '21 12:11 fragilehm

@fragilehm we didn't define priorities yet, but it should not be super hard, what's about submitting a PR? would you be interested? I can guide with reviews

marandaneto avatar Nov 15 '21 13:11 marandaneto

Has anyone made any progress on this or is there another way to use env variables over sentry.properties?

kylegillen avatar Jun 23 '23 21:06 kylegillen

In the current version of RN SDK https://github.com/getsentry/sentry-react-native/releases/tag/5.6.0 and bundled Sentry CLI https://github.com/getsentry/sentry-cli/releases/tag/2.18.1 this works.

If auth token is present in sentry.properties it's used from the file. If not .env file is loaded and SENTRY_AUTH_TOKEN env is used.

krystofwoldrich avatar Jun 26 '23 09:06 krystofwoldrich