Skip to content

Commit 82e3726

Browse files
authored
Merge pull request Azure#10552 from filizt/crossPlatformFileNames
[Blueprint] Blueprint and artifact folder/file names should be platform agnostic
2 parents abdff64 + b0d0e13 commit 82e3726

File tree

2 files changed

+20
-29
lines changed

2 files changed

+20
-29
lines changed

src/Blueprint/Blueprint/Cmdlets/BlueprintCmdletBase.cs

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
using Microsoft.Azure.Management.Internal.Resources.Models;
2525
using Microsoft.WindowsAzure.Commands.Utilities.Common;
2626
using Provider = Microsoft.Azure.Management.Internal.ResourceManager.Version2018_05_01.Models.Provider;
27+
using System.Linq;
2728

2829
namespace Microsoft.Azure.Commands.Blueprint.Cmdlets
2930
{
@@ -175,44 +176,37 @@ protected string GetValidatedFilePath(string fileFullName)
175176
}
176177

177178
/// <summary>
178-
/// This overloaded function expects a folder path and a file name and combines them. Checks if resulting full file name exist.
179+
/// Returns the blueprint file path.
179180
/// </summary>
180-
/// <param name="inputPath"></param>
181-
/// <param name="fileName"></param>
181+
/// <param name="path"></param>
182182
/// <returns></returns>
183-
protected string GetValidatedFilePath(string path, string fileName)
183+
protected string GetValidatedFilePathForBlueprint(string path)
184184
{
185-
var resolvedPath = ResolveUserPath(path);
186-
187-
var blueprintPath = Path.Combine(resolvedPath, fileName + ".json");
188-
189-
if (!AzureSession.Instance.DataStore.FileExists(blueprintPath))
185+
var blueprintFileName = AzureSession.Instance.DataStore.GetFiles(path, "*.*", SearchOption.TopDirectoryOnly)
186+
.Select(file => Path.GetFileName(file))
187+
.FirstOrDefault(name => String.Equals(name, "blueprint.json", StringComparison.OrdinalIgnoreCase));
188+
189+
if (blueprintFileName == null)
190190
{
191191
throw new Exception(
192-
$"Cannot locate a file with the name {fileName} in: {resolvedPath}.");
192+
$"Cannot locate Blueprint.json in: {path}.");
193193
}
194194

195-
return blueprintPath;
195+
return Path.Combine(path, blueprintFileName);
196196
}
197197

198198
/// <summary>
199-
/// Combines input folder path and folder name and check if the resulting path exists.
199+
/// Returns the artifacts folder path.
200200
/// </summary>
201-
/// <param name="inputPath"></param>
202-
/// <param name="folderName"></param>
201+
/// <param name="path"></param>
203202
/// <returns></returns>
204-
protected string GetValidatedFolderPath(string path, string folderName)
203+
protected string GetValidatedFolderPathForArtifacts(string path)
205204
{
206-
var resolvedPath = ResolveUserPath(path);
207-
208-
var artifactsPath = Path.Combine(resolvedPath, folderName);
209-
210-
if (!AzureSession.Instance.DataStore.DirectoryExists(artifactsPath))
211-
{
212-
artifactsPath = null;
213-
}
205+
var artifactsFolderName = AzureSession.Instance.DataStore.GetDirectories(path)
206+
.Select(folder => Path.GetFileName(folder))
207+
.FirstOrDefault(name => String.Equals(name, "artifacts", StringComparison.OrdinalIgnoreCase));
214208

215-
return artifactsPath;
209+
return artifactsFolderName == null ? null : Path.Combine(path, artifactsFolderName);
216210
}
217211
}
218212
}

src/Blueprint/Blueprint/Cmdlets/BlueprintDefinition/BlueprintDefinitionCmdletBase.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@ private async Task<string> GetManagementGroupAncestorsAsync(string subscriptionI
101101

102102
protected void ImportBlueprint(string blueprintName, string scope, string inputPath, bool force)
103103
{
104-
const string blueprintFileName = "Blueprint";
105-
var blueprintPath = GetValidatedFilePath(inputPath, blueprintFileName);
104+
var blueprintPath = GetValidatedFilePathForBlueprint(ResolveUserPath(inputPath));
106105

107106
BlueprintModel bpObject;
108107
try
@@ -170,9 +169,7 @@ protected string CreateFolderIfNotExist(string path, string folderName)
170169

171170
protected void ImportArtifacts(string blueprintName, string scope, string inputPath)
172171
{
173-
const string artifacts = "Artifacts";
174-
175-
var artifactsPath = GetValidatedFolderPath(inputPath, artifacts);
172+
var artifactsPath = GetValidatedFolderPathForArtifacts(ResolveUserPath(inputPath));
176173

177174
if (artifactsPath == null)
178175
{

0 commit comments

Comments
 (0)