2023-01-27 03:22:44 -08:00
|
|
|
|
import type {
|
2023-03-09 09:13:15 -08:00
|
|
|
|
IPollFunctions,
|
2023-01-27 03:22:44 -08:00
|
|
|
|
IDataObject,
|
|
|
|
|
INodeExecutionData,
|
|
|
|
|
INodeType,
|
|
|
|
|
INodeTypeDescription,
|
|
|
|
|
} from 'n8n-workflow';
|
2022-10-07 06:05:48 -07:00
|
|
|
|
|
|
|
|
|
import moment from 'moment';
|
|
|
|
|
|
|
|
|
|
import { venafiApiRequest } from './GenericFunctions';
|
|
|
|
|
|
|
|
|
|
export class VenafiTlsProtectDatacenterTrigger implements INodeType {
|
|
|
|
|
description: INodeTypeDescription = {
|
|
|
|
|
displayName: 'Venafi TLS Protect Datacenter Trigger',
|
|
|
|
|
name: 'venafiTlsProtectDatacenterTrigger',
|
|
|
|
|
icon: 'file:../venafi.svg',
|
|
|
|
|
group: ['trigger'],
|
|
|
|
|
version: 1,
|
|
|
|
|
subtitle: '={{$parameter["triggerOn"]}}',
|
2022-10-25 00:06:54 -07:00
|
|
|
|
description: 'Starts the workflow when Venafi events occur',
|
2022-10-07 06:05:48 -07:00
|
|
|
|
defaults: {
|
|
|
|
|
name: 'Venafi TLS Protect Datacenter',
|
|
|
|
|
},
|
|
|
|
|
credentials: [
|
|
|
|
|
{
|
|
|
|
|
name: 'venafiTlsProtectDatacenterApi',
|
|
|
|
|
required: true,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
polling: true,
|
|
|
|
|
inputs: [],
|
|
|
|
|
outputs: ['main'],
|
|
|
|
|
properties: [
|
|
|
|
|
{
|
|
|
|
|
displayName: 'Trigger On',
|
|
|
|
|
name: 'triggerOn',
|
|
|
|
|
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 qs: IDataObject = {};
|
|
|
|
|
|
|
|
|
|
const now = moment().format();
|
|
|
|
|
|
2023-01-19 04:37:19 -08:00
|
|
|
|
qs.ValidToGreater = webhookData.lastTimeChecked || now;
|
2022-10-07 06:05:48 -07:00
|
|
|
|
|
|
|
|
|
qs.ValidToLess = now;
|
|
|
|
|
|
|
|
|
|
const { Certificates: certificates } = await venafiApiRequest.call(
|
|
|
|
|
this,
|
|
|
|
|
'GET',
|
|
|
|
|
'/vedsdk/certificates',
|
|
|
|
|
{},
|
|
|
|
|
qs,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
webhookData.lastTimeChecked = qs.ValidToLess;
|
|
|
|
|
|
|
|
|
|
if (Array.isArray(certificates) && certificates.length !== 0) {
|
|
|
|
|
return [this.helpers.returnJsonArray(certificates)];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|