Skip to content

Commit 5b12a13

Browse files
committed
update checkForMultipleApiKeys
1 parent 62217e2 commit 5b12a13

1 file changed

Lines changed: 8 additions & 15 deletions

File tree

src/index.ts

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -634,10 +634,11 @@ function validateConfiguration(config: Configuration): void {
634634
config.apiKey === undefined &&
635635
process.env.DATADOG_API_KEY === undefined &&
636636
config.apiKMSKey === undefined &&
637-
config.apiKeySecretArn === undefined
637+
config.apiKeySecretArn === undefined &&
638+
config.apiKeySsmArn === undefined
638639
) {
639640
throw new Error(
640-
"The environment variable `DATADOG_API_KEY` or configuration variable `apiKMSKey` or `apiKeySecretArn` must be set because `addExtension` is set to true as default.",
641+
"The environment variable `DATADOG_API_KEY` or configuration variable `apiKMSKey`, `apiKeySecretArn`, or `apiKeySsmArn` must be set because `addExtension` is set to true as default.",
641642
);
642643
}
643644
}
@@ -656,18 +657,10 @@ function validateConfiguration(config: Configuration): void {
656657
}
657658

658659
function checkForMultipleApiKeys(config: Configuration): void {
659-
let multipleApiKeysMessage;
660-
if (config.apiKey !== undefined && config.apiKMSKey !== undefined && config.apiKeySecretArn !== undefined) {
661-
multipleApiKeysMessage = "`apiKey`, `apiKMSKey`, and `apiKeySecretArn`";
662-
} else if (config.apiKey !== undefined && config.apiKMSKey !== undefined) {
663-
multipleApiKeysMessage = "`apiKey` and `apiKMSKey`";
664-
} else if (config.apiKey !== undefined && config.apiKeySecretArn !== undefined) {
665-
multipleApiKeysMessage = "`apiKey` and `apiKeySecretArn`";
666-
} else if (config.apiKMSKey !== undefined && config.apiKeySecretArn !== undefined) {
667-
multipleApiKeysMessage = "`apiKMSKey` and `apiKeySecretArn`";
668-
}
669-
670-
if (multipleApiKeysMessage) {
671-
throw new Error(`${multipleApiKeysMessage} should not be set at the same time.`);
660+
const hasMultipleApiKeys = [config.apiKey, config.apiKMSKey, config.apiKeySecretArn, config.apiKeySsmArn]
661+
.filter(key => key !== undefined).length;
662+
663+
if (hasMultipleApiKeys) {
664+
throw new Error("Only one of `apiKey`, `apiKMSKey`, `apiKeySecretArn`, or `apiKeySsmArn` should be set at the same time.");
672665
}
673666
}

0 commit comments

Comments
 (0)