From abf716bc07f1f4ff48b567061e66a6463b20da6f Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Wed, 31 Mar 2021 14:29:47 -0700 Subject: [PATCH 1/3] Expand path for template conversion --- src/Commands/ConvertFromArmTemplateCommand.cs | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/Commands/ConvertFromArmTemplateCommand.cs b/src/Commands/ConvertFromArmTemplateCommand.cs index 335210d..ed5a57b 100644 --- a/src/Commands/ConvertFromArmTemplateCommand.cs +++ b/src/Commands/ConvertFromArmTemplateCommand.cs @@ -3,9 +3,11 @@ // Licensed under the MIT License. using PSArm.Commands.Internal; +using PSArm.Internal; using PSArm.Serialization; using PSArm.Templates; using System; +using System.IO; using System.Management.Automation; namespace PSArm.Commands @@ -49,9 +51,34 @@ protected override void ProcessRecord() return; case "Path": - foreach (string path in Path) + foreach (string wildcardPath in Path) { - WriteObject(_parser.ParseFile(path)); + foreach (string path in GetResolvedProviderPathFromPSPath(wildcardPath, out ProviderInfo provider)) + { + if (!provider.Name.Is("FileSystem")) + { + WriteError( + new ErrorRecord( + new IOException($"Cannot convert non-filesystem template path '{path}'"), + "BadProviderPath", + ErrorCategory.InvalidArgument, + path)); + continue; + } + + if (!File.Exists(path)) + { + WriteError( + new ErrorRecord( + new FileNotFoundException($"ARM template file '{path}' does not exist"), + "TemplateFileNotFound", + ErrorCategory.ResourceUnavailable, + path)); + continue; + } + + WriteObject(_parser.ParseFile(path)); + } } return; From c0209fba0e0f2aac95a8c24d8c5cb11ad764fbb5 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Wed, 31 Mar 2021 14:55:19 -0700 Subject: [PATCH 2/3] Indicate wildcard support --- src/Commands/ConvertFromArmTemplateCommand.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Commands/ConvertFromArmTemplateCommand.cs b/src/Commands/ConvertFromArmTemplateCommand.cs index ed5a57b..8a71c35 100644 --- a/src/Commands/ConvertFromArmTemplateCommand.cs +++ b/src/Commands/ConvertFromArmTemplateCommand.cs @@ -27,6 +27,7 @@ public ConvertFromArmTemplateCommand() } [ValidateNotNullOrEmpty] + [SupportsWildcards] [Parameter(ParameterSetName = "Path", Position = 0, Mandatory = true)] public string[] Path { get; set; } From a3689ef7aab3f6a18cfa0f75abe236b2026d4112 Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Mon, 26 Apr 2021 17:00:15 -0700 Subject: [PATCH 3/3] add test --- test/pester/Conversion.Tests.ps1 | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/pester/Conversion.Tests.ps1 b/test/pester/Conversion.Tests.ps1 index 75f2b0b..802a662 100644 --- a/test/pester/Conversion.Tests.ps1 +++ b/test/pester/Conversion.Tests.ps1 @@ -20,4 +20,14 @@ Describe "ARM conversion cmdlets" { Assert-StructurallyEqual -ComparisonObject $original -JsonObject $created } + + It 'Can accept relative path' { + try { + Push-Location "$PSScriptRoot/assets" + ConvertFrom-ArmTemplate -Path ./roundtrip-template.json | Should -Not -BeNullOrEmpty + } + finally { + Pop-Location + } + } }