Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store access token in secureJsonData #277

Merged
merged 2 commits into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkg/trino/models/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,8 @@ func (s *TrinoDatasourceSettings) Load(config backend.DataSourceInstanceSettings
if err != nil {
return err
}
if token, ok := config.DecryptedSecureJSONData["accessToken"]; ok {
s.AccessToken = token
}
return nil
}
21 changes: 13 additions & 8 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 { DataSourceHttpSettings, InlineField, InlineSwitch, SecretInput } 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}})
nineinchnick marked this conversation as resolved.
Show resolved Hide resolved
}
const onResetToken = () => {
onOptionsChange({...options, secureJsonFields: {...options.secureJsonFields, accessToken: false }, secureJsonData: {...options.secureJsonData, accessToken: '' }});
};
return (
<div className="gf-form-group">
<DataSourceHttpSettings
Expand All @@ -41,14 +44,16 @@ 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 || ''}
<SecretInput
value={options.secureJsonData?.accessToken ?? ''}
isConfigured={options.secureJsonFields?.accessToken}
onChange={onTokenChange}
width={40}
onReset={onResetToken}
/>
</InlineField>
</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
}
}
}
Loading