projectKeyCredentials.tsx 5.7 KB

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