-
Notifications
You must be signed in to change notification settings - Fork 147
Expand file tree
/
Copy pathGoogleJWT.tsx
More file actions
81 lines (79 loc) · 2.75 KB
/
Copy pathGoogleJWT.tsx
File metadata and controls
81 lines (79 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import React, { useState } from 'react';
import { FileDropzone, LinkButton, Button, InlineFormLabel, Input } from '@grafana/ui';
import type { DataSourceSettings } from '@grafana/data';
import type { InfinityOptions } from '@/types';
type GoogleJWTEditorProps = {
options: DataSourceSettings<InfinityOptions, {}>;
onChange: (options: DataSourceSettings<InfinityOptions, {}>) => void;
children?: React.ReactNode;
moreLink?: string;
};
export const GoogleJWTEditor = (props: GoogleJWTEditorProps) => {
const { options, onChange: onOptionsChange } = props;
const [jwt, setJwt] = useState<any>(null);
const [scopes, setScopes] = useState<string>((options?.jsonData?.oauth2?.scopes || []).join(''));
return (
<>
<div className="gf-form">
<FileDropzone
options={{ multiple: false }}
onLoad={(result) => {
try {
const json = JSON.parse(result as string);
setJwt(json);
} catch (ex) {
setJwt(null);
}
}}
/>
</div>
{(scopes !== '' || jwt !== null) && (
<div className="gf-form">
<InlineFormLabel width={10} tooltip="Scopes optionally specifies a list of requested permission scopes. Enter comma separated values">
Scopes
</InlineFormLabel>
<Input onChange={(e) => setScopes(e.currentTarget.value)} value={scopes} placeholder={'Comma separated values of scopes'} />
</div>
)}
{props.children}
<div style={{ textAlign: 'center', width: '100%', marginBlock: '20px' }}>
{props.moreLink && (
<LinkButton href={props.moreLink} target="_blank" variant={'secondary'} icon="question-circle">
More details
</LinkButton>
)}
<Button
style={{ marginInline: '10px' }}
onClick={() => {
if (jwt !== null) {
onOptionsChange({
...options,
jsonData: {
...options.jsonData,
auth_method: 'oauth2',
oauth2: {
oauth2_type: 'jwt',
email: jwt['client_email'] || '',
private_key_id: jwt['private_key_id'],
token_url: jwt['token_uri'],
scopes: scopes.split(','),
},
},
secureJsonData: {
...options.secureJsonData,
oauth2JWTPrivateKey: jwt['private_key'],
},
secureJsonFields: {
...options.secureJsonFields,
oauth2JWTPrivateKey: true,
},
});
}
}}
>
Update
</Button>
</div>
</>
);
};