Skip to content

Commit

Permalink
Fix the semver version check for adminPassword props (#91)
Browse files Browse the repository at this point in the history
Signed-off-by: Sayali Gaikawad <[email protected]>
  • Loading branch information
gaiksaya authored Jan 8, 2024
1 parent 71fa6ba commit 020d9c3
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 11 deletions.
3 changes: 2 additions & 1 deletion lib/infra/infra-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { LogGroup, RetentionDays } from 'aws-cdk-lib/aws-logs';
import { readFileSync } from 'fs';
import { dump, load } from 'js-yaml';
import { join } from 'path';
import { satisfies } from 'semver';
import { CloudwatchAgent } from '../cloudwatch/cloudwatch-agent';
import { ProcstatMetricDefinition } from '../cloudwatch/metrics-section';
import { InfraStackMonitoring } from '../monitoring/alarms';
Expand Down Expand Up @@ -206,7 +207,7 @@ export class InfraStack extends Stack {
this.securityDisabled = securityDisabled === 'true';

this.adminPassword = this.securityDisabled ? '' : `${props?.adminPassword ?? scope.node.tryGetContext('adminPassword')}`;
if (!this.securityDisabled && Number.parseFloat(this.distVersion) >= 2.12 && this.adminPassword === 'undefined') {
if (!this.securityDisabled && satisfies(this.distVersion, '>=2.12.0') && this.adminPassword === 'undefined') {
throw new Error('adminPassword parameter is required to be set when security is enabled');
}

Expand Down
26 changes: 20 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
},
"devDependencies": {
"@types/jest": "^27.5.2",
"@types/js-yaml": "^4.0.5",
"@types/node": "10.17.27",
"@types/prettier": "2.6.0",
"@types/js-yaml": "^4.0.5",
"@types/semver": "^7.5.6",
"aws-cdk": "2.45.0",
"jest": "^27.5.1",
"ts-jest": "^27.1.4",
Expand All @@ -27,10 +28,11 @@
"@typescript-eslint/parser": "^4.31.1",
"aws-cdk-lib": "2.45.0",
"constructs": "^10.0.0",
"js-yaml": "^4.1.0",
"source-map-support": "^0.5.21",
"eslint": "^7.32.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-plugin-import": "^2.24.2"
"eslint-plugin-import": "^2.24.2",
"js-yaml": "^4.1.0",
"semver": "^7.5.4",
"source-map-support": "^0.5.21"
}
}
32 changes: 32 additions & 0 deletions test/opensearch-cluster-cdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -736,3 +736,35 @@ test('Should not throw error when security is enabled and adminPassword is defi
env: { account: 'test-account', region: 'us-east-1' },
});
});

test('Should not throw error when security is enabled and version is less than 2.12', () => {
const app = new App({
context: {
securityDisabled: false,
minDistribution: false,
distributionUrl: 'www.example.com',
cpuArch: 'x64',
singleNodeCluster: false,
dashboardsUrl: 'www.example.com',
distVersion: '2.4.0',
serverAccessType: 'ipv4',
restrictServerAccessTo: 'all',
managerNodeCount: 0,
dataNodeCount: 3,
dataNodeStorage: 200,
customRoleArn: 'arn:aws:iam::12345678:role/customRoleName',
},
});

// WHEN
const networkStack = new NetworkStack(app, 'opensearch-network-stack', {
env: { account: 'test-account', region: 'us-east-1' },
});

// @ts-ignore
const infraStack = new InfraStack(app, 'opensearch-infra-stack', {
vpc: networkStack.vpc,
securityGroup: networkStack.osSecurityGroup,
env: { account: 'test-account', region: 'us-east-1' },
});
});

0 comments on commit 020d9c3

Please sign in to comment.