DataSourceHttpSettings.tsx 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. import React, { PureComponent } from 'react';
  2. interface Props {
  3. access: any;
  4. basicAuth: any;
  5. showAccessOption: any;
  6. tlsAuth: any;
  7. tlsAuthWithCACert: any;
  8. tlsCACert: any;
  9. tlsClientCert: any;
  10. tlsClientKey: any;
  11. url: any;
  12. }
  13. interface State {
  14. basicAuthUser: string;
  15. basicAuthPassword: string;
  16. showAccessHelp: boolean;
  17. }
  18. export default class DataSourceHttpSettings extends PureComponent<Props, State> {
  19. state = {
  20. basicAuthUser: '',
  21. basicAuthPassword: '',
  22. showAccessHelp: false,
  23. };
  24. onToggleAccessHelp = () => {};
  25. render() {
  26. const {
  27. access,
  28. basicAuth,
  29. showAccessOption,
  30. tlsAuth,
  31. tlsAuthWithCACert,
  32. tlsCACert,
  33. tlsClientCert,
  34. tlsClientKey,
  35. url,
  36. } = this.props;
  37. const { showAccessHelp, basicAuthUser, basicAuthPassword } = this.state;
  38. // const accessOptions = [{key: 'proxy', value: 'Server (Default)'}, { key: 'direct', value: 'Browser'}];
  39. return (
  40. <div className="gf-form-group">
  41. <h3 className="page-heading">HTTP</h3>
  42. <div className="gf-form-group">
  43. <div className="gf-form-inline">
  44. <div className="gf-form max-width-30">
  45. <span className="gf-form-label width-10">URL</span>
  46. <input className="gf-form-input" type="text" value={url} placeholder="https://localhost:9090" />
  47. </div>
  48. </div>
  49. {showAccessOption && (
  50. <div className="gf-form-inline">
  51. <div className="gf-form max-width-30">
  52. <span className="gf-form-label width-10">Access</span>
  53. <div className="gf-form-select-wrapper max-width-24" />
  54. </div>
  55. <div className="gf-form">
  56. <label className="gf-form-label query-keyword pointer" onClick={this.onToggleAccessHelp}>
  57. Help&nbsp;
  58. {showAccessHelp && <i className="fa fa-caret-down" />}
  59. {!showAccessHelp && <i className="fa fa-caret-right">&nbsp;</i>}
  60. </label>
  61. </div>
  62. </div>
  63. )}
  64. {showAccessHelp && (
  65. <div className="grafana-info-box m-t-2">
  66. <p>
  67. Access mode controls how requests to the data source will be handled.
  68. <strong>
  69. <i>Server</i>
  70. </strong>{' '}
  71. should be the preferred way if nothing else stated.
  72. </p>
  73. <div className="alert-title">Server access mode (Default):</div>
  74. <p>
  75. All requests will be made from the browser to Grafana backend/server which in turn will forward the
  76. requests to the data source and by that circumvent possible Cross-Origin Resource Sharing (CORS)
  77. requirements. The URL needs to be accessible from the grafana backend/server if you select this access
  78. mode.
  79. </p>
  80. <div className="alert-title">Browser access mode:</div>
  81. <p>
  82. All requests will be made from the browser directly to the data source and may be subject to
  83. Cross-Origin Resource Sharing (CORS) requirements. The URL needs to be accessible from the browser if
  84. you select this access mode.
  85. </p>
  86. </div>
  87. )}
  88. {access === 'proxy' && (
  89. <div className="gf-form-inline">
  90. <div className="gf-form">
  91. <span className="gf-form-label width-10">Whitelisted Cookies</span>
  92. </div>
  93. </div>
  94. )}
  95. <h3 className="page-heading">Auth</h3>
  96. <div className="gf-form-group">
  97. <div className="gf-form-inline" />
  98. <div className="gf-form-inline" />
  99. <div className="gf-form-inline" />
  100. </div>
  101. {basicAuth && (
  102. <div className="gf-form-group">
  103. <h6>Basic Auth Details</h6>
  104. <div className="gf-form">
  105. <span className="gf-form-label width-10">User</span>
  106. <input className="gf-form-input max-width-21" type="text" value={basicAuthUser} placeholder="User" />
  107. </div>
  108. <div className="gf-form">
  109. <span className="gf-form-label width-10">Password</span>
  110. <input
  111. className="gf-form-input max-width-21"
  112. type="password"
  113. value={basicAuthPassword}
  114. placeholder="Password"
  115. />
  116. </div>
  117. </div>
  118. )}
  119. {(tlsAuth || tlsAuthWithCACert) &&
  120. access === 'proxy' && (
  121. <div className="gf-form-group">
  122. <div className="gf-form">
  123. <h6>TLS Auth Details</h6>
  124. </div>
  125. {tlsAuthWithCACert && (
  126. <div>
  127. <div className="gf-form-inline">
  128. <div className="gf-form gf-form--v-stretch">
  129. <label className="gf-form-label width-7">CA Cert</label>
  130. </div>
  131. {!tlsCACert && (
  132. <div className="gf-form gf-form--grow">
  133. <textarea
  134. rows={7}
  135. className="gf-form-input gf-form-textarea"
  136. value={tlsCACert}
  137. placeholder="Begins with -----BEGIN CERTIFICATE-----"
  138. />
  139. </div>
  140. )}
  141. {tlsCACert && (
  142. <div className="gf-form">
  143. <input type="text" className="gf-form-input max-width-12" value="configured" />
  144. <a className="btn btn-secondary gf-form-btn" href="#" onClick={() => {}}>
  145. reset
  146. </a>
  147. </div>
  148. )}
  149. </div>
  150. </div>
  151. )}
  152. {tlsAuth && (
  153. <div>
  154. <div className="gf-form-inline">
  155. <div className="gf-form gf-form--v-stretch">
  156. <label className="gf-form-label width-7">Client Cert</label>
  157. </div>
  158. {!tlsClientCert && (
  159. <div className="gf-form gf-form--grow">
  160. <textarea
  161. rows={7}
  162. className="gf-form-input gf-form-textarea"
  163. value={tlsClientCert}
  164. placeholder="Begins with -----BEGIN CERTIFICATE-----"
  165. required
  166. />
  167. </div>
  168. )}
  169. {tlsClientCert && (
  170. <div className="gf-form">
  171. <input type="text" className="gf-form-input max-width-12" value="configured" />
  172. <a className="btn btn-secondary gf-form-btn" href="#" onClick={() => {}}>
  173. reset
  174. </a>
  175. </div>
  176. )}
  177. </div>
  178. <div className="gf-form-inline">
  179. <div className="gf-form gf-form--v-stretch">
  180. <label className="gf-form-label width-7">Client Key</label>
  181. </div>
  182. {tlsClientKey && (
  183. <div className="gf-form gf-form--grow">
  184. <textarea
  185. rows={7}
  186. className="gf-form-input gf-form-textarea"
  187. value={tlsClientKey}
  188. placeholder="Begins with -----BEGIN RSA PRIVATE KEY-----"
  189. />
  190. </div>
  191. )}
  192. {tlsClientKey && (
  193. <div className="gf-form">
  194. <input type="text" className="gf-form-input max-width-12" value="configured" />
  195. <a className="btn btn-secondary gf-form-btn" href="#" onClick={() => {}}>
  196. reset
  197. </a>
  198. </div>
  199. )}
  200. </div>
  201. </div>
  202. )}
  203. </div>
  204. )}
  205. </div>
  206. </div>
  207. );
  208. }
  209. }