* Tries connection to server to determine if client IP address is restricted by the firewall. * First tries with master connection, and then with user DB if first one fails. * @param SqlConnectionConfig The connection configuration to try. * @returns The client IP address if firewall
(connectionConfig: SqlConnectionConfig)
| 23 | * @returns The client IP address if firewall restriction is present, or an empty string if connection succeeds. Throws otherwise. |
| 24 | */ |
| 25 | static async detectIPAddress(connectionConfig: SqlConnectionConfig): Promise<string> { |
| 26 | // First try connection to master |
| 27 | let result = await this.tryConnection(connectionConfig, true); |
| 28 | if (result.success) { |
| 29 | return ''; |
| 30 | } |
| 31 | else if (result.ipAddress) { |
| 32 | return result.ipAddress; |
| 33 | } |
| 34 | |
| 35 | // Retry connection with user DB |
| 36 | result = await this.tryConnection(connectionConfig, false); |
| 37 | if (result.success) { |
| 38 | return ''; |
| 39 | } |
| 40 | else if (result.ipAddress) { |
| 41 | return result.ipAddress; |
| 42 | } |
| 43 | else { |
| 44 | throw new Error(`Failed to add firewall rule. Unable to detect client IP Address. ${result.errorMessage}`); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Tries connection with the specified configuration. |