mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Update dependency prettier to v2.5.1 * prettier fixes * chore(toolkit): bump prettier to 2.5.1 * style(eslint): bump grafana config to 2.5.2 in core and toolkit * style(mssql-datasource): fix no-inferrable-types eslint errors Co-authored-by: Renovate Bot <bot@renovateapp.com> Co-authored-by: Ashley Harrison <ashley.harrison@grafana.com> Co-authored-by: Jack Westbrook <jack.westbrook@gmail.com>
44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
/**
|
|
* Set of handlers for secure password field in Angular components. They handle backward compatibility with
|
|
* passwords stored in plain text fields.
|
|
*/
|
|
|
|
import { SyntheticEvent } from 'react';
|
|
|
|
export enum PasswordFieldEnum {
|
|
Password = 'password',
|
|
BasicAuthPassword = 'basicAuthPassword',
|
|
}
|
|
|
|
/**
|
|
* Basic shape for settings controllers in at the moment mostly angular data source plugins.
|
|
*/
|
|
export type Ctrl = {
|
|
current: {
|
|
secureJsonFields: {
|
|
[key: string]: boolean;
|
|
};
|
|
secureJsonData?: {
|
|
[key: string]: string;
|
|
};
|
|
password?: string;
|
|
basicAuthPassword?: string;
|
|
};
|
|
};
|
|
|
|
export const createResetHandler =
|
|
(ctrl: Ctrl, field: PasswordFieldEnum) => (event: SyntheticEvent<HTMLInputElement>) => {
|
|
event.preventDefault();
|
|
// Reset also normal plain text password to remove it and only save it in secureJsonData.
|
|
ctrl.current[field] = undefined;
|
|
ctrl.current.secureJsonFields[field] = false;
|
|
ctrl.current.secureJsonData = ctrl.current.secureJsonData || {};
|
|
ctrl.current.secureJsonData[field] = '';
|
|
};
|
|
|
|
export const createChangeHandler =
|
|
(ctrl: any, field: PasswordFieldEnum) => (event: SyntheticEvent<HTMLInputElement>) => {
|
|
ctrl.current.secureJsonData = ctrl.current.secureJsonData || {};
|
|
ctrl.current.secureJsonData[field] = event.currentTarget.value;
|
|
};
|