feat(Venafi TLS Protect Cloud Node): make issuing template depend on application (#4476)

*  Make issuing template depending on application

*  Make validity period type string

*  Reorder certificateRequest:create fields semantically
This commit is contained in:
Ricardo Espinoza 2022-11-01 09:56:00 -04:00 committed by GitHub
parent 2b5613ed68
commit d1d1288ba9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 53 additions and 57 deletions

View file

@ -64,6 +64,9 @@ export const certificateRequestFields: INodeProperties[] = [
'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>', 'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
typeOptions: { typeOptions: {
loadOptionsMethod: 'getCertificateIssuingTemplates', loadOptionsMethod: 'getCertificateIssuingTemplates',
loadOptionsDependsOn: [
'applicationId',
],
}, },
displayOptions: { displayOptions: {
show: { show: {
@ -134,11 +137,23 @@ export const certificateRequestFields: INodeProperties[] = [
}, },
options: [ options: [
{ {
displayName: 'Country', displayName: 'Key Type',
name: 'country', name: 'keyType',
type: 'string', type: 'options',
default: '', options: [
description: 'A 2 letter country code', {
name: 'EC',
value: 'EC',
description: 'Elliptic Curve (EC)',
},
{
name: 'RSA',
value: 'RSA',
description: 'Rivest, Shamir, Adleman key (RSA)',
},
],
default: 'RSA',
description: 'The encryption algorithm for the public key',
}, },
{ {
displayName: 'Key Curve', displayName: 'Key Curve',
@ -180,40 +195,14 @@ export const certificateRequestFields: INodeProperties[] = [
description: 'The number of bits to allow for key generation', description: 'The number of bits to allow for key generation',
}, },
{ {
displayName: 'Key Type', displayName: '(O) Organization',
name: 'keyType',
type: 'options',
options: [
{
name: 'EC',
value: 'EC',
description: 'Elliptic Curve (EC)',
},
{
name: 'RSA',
value: 'RSA',
description: 'Rivest, Shamir, Adleman key (RSA)',
},
],
default: 'RSA',
description: 'The encryption algorithm for the public key',
},
{
displayName: 'Locality',
name: 'locality',
type: 'string',
default: '',
description: 'The name of a city or town',
},
{
displayName: 'Organization',
name: 'organization', name: 'organization',
type: 'string', type: 'string',
default: '', default: '',
description: 'The name of a company or organization', description: 'The name of a company or organization',
}, },
{ {
displayName: 'Organizational Units', displayName: '(OU) Organizational Unit(s)',
name: 'organizationalUnits', name: 'organizationalUnits',
type: 'string', type: 'string',
typeOptions: { typeOptions: {
@ -223,12 +212,27 @@ export const certificateRequestFields: INodeProperties[] = [
description: 'The name of a department or section', description: 'The name of a department or section',
}, },
{ {
displayName: 'State', displayName: '(L) City/Locality',
name: 'locality',
type: 'string',
default: '',
description: 'The name of a city or town',
},
{
displayName: '(ST) State',
name: 'state', name: 'state',
type: 'string', type: 'string',
default: '', default: '',
description: 'The name of a state or province', description: 'The name of a state or province',
}, },
{
displayName: '(C) Country',
name: 'country',
type: 'string',
default: '',
description: 'A 2 letter country code',
},
{ {
displayName: 'Subject Alt Names', displayName: 'Subject Alt Names',
name: 'SubjectAltNamesUi', name: 'SubjectAltNamesUi',
@ -316,22 +320,11 @@ export const certificateRequestFields: INodeProperties[] = [
{ {
displayName: 'Validity Period', displayName: 'Validity Period',
name: 'validityPeriod', name: 'validityPeriod',
type: 'options', type: 'string',
options: [ placeholder: 'P1Y',
{
name: '1 Year',
value: 'P1Y',
},
{
name: '10 Days',
value: 'P10D',
},
{
name: '12 Hours',
value: 'PT12H',
},
],
default: 'P1Y', default: 'P1Y',
description: 'Specify how long the issued certificate should be valid for. Use ISO8601 format.',
hint: 'e.g. 1 year -> P1Y',
}, },
], ],
}, },

View file

@ -80,6 +80,7 @@ export class VenafiTlsProtectCloud implements INodeType {
'GET', 'GET',
'/outagedetection/v1/applications', '/outagedetection/v1/applications',
); );
for (const application of applications) { for (const application of applications) {
returnData.push({ returnData.push({
name: application.name, name: application.name,
@ -109,15 +110,18 @@ export class VenafiTlsProtectCloud implements INodeType {
this: ILoadOptionsFunctions, this: ILoadOptionsFunctions,
): Promise<INodePropertyOptions[]> { ): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = []; const returnData: INodePropertyOptions[] = [];
const { certificateIssuingTemplates } = await venafiApiRequest.call( const currentApplication: string = this.getCurrentNodeParameter('applicationId') as string;
const { certificateIssuingTemplateAliasIdMap } = await venafiApiRequest.call(
this, this,
'GET', 'GET',
'/v1/certificateissuingtemplates', `/outagedetection/v1/applications/${currentApplication}`,
); ) as { certificateIssuingTemplateAliasIdMap: { [key: string]: string } };
for (const issueTemplate of certificateIssuingTemplates) {
for (const [templateName, templateId] of Object.entries(certificateIssuingTemplateAliasIdMap)) {
returnData.push({ returnData.push({
name: issueTemplate.name, name: templateName,
value: issueTemplate.id, value: templateId,
}); });
} }
return returnData; return returnData;
@ -472,7 +476,6 @@ export class VenafiTlsProtectCloud implements INodeType {
itemData: { item: i }, itemData: { item: i },
}), }),
); );
} catch (error) { } catch (error) {
if (this.continueOnFail()) { if (this.continueOnFail()) {
returnData.push({ json: { error: error.message } }); returnData.push({ json: { error: error.message } });