n8n/packages/nodes-base/nodes/Venafi/ProtectCloud/VenafiTlsProtectCloudTrigger.node.ts
Ricardo Espinoza d36e920997
feat(Venafi TLS Protect Cloud): add Venafi TLS Protect Cloud (#4253)
*  Venafi TTL Protect Cloud

*  Improvements

*  Add authenticate generic type

*  Add paired items

*  Add codex

*  Update package.json
2022-10-07 09:48:45 -04:00

102 lines
2.2 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { IPollFunctions } from 'n8n-core';
import { INodeExecutionData, INodeType, INodeTypeDescription } from 'n8n-workflow';
import moment from 'moment';
import { venafiApiRequest } from './GenericFunctions';
export class VenafiTlsProtectCloudTrigger implements INodeType {
description: INodeTypeDescription = {
displayName: 'Venafi TLS Protect Cloud Trigger',
name: 'venafiTlsProtectCloudTrigger',
icon: 'file:../venafi.svg',
group: ['trigger'],
version: 1,
subtitle: '={{$parameter["triggerOn"]}}',
description: 'Starts the workflow when Venafi events occure',
defaults: {
name: 'Venafi TLS Protect Cloud',
color: '#000000',
},
credentials: [
{
name: 'venafiTlsProtectCloudApi',
required: true,
},
],
polling: true,
inputs: [],
outputs: ['main'],
properties: [
{
displayName: 'Trigger On',
name: 'trigger On',
type: 'options',
options: [
{
name: 'Certificate Expired',
value: 'certificateExpired',
},
],
required: true,
default: 'certificateExpired',
},
],
};
async poll(this: IPollFunctions): Promise<INodeExecutionData[][] | null> {
const webhookData = this.getWorkflowStaticData('node');
const event = this.getNodeParameter('event') as string;
const now = moment().format();
const startDate = webhookData.lastTimeChecked || now;
const endDate = now;
const { certificates: certificates } = await venafiApiRequest.call(
this,
'POST',
`/outagedetection/v1/certificatesearch`,
{
expression: {
operands: [
{
operator: 'AND',
operands: [
{
field: 'validityEnd',
operator: 'LTE',
values: [endDate],
},
{
field: 'validityEnd',
operator: 'GTE',
values: [startDate],
},
],
},
],
},
ordering: {
orders: [
{
field: 'certificatInstanceModificationDate',
direction: 'DESC',
},
],
},
},
{},
);
webhookData.lastTimeChecked = endDate;
if (Array.isArray(certificates) && certificates.length) {
return [this.helpers.returnJsonArray(certificates)];
}
return null;
}
}