-
Notifications
You must be signed in to change notification settings - Fork 916
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Refactor] Replace url parse format resolve with whatwg url #2910
Changes from 51 commits
4a67aec
c37c80d
c2511a8
2921fda
3247937
defe504
12cc53f
2218ede
3fc62a3
d1cc130
14b5497
a76fd60
592301b
5fabfd3
7c5e014
1517b5a
7248b3f
fea59fe
73a0cb4
0a293d1
7792efa
652a81c
7b0a2fc
90e29a1
9e8818c
f683ba2
b53ee93
c910dea
3d84d50
b73ac85
507c3a8
3bf1cad
f5a13f0
1731fc0
2d007f0
c2feeb4
610ca30
91c36b9
a2d7108
32ec422
3408cc5
27529b1
803c96a
63a8e87
12d2e78
4b061b3
ec8ce6a
d8ad24d
c74698b
9154295
6ebdd20
3d93282
a846ba1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,6 @@ | |
*************************************************************/ | ||
|
||
import Path from 'path'; | ||
import Url from 'url'; | ||
import readline from 'readline'; | ||
|
||
import { RunWithCommands, createFlagError } from '@osd/dev-utils'; | ||
|
@@ -72,7 +71,7 @@ export function runCli() { | |
throw createFlagError('--opensearch-url must be a string'); | ||
} | ||
if (!opensearchUrl && config) { | ||
opensearchUrl = Url.format(config.get('servers.opensearch')); | ||
opensearchUrl = config.get('servers.opensearch').fullURL.toString().slice(0, -1); | ||
} | ||
if (!opensearchUrl) { | ||
throw createFlagError('--opensearch-url or --config must be defined'); | ||
|
@@ -83,7 +82,10 @@ export function runCli() { | |
throw createFlagError('--opensearch-dashboards-url must be a string'); | ||
} | ||
if (!opensearchDashboardsUrl && config) { | ||
opensearchDashboardsUrl = Url.format(config.get('servers.opensearchDashboards')); | ||
opensearchDashboardsUrl = config | ||
.get('servers.opensearchDashboards') | ||
.fullURL.toString() | ||
.slice(0, -1) as string; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we still need the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah. The |
||
} | ||
if (!opensearchDashboardsUrl) { | ||
throw createFlagError('---url or --config must be defined'); | ||
|
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().fullURL.toString().slice(0, -1); | ||
} | ||
|
||
getBuildFrom() { | ||
|
@@ -56,30 +55,37 @@ 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); | ||
joshuarrrr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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, | ||
}; | ||
} | ||
|
||
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, | ||
}; | ||
} | ||
})(); |
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,7 @@ interface UrlParts { | |
auth?: string; | ||
username?: string; | ||
password?: string; | ||
fullURL: URL; | ||
} | ||
|
||
export const osdTestConfig = new (class OsdTestConfig { | ||
|
@@ -48,32 +48,43 @@ 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, | ||
}; | ||
} | ||
|
||
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, | ||
joshuarrrr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
} | ||
})(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍