Skip to content

Commit

Permalink
Introduce AuthenticationMethod enum
Browse files Browse the repository at this point in the history
  • Loading branch information
bracki committed Feb 16, 2021
1 parent 89a0dd8 commit 47812f9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
28 changes: 23 additions & 5 deletions packages/@aws-cdk/aws-lambda-event-sources/lib/kafka.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ export interface ManagedKafkaEventSourceProps extends KafkaEventSourceProps {
readonly clusterArn: string
}

/**
* The authentication method to use with SelfManagedKafkaEventSource
*/
export enum AuthenticationMethod {
/**
* SASL_SCRAM_512_AUTH authentication method for your Kafka cluster
*/
SASL_SCRAM_512_AUTH = 'SASL_SCRAM_512_AUTH',
/**
* SASL_SCRAM_256_AUTH authentication method for your Kafka cluster
*/
SASL_SCRAM_256_AUTH = 'SASL_SCRAM_512_AUTH',
}

/**
* Properties for a self managed Kafka cluster event source.
* If your Kafka cluster is only reachable via VPC make sure to configure it.
Expand Down Expand Up @@ -66,7 +80,7 @@ export interface SelfManagedKafkaEventSourceProps extends KafkaEventSourceProps
*
* @default - SASL_SCRAM_512_AUTH
*/
readonly authenticationMethod?: 'SASL_SCRAM_512_AUTH' | 'SASL_SCRAM_256_AUTH'
readonly authenticationMethod?: AuthenticationMethod
}

/**
Expand Down Expand Up @@ -123,10 +137,14 @@ export class SelfManagedKafkaEventSource extends StreamEventSource {

public bind(target: lambda.IFunction) {
let authenticationMethod;
if (this.innerProps.authenticationMethod == undefined || this.innerProps.authenticationMethod == 'SASL_SCRAM_512_AUTH') {
authenticationMethod = lambda.SourceAccessConfigurationType.SASL_SCRAM_512_AUTH;
} else {
authenticationMethod = lambda.SourceAccessConfigurationType.SASL_SCRAM_256_AUTH;
switch (this.innerProps.authenticationMethod) {
case AuthenticationMethod.SASL_SCRAM_256_AUTH:
authenticationMethod = lambda.SourceAccessConfigurationType.SASL_SCRAM_256_AUTH;
break;
case AuthenticationMethod.SASL_SCRAM_512_AUTH:
default:
authenticationMethod = lambda.SourceAccessConfigurationType.SASL_SCRAM_512_AUTH;
break;
}
let sourceAccessConfigurations = [{ type: authenticationMethod, uri: this.innerProps.secret.secretArn }];
if (this.innerProps.vpcSubnets !== undefined && this.innerProps.securityGroup !== undefined) {
Expand Down
7 changes: 4 additions & 3 deletions packages/@aws-cdk/aws-lambda-event-sources/test/test.kafka.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { expect, haveResource } from '@aws-cdk/assert';
import { arrayWith, expect, haveResource } from '@aws-cdk/assert';
import { SecurityGroup, SubnetType, Vpc } from '@aws-cdk/aws-ec2';
import * as lambda from '@aws-cdk/aws-lambda';
import { Secret } from '@aws-cdk/aws-secretsmanager';
import * as cdk from '@aws-cdk/core';
import { Test } from 'nodeunit';
import * as sources from '../lib';
import { AuthenticationMethod } from '../lib';
import { TestFunction } from './test-function';

export = {
Expand Down Expand Up @@ -215,10 +216,10 @@ export = {
vpc: vpc,
vpcSubnets: { subnetType: SubnetType.PRIVATE },
securityGroup: sg,
authenticationMethod: 'SASL_SCRAM_256_AUTH',
authenticationMethod: AuthenticationMethod.SASL_SCRAM_256_AUTH,
}));

expect(stack).to(haveResourceLike('AWS::Lambda::EventSourceMapping', {
expect(stack).to(haveResource('AWS::Lambda::EventSourceMapping', {
SourceAccessConfigurations: arrayWith(
{
Type: 'SASL_SCRAM_256_AUTH',
Expand Down

0 comments on commit 47812f9

Please sign in to comment.