-
Notifications
You must be signed in to change notification settings - Fork 8
Conversation
src/config.ts
Outdated
complexCustomFields: { | ||
type: 'json', | ||
mask: false, | ||
optional: true, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not use a different config field for this, should be handled within the existing "customFields" field
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed complexCustomFields from config
complexCustomFieldsToInclude.forEach((path) => { | ||
const [baseFieldId, ...nestedPathParts] = path.split('.'); | ||
if (issue.fields[baseFieldId] !== undefined) { | ||
const nestedPath = nestedPathParts.join('.'); | ||
const fieldValue = getNestedValue(issue.fields[baseFieldId], nestedPath); | ||
if (fieldValue !== undefined) { | ||
if (fieldsById && fieldsById[baseFieldId]) { | ||
const baseFieldName = camelCase(fieldsById[baseFieldId].name); | ||
const formattedPathParts = nestedPathParts.map((part) => { | ||
const match = part.match(/^(\w+)(?:\[(\d+)\])?$/); | ||
if (match) { | ||
const [, key, index] = match; | ||
if (index !== undefined) { | ||
return `${camelCase(key)}${index}`; | ||
} | ||
return camelCase(key); | ||
} | ||
return camelCase(part); | ||
}); | ||
const formattedPath = [baseFieldName, ...formattedPathParts].join(''); | ||
setFlatNestedValue(customFields, formattedPath, fieldValue); | ||
} | ||
} | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This implementation can be simplified with lodash get
method and the field name formatting can also be simplified:
for (const path of complexCustomFieldsToInclude) {
const [baseFieldId, ...rest] = path.split('.');
const nestedPath = rest.join('.');
if (!issue.fields[baseFieldId]) {
continue;
}
const extractedValue = get(issue.fields[baseFieldId], nestedPath);
if (!extractedValue) {
continue;
}
const baseFieldName = camelCase(fieldsById[baseFieldId].name);
const fieldName = nestedPath.split(/[\.\[\]]+/).map(camelCase).join('');
customFields[`${baseFieldName}${fieldName}`] = extractedValue;
}
Also this should be adapted to be inside the loop in line 105 because all custom fields should come in the customFields
config field. So you can verify first if it's a complex field and execute this logic, if it's not execute the logic for simple fields as it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this makes sense, moved the suggested logic inside the loop and verifying if its a complex field or simple field
src/steps/issues.ts
Outdated
logger.info( | ||
{ | ||
complexCustomFields: config.complexCustomFields, | ||
allFieldIdsAndNames: Object.values(fieldsById).map( | ||
(field) => `${field.id}: ${field.name ?? 'undefined field name'}`, | ||
), | ||
}, | ||
'Complex custom fields to ingest.', | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not necessary as these will be part of customFields
config
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed the log
resolved PR comments
🚀 PR was released in |
Description
Thank you for contributing to a JupiterOne integration!
Please include a summary of the change and which issue is fixed. Please also
include relevant motivation and context. List any dependencies that are required
for this change.
Summary
Type of change
Please leave any irrelevant options unchecked.
not work as expected)
Checklist
General Development Checklist:
Integration Development Checklist:
Please leave any irrelevant options unchecked.
endpoints, and have documented any additional permissions in
jupiterone.md
, where necessary.API
using
dependsOn
JupiterOne data model
to ensure that any new entities/relationships, and relevant properties,
match the recommended model for this class of data
CHANGELOG.md
file to describe my changesreviewed all existing managed questions referencing the entities,
relationships, and their property names, to ensure those questions still
function with my changes.