Skip to content

Commit

Permalink
Add serverUrl property and refactor slice(0, -1) to it
Browse files Browse the repository at this point in the history
Signed-off-by: Lin Wang <wonglam@amazon.com>
  • Loading branch information
wanglam committed Mar 21, 2023
1 parent 3d93282 commit a846ba1
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 28 deletions.
7 changes: 2 additions & 5 deletions packages/osd-opensearch-archiver/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export function runCli() {
throw createFlagError('--opensearch-url must be a string');
}
if (!opensearchUrl && config) {
opensearchUrl = config.get('servers.opensearch').fullURL.toString().slice(0, -1);
opensearchUrl = config.get('servers.opensearch.serverUrl');
}
if (!opensearchUrl) {
throw createFlagError('--opensearch-url or --config must be defined');
Expand All @@ -82,10 +82,7 @@ export function runCli() {
throw createFlagError('--opensearch-dashboards-url must be a string');
}
if (!opensearchDashboardsUrl && config) {
opensearchDashboardsUrl = config
.get('servers.opensearchDashboards')
.fullURL.toString()
.slice(0, -1) as string;
opensearchDashboardsUrl = config.get('servers.opensearchDashboards.serverUrl') as string;
}
if (!opensearchDashboardsUrl) {
throw createFlagError('---url or --config must be defined');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const urlPartsSchema = () =>
hash: Joi.string().regex(/^\//, 'start with a /'),
certificateAuthorities: Joi.array().items(Joi.binary()).optional(),
fullURL: Joi.object().type(URL),
serverUrl: Joi.string(),
})
.default();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const opensearchTestConfig = new (class OpenSearchTestConfig {
}

getUrl() {
return this.getUrlParts().fullURL.toString().slice(0, -1);
return this.getUrlParts().serverUrl;
}

getBuildFrom() {
Expand All @@ -66,6 +66,7 @@ export const opensearchTestConfig = new (class OpenSearchTestConfig {
password: testOpenSearchUrl.password,
auth: `${testOpenSearchUrl.username}:${testOpenSearchUrl.password}`,
fullURL: testOpenSearchUrl,
serverUrl: testOpenSearchUrl.toString().slice(0, -1),
};
}

Expand All @@ -86,6 +87,7 @@ export const opensearchTestConfig = new (class OpenSearchTestConfig {
username: username,
password: password,
fullURL,
serverUrl: fullURL.toString().slice(0, -1),
};
}
})();
3 changes: 3 additions & 0 deletions packages/osd-test/src/osd/osd_test_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ interface UrlParts {
username?: string;
password?: string;
fullURL: URL;
serverUrl: string;
}

export const osdTestConfig = new (class OsdTestConfig {
Expand All @@ -63,6 +64,7 @@ export const osdTestConfig = new (class OsdTestConfig {
username: testOpenSearchDashboardsUrl.username ?? undefined,
password: testOpenSearchDashboardsUrl.password ?? undefined,
fullURL: testOpenSearchDashboardsUrl,
serverUrl: testOpenSearchDashboardsUrl.toString().slice(0, -1),
};
}

Expand All @@ -85,6 +87,7 @@ export const osdTestConfig = new (class OsdTestConfig {
username,
password,
fullURL,
serverUrl: fullURL.toString().slice(0, -1),
};
}
})();
7 changes: 2 additions & 5 deletions test/api_integration/services/supertest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,12 @@ import supertestAsPromised from 'supertest-as-promised';

export function OpenSearchDashboardsSupertestProvider({ getService }: FtrProviderContext) {
const config = getService('config');
const opensearchDashboardsServerUrl = config
.get('servers.opensearchDashboards')
.fullURL.toString()
.slice(0, -1);
const opensearchDashboardsServerUrl = config.get('servers.opensearchDashboards.serverUrl');
return supertestAsPromised(opensearchDashboardsServerUrl);
}

export function OpenSearchSupertestProvider({ getService }: FtrProviderContext) {
const config = getService('config');
const elasticSearchServerUrl = config.get('servers.opensearch').fullURL.toString().slice(0, -1);
const elasticSearchServerUrl = config.get('servers.opensearch.serverUrl');
return supertestAsPromised(elasticSearchServerUrl);
}
2 changes: 1 addition & 1 deletion test/common/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default function () {
'--logging.json=false',
`--server.port=${osdTestConfig.getPort()}`,
'--status.allowAnonymous=true',
`--opensearch.hosts=${servers.opensearch.fullURL.toString().slice(0, -1)}`,
`--opensearch.hosts=${servers.opensearch.serverUrl}`,
`--opensearch.username=${opensearchDashboardsServerTestUser.username}`,
`--opensearch.password=${opensearchDashboardsServerTestUser.password}`,
`--home.disableWelcomeScreen=false`,
Expand Down
2 changes: 1 addition & 1 deletion test/common/services/legacy_opensearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function LegacyOpenSearchProvider({

return new legacyOpenSearch.Client({
apiVersion: DEFAULT_API_VERSION,
host: config.get('servers.opensearch.fullURL').toString().slice(0, -1),
host: config.get('servers.opensearch.serverUrl'),
requestTimeout: config.get('timeouts.opensearchRequestTimeout'),
});
}
4 changes: 2 additions & 2 deletions test/common/services/opensearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ export function OpenSearchProvider({ getService }: FtrProviderContext) {

if (process.env.TEST_CLOUD) {
return new Client({
nodes: [config.get('servers.opensearch.fullURL').toString().slice(0, -1)],
nodes: [config.get('servers.opensearch.serverUrl')],
requestTimeout: config.get('timeouts.opensearchRequestTimeout'),
});
} else {
return new Client({
ssl: {
ca: fs.readFileSync(CA_CERT_PATH, 'utf-8'),
},
nodes: [config.get('servers.opensearch.fullURL').toString().slice(0, -1)],
nodes: [config.get('servers.opensearch.serverUrl')],
requestTimeout: config.get('timeouts.opensearchRequestTimeout'),
});
}
Expand Down
5 changes: 1 addition & 4 deletions test/common/services/opensearch_archiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ export function OpenSearchArchiverProvider({
client,
dataDir,
log,
opensearchDashboardsUrl: config
.get('servers.opensearchDashboards.fullURL')
.toString()
.slice(0, -1),
opensearchDashboardsUrl: config.get('servers.opensearchDashboards.serverUrl'),
});

if (hasService('opensearchDashboardsServer')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function OpenSearchDashboardsServerProvider({ getService }: FtrProviderCo
const log = getService('log');
const config = getService('config');
const lifecycle = getService('lifecycle');
const url = config.get('servers.opensearchDashboards.fullURL').toString().slice(0, -1);
const url = config.get('servers.opensearchDashboards.serverUrl');
const defaults = config.get('uiSettings.defaults');
const osd = new OsdClient({
log,
Expand Down
5 changes: 1 addition & 4 deletions test/functional/services/supertest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ import supertestAsPromised from 'supertest-as-promised';

export function OpenSearchDashboardsSupertestProvider({ getService }: FtrProviderContext) {
const config = getService('config');
const opensearchDashboardsServerUrl = config
.get('servers.opensearchDashboards.fullURL')
.toString()
.slice(0, -1);
const opensearchDashboardsServerUrl = config.get('servers.opensearchDashboards.serverUrl');
return supertestAsPromised(opensearchDashboardsServerUrl);
}
6 changes: 2 additions & 4 deletions test/server_integration/services/supertest.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ export function createOpenSearchDashboardsSupertestProvider({
return function ({ getService }) {
const config = getService('config');
opensearchDashboardsUrl =
opensearchDashboardsUrl ??
config.get('servers.opensearchDashboards.fullURL').toString().slice(0, -1);
opensearchDashboardsUrl ?? config.get('servers.opensearchDashboards.serverUrl');

return certificateAuthorities
? supertestAsPromised.agent(opensearchDashboardsUrl, { ca: certificateAuthorities })
Expand All @@ -57,6 +56,5 @@ export function OpenSearchDashboardsSupertestWithoutAuthProvider({ getService })

export function OpenSearchSupertestProvider({ getService }) {
const config = getService('config');
const opensearchServerURL = config.get('servers.opensearch.fullURL');
return supertestAsPromised(opensearchServerURL.toString().slice(0, -1));
return supertestAsPromised(config.get('servers.opensearch.serverUrl'));
}

0 comments on commit a846ba1

Please sign in to comment.