Skip to content

Commit

Permalink
Store access token in secureJsonData
Browse files Browse the repository at this point in the history
  • Loading branch information
nineinchnick committed Nov 18, 2024
1 parent 856c638 commit 5d6633d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
27 changes: 20 additions & 7 deletions src/ConfigEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { ChangeEvent, PureComponent } from 'react';
import { DataSourceHttpSettings, InlineField, InlineSwitch, Input } from '@grafana/ui';
import { DataSourcePluginOptionsEditorProps } from '@grafana/data';
import { TrinoDataSourceOptions } from './types';
import {TrinoDataSourceOptions, TrinoSecureJsonData} from './types';

interface Props extends DataSourcePluginOptionsEditorProps<TrinoDataSourceOptions> {}
interface Props extends DataSourcePluginOptionsEditorProps<TrinoDataSourceOptions, TrinoSecureJsonData> {}

interface State {}

Expand All @@ -14,8 +14,11 @@ export class ConfigEditor extends PureComponent<Props, State> {
onOptionsChange({...options, jsonData: {...options.jsonData, enableImpersonation: event.target.checked}})
}
const onTokenChange = (event: ChangeEvent<HTMLInputElement>) => {
onOptionsChange({...options, jsonData: {...options.jsonData, accessToken: event.target.value}})
onOptionsChange({...options, secureJsonData: {...options.secureJsonData, accessToken: event.target.value}})
}
const onResetToken = () => {
onOptionsChange({...options, secureJsonFields: {...options.secureJsonFields, accessToken: false }, secureJsonData: {...options.secureJsonData, accessToken: '' }});
};
return (
<div className="gf-form-group">
<DataSourceHttpSettings
Expand All @@ -41,16 +44,26 @@ export class ConfigEditor extends PureComponent<Props, State> {
</div>
<div className="gf-form-inline">
<InlineField
label="Access Token"
tooltip="If set, use the Access Token for authentication to Trino"
label="Access token"
tooltip="If set, use the access token for authentication to Trino"
labelWidth={26}
>
<Input
value={options.jsonData?.accessToken || ''}
<Input
placeholder={options.secureJsonFields?.accessToken ? 'configured' : ''}
value={options.secureJsonData?.accessToken ?? ''}
onChange={onTokenChange}
width={40}
/>
</InlineField>
<InlineField
label="Reset access token"
tooltip="Clear any previously set access token"
labelWidth={26}
>
<InlineSwitch
onChange={onResetToken}
/>
</InlineField>
</div>
</div>
</div>
Expand Down
5 changes: 4 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,12 @@ ORDER BY
* These are options configured for each DataSource instance.
*/

export interface TrinoSecureJsonData {
accessToken?: string;
}

export interface TrinoDataSourceOptions extends DataSourceJsonData {
enableImpersonation?: boolean;
accessToken?: string;
}
/**
* Value that is used in the backend, but never sent over HTTP to the frontend
Expand Down
6 changes: 4 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"compilerOptions": {
"rootDir": "./src",
"baseUrl": "./src",
"typeRoots": ["./node_modules/@types"]
"typeRoots": ["./node_modules/@types"],
"jsx": "react",
"allowSyntheticDefaultImports": true
}
}
}

0 comments on commit 5d6633d

Please sign in to comment.