-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(elasticsearch): deprecate all APIs except
ElasticsearchVersion
(
#19296) Closes #16530. Depends on #16529. This PR deprecates all APIs in `elasticsearch` in favor of the `opensearchservice` module. However, it does not deprecate `elasticsearch` as a module, since there are rules in place that disallow stable modules (like `cloudformation-include`) from depending on deprecated modules. See #19392. > `ElasticsearchVersion` was not deprecated due to a quirk in how the module is imported. It looks like, on import, the static properties `public static readonly V7_10 = ElasticsearchVersion.of('7.10');` actually tries to make the api call `of()`, which is deprecated. So imports fail with a message about using the deprecated api `ElasticsearchVersion.of()`. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
Showing
6 changed files
with
440 additions
and
244 deletions.
There are no files selected for viewing
235 changes: 119 additions & 116 deletions
235
packages/@aws-cdk/aws-appsync/test/appsync-elasticsearch.test.ts
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 |
---|---|---|
@@ -1,151 +1,154 @@ | ||
import * as path from 'path'; | ||
import { Template } from '@aws-cdk/assertions'; | ||
import * as es from '@aws-cdk/aws-elasticsearch'; | ||
import { testDeprecated } from '@aws-cdk/cdk-build-tools'; | ||
import { describeDeprecated } from '@aws-cdk/cdk-build-tools'; | ||
import * as cdk from '@aws-cdk/core'; | ||
import * as appsync from '../lib'; | ||
|
||
// GLOBAL GIVEN | ||
let stack: cdk.Stack; | ||
let api: appsync.GraphqlApi; | ||
let domain: es.Domain; | ||
beforeEach(() => { | ||
stack = new cdk.Stack(); | ||
api = new appsync.GraphqlApi(stack, 'baseApi', { | ||
name: 'api', | ||
schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), | ||
}); | ||
domain = new es.Domain(stack, 'EsDomain', { | ||
version: es.ElasticsearchVersion.V7_10, | ||
}); | ||
}); | ||
|
||
describe('Elasticsearch Data Source Configuration', () => { | ||
testDeprecated('Elasticsearch configure properly', () => { | ||
// WHEN | ||
api.addElasticsearchDataSource('ds', domain); | ||
|
||
// THEN | ||
Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { | ||
PolicyDocument: { | ||
Version: '2012-10-17', | ||
Statement: [{ | ||
Action: [ | ||
'es:ESHttpGet', | ||
'es:ESHttpHead', | ||
'es:ESHttpDelete', | ||
'es:ESHttpPost', | ||
'es:ESHttpPut', | ||
'es:ESHttpPatch', | ||
], | ||
Effect: 'Allow', | ||
Resource: [{ | ||
'Fn::GetAtt': ['EsDomain1213C634', 'Arn'], | ||
}, | ||
{ | ||
'Fn::Join': ['', [{ | ||
'Fn::GetAtt': ['EsDomain1213C634', 'Arn'], | ||
}, '/*']], | ||
}], | ||
}], | ||
}, | ||
|
||
describeDeprecated('Appsync Elasticsearch integration', () => { | ||
beforeEach(() => { | ||
stack = new cdk.Stack(); | ||
api = new appsync.GraphqlApi(stack, 'baseApi', { | ||
name: 'api', | ||
schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), | ||
}); | ||
domain = new es.Domain(stack, 'EsDomain', { | ||
version: es.ElasticsearchVersion.V7_10, | ||
}); | ||
}); | ||
|
||
testDeprecated('Elastic search configuration contains fully qualified url', () => { | ||
// WHEN | ||
api.addElasticsearchDataSource('ds', domain); | ||
|
||
// THEN | ||
Template.fromStack(stack).hasResourceProperties('AWS::AppSync::DataSource', { | ||
ElasticsearchConfig: { | ||
Endpoint: { | ||
'Fn::Join': ['', ['https://', { | ||
'Fn::GetAtt': ['EsDomain1213C634', 'DomainEndpoint'], | ||
}]], | ||
describe('Elasticsearch Data Source Configuration', () => { | ||
test('Elasticsearch configure properly', () => { | ||
// WHEN | ||
api.addElasticsearchDataSource('ds', domain); | ||
|
||
// THEN | ||
Template.fromStack(stack).hasResourceProperties('AWS::IAM::Policy', { | ||
PolicyDocument: { | ||
Version: '2012-10-17', | ||
Statement: [{ | ||
Action: [ | ||
'es:ESHttpGet', | ||
'es:ESHttpHead', | ||
'es:ESHttpDelete', | ||
'es:ESHttpPost', | ||
'es:ESHttpPut', | ||
'es:ESHttpPatch', | ||
], | ||
Effect: 'Allow', | ||
Resource: [{ | ||
'Fn::GetAtt': ['EsDomain1213C634', 'Arn'], | ||
}, | ||
{ | ||
'Fn::Join': ['', [{ | ||
'Fn::GetAtt': ['EsDomain1213C634', 'Arn'], | ||
}, '/*']], | ||
}], | ||
}], | ||
}, | ||
}, | ||
}); | ||
}); | ||
}); | ||
|
||
testDeprecated('default configuration produces name identical to the id', () => { | ||
// WHEN | ||
api.addElasticsearchDataSource('ds', domain); | ||
test('Elastic search configuration contains fully qualified url', () => { | ||
// WHEN | ||
api.addElasticsearchDataSource('ds', domain); | ||
|
||
// THEN | ||
Template.fromStack(stack).hasResourceProperties('AWS::AppSync::DataSource', { | ||
Type: 'AMAZON_ELASTICSEARCH', | ||
Name: 'ds', | ||
// THEN | ||
Template.fromStack(stack).hasResourceProperties('AWS::AppSync::DataSource', { | ||
ElasticsearchConfig: { | ||
Endpoint: { | ||
'Fn::Join': ['', ['https://', { | ||
'Fn::GetAtt': ['EsDomain1213C634', 'DomainEndpoint'], | ||
}]], | ||
}, | ||
}, | ||
}); | ||
}); | ||
}); | ||
|
||
testDeprecated('appsync configures name correctly', () => { | ||
// WHEN | ||
api.addElasticsearchDataSource('ds', domain, { | ||
name: 'custom', | ||
}); | ||
test('default configuration produces name identical to the id', () => { | ||
// WHEN | ||
api.addElasticsearchDataSource('ds', domain); | ||
|
||
// THEN | ||
Template.fromStack(stack).hasResourceProperties('AWS::AppSync::DataSource', { | ||
Type: 'AMAZON_ELASTICSEARCH', | ||
Name: 'custom', | ||
// THEN | ||
Template.fromStack(stack).hasResourceProperties('AWS::AppSync::DataSource', { | ||
Type: 'AMAZON_ELASTICSEARCH', | ||
Name: 'ds', | ||
}); | ||
}); | ||
}); | ||
|
||
testDeprecated('appsync configures name and description correctly', () => { | ||
// WHEN | ||
api.addElasticsearchDataSource('ds', domain, { | ||
name: 'custom', | ||
description: 'custom description', | ||
test('appsync configures name correctly', () => { | ||
// WHEN | ||
api.addElasticsearchDataSource('ds', domain, { | ||
name: 'custom', | ||
}); | ||
|
||
// THEN | ||
Template.fromStack(stack).hasResourceProperties('AWS::AppSync::DataSource', { | ||
Type: 'AMAZON_ELASTICSEARCH', | ||
Name: 'custom', | ||
}); | ||
}); | ||
|
||
// THEN | ||
Template.fromStack(stack).hasResourceProperties('AWS::AppSync::DataSource', { | ||
Type: 'AMAZON_ELASTICSEARCH', | ||
Name: 'custom', | ||
Description: 'custom description', | ||
test('appsync configures name and description correctly', () => { | ||
// WHEN | ||
api.addElasticsearchDataSource('ds', domain, { | ||
name: 'custom', | ||
description: 'custom description', | ||
}); | ||
|
||
// THEN | ||
Template.fromStack(stack).hasResourceProperties('AWS::AppSync::DataSource', { | ||
Type: 'AMAZON_ELASTICSEARCH', | ||
Name: 'custom', | ||
Description: 'custom description', | ||
}); | ||
}); | ||
}); | ||
|
||
testDeprecated('appsync errors when creating multiple elasticsearch data sources with no configuration', () => { | ||
// WHEN | ||
const when = () => { | ||
api.addElasticsearchDataSource('ds', domain); | ||
api.addElasticsearchDataSource('ds', domain); | ||
}; | ||
|
||
// THEN | ||
expect(when).toThrow('There is already a Construct with name \'ds\' in GraphqlApi [baseApi]'); | ||
}); | ||
}); | ||
|
||
describe('adding elasticsearch data source from imported api', () => { | ||
testDeprecated('imported api can add ElasticsearchDataSource from id', () => { | ||
// WHEN | ||
const importedApi = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'importedApi', { | ||
graphqlApiId: api.apiId, | ||
}); | ||
importedApi.addElasticsearchDataSource('ds', domain); | ||
test('appsync errors when creating multiple elasticsearch data sources with no configuration', () => { | ||
// WHEN | ||
const when = () => { | ||
api.addElasticsearchDataSource('ds', domain); | ||
api.addElasticsearchDataSource('ds', domain); | ||
}; | ||
|
||
// THEN | ||
Template.fromStack(stack).hasResourceProperties('AWS::AppSync::DataSource', { | ||
Type: 'AMAZON_ELASTICSEARCH', | ||
ApiId: { 'Fn::GetAtt': ['baseApiCDA4D43A', 'ApiId'] }, | ||
// THEN | ||
expect(when).toThrow('There is already a Construct with name \'ds\' in GraphqlApi [baseApi]'); | ||
}); | ||
}); | ||
|
||
testDeprecated('imported api can add ElasticsearchDataSource from attributes', () => { | ||
// WHEN | ||
const importedApi = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'importedApi', { | ||
graphqlApiId: api.apiId, | ||
graphqlApiArn: api.arn, | ||
describe('adding elasticsearch data source from imported api', () => { | ||
test('imported api can add ElasticsearchDataSource from id', () => { | ||
// WHEN | ||
const importedApi = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'importedApi', { | ||
graphqlApiId: api.apiId, | ||
}); | ||
importedApi.addElasticsearchDataSource('ds', domain); | ||
|
||
// THEN | ||
Template.fromStack(stack).hasResourceProperties('AWS::AppSync::DataSource', { | ||
Type: 'AMAZON_ELASTICSEARCH', | ||
ApiId: { 'Fn::GetAtt': ['baseApiCDA4D43A', 'ApiId'] }, | ||
}); | ||
}); | ||
importedApi.addElasticsearchDataSource('ds', domain); | ||
|
||
// THEN | ||
Template.fromStack(stack).hasResourceProperties('AWS::AppSync::DataSource', { | ||
Type: 'AMAZON_ELASTICSEARCH', | ||
ApiId: { 'Fn::GetAtt': ['baseApiCDA4D43A', 'ApiId'] }, | ||
test('imported api can add ElasticsearchDataSource from attributes', () => { | ||
// WHEN | ||
const importedApi = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'importedApi', { | ||
graphqlApiId: api.apiId, | ||
graphqlApiArn: api.arn, | ||
}); | ||
importedApi.addElasticsearchDataSource('ds', domain); | ||
|
||
// THEN | ||
Template.fromStack(stack).hasResourceProperties('AWS::AppSync::DataSource', { | ||
Type: 'AMAZON_ELASTICSEARCH', | ||
ApiId: { 'Fn::GetAtt': ['baseApiCDA4D43A', 'ApiId'] }, | ||
}); | ||
}); | ||
}); | ||
}); |
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.