Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/@aws-cdk/aws-msk-alpha/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,12 @@ baseConfig.parserOptions.project = __dirname + '/tsconfig.json';
baseConfig.rules['import/no-extraneous-dependencies'] = ['error', { devDependencies: true, peerDependencies: true } ];
baseConfig.rules['import/order'] = 'off';
baseConfig.rules['@aws-cdk/invalid-cfn-imports'] = 'off';
baseConfig.rules['@cdklabs/no-throw-default-error'] = ['error'];
baseConfig.overrides.push({
files: ["./test/**"],
rules: {
"@cdklabs/no-throw-default-error": "off",
},
});

module.exports = baseConfig;
20 changes: 8 additions & 12 deletions packages/@aws-cdk/aws-msk-alpha/lib/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export abstract class ClusterBase extends core.Resource implements ICluster {
/** Manages connections for the cluster */
public get connections(): ec2.Connections {
if (!this._connections) {
throw new Error('An imported Cluster cannot manage its security groups');
throw new core.ValidationError('An imported Cluster cannot manage its security groups', this);
}
return this._connections;
}
Expand Down Expand Up @@ -477,26 +477,24 @@ export class Cluster extends ClusterBase {
});

if (subnetSelection.subnets.length < 2) {
throw Error(`Cluster requires at least 2 subnets, got ${subnetSelection.subnets.length}`);
throw new core.ValidationError(`Cluster requires at least 2 subnets, got ${subnetSelection.subnets.length}`, this);
}

if (props.encryptionInTransit?.clientBroker === ClientBrokerEncryption.PLAINTEXT && props.clientAuthentication) {
throw Error('To enable client authentication, you must enabled TLS-encrypted traffic between clients and brokers.');
throw new core.ValidationError('To enable client authentication, you must enabled TLS-encrypted traffic between clients and brokers.', this);
} else if (
props.encryptionInTransit?.clientBroker ===
ClientBrokerEncryption.TLS_PLAINTEXT &&
(props.clientAuthentication?.saslProps?.scram ||
props.clientAuthentication?.saslProps?.iam)
) {
throw Error(
'To enable SASL/SCRAM or IAM authentication, you must only allow TLS-encrypted traffic between clients and brokers.',
);
throw new core.ValidationError('To enable SASL/SCRAM or IAM authentication, you must only allow TLS-encrypted traffic between clients and brokers.', this);
}

const volumeSize = props.ebsStorageInfo?.volumeSize ?? 1000;
// Minimum: 1 GiB, maximum: 16384 GiB
if (volumeSize < 1 || volumeSize > 16384) {
throw Error('EBS volume size should be in the range 1-16384');
throw new core.ValidationError('EBS volume size should be in the range 1-16384', this);
}

const instanceType = props.instanceType
Expand All @@ -507,12 +505,12 @@ export class Cluster extends ClusterBase {

if (props.storageMode && props.storageMode === StorageMode.TIERED) {
if (!props.kafkaVersion.isTieredStorageCompatible()) {
throw Error(`To deploy a tiered cluster you must select a compatible Kafka version, got ${props.kafkaVersion.version}`);
throw new core.ValidationError(`To deploy a tiered cluster you must select a compatible Kafka version, got ${props.kafkaVersion.version}`, this);
}
if (instanceType === this.mskInstanceType(
ec2.InstanceType.of(ec2.InstanceClass.T3, ec2.InstanceSize.SMALL),
)) {
throw Error('Tiered storage doesn\'t support broker type t3.small');
throw new core.ValidationError('Tiered storage doesn\'t support broker type t3.small', this);
}
}

Expand Down Expand Up @@ -883,9 +881,7 @@ export class Cluster extends ClusterBase {
installLatestAwsSdk: false,
});
} else {
throw Error(
'Cannot create users if an authentication KMS key has not been created/provided.',
);
throw new core.ValidationError('Cannot create users if an authentication KMS key has not been created/provided.', this);
}
}
}
10 changes: 4 additions & 6 deletions packages/@aws-cdk/aws-msk-alpha/lib/serverless-cluster.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import { Fn, Lazy, Names } from 'aws-cdk-lib';
import { Fn, Lazy, Names, ValidationError } from 'aws-cdk-lib';
import * as constructs from 'constructs';
import { ClusterBase, ICluster } from '.';
import { CfnServerlessCluster } from 'aws-cdk-lib/aws-msk';
Expand Down Expand Up @@ -87,7 +87,7 @@ export class ServerlessCluster extends ClusterBase {
addConstructMetadata(this, props);

if (props.vpcConfigs.length < 1 || props.vpcConfigs.length > 5) {
throw Error(`\`vpcConfigs\` must contain between 1 and 5 configurations, got ${props.vpcConfigs.length} configurations.`);
throw new ValidationError(`\`vpcConfigs\` must contain between 1 and 5 configurations, got ${props.vpcConfigs.length} configurations.`, this);
}

const vpcConfigs = props.vpcConfigs.map((vpcConfig, index) => this._renderVpcConfig(vpcConfig, index));
Expand Down Expand Up @@ -127,16 +127,14 @@ export class ServerlessCluster extends ClusterBase {
const subnetSelection = vpcConfig.vpc.selectSubnets(vpcConfig.vpcSubnets);

if (subnetSelection.subnets.length < 2) {
throw Error(
`Cluster requires at least 2 subnets, got ${subnetSelection.subnets.length} subnet.`,
);
throw new ValidationError(`Cluster requires at least 2 subnets, got ${subnetSelection.subnets.length} subnet.`, this);
}

let securityGroups: ec2.ISecurityGroup[] = [];

if (vpcConfig.securityGroups) {
if (vpcConfig.securityGroups.length < 1 || vpcConfig.securityGroups.length > 5) {
throw Error(`\`securityGroups\` must contain between 1 and 5 elements, got ${vpcConfig.securityGroups.length} elements.`);
throw new ValidationError(`\`securityGroups\` must contain between 1 and 5 elements, got ${vpcConfig.securityGroups.length} elements.`, this);
}
securityGroups = vpcConfig.securityGroups;
} else {
Expand Down
Loading