forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Refactor] Replace url parse format resolve with whatwg url (opensear…
…ch-project#2910) Replace the url.parse/url.format/url.resolve function in the code base with whatwg-url. The main change is to change the url.parse to new URL(), and change url.format to [URL object].toString and change the url.resolve to new URL() toString(). Another major change is to replace the url parts in test config with URL object for transmission. Partially completes opensearch-project#1561 Signed-off-by: Lin Wang <[email protected]> Co-authored-by: Josh Romero <[email protected]>
- Loading branch information
1 parent
79a1052
commit bd51e23
Showing
49 changed files
with
240 additions
and
289 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,6 @@ | |
* under the License. | ||
*/ | ||
|
||
import url, { format as formatUrl } from 'url'; | ||
import pkg from '../../../../package.json'; | ||
import { adminTestUser } from '../osd'; | ||
|
||
|
@@ -42,7 +41,7 @@ export const opensearchTestConfig = new (class OpenSearchTestConfig { | |
} | ||
|
||
getUrl() { | ||
return formatUrl(this.getUrlParts()); | ||
return this.getUrlParts().serverUrl; | ||
} | ||
|
||
getBuildFrom() { | ||
|
@@ -56,30 +55,39 @@ export const opensearchTestConfig = new (class OpenSearchTestConfig { | |
getUrlParts() { | ||
// Allow setting one complete TEST_OPENSEARCH_URL for opensearch like https://opensearch:[email protected]:9200 | ||
if (process.env.TEST_OPENSEARCH_URL) { | ||
const testOpenSearchUrl = url.parse(process.env.TEST_OPENSEARCH_URL); | ||
const testOpenSearchUrl = new URL('', process.env.TEST_OPENSEARCH_URL); | ||
testOpenSearchUrl.pathname = ''; | ||
return { | ||
// have to remove the ":" off protocol | ||
protocol: testOpenSearchUrl.protocol.slice(0, -1), | ||
hostname: testOpenSearchUrl.hostname, | ||
port: parseInt(testOpenSearchUrl.port, 10), | ||
username: testOpenSearchUrl.auth.split(':')[0], | ||
password: testOpenSearchUrl.auth.split(':')[1], | ||
auth: testOpenSearchUrl.auth, | ||
username: testOpenSearchUrl.username, | ||
password: testOpenSearchUrl.password, | ||
auth: `${testOpenSearchUrl.username}:${testOpenSearchUrl.password}`, | ||
fullURL: testOpenSearchUrl, | ||
serverUrl: testOpenSearchUrl.toString().slice(0, -1), | ||
}; | ||
} | ||
|
||
const username = process.env.TEST_OPENSEARCH_USERNAME || adminTestUser.username; | ||
const password = process.env.TEST_OPENSEARCH_PASSWORD || adminTestUser.password; | ||
const protocol = process.env.TEST_OPENSEARCH_PROTOCOL || 'http'; | ||
const hostname = process.env.TEST_OPENSEARCH_HOSTNAME || 'localhost'; | ||
const port = parseInt(process.env.TEST_OPENSEARCH_PORT, 10) || 9220; | ||
const fullURL = new URL('', `${protocol}://${username}:${password}@${hostname}:${port}`); | ||
|
||
return { | ||
// Allow setting any individual component(s) of the URL, | ||
// or use default values (username and password from ../osd/users.js) | ||
protocol: process.env.TEST_OPENSEARCH_PROTOCOL || 'http', | ||
hostname: process.env.TEST_OPENSEARCH_HOSTNAME || 'localhost', | ||
port: parseInt(process.env.TEST_OPENSEARCH_PORT, 10) || 9220, | ||
protocol, | ||
hostname, | ||
port, | ||
auth: `${username}:${password}`, | ||
username: username, | ||
password: password, | ||
fullURL, | ||
serverUrl: fullURL.toString().slice(0, -1), | ||
}; | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,6 @@ | |
* under the License. | ||
*/ | ||
|
||
import url from 'url'; | ||
import { opensearchDashboardsTestUser } from './users'; | ||
|
||
interface UrlParts { | ||
|
@@ -38,6 +37,8 @@ interface UrlParts { | |
auth?: string; | ||
username?: string; | ||
password?: string; | ||
fullURL: URL; | ||
serverUrl: string; | ||
} | ||
|
||
export const osdTestConfig = new (class OsdTestConfig { | ||
|
@@ -48,32 +49,45 @@ export const osdTestConfig = new (class OsdTestConfig { | |
getUrlParts(): UrlParts { | ||
// allow setting one complete TEST_OPENSEARCH_DASHBOARDS_URL for opensearch like https://opensearch:[email protected]:9200 | ||
if (process.env.TEST_OPENSEARCH_DASHBOARDS_URL) { | ||
const testOpenSearchDashboardsUrl = url.parse(process.env.TEST_OPENSEARCH_DASHBOARDS_URL); | ||
const testOpenSearchDashboardsUrl = new URL('', process.env.TEST_OPENSEARCH_DASHBOARDS_URL); | ||
testOpenSearchDashboardsUrl.pathname = ''; | ||
return { | ||
protocol: testOpenSearchDashboardsUrl.protocol?.slice(0, -1), | ||
hostname: testOpenSearchDashboardsUrl.hostname ?? undefined, | ||
port: testOpenSearchDashboardsUrl.port | ||
? parseInt(testOpenSearchDashboardsUrl.port, 10) | ||
: undefined, | ||
auth: testOpenSearchDashboardsUrl.auth ?? undefined, | ||
username: testOpenSearchDashboardsUrl.auth?.split(':')[0], | ||
password: testOpenSearchDashboardsUrl.auth?.split(':')[1], | ||
auth: | ||
testOpenSearchDashboardsUrl.username && testOpenSearchDashboardsUrl.password | ||
? `${testOpenSearchDashboardsUrl.username}:${testOpenSearchDashboardsUrl.password}` | ||
: undefined, | ||
username: testOpenSearchDashboardsUrl.username ?? undefined, | ||
password: testOpenSearchDashboardsUrl.password ?? undefined, | ||
fullURL: testOpenSearchDashboardsUrl, | ||
serverUrl: testOpenSearchDashboardsUrl.toString().slice(0, -1), | ||
}; | ||
} | ||
|
||
const username = | ||
process.env.TEST_OPENSEARCH_DASHBOARDS_USERNAME || opensearchDashboardsTestUser.username; | ||
const password = | ||
process.env.TEST_OPENSEARCH_DASHBOARDS_PASSWORD || opensearchDashboardsTestUser.password; | ||
const protocol = process.env.TEST_OPENSEARCH_DASHBOARDS_PROTOCOL || 'http'; | ||
const hostname = process.env.TEST_OPENSEARCH_DASHBOARDS_HOSTNAME || 'localhost'; | ||
const port = process.env.TEST_OPENSEARCH_DASHBOARDS_PORT | ||
? parseInt(process.env.TEST_OPENSEARCH_DASHBOARDS_PORT, 10) | ||
: 5620; | ||
const fullURL = new URL(`${protocol}://${username}:${password}@${hostname}:${port}`); | ||
|
||
return { | ||
protocol: process.env.TEST_OPENSEARCH_DASHBOARDS_PROTOCOL || 'http', | ||
hostname: process.env.TEST_OPENSEARCH_DASHBOARDS_HOSTNAME || 'localhost', | ||
port: process.env.TEST_OPENSEARCH_DASHBOARDS_PORT | ||
? parseInt(process.env.TEST_OPENSEARCH_DASHBOARDS_PORT, 10) | ||
: 5620, | ||
protocol, | ||
hostname, | ||
port, | ||
auth: `${username}:${password}`, | ||
username, | ||
password, | ||
fullURL, | ||
serverUrl: fullURL.toString().slice(0, -1), | ||
}; | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.