Skip to content

Commit

Permalink
feat(appsync) remove nested construction of awsIamConfig in HttpDataS…
Browse files Browse the repository at this point in the history
…ource
  • Loading branch information
haruharuharuby committed Aug 28, 2020
1 parent 26fe550 commit e6250b2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 28 deletions.
53 changes: 30 additions & 23 deletions packages/@aws-cdk/aws-appsync/lib/data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,24 +212,14 @@ export interface AwsIamConfig {
*/
readonly authorizationType: 'AWS_IAM';
/**
* The IAM signing configuration required by the HTTP endpoint
* The signing region for AWS IAM authorization
*/
readonly awsIamConfig: AwsIamConfigSigning;
}
readonly signingRegion: string;

/**
* The IAM signing config in case the HTTP endpoint requires authorization
*/
export interface AwsIamConfigSigning {
/**
* The signing region for AWS IAM authorization
*/
readonly signingRegion: string;

/**
* The signing service name for AWS IAM authorization
*/
readonly signingServiceName: string;
/**
* The signing service name for AWS IAM authorization
*/
readonly signingServiceName: string;
}

/**
Expand All @@ -248,13 +238,30 @@ export interface HttpDataSourceProps extends BaseDataSourceProps {
*/
export class HttpDataSource extends BaseDataSource {
constructor(scope: Construct, id: string, props: HttpDataSourceProps) {
super(scope, id, props, {
httpConfig: {
endpoint: props.endpoint,
authorizationConfig: props.authorizationConfig
},
type: 'HTTP',
});
if (!props.authorizationConfig) {
super(scope, id, props, {
httpConfig: {
endpoint: props.endpoint
},
type: 'HTTP',
})
} else {
const authConfig = props.authorizationConfig
super(scope, id, props, {
httpConfig: {
endpoint: props.endpoint,
authorizationConfig: {
authorizationType: authConfig.authorizationType,
awsIamConfig: {
signingRegion: authConfig.signingRegion,
signingServiceName: authConfig.signingServiceName
}

}
},
type: 'HTTP',
})
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-appsync/lib/graphqlapi-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export interface IGraphqlApi extends IResource {
* @param lambdaFunction The Lambda function to call to interact with this data source
* @param options The optional configuration for this data source
*/
addLambdaDataSource(id: string, lambdaFunction: IFunction, options?: DataSourceOptions): LambdaDataSource;
addLambdaDataSource(id: string, lambdaFunction: IFunction, options?: HttpDataSourceOptions): LambdaDataSource;

/**
* Add schema dependency if not imported
Expand Down
6 changes: 2 additions & 4 deletions packages/@aws-cdk/aws-appsync/test/appsync-http.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,8 @@ describe('Http Data Source configuration', () => {
description: 'custom description',
authorizationConfig: {
authorizationType: 'AWS_IAM',
awsIamConfig: {
signingRegion: 'us-east-1',
signingServiceName: 'states'
}
signingRegion: 'us-east-1',
signingServiceName: 'states'
}
});

Expand Down

0 comments on commit e6250b2

Please sign in to comment.