export async function processControlFile()

in lambda/src/controls.ts [54:99]


export async function processControlFile(dataFile: DataFile): Promise<void> {
    const controlDefinition = dataFile.data as Control;
    console.log(controlDefinition);

    // get the list of all custom controls
    const controlList = await loadCustomControlList();

    // check whether or not the control already exists
    const existingControl = controlList.find(
        ({ name }) => name === controlDefinition.name
    );

    if (!controlDefinition.datasources) {
        controlDefinition.datasources = [
            {
                sourceName: 'Manual Attestation',
                sourceDescription: 'Manual attestation',
                sourceSetUpOption: 'Procedural_Controls_Mapping',
                sourceType: 'MANUAL',
            },
        ];
    }
    // create or update the control
    if (!existingControl) {
        console.log('create new control');
        const request = {
            ...buildControlRequest(controlDefinition),
            tags: controlDefinition.tags,
        };
        const response = await auditManager.createControl(request).promise();
        console.log(response);
    } else {
        const controlId = existingControl.id || '';
        const resourceArn = existingControl.arn || '';
        console.log(`update existing control id = ${controlId}`);
        const request: AWS.AuditManager.UpdateControlRequest = {
            ...buildControlRequest(controlDefinition),
            controlId,
        };
        const response = await auditManager.updateControl(request).promise();
        console.log(response);

        //update tags
        await updateTags(resourceArn, controlDefinition.tags);
    }
}