From 8c8eb7befe0efac3665a65223ec9f3596be247d1 Mon Sep 17 00:00:00 2001 From: Saud Khanzada Date: Thu, 8 Apr 2021 20:59:06 +0500 Subject: [PATCH] fix(elasticsearch): update extractNameFromEndpoint method to remove search- prefix from domainEndpoint fixes: #13380 --- packages/@aws-cdk/aws-elasticsearch/lib/domain.ts | 9 +++++---- packages/@aws-cdk/aws-elasticsearch/test/domain.test.ts | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/@aws-cdk/aws-elasticsearch/lib/domain.ts b/packages/@aws-cdk/aws-elasticsearch/lib/domain.ts index a995b7394fe7d..bc538d026a64f 100644 --- a/packages/@aws-cdk/aws-elasticsearch/lib/domain.ts +++ b/packages/@aws-cdk/aws-elasticsearch/lib/domain.ts @@ -1759,11 +1759,12 @@ export class Domain extends DomainBase implements IDomain, ec2.IConnectable { * * Domain endpoints look like this: * - * https://example-domain-jcjotrt6f7otem4sqcwbch3c4u.us-east-1.es.amazonaws.com - * https://-..es.amazonaws.com + * https://search-example-domain-jcjotrt6f7otem4sqcwbch3c4u.us-east-1.es.amazonaws.com + * https://search--..es.amazonaws.com * * ..which means that in order to extract the domain name from the endpoint, we can - * split the endpoint using "-" and select the component in index 0. + * split the endpoint using "-" and select the component in index 0, and then replace + * the "search-" prefix. * * @param domainEndpoint The Elasticsearch domain endpoint */ @@ -1771,7 +1772,7 @@ function extractNameFromEndpoint(domainEndpoint: string) { const { hostname } = new URL(domainEndpoint); const domain = hostname.split('.')[0]; const suffix = '-' + domain.split('-').slice(-1)[0]; - return domain.split(suffix)[0]; + return domain.split(suffix)[0].replace('search-', ''); } /** diff --git a/packages/@aws-cdk/aws-elasticsearch/test/domain.test.ts b/packages/@aws-cdk/aws-elasticsearch/test/domain.test.ts index 8d21564a0e0eb..13cfabc2b105e 100644 --- a/packages/@aws-cdk/aws-elasticsearch/test/domain.test.ts +++ b/packages/@aws-cdk/aws-elasticsearch/test/domain.test.ts @@ -699,7 +699,7 @@ describe('grants', () => { }); test('"grant" for an imported domain', () => { - const domainEndpoint = 'https://test-domain-2w2x2u3tifly-jcjotrt6f7otem4sqcwbch3c4u.testregion.es.amazonaws.com'; + const domainEndpoint = 'https://search-test-domain-2w2x2u3tifly-jcjotrt6f7otem4sqcwbch3c4u.testregion.es.amazonaws.com'; const domain = Domain.fromDomainEndpoint(stack, 'Domain', domainEndpoint); const user = new iam.User(stack, 'user'); @@ -889,7 +889,7 @@ describe('import', () => { test('static fromDomainEndpoint(endpoint) allows importing an external/existing domain', () => { const domainName = 'test-domain-2w2x2u3tifly'; - const domainEndpoint = `https://${domainName}-jcjotrt6f7otem4sqcwbch3c4u.testregion.es.amazonaws.com`; + const domainEndpoint = `https://search-${domainName}-jcjotrt6f7otem4sqcwbch3c4u.testregion.es.amazonaws.com`; const imported = Domain.fromDomainEndpoint(stack, 'Domain', domainEndpoint); expect(imported.domainName).toEqual(domainName);