projectKeyCredentials.tsx 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. import {Component, Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import Field from 'sentry/components/forms/field';
  4. import TextCopyInput from 'sentry/components/forms/textCopyInput';
  5. import ExternalLink from 'sentry/components/links/externalLink';
  6. import Link from 'sentry/components/links/link';
  7. import {t, tct} from 'sentry/locale';
  8. import space from 'sentry/styles/space';
  9. import getDynamicText from 'sentry/utils/getDynamicText';
  10. import {ProjectKey} from 'sentry/views/settings/project/projectKeys/types';
  11. const DEFAULT_PROPS = {
  12. showDsn: true,
  13. showDsnPublic: true,
  14. showSecurityEndpoint: true,
  15. showMinidump: true,
  16. showUnreal: true,
  17. showPublicKey: false,
  18. showSecretKey: false,
  19. showProjectId: false,
  20. };
  21. type Props = {
  22. data: ProjectKey;
  23. projectId: string;
  24. } & typeof DEFAULT_PROPS;
  25. type State = {
  26. showDeprecatedDsn: boolean;
  27. };
  28. class ProjectKeyCredentials extends Component<Props, State> {
  29. static defaultProps = DEFAULT_PROPS;
  30. state: State = {
  31. showDeprecatedDsn: false,
  32. };
  33. toggleDeprecatedDsn = () => {
  34. this.setState(state => ({
  35. showDeprecatedDsn: !state.showDeprecatedDsn,
  36. }));
  37. };
  38. render() {
  39. const {showDeprecatedDsn} = this.state;
  40. const {
  41. projectId,
  42. data,
  43. showDsn,
  44. showDsnPublic,
  45. showSecurityEndpoint,
  46. showMinidump,
  47. showUnreal,
  48. showPublicKey,
  49. showSecretKey,
  50. showProjectId,
  51. } = this.props;
  52. return (
  53. <Fragment>
  54. {showDsnPublic && (
  55. <Field
  56. label={t('DSN')}
  57. inline={false}
  58. flexibleControlStateSize
  59. help={tct('The DSN tells the SDK where to send the events to. [link]', {
  60. link: showDsn ? (
  61. <Link to="" onClick={this.toggleDeprecatedDsn}>
  62. {showDeprecatedDsn
  63. ? t('Hide deprecated DSN')
  64. : t('Show deprecated DSN')}
  65. </Link>
  66. ) : null,
  67. })}
  68. >
  69. <TextCopyInput>
  70. {getDynamicText({
  71. value: data.dsn.public,
  72. fixed: '__DSN__',
  73. })}
  74. </TextCopyInput>
  75. {showDeprecatedDsn && (
  76. <StyledField
  77. label={null}
  78. help={t(
  79. 'Deprecated DSN includes a secret which is no longer required by newer SDK versions. If you are unsure which to use, follow installation instructions for your language.'
  80. )}
  81. inline={false}
  82. flexibleControlStateSize
  83. >
  84. <TextCopyInput>
  85. {getDynamicText({
  86. value: data.dsn.secret,
  87. fixed: '__DSN_DEPRECATED__',
  88. })}
  89. </TextCopyInput>
  90. </StyledField>
  91. )}
  92. </Field>
  93. )}
  94. {/* this edge case should imho not happen, but just to be sure */}
  95. {!showDsnPublic && showDsn && (
  96. <Field
  97. label={t('DSN (Deprecated)')}
  98. help={t(
  99. 'Deprecated DSN includes a secret which is no longer required by newer SDK versions. If you are unsure which to use, follow installation instructions for your language.'
  100. )}
  101. inline={false}
  102. flexibleControlStateSize
  103. >
  104. <TextCopyInput>
  105. {getDynamicText({
  106. value: data.dsn.secret,
  107. fixed: '__DSN_DEPRECATED__',
  108. })}
  109. </TextCopyInput>
  110. </Field>
  111. )}
  112. {showSecurityEndpoint && (
  113. <Field
  114. label={t('Security Header Endpoint')}
  115. help={t(
  116. 'Use your security header endpoint for features like CSP and Expect-CT reports.'
  117. )}
  118. inline={false}
  119. flexibleControlStateSize
  120. >
  121. <TextCopyInput>
  122. {getDynamicText({
  123. value: data.dsn.security,
  124. fixed: '__SECURITY_HEADER_ENDPOINT__',
  125. })}
  126. </TextCopyInput>
  127. </Field>
  128. )}
  129. {showMinidump && (
  130. <Field
  131. label={t('Minidump Endpoint')}
  132. help={tct(
  133. 'Use this endpoint to upload [link], for example with Electron, Crashpad or Breakpad.',
  134. {
  135. link: (
  136. <ExternalLink href="https://docs.sentry.io/platforms/native/guides/minidumps/">
  137. minidump crash reports
  138. </ExternalLink>
  139. ),
  140. }
  141. )}
  142. inline={false}
  143. flexibleControlStateSize
  144. >
  145. <TextCopyInput>
  146. {getDynamicText({
  147. value: data.dsn.minidump,
  148. fixed: '__MINIDUMP_ENDPOINT__',
  149. })}
  150. </TextCopyInput>
  151. </Field>
  152. )}
  153. {showUnreal && (
  154. <Field
  155. label={t('Unreal Engine 4 Endpoint')}
  156. help={t('Use this endpoint to configure your UE4 Crash Reporter.')}
  157. inline={false}
  158. flexibleControlStateSize
  159. >
  160. <TextCopyInput>
  161. {getDynamicText({
  162. value: data.dsn.unreal || '',
  163. fixed: '__UNREAL_ENDPOINT__',
  164. })}
  165. </TextCopyInput>
  166. </Field>
  167. )}
  168. {showPublicKey && (
  169. <Field label={t('Public Key')} inline flexibleControlStateSize>
  170. <TextCopyInput>
  171. {getDynamicText({
  172. value: data.public,
  173. fixed: '__PUBLICKEY__',
  174. })}
  175. </TextCopyInput>
  176. </Field>
  177. )}
  178. {showSecretKey && (
  179. <Field label={t('Secret Key')} inline flexibleControlStateSize>
  180. <TextCopyInput>
  181. {getDynamicText({
  182. value: data.secret,
  183. fixed: '__SECRETKEY__',
  184. })}
  185. </TextCopyInput>
  186. </Field>
  187. )}
  188. {showProjectId && (
  189. <Field label={t('Project ID')} inline flexibleControlStateSize>
  190. <TextCopyInput>
  191. {getDynamicText({
  192. value: projectId,
  193. fixed: '__PROJECTID__',
  194. })}
  195. </TextCopyInput>
  196. </Field>
  197. )}
  198. </Fragment>
  199. );
  200. }
  201. }
  202. const StyledField = styled(Field)`
  203. padding: ${space(0.5)} 0 0 0;
  204. `;
  205. export default ProjectKeyCredentials;