config_ctrl.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import {
  2. createChangeHandler,
  3. createResetHandler,
  4. PasswordFieldEnum,
  5. } from '../../../features/datasources/utils/passwordHandlers';
  6. export class MssqlConfigCtrl {
  7. static templateUrl = 'partials/config.html';
  8. // Set through angular bindings
  9. declare current: any;
  10. onPasswordReset: ReturnType<typeof createResetHandler>;
  11. onPasswordChange: ReturnType<typeof createChangeHandler>;
  12. showUserCredentials = false;
  13. showTlsConfig = false;
  14. showCertificateConfig = false;
  15. /** @ngInject */
  16. constructor($scope: any) {
  17. this.current = $scope.ctrl.current;
  18. this.current.jsonData.encrypt = this.current.jsonData.encrypt || 'false';
  19. this.current.jsonData.sslRootCertFile = this.current.jsonData.sslRootCertFile || '';
  20. this.current.jsonData.tlsSkipVerify = this.current.jsonData.tlsSkipVerify || false;
  21. this.current.jsonData.serverName = this.current.jsonData.serverName || '';
  22. this.current.jsonData.authenticationType = this.current.jsonData.authenticationType || 'SQL Server Authentication';
  23. this.onPasswordReset = createResetHandler(this, PasswordFieldEnum.Password);
  24. this.onPasswordChange = createChangeHandler(this, PasswordFieldEnum.Password);
  25. this.onAuthenticationTypeChange();
  26. this.onEncryptChange();
  27. }
  28. onAuthenticationTypeChange() {
  29. // This is using the fallback in https://github.com/denisenkom/go-mssqldb to use Windows Auth if login/user id is empty.
  30. if (this.current.jsonData.authenticationType === 'Windows Authentication') {
  31. this.current.user = '';
  32. this.current.password = '';
  33. }
  34. this.showUserCredentials = this.current.jsonData.authenticationType !== 'Windows Authentication';
  35. }
  36. onEncryptChange() {
  37. this.showTlsConfig = this.current.jsonData.encrypt === 'true';
  38. this.showCertificateConfig = this.showTlsConfig && this.current.jsonData.tlsSkipVerify === false;
  39. }
  40. }