MCPcopy Create free account
hub / github.com/Azure/sql-action / detectIPAddress

Method detectIPAddress

src/SqlUtils.ts:25–46  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

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.

Callers 1

runFunction · 0.45

Calls 1

tryConnectionMethod · 0.95

Tested by

no test coverage detected