Skip to content

Commit

Permalink
Checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
bhillkeyfactor committed Feb 23, 2024
1 parent 75488ab commit 2cdd99e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
5 changes: 2 additions & 3 deletions PaloAlto/Client/PaloAltoClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,12 +317,11 @@ public async Task<ErrorSuccessResponse> SubmitDeleteBinding(JobEntryParams jobEn
}

public async Task<ErrorSuccessResponse> 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}";
Expand Down
22 changes: 19 additions & 3 deletions PaloAlto/Validators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -52,15 +68,15 @@ 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 +=
"You do not need a device group with a Palo Alto Firewall. It is only required for Panorama.";
}

// 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,
Expand All @@ -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 +=
Expand Down

0 comments on commit 2cdd99e

Please sign in to comment.