mirror of
https://github.com/grafana/grafana.git
synced 2025-02-20 11:48:34 -06:00
* postgres SSL certification * add back the UI to configure SSL Authentication files by file path * add backend logic * correct unittest * mini changes * Update public/app/plugins/datasource/postgres/config_ctrl.ts Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com> * Update public/app/plugins/datasource/postgres/partials/config.html Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com> * mutex * check file exist before remove * change permission * change default configuremethod to file-path * Update public/app/plugins/datasource/postgres/partials/config.html Co-authored-by: Marcus Efraimsson <marcus.efraimsson@gmail.com> * Update public/app/plugins/datasource/postgres/partials/config.html Co-authored-by: Marcus Efraimsson <marcus.efraimsson@gmail.com> * Update public/app/plugins/datasource/postgres/partials/config.html Co-authored-by: Marcus Efraimsson <marcus.efraimsson@gmail.com> * Update public/app/plugins/datasource/postgres/partials/config.html Co-authored-by: Marcus Efraimsson <marcus.efraimsson@gmail.com> * rename sslconfiguremethod to sslconfigurationmethod * frontend update * solve comments * Postgres: Convert tests to stdlib Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Postgres: Be consistent about TLS/SSL terminology Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * fix init inconsistancy * Fix tests Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * naming convention * Fix tests Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Fix tests Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Undo change Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Fix TLS issue Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Fix tests Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Fix tests Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * change permissions * Fix data source field names Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Clean up HTML Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Improve popover text Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Fix SSL input bug Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Undo unnecessary change Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Clean up backend code Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Fix build Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * More consistent naming Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Clean up code Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Enforce certificate file permissions Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * add settings * Undo changes Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * fix windows file path * PostgresDataSource: Fix mutex usage Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Fix tests Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Update pkg/tsdb/postgres/postgres.go Co-authored-by: Marcus Efraimsson <marcus.efraimsson@gmail.com> * Apply suggestions from code review Co-authored-by: Marcus Efraimsson <marcus.efraimsson@gmail.com> * fix compilation * fix unittest * Apply suggestions from code review Co-authored-by: Marcus Efraimsson <marcus.efraimsson@gmail.com> * Apply suggestions from code review Co-authored-by: Marcus Efraimsson <marcus.efraimsson@gmail.com> * mock function * change kmutex package * add kmutex into middleware * lock connection file per datasource * add unittest regarding concurrency * version should be equal * adding unittest * fix the loop * fix unitest * fix postgres unittst * remove comments * move dataPath from arg to tlsManager struct field * Use DecryptedValues method Use cached decrypted values instead of using secure json data decrypt which will decrypt unchanged values over and over again. * remove unneeded mutex in tests and cleanup tests * fix the lint Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com> Co-authored-by: Marcus Efraimsson <marcus.efraimsson@gmail.com>
90 lines
2.9 KiB
TypeScript
90 lines
2.9 KiB
TypeScript
import _ from 'lodash';
|
|
import {
|
|
createChangeHandler,
|
|
createResetHandler,
|
|
PasswordFieldEnum,
|
|
} from '../../../features/datasources/utils/passwordHandlers';
|
|
import DatasourceSrv from 'app/features/plugins/datasource_srv';
|
|
|
|
export class PostgresConfigCtrl {
|
|
static templateUrl = 'partials/config.html';
|
|
|
|
current: any;
|
|
datasourceSrv: any;
|
|
showTimescaleDBHelp: boolean;
|
|
onPasswordReset: ReturnType<typeof createResetHandler>;
|
|
onPasswordChange: ReturnType<typeof createChangeHandler>;
|
|
|
|
/** @ngInject */
|
|
constructor($scope: any, datasourceSrv: DatasourceSrv) {
|
|
this.datasourceSrv = datasourceSrv;
|
|
this.current.jsonData.sslmode = this.current.jsonData.sslmode || 'verify-full';
|
|
this.current.jsonData.tlsConfigurationMethod = this.current.jsonData.tlsConfigurationMethod || 'file-path';
|
|
this.current.jsonData.postgresVersion = this.current.jsonData.postgresVersion || 903;
|
|
this.showTimescaleDBHelp = false;
|
|
this.autoDetectFeatures();
|
|
this.onPasswordReset = createResetHandler(this, PasswordFieldEnum.Password);
|
|
this.onPasswordChange = createChangeHandler(this, PasswordFieldEnum.Password);
|
|
this.tlsModeMapping();
|
|
}
|
|
|
|
autoDetectFeatures() {
|
|
if (!this.current.id) {
|
|
return;
|
|
}
|
|
|
|
this.datasourceSrv.loadDatasource(this.current.name).then((ds: any) => {
|
|
return ds.getVersion().then((version: any) => {
|
|
version = Number(version[0].text);
|
|
|
|
// timescaledb is only available for 9.6+
|
|
if (version >= 906) {
|
|
ds.getTimescaleDBVersion().then((version: any) => {
|
|
if (version.length === 1) {
|
|
this.current.jsonData.timescaledb = true;
|
|
}
|
|
});
|
|
}
|
|
|
|
const major = Math.trunc(version / 100);
|
|
const minor = version % 100;
|
|
let name = String(major);
|
|
if (version < 1000) {
|
|
name = String(major) + '.' + String(minor);
|
|
}
|
|
if (!_.find(this.postgresVersions, (p: any) => p.value === version)) {
|
|
this.postgresVersions.push({ name: name, value: version });
|
|
}
|
|
this.current.jsonData.postgresVersion = version;
|
|
});
|
|
});
|
|
}
|
|
|
|
toggleTimescaleDBHelp() {
|
|
this.showTimescaleDBHelp = !this.showTimescaleDBHelp;
|
|
}
|
|
|
|
tlsModeMapping() {
|
|
if (this.current.jsonData.sslmode === 'disable') {
|
|
this.current.jsonData.tlsAuth = false;
|
|
this.current.jsonData.tlsAuthWithCACert = false;
|
|
this.current.jsonData.tlsSkipVerify = true;
|
|
} else {
|
|
this.current.jsonData.tlsAuth = true;
|
|
this.current.jsonData.tlsAuthWithCACert = true;
|
|
this.current.jsonData.tlsSkipVerify = false;
|
|
}
|
|
}
|
|
|
|
// the value portion is derived from postgres server_version_num/100
|
|
postgresVersions = [
|
|
{ name: '9.3', value: 903 },
|
|
{ name: '9.4', value: 904 },
|
|
{ name: '9.5', value: 905 },
|
|
{ name: '9.6', value: 906 },
|
|
{ name: '10', value: 1000 },
|
|
{ name: '11', value: 1100 },
|
|
{ name: '12', value: 1200 },
|
|
];
|
|
}
|