From 2cdd99ee7a14abb5f81b483569a59aabbc5fb009 Mon Sep 17 00:00:00 2001 From: Brian Hill Date: Fri, 23 Feb 2024 00:18:39 +0000 Subject: [PATCH] Checkpoint --- PaloAlto/Client/PaloAltoClient.cs | 5 ++--- PaloAlto/Validators.cs | 22 +++++++++++++++++++--- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/PaloAlto/Client/PaloAltoClient.cs b/PaloAlto/Client/PaloAltoClient.cs index 4a8a194..b828d9a 100644 --- a/PaloAlto/Client/PaloAltoClient.cs +++ b/PaloAlto/Client/PaloAltoClient.cs @@ -317,12 +317,11 @@ public async Task SubmitDeleteBinding(JobEntryParams jobEn } public async Task ImportCertificate(string name, string passPhrase, byte[] bytes, - string includeKey, string category, string templateName) + string includeKey, string category, string storePath) { try { - if (templateName == "/") - templateName = ""; + var templateName=GetTemplateName(storePath); var uri = $@"/api/?type=import&category={category}&certificate-name={name}&format=pem&include-key={includeKey}&passphrase={passPhrase}&target-tpl={templateName}&target-tpl-vsys=&vsys&key={ApiKey}"; var boundary = $"--------------------------{Guid.NewGuid():N}"; diff --git a/PaloAlto/Validators.cs b/PaloAlto/Validators.cs index e1d57a2..04d17c8 100644 --- a/PaloAlto/Validators.cs +++ b/PaloAlto/Validators.cs @@ -13,6 +13,7 @@ // limitations under the License. using System.Linq; +using System.Text.RegularExpressions; using Keyfactor.Extensions.Orchestrator.PaloAlto.Client; using Keyfactor.Extensions.Orchestrator.PaloAlto.Models.Responses; using Keyfactor.Orchestrators.Common.Enums; @@ -44,6 +45,21 @@ public static string BuildPaloError(ErrorSuccessResponse bindingsResponseResult) if (!string.IsNullOrEmpty(errorResponse)) return errorResponse.Substring(0, errorResponse.Length - 2); return errorResponse; + } + + private static string GetTemplateName(string storePath) + { + string pattern = @"\/template\/entry\[@name='([^']+)'\]"; + Regex regex = new Regex(pattern); + Match match = regex.Match(storePath); + + string templateName = string.Empty; + if (match.Success) + { + templateName = match.Groups[1].Value; + } + + return templateName; } public static (bool valid, JobResult result) ValidateStoreProperties(JobProperties storeProperties, @@ -52,7 +68,7 @@ public static (bool valid, JobResult result) ValidateStoreProperties(JobProperti var errors = string.Empty; // If it is a firewall (store path of /) then you don't need the Group Name - if (storePath== "/") + if (!storePath.Contains("template",System.StringComparison.CurrentCultureIgnoreCase)) if (!string.IsNullOrEmpty(storeProperties?.DeviceGroup)) { errors += @@ -60,7 +76,7 @@ public static (bool valid, JobResult result) ValidateStoreProperties(JobProperti } // Considered Panorama device if store path is not "/" and there is a valid value for store path - if (storePath != "/") + if (storePath.Contains("template", System.StringComparison.CurrentCultureIgnoreCase)) { var client = new PaloAltoClient(clientMachine, @@ -84,7 +100,7 @@ public static (bool valid, JobResult result) ValidateStoreProperties(JobProperti //Validate Template Exists in Panorama, required for Panorama var templateList = client.GetTemplateList(); - var templates = templateList.Result.Result.Entry.Where(d => d.Name == storePath); + var templates = templateList.Result.Result.Entry.Where(d => d.Name == GetTemplateName(storePath)); if (!templates.Any()) { errors +=