Skip to content
This repository has been archived by the owner on Sep 3, 2024. It is now read-only.

Commit

Permalink
Merge pull request #56 from JupiterOne/INT-11375
Browse files Browse the repository at this point in the history
Int 11375
  • Loading branch information
Gonzalo-Avalos-Ribas authored Jul 30, 2024
2 parents 54e2a19 + 5395f1d commit 7857d6e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
5 changes: 4 additions & 1 deletion src/util/cmdbHierarchyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ async function getParentClass(
return newParent.name;
}
} catch (error) {
logger.error({ error }, 'Could not find super class');
logger.error(
{ err: error, result: dictionariesPaginatedResponse.result },
'Could not find super class',
);
throw error;
}
}
Expand Down
41 changes: 24 additions & 17 deletions src/validateInvocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,33 @@ export default async function validateInvocation(
const client = new ServiceNowClient(config, context.logger);
await client.validate();
//Validate CMDB configuration.
if (config.cmdb_parent) {
const cmdb_parents = getParsedCMDBClassList(config.cmdb_parent);
if (cmdb_parents.length > 10) {
throw new IntegrationValidationError(
`This integration only supports up to 10 CMDB classes per instance. Please update config to specify 10 or fewer.`,
let response;
try {
if (config.cmdb_parent) {
const cmdb_parents = getParsedCMDBClassList(config.cmdb_parent);
if (cmdb_parents.length > 10) {
throw new IntegrationValidationError(
`This integration only supports up to 10 CMDB classes per instance. Please update config to specify 10 or fewer.`,
);
}
response = await validateMultipleClasses(
client,
cmdb_parents,
context.logger,
);
}
const response = await validateMultipleClasses(
client,
cmdb_parents,
context.logger,
} catch (error) {
throw new IntegrationValidationError(
`Invalid configuration of cmdb. Error: ${error.message}`,
);
}

if (response.invalidClasses.length > 0) {
throw new IntegrationValidationError(
'CMDB classes are incorrect. ' +
'The class(es): ' +
response.invalidClasses.join(', ') +
" don't exist in your ServiceNow account. ",
);
}
if (response?.invalidClasses?.length > 0) {
throw new IntegrationValidationError(
'CMDB classes are incorrect. ' +
'The class(es): ' +
response.invalidClasses.join(', ') +
" don't exist in your ServiceNow account. ",
);
}
}

0 comments on commit 7857d6e

Please sign in to comment.