public SSHProxy(string server, int port, string sshServer, int sshPort, SshProxyCredentials sshCredentials) { this.Server = server; this.Port = port; this.SshServer = sshServer; this.SshPort = sshPort; this.SshCredentials = sshCredentials; _lastUsed = DateTime.Now; }
public bool TryUseDbConnection(DatabaseConnection connection, Action <DbConnection> action, out string error) { string password = _passwordManager.GetSecret(SecretType.DatabasePassword.ToString() + "_" + connection.DatabaseConnectionID); SshProxyCredentials credentials = null; if (connection.UseSsh) { credentials = new SshProxyCredentials(_passwordManager, connection); } return(TryUseDbConnection(connection.Type, connection.Server, connection.Port, connection.UseSsh, connection.SshServer, connection.SshPort, credentials, connection.Username, password, connection.DatabaseName, action, out error)); }
public bool TryUseDbConnection(DatabaseType type, string server, int port, bool useSsh, string sshServer, int?sshPort, SshProxyCredentials credentials, string username, string password, string databaseName, out string error) { return(TryUseDbConnection(type, server, port, useSsh, sshServer, sshPort, credentials, username, password, databaseName, conn => { return; }, out error)); }
public bool TryUseDbConnection(DatabaseType type, string server, int port, bool useSsh, string sshServer, int?sshPort, SshProxyCredentials credentials, string username, string password, string databaseName, Action <DbConnection> action, out string error) { error = null; bool databaseAccessDenied = false; try { if (useSsh) { return(SSHProxyManager.TryUseProxy(server, port, sshServer, sshPort.GetValueOrDefault(22), credentials, proxy => { using (var conn = GetDbConnection(type, proxy.ProxyServer, proxy.ProxyPort, username, password, databaseName)) { action(conn); } }, out error)); } else { using (var conn = GetDbConnection(type, server, port, username, password, databaseName)) { action(conn); return(true); } } } catch (MySqlException e) { if (e.InnerException != null && e.InnerException.Message != null && e.InnerException.Message.StartsWith("Access denied")) { databaseAccessDenied = true; } else { throw; } } catch (SqlException e) { error = e.Message; } catch (Exception e) { error = e.Message; } if (databaseAccessDenied) { error = string.Format("Access denied for user='******'. Please check username and password are correct.", username); } return(error == null); }
public static bool TryUseProxy(string server, int port, string sshServer, int sshPort, SshProxyCredentials credentials, Action <SSHProxy> action, out string error) { error = null; Initialize(); SSHProxy proxy = null; if (TryAcquireExistingProxy(server, port, out proxy)) { UseProxy(proxy, action); return(true); } else { proxy = new SSHProxy(server, port, sshServer, sshPort, credentials); lock (_lock) { _proxies.Add(proxy); } Task.Run(() => proxy.Run()); proxy.WaitUntilStarted(); if (proxy.RequestUse()) { UseProxy(proxy, action); return(true); } else { error = proxy.Error; return(false); } } }
public static bool TryUseProxy(IPasswordManager passwordManager, DatabaseConnection connection, Action <SSHProxy> action, out string error) { SshProxyCredentials credentials = new SshProxyCredentials(passwordManager, connection); return(TryUseProxy(connection.Server, connection.Port, connection.SshServer, connection.SshPort.GetValueOrDefault(22), credentials, action, out error)); }
public static bool TryUseProxy(string server, int port, string sshServer, int sshPort, SshProxyCredentials credentials, DatabaseConnection connection, Action <SSHProxy> action, out string error) { return(TryUseProxy(server, port, sshServer, sshPort, credentials, action, out error)); }