|
16 | 16 |
|
17 | 17 | import React, { PureComponent } from 'react'; |
18 | 18 | import { DataSourcePluginOptionsEditorProps } from '@grafana/data'; |
19 | | -import { DataSourceSecureJsonData, ConnectionConfig } from '@grafana/google-sdk'; |
20 | | -import { Label } from '@grafana/ui'; |
21 | | -import { CloudLoggingOptions } from 'types'; |
| 19 | +import { ConnectionConfig } from '@grafana/google-sdk'; |
| 20 | +import { Label, SecretInput } from '@grafana/ui'; |
| 21 | +import { CloudLoggingOptions, DataSourceSecureJsonData } from './types'; |
22 | 22 |
|
23 | 23 | export type Props = DataSourcePluginOptionsEditorProps<CloudLoggingOptions, DataSourceSecureJsonData>; |
24 | 24 |
|
25 | 25 | export class ConfigEditor extends PureComponent<Props> { |
26 | | - state = { |
27 | | - isChecked: this.props.options.jsonData.usingImpersonation || false, |
28 | | - sa: this.props.options.jsonData.serviceAccountToImpersonate || '', |
29 | | - }; |
30 | | - handleClick = () => { |
31 | | - this.props.options.jsonData.usingImpersonation = !this.state.isChecked; |
32 | | - this.setState({ |
33 | | - isChecked: !this.state.isChecked, |
34 | | - }); |
35 | | - } |
36 | | - render() { |
37 | | - return ( |
38 | | - <> |
39 | | - <ConnectionConfig {...this.props}></ConnectionConfig> |
40 | | - <div> |
41 | | - <input type="checkbox" onChange={this.handleClick} checked={this.state.isChecked} /> To impersonate an existing Google Cloud service account. |
42 | | - <div hidden={!this.state.isChecked}> |
43 | | - <Label>Service Account:</Label> |
44 | | - <input |
45 | | - size={60} |
46 | | - id="serviceAccount" |
47 | | - value={this.state.sa} |
48 | | - onChange={(e) => { |
49 | | - this.setState({ sa: e.target.value }, |
50 | | - () => { this.props.options.jsonData.serviceAccountToImpersonate = this.state.sa; }); |
51 | | - }} |
52 | | - /> |
53 | | - </div> |
54 | | - </div> |
55 | | - </> |
56 | | - ); |
57 | | - } |
| 26 | + state = { |
| 27 | + isChecked: this.props.options.jsonData.usingImpersonation || false, |
| 28 | + sa: this.props.options.jsonData.serviceAccountToImpersonate || '', |
| 29 | + }; |
| 30 | + |
| 31 | + handleClick = () => { |
| 32 | + this.props.options.jsonData.usingImpersonation = !this.state.isChecked; |
| 33 | + this.setState({ |
| 34 | + isChecked: !this.state.isChecked, |
| 35 | + }); |
| 36 | + }; |
| 37 | + render() { |
| 38 | + const { options, onOptionsChange } = this.props; |
| 39 | + const secureJsonData = options.secureJsonData || {}; |
| 40 | + |
| 41 | + return ( |
| 42 | + <> |
| 43 | + <ConnectionConfig {...this.props}></ConnectionConfig> |
| 44 | + <div> |
| 45 | + <input type="checkbox" onChange={this.handleClick} checked={this.state.isChecked} /> To impersonate an |
| 46 | + existing Google Cloud service account. |
| 47 | + <div hidden={!this.state.isChecked}> |
| 48 | + <Label>Service Account:</Label> |
| 49 | + <input |
| 50 | + size={60} |
| 51 | + id="serviceAccount" |
| 52 | + value={this.state.sa} |
| 53 | + onChange={(e) => { |
| 54 | + this.setState({ sa: e.target.value }, () => { |
| 55 | + this.props.options.jsonData.serviceAccountToImpersonate = this.state.sa; |
| 56 | + }); |
| 57 | + }} |
| 58 | + /> |
| 59 | + </div> |
| 60 | + <div style={{ marginTop: '10px' }}> |
| 61 | + <div className="gf-form-label__desc"> |
| 62 | + Alternatively, configure a temporary access token and a project ID. This will override other |
| 63 | + authentication methods. |
| 64 | + </div> |
| 65 | + <div style={{ marginTop: '10px' }}> |
| 66 | + <Label>Access Token</Label> |
| 67 | + <SecretInput |
| 68 | + value={secureJsonData.accessToken || ''} |
| 69 | + onChange={(e: React.ChangeEvent<HTMLInputElement>) => { |
| 70 | + onOptionsChange({ |
| 71 | + ...options, |
| 72 | + secureJsonData: { |
| 73 | + ...secureJsonData, |
| 74 | + accessToken: e.target.value, |
| 75 | + }, |
| 76 | + }); |
| 77 | + }} |
| 78 | + isConfigured={!!options.secureJsonFields?.accessToken} |
| 79 | + onReset={() => { |
| 80 | + onOptionsChange({ |
| 81 | + ...options, |
| 82 | + secureJsonData: { |
| 83 | + ...secureJsonData, |
| 84 | + accessToken: '', |
| 85 | + }, |
| 86 | + secureJsonFields: { |
| 87 | + ...options.secureJsonFields, |
| 88 | + accessToken: false, |
| 89 | + }, |
| 90 | + }); |
| 91 | + }} |
| 92 | + /> |
| 93 | + </div> |
| 94 | + <div style={{ marginTop: '10px' }}> |
| 95 | + <Label>Project ID</Label> |
| 96 | + <input |
| 97 | + value={options.jsonData.defaultProject || ''} |
| 98 | + onChange={(e: React.ChangeEvent<HTMLInputElement>) => { |
| 99 | + onOptionsChange({ |
| 100 | + ...options, |
| 101 | + jsonData: { |
| 102 | + ...options.jsonData, |
| 103 | + defaultProject: e.target.value, |
| 104 | + }, |
| 105 | + }); |
| 106 | + }} |
| 107 | + /> |
| 108 | + </div> |
| 109 | + </div> |
| 110 | + </div> |
| 111 | + </> |
| 112 | + ); |
| 113 | + } |
58 | 114 | } |
0 commit comments