Skip to content

Commit 2fc295e

Browse files
authored
Update ConnectorPackageValidator.ps1 (microsoft#3629)
Handled some typical internal structure issues in connector/flow/plugin solution zip
1 parent 5c71cc0 commit 2fc295e

File tree

1 file changed

+121
-94
lines changed

1 file changed

+121
-94
lines changed

scripts/ConnectorPackageValidator.ps1

Lines changed: 121 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,14 @@ try {
324324
$secondLevelZipFiles = Get-ChildItem -Path "$tempFolder2/$pkgAssetFoldereName" -Filter "*.zip" | Select-Object -ExpandProperty Name
325325
$originalParentFolderPath = $parentFolderPath
326326
$nodesToCheck = @()
327+
$isConnectorSolutionPresent= $false
328+
$isFlowSolutionPresent = $false
329+
$isPluginSolutionPresent = $false
327330
foreach ($secondLevelZipFile in $secondLevelZipFiles) {
331+
$isConnectorFound = $false
332+
$isWorkflowsFound = $false
333+
$isPluginFound = $false
334+
328335
$tempFolder3 = New-Item -ItemType Directory -Path (Join-Path $env:TEMP (New-Guid))
329336
# Update the corret currentFolder to the parentFolderPath
330337
$parentFolderPath = "$originalParentFolderPath/$secondLevelZipFile"
@@ -354,113 +361,132 @@ try {
354361
# Read the customizations.xml and look for any node "Connector" or "Workflows". If they exist, validate if the folders also exist
355362
# Define the path to your XML file and the node name you want to check
356363
$xmlFilePath = "$tempFolder3/customizations.xml"
357-
$nodeNameToCheck = "Connector"
358-
364+
$connectorNodeName = "Connector"
359365
# Load the XML file into an XmlDocument object
360366
[xml]$xmlContent = Get-Content -Path $xmlFilePath
361-
362367
# Use XPath to find the node
363-
$nodeToCheck = $xmlContent.SelectSingleNode("//$nodeNameToCheck")
364-
365-
# Check if the node exists and output the result
366-
if ($nodeToCheck -ne $null) {
367-
if ($nodeToCheck.HasChildNodes -or $nodeToCheck.Attributes.Count -gt 0) {
368-
# check if the folder name is present with the same name
369-
$nodeNameFolder = Get-ChildItem -Path "$tempFolder3" -Directory | Where-Object {$_.Name -eq $nodeNameToCheck}
370-
if (-not $nodeNameFolder) {
371-
Write-Host "The solution zip file '$secondLevelZipFile' in '$originalParentFolderPath' should contain one folder namely '$nodeNameToCheck'."
372-
Write-Host "The folders should match the customization.xml file. They are present by default in an exported solution and should not be modified/removed manually."
373-
Write-Host "Please add the required folder to the solution zip or export the correctsolution again."
374-
DisplayReferDocumentation
375-
Write-Host ""
376-
Write-Host "Validation failed: Invalid package structure. Check previous messages for details." -ForegroundColor Red
377-
Write-Host ""
378-
RemoveTempFolder $tempFolder
379-
RemoveTempFolder $tempFolder2
380-
RemoveTempFolder $tempFolder3
381-
exit
382-
}
368+
$connectorNode = $xmlContent.SelectSingleNode("//$connectorNodeName")
369+
370+
# Check if the connector node exists and set the appropriate flags
371+
if ($connectorNode -ne $null) {
372+
if ($connectorNode.HasChildNodes -or $connectorNode.Attributes.Count -gt 0) {
373+
$isConnectorFound = $true
383374
}
384375
}
385376

386-
$nodeNameToCheck = "Workflows"
377+
$workflowsNodeName = "Workflows"
387378
# Use XPath to find the node
388-
$nodeToCheck = $xmlContent.SelectSingleNode("//$nodeNameToCheck")
389-
390-
# Check if the node exists and output the result
391-
if ($nodeToCheck -ne $null) {
392-
if ($nodeToCheck.HasChildNodes -or $nodeToCheck.Attributes.Count -gt 0) {
393-
# check if the folder name is present with the same name
394-
$nodeNameFolder = Get-ChildItem -Path "$tempFolder3" -Directory | Where-Object {$_.Name -eq $nodeNameToCheck}
395-
if (-not $nodeNameFolder) {
396-
Write-Host "The solution zip file '$secondLevelZipFile' in '$originalParentFolderPath' should contain one folder namely '$nodeNameToCheck'."
397-
Write-Host "The folders should match the customization.xml file. They are present by default in an exported solution and should not be modified/removed manually."
398-
Write-Host "Please add the required folder to the solution zip or export the correct solution again."
399-
DisplayReferDocumentation
400-
Write-Host ""
401-
Write-Host "Validation failed: Invalid package structure. Check previous messages for details." -ForegroundColor Red
402-
Write-Host ""
403-
RemoveTempFolder $tempFolder
404-
RemoveTempFolder $tempFolder2
405-
RemoveTempFolder $tempFolder3
406-
exit
407-
}
379+
$workflowsNode = $xmlContent.SelectSingleNode("//$workflowsNodeName")
380+
381+
# Check if the workflows node exists and set the appropriate flags
382+
if ($workflowsNode -ne $null) {
383+
if ($workflowsNode.HasChildNodes -or $workflowsNode.Attributes.Count -gt 0) {
384+
$isWorkflowsFound = $true
408385
}
409386
}
410-
# aiplugin operation
411-
$nodeNameToCheck = "aicopilot_aiplugin"
412-
# Use XPath to find the node
413-
$nodeToCheck = $xmlContent.SelectSingleNode("//$nodeNameToCheck")
414-
415-
# Check if the node exists and output the result
416-
if ($nodeToCheck -ne $null) {
417-
if ($nodeToCheck.HasChildNodes -or $nodeToCheck.Attributes.Count -gt 0) {
418-
# check if the folder name is present with the same name
419-
$folderNameToCheck1 = "aiplugins"
420-
$nodeNameFolder1 = Get-ChildItem -Path "$tempFolder3" -Directory | Where-Object {$_.Name -eq $folderNameToCheck1}
421-
$folderNameToCheck2 = "aipluginoperations"
422-
$nodeNameFolder2 = Get-ChildItem -Path "$tempFolder3" -Directory | Where-Object {$_.Name -eq $folderNameToCheck2}
423-
if ((-not $nodeNameFolder1) -and (-not $nodeNameFolder2)) {
424-
Write-Host "The solution zip file '$secondLevelZipFile' in '$originalParentFolderPath' should contain folders namely '$folderNameToCheck1, $folderNameToCheck2'."
425-
Write-Host "The folders should match the customization.xml file. They are present by default in an exported solution and should not be modified/removed manually."
426-
Write-Host "Please add the required folders to the solution zip or export the correct solution again."
427-
DisplayReferDocumentation
428-
Write-Host ""
429-
Write-Host "Validation failed: Invalid package structure. Check previous messages for details." -ForegroundColor Red
430-
Write-Host ""
431-
RemoveTempFolder $tempFolder
432-
RemoveTempFolder $tempFolder2
433-
RemoveTempFolder $tempFolder3
434-
exit
435-
} elseif (-not $nodeNameFolder1) {
436-
Write-Host "The solution zip file '$secondLevelZipFile' in '$originalParentFolderPath' should contain a folder namely '$folderNameToCheck1'."
437-
Write-Host "The folders should match the customization.xml file. They are present by default in an exported solution and should not be modified/removed manually."
438-
Write-Host "Please add the required folder to the solution zip or export the correct solution again."
439-
DisplayReferDocumentation
440-
Write-Host ""
441-
Write-Host "Validation failed: Invalid package structure. Check previous messages for details." -ForegroundColor Red
442-
Write-Host ""
443-
RemoveTempFolder $tempFolder
444-
RemoveTempFolder $tempFolder2
445-
RemoveTempFolder $tempFolder3
446-
exit
447-
} elseif (-not $nodeNameFolder2) {
448-
Write-Host "The solution zip file '$secondLevelZipFile' in '$originalParentFolderPath' should contain a folder namely '$folderNameToCheck2'."
449-
Write-Host "The folders should match the customization.xml file. They are present by default in an exported solution and should not be modified/removed manually."
450-
Write-Host "Please add the required folder to the solution zip or export the correct solution again."
451-
DisplayReferDocumentation
452-
Write-Host ""
453-
Write-Host "Validation failed: Invalid package structure. Check previous messages for details." -ForegroundColor Red
454-
Write-Host ""
455-
RemoveTempFolder $tempFolder
456-
RemoveTempFolder $tempFolder2
457-
RemoveTempFolder $tempFolder3
458-
exit
387+
388+
if ($pluginEnabled) {
389+
# aiplugin operation
390+
$pluginNodeName = "aicopilot_aiplugin"
391+
# Use XPath to find the node
392+
$pluginNode = $xmlContent.SelectSingleNode("//$pluginNodeName")
393+
394+
# Check if the aicopilot_aiplugin node exists and set the appropriate flags
395+
if ($pluginNode -ne $null) {
396+
if ($pluginNode.HasChildNodes -or $pluginNode.Attributes.Count -gt 0) {
397+
$isPluginFound = $true
459398
}
460399
}
461400
}
462-
}
401+
402+
# categorize each of the solution zip
403+
if (($isConnectorFound) -and (-not $isWorkflowsFound) -and (-not $isPluginFound)) {
404+
$isConnectorSolutionPresent = $true
405+
}
406+
if (($isConnectorFound) -and ($isWorkflowsFound) -and (-not $isPluginFound)) {
407+
$isFlowSolutionPresent = $true
408+
}
409+
if (($isConnectorFound) -and (-not $isWorkflowsFound) -and ($isPluginFound)) {
410+
$isPluginSolutionPresent = $true
411+
$workFlowsFolderCount++
412+
}
413+
# check if the connector folder name is present with the same name
414+
if ($isConnectorFound) {
415+
$connectorFolder = Get-ChildItem -Path "$tempFolder3" -Directory | Where-Object {$_.Name -eq $connectorNodeName}
416+
if (-not $connectorFolder) {
417+
Write-Host "The solution zip file '$secondLevelZipFile' in '$originalParentFolderPath' should contain one folder namely '$connectorNodeName."
418+
Write-Host "The folders should match the customization.xml file. They are present by default in an exported solution and should not be modified/removed manually."
419+
Write-Host "Please add the required folder to the solution zip or export the correctsolution again."
420+
DisplayReferDocumentation
421+
Write-Host ""
422+
Write-Host "Validation failed: Invalid package structure. Check previous messages for details." -ForegroundColor Red
423+
Write-Host ""
424+
RemoveTempFolder $tempFolder
425+
RemoveTempFolder $tempFolder2
426+
RemoveTempFolder $tempFolder3
427+
exit
428+
}
429+
}
463430

431+
if ($isWorkflowsFound) {
432+
# check if the folder name is present with the same name
433+
$connectorFolder = Get-ChildItem -Path "$tempFolder3" -Directory | Where-Object {$_.Name -eq $connectorNodeName}
434+
$workFlowsFolder = Get-ChildItem -Path "$tempFolder3" -Directory | Where-Object {$_.Name -eq $workflowsNodeName}
435+
if ((-not $workFlowsFolder) -or (-not $connectorFolder)) {
436+
$folderNameMissing = if ((-not $workFlowsFolder) -and $connectorFolder) {"folder namely '$workflowsNodeName'"} elseif ((-not $connectorFolder) -and $workFlowsFolder) {"folder namely '$connectorNodeName"} else {"folders namely '$connectorNodeName', '$workflowsNodeName'"}
437+
Write-Host "The solution zip file '$secondLevelZipFile' in '$originalParentFolderPath' should contain '$folderNameMissing'."
438+
Write-Host "The folders should match the customization.xml file. They are present by default in an exported solution and should not be modified/removed manually."
439+
Write-Host "Please add the required folder to the solution zip or export the correct solution again."
440+
DisplayReferDocumentation
441+
Write-Host ""
442+
Write-Host "Validation failed: Invalid package structure. Check previous messages for details." -ForegroundColor Red
443+
Write-Host ""
444+
RemoveTempFolder $tempFolder
445+
RemoveTempFolder $tempFolder2
446+
RemoveTempFolder $tempFolder3
447+
exit
448+
}
449+
}
450+
451+
if ($isPluginFound) {
452+
# check if the AI plugin related folder names are present with the same name
453+
$connectorFolder = Get-ChildItem -Path "$tempFolder3" -Directory | Where-Object {$_.Name -eq $connectorNodeName}
454+
$folderNameToCheck1 = "aiplugins"
455+
$nodeNameFolder1 = Get-ChildItem -Path "$tempFolder3" -Directory | Where-Object {$_.Name -eq $folderNameToCheck1}
456+
$folderNameToCheck2 = "aipluginoperations"
457+
$nodeNameFolder2 = Get-ChildItem -Path "$tempFolder3" -Directory | Where-Object {$_.Name -eq $folderNameToCheck2}
458+
459+
if ((-not $connectorFolder) -or (-not $nodeNameFolder1) -or (-not $nodeNameFolder2)) {
460+
$folderNameMissing = if ((-not $nodeNameFolder1) -and $connectorFolder -and $nodeNameFolder2) {"folder namely '$folderNameToCheck1'"} elseif ((-not $connectorFolder) -and $nodeNameFolder1 -and $nodeNameFolder2) {"folder namely '$connectorNodeName"} elseif ((-not $nodeNameFolder2) -and $connectorFolder -and $nodeNameFolder2) {"folder namely '$folderNameToCheck2"} elseif ((-not $nodeNameFolder1) -and (-not $connectorFolder) -and $nodeNameFolder2) {"folders namely '$connectorNodeName', '$folderNameToCheck1'"} elseif ((-not $nodeNameFolder2) -and (-not $connectorFolder) -and $nodeNameFolder1) {"folders namely '$connectorNodeName', '$folderNameToCheck2'"} elseif ((-not $nodeNameFolder1) -and (-not $nodeNameFolder2) -and $connectorFolder) {"folders namely '$folderNameToCheck1', '$folderNameToCheck2'"} else {"folders namely '$connectorNodeName', '$folderNameToCheck1'. '$folderNameToCheck2'"}
461+
Write-Host "The solution zip file '$secondLevelZipFile' in '$originalParentFolderPath' should contain '$folderNameMissing"
462+
Write-Host "The folders should match the customization.xml file. They are present by default in an exported solution and should not be modified/removed manually."
463+
Write-Host "Please add the required folders to the solution zip or export the correct solution again."
464+
DisplayReferDocumentation
465+
Write-Host ""
466+
Write-Host "Validation failed: Invalid package structure. Check previous messages for details." -ForegroundColor Red
467+
Write-Host ""
468+
RemoveTempFolder $tempFolder
469+
RemoveTempFolder $tempFolder2
470+
RemoveTempFolder $tempFolder3
471+
exit
472+
}
473+
}
474+
}
475+
if (-not $isConnectorSolutionPresent) {
476+
Write-Host "Connector solution in '$originalParentFolderPath' is invalid. Connector solution should only contain 'Connector' folder."
477+
Write-Host "Validate the connector solution has no extra component except 'Connector'. If not so, please remove them from the solution and export again."
478+
$resultOfValidation = $false
479+
}
480+
elseif (-not $isFlowSolutionPresent) {
481+
Write-Host "Flow solution in '$originalParentFolderPath' is invalid. Flow solution should contain both 'Connector' and 'Workflows' folders."
482+
Write-Host "Validate the flow solution has both 'Connector' and 'Workflows' components. If not so, please recreate the solution and export again."
483+
$resultOfValidation = $false
484+
}
485+
elseif ($pluginEnabled -and (-not $isPluginSolutionPresent)) {
486+
Write-Host "Plugin solution in '$originalParentFolderPath' is invalid. Plugin solution should contain 'Connector', 'aiplugins' and 'aipluginoperations' folders."
487+
Write-Host "Validate the plugin solution has 'Connector', 'aiplugins' and 'aipluginoperations' components. If not so, please recreate the solution and export again."
488+
$resultOfValidation = $false
489+
}
464490
if ($resultOfValidation) {
465491
Write-Host "Validation successful: The package structure is correct." -ForegroundColor Green
466492
Write-Host ""
@@ -471,6 +497,7 @@ try {
471497
Write-Host ""
472498
}
473499
}
500+
474501
catch {
475502
Write-Host "Validation failed: Internal issue while working with current folder as '$parentFolderPath' - error occurred: $($_.Exception.Message)" -ForegroundColor Yellow
476503
Write-Host ""

0 commit comments

Comments
 (0)