Skip to content

Add proper path resolution to -Path/File parameters #6986

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Aug 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public override void ExecuteCmdlet()
if (ShouldProcess(Name, VerbsData.Export))
{
var ret = this.AutomationClient.GetConfigurationContent(this.ResourceGroupName,
this.AutomationAccountName, this.Name, isDraft, OutputFolder, this.Force);
this.AutomationAccountName, this.Name, isDraft, ResolveUserPath(OutputFolder), this.Force);

this.WriteObject(ret, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public override void ExecuteCmdlet()
if (ShouldProcess(ReportId.ToString(), VerbsData.Export))
{
var ret = this.AutomationClient.GetDscNodeReportContent(this.ResourceGroupName,
this.AutomationAccountName, this.NodeId, this.ReportId, OutputFolder, overwriteExistingFile);
this.AutomationAccountName, this.NodeId, this.ReportId, ResolveUserPath(OutputFolder), overwriteExistingFile);

this.WriteObject(ret, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected override void AutomationProcessRecord()
if (ShouldProcess(Name, VerbsData.Export))
{
var outputFolder = this.AutomationClient.ExportRunbook(this.ResourceGroupName,
this.AutomationAccountName, this.Name, isDraft, this.OutputFolder, this.Force.IsPresent);
this.AutomationAccountName, this.Name, isDraft, ResolveUserPath(this.OutputFolder), this.Force.IsPresent);

this.WriteObject(outputFolder, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public SwitchParameter Force
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
public override void ExecuteCmdlet()
{
OutputFolder = ResolveUserPath(OutputFolder);
this.ConfirmAction(
this.Force.IsPresent,
string.Format(CultureInfo.CurrentCulture, Resources.DscMetaMofHasKeysWarning),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public override void ExecuteCmdlet()
var configuration = this.AutomationClient.CreateConfiguration(
this.ResourceGroupName,
this.AutomationAccountName,
this.SourcePath,
ResolveUserPath(this.SourcePath),
this.Tags,
this.Description,
this.LogVerbose,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public override void ExecuteCmdlet()
{
if (ShouldProcess(Path, VerbsData.Import))
{
Path = ResolveUserPath(Path);
var nodeName = System.IO.Path.GetFileNameWithoutExtension(Path);
var nodeConfigurationName = ConfigurationName + "." + nodeName;
NodeConfiguration nodeConfigurationModel = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public class NewAzureAutomationCertificate : AzureAutomationBaseCmdlet
protected override void AutomationProcessRecord()
{

var createdCertificate = this.AutomationClient.CreateCertificate(this.ResourceGroupName, this.AutomationAccountName, this.Name, this.ResolvePath(this.Path), this.Password, this.Description, this.Exportable.IsPresent);
var createdCertificate = this.AutomationClient.CreateCertificate(this.ResourceGroupName, this.AutomationAccountName, this.Name, this.ResolvePath(Path), this.Password, this.Description, this.Exportable.IsPresent);

this.WriteObject(createdCertificate);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1895,7 +1895,7 @@ private DirectoryInfo WriteRunbookToFile(string outputFolder, string runbookName

var fileExtension = IsGraphRunbook(runbookType) ? Constants.SupportedFileExtensions.Graph : Constants.SupportedFileExtensions.PowerShellScript;

var outputFilePath = outputFolderFullPath + "\\" + runbookName + fileExtension;
var outputFilePath = Path.Combine(outputFolderFullPath, runbookName + fileExtension);

// file exists and overwrite Not specified
if (File.Exists(outputFilePath) && !overwriteExistingFile)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public class GetBatchNodeFileContentCommand : BatchObjectModelCmdletBase

public override void ExecuteCmdlet()
{
DestinationPath = ResolveUserPath(DestinationPath);
if (this.ByteRangeEnd != null && this.ByteRangeStart == null)
{
this.ByteRangeStart = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public override void ExecuteCmdlet()
result.EndTime = DateTime.Now;
if (!string.IsNullOrWhiteSpace(this.Path))
{
File.WriteAllText(this.Path, op.Body.Resources[0].ToString());
File.WriteAllText(ResolveUserPath(this.Path), op.Body.Resources[0].ToString());
}
WriteObject(result);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public class ExportAzureDataLakeStoreItem : DataLakeStoreFileSystemCmdletBase
public override void ExecuteCmdlet()
{
// We will let this throw itself if the path they give us is invalid
var powerShellReadyPath = SessionState.Path.GetUnresolvedProviderPathFromPSPath(Destination);
var powerShellReadyPath = ResolveUserPath(Destination);
ConfirmAction(
VerbsData.Export,
Path.TransformedPath,
Expand All @@ -119,8 +119,7 @@ public override void ExecuteCmdlet()
{
if (ParameterSetName.Equals(DiagnosticParameterSetName) && DiagnosticLogLevel != LogLevel.None)
{
var diagnosticPath =
SessionState.Path.GetUnresolvedProviderPathFromPSPath(DiagnosticLogPath);
var diagnosticPath = ResolveUserPath(DiagnosticLogPath);
DataLakeStoreFileSystemClient.SetupFileLogging(DiagnosticLogLevel, diagnosticPath);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public class ImportAzureDataLakeStoreItem : DataLakeStoreFileSystemCmdletBase

public override void ExecuteCmdlet()
{
var powerShellSourcePath = SessionState.Path.GetUnresolvedProviderPathFromPSPath(Path);
var powerShellSourcePath = ResolveUserPath(Path);
ConfirmAction(
Resources.UploadFileMessage,
Destination.TransformedPath,
Expand All @@ -128,8 +128,7 @@ public override void ExecuteCmdlet()
{
if (ParameterSetName.Equals(DiagnosticParameterSetName) && DiagnosticLogLevel != LogLevel.None)
{
var diagnosticPath =
SessionState.Path.GetUnresolvedProviderPathFromPSPath(DiagnosticLogPath);
var diagnosticPath = ResolveUserPath(DiagnosticLogPath);
DataLakeStoreFileSystemClient.SetupFileLogging(DiagnosticLogLevel, diagnosticPath);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public class AddAzureRmIoTDeviceProvisioningServiceCertificate : IotDpsBaseCmdle

public override void ExecuteCmdlet()
{
Path = ResolveUserPath(Path);
if (ShouldProcess(Name, DPSResources.AddCertificate))
{
switch (ParameterSetName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public class SetAzureRmIoTDeviceProvisioningServiceCertificate : IotDpsBaseCmdle

public override void ExecuteCmdlet()
{
Path = ResolveUserPath(Path);
if (ShouldProcess(Name, DPSResources.SetCertificate))
{
switch (ParameterSetName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public class AddAzureRmIotHubCertificate : IotHubBaseCmdlet

public override void ExecuteCmdlet()
{
Path = ResolveUserPath(Path);
if (ShouldProcess(CertificateName, Properties.Resources.AddIotHubCertificate))
{
string certificate = string.Empty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public class SetAzureRmIotHubVerifiedCertificate : IotHubBaseCmdlet

public override void ExecuteCmdlet()
{
Path = ResolveUserPath(Path);
if (ShouldProcess(CertificateName, Properties.Resources.VerifyIotHubCertificate))
{
string certificate = string.Empty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public override void ExecuteCmdlet()

internal X509Certificate2Collection InitializeCertificateCollection()
{
FileInfo certFile = new FileInfo(this.GetUnresolvedProviderPathFromPSPath(this.FilePath));
FileInfo certFile = new FileInfo(ResolveUserPath(this.FilePath));
if (!certFile.Exists)
{
throw new FileNotFoundException(string.Format(KeyVaultProperties.Resources.CertificateFileNotFound, this.FilePath));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public override void ExecuteCmdlet()

if (ShouldProcess(VaultName, Properties.Resources.RestoreManagedStorageAccount))
{
var resolvedFilePath = this.GetUnresolvedProviderPathFromPSPath(InputFile);
var resolvedFilePath = this.ResolveUserPath(InputFile);

if (!AzureSession.Instance.DataStore.FileExists(resolvedFilePath))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public override void ExecuteCmdlet()

if (ShouldProcess(VaultName, Properties.Resources.RestoreCertificate))
{
var resolvedFilePath = this.GetUnresolvedProviderPathFromPSPath(InputFile);
var resolvedFilePath = this.ResolveUserPath(InputFile);

if (!AzureSession.Instance.DataStore.FileExists(resolvedFilePath))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,17 @@ public override void ExecuteCmdlet()

if (ShouldProcess(VaultName, Properties.Resources.RestoreKey))
{
var filePath = ResolvePath(InputFile);
var filePath = ResolveKeyVaultPath(InputFile);

var restoredKeyBundle = this.DataServiceClient.RestoreKey(VaultName, filePath);

this.WriteObject(restoredKeyBundle);
}
}

private string ResolvePath(string filePath)
private string ResolveKeyVaultPath(string filePath)
{
FileInfo keyFile = new FileInfo(this.GetUnresolvedProviderPathFromPSPath(filePath));
FileInfo keyFile = new FileInfo(this.ResolveUserPath(filePath));
if (!keyFile.Exists)
{
throw new FileNotFoundException(string.Format(Resources.BackupKeyFileNotFound, filePath));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public override void ExecuteCmdlet( )

if (ShouldProcess(VaultName, Properties.Resources.RestoreSecret))
{
var resolvedFilePath = this.GetUnresolvedProviderPathFromPSPath(InputFile);
var resolvedFilePath = this.ResolveUserPath(InputFile);

if (!AzureSession.Instance.DataStore.FileExists(resolvedFilePath))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public override void ExecuteCmdlet()
bool executionComplete = false;
if (MyInvocation.BoundParameters.ContainsKey("Path"))
{
Path = this.ResolveUserPath(Path);
ConfirmAction(string.Format(Resources.ProcessImportContextFromFile, Path), Resources.ImportContextTarget, () =>
{
if (!AzureSession.Instance.DataStore.FileExists(Path))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class SaveAzureRMContextCommand : AzureRMCmdlet

public override void ExecuteCmdlet()
{
Path = this.ResolveUserPath(Path);
if (Profile != null)
{
if (ShouldProcess(string.Format(Resources.ProfileArgumentWrite, Path),
Expand Down
34 changes: 17 additions & 17 deletions src/ResourceManager/Profile/Commands.Profile/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@
<package id="Microsoft.Azure.Management.Authorization" version="2.0.0" targetFramework="net45" />
<package id="Microsoft.Azure.Management.ResourceManager" version="1.9.0-preview" targetFramework="net452" />
<package id="Microsoft.Azure.Management.Resources" version="2.20.1-preview" targetFramework="net452" />
<package id="Microsoft.Azure.PowerShell.Aks" version="1.0.93-preview" targetFramework="net452" />
<package id="Microsoft.Azure.PowerShell.Authentication" version="1.0.93-preview" targetFramework="net452" />
<package id="Microsoft.Azure.PowerShell.Authentication.Abstractions" version="1.0.93-preview" targetFramework="net452" />
<package id="Microsoft.Azure.PowerShell.Authentication.ResourceManager" version="1.0.93-preview" targetFramework="net452" />
<package id="Microsoft.Azure.PowerShell.Authorization" version="1.0.93-preview" targetFramework="net452" />
<package id="Microsoft.Azure.PowerShell.Common" version="1.0.93-preview" targetFramework="net452" />
<package id="Microsoft.Azure.PowerShell.Compute" version="1.0.93-preview" targetFramework="net452" />
<package id="Microsoft.Azure.PowerShell.Graph.Rbac" version="1.0.93-preview" targetFramework="net452" />
<package id="Microsoft.Azure.PowerShell.KeyVault" version="1.0.93-preview" targetFramework="net452" />
<package id="Microsoft.Azure.PowerShell.Network" version="1.0.93-preview" targetFramework="net452" />
<package id="Microsoft.Azure.PowerShell.ResourceManager" version="1.0.93-preview" targetFramework="net452" />
<package id="Microsoft.Azure.PowerShell.ScenarioTest.ResourceManager" version="1.0.93-preview" targetFramework="net452" />
<package id="Microsoft.Azure.PowerShell.ServiceManagement" version="1.0.93-preview" targetFramework="net452" />
<package id="Microsoft.Azure.PowerShell.Storage" version="1.0.93-preview" targetFramework="net452" />
<package id="Microsoft.Azure.PowerShell.Storage.Management" version="1.0.93-preview" targetFramework="net452" />
<package id="Microsoft.Azure.PowerShell.Strategies" version="1.0.93-preview" targetFramework="net452" />
<package id="Microsoft.Azure.PowerShell.Websites" version="1.0.93-preview" targetFramework="net452" />
<package id="Microsoft.Azure.PowerShell.Aks" version="1.0.94-preview" targetFramework="net452" />
<package id="Microsoft.Azure.PowerShell.Authentication" version="1.0.94-preview" targetFramework="net452" />
<package id="Microsoft.Azure.PowerShell.Authentication.Abstractions" version="1.0.94-preview" targetFramework="net452" />
<package id="Microsoft.Azure.PowerShell.Authentication.ResourceManager" version="1.0.94-preview" targetFramework="net452" />
<package id="Microsoft.Azure.PowerShell.Authorization" version="1.0.94-preview" targetFramework="net452" />
<package id="Microsoft.Azure.PowerShell.Common" version="1.0.94-preview" targetFramework="net452" />
<package id="Microsoft.Azure.PowerShell.Compute" version="1.0.94-preview" targetFramework="net452" />
<package id="Microsoft.Azure.PowerShell.Graph.Rbac" version="1.0.94-preview" targetFramework="net452" />
<package id="Microsoft.Azure.PowerShell.KeyVault" version="1.0.94-preview" targetFramework="net452" />
<package id="Microsoft.Azure.PowerShell.Network" version="1.0.94-preview" targetFramework="net452" />
<package id="Microsoft.Azure.PowerShell.ResourceManager" version="1.0.94-preview" targetFramework="net452" />
<package id="Microsoft.Azure.PowerShell.ScenarioTest.ResourceManager" version="1.0.94-preview" targetFramework="net452" />
<package id="Microsoft.Azure.PowerShell.ServiceManagement" version="1.0.94-preview" targetFramework="net452" />
<package id="Microsoft.Azure.PowerShell.Storage" version="1.0.94-preview" targetFramework="net452" />
<package id="Microsoft.Azure.PowerShell.Storage.Management" version="1.0.94-preview" targetFramework="net452" />
<package id="Microsoft.Azure.PowerShell.Strategies" version="1.0.94-preview" targetFramework="net452" />
<package id="Microsoft.Azure.PowerShell.Websites" version="1.0.94-preview" targetFramework="net452" />
<package id="Microsoft.Azure.Test.Framework" version="1.0.6179.26854-prerelease" targetFramework="net452" />
<package id="Microsoft.Azure.Test.HttpRecorder" version="1.8.1" targetFramework="net452" />
<package id="Microsoft.Bcl" version="1.1.9" targetFramework="net452" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ private void GetRecoveryPlanFile(
System.IO.Path.GetDirectoryName(this.Path)));
}

var fullFileName = this.Path;
var fullFileName = ResolveUserPath(this.Path);
using (var file = new StreamWriter(
fullFileName,
false))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +152,18 @@ public override void ExecuteSiteRecoveryCmdlet()
break;
case ASRParameterSets.ByRPFile:

if (!File.Exists(this.Path))
var filePath = ResolveUserPath(this.Path);

if (!File.Exists(filePath))
{
throw new FileNotFoundException(
string.Format(
Resources.FileNotFound,
this.Path));
filePath));

;
}

var filePath = this.Path;

using (var file = new StreamReader(filePath))
{
this.recoveryPlan = JsonConvert.DeserializeObject<RecoveryPlan>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,17 @@ public override void ExecuteSiteRecoveryCmdlet()
break;
case ASRParameterSets.ByRPFile:

if (!File.Exists(this.Path))
var filePath = ResolveUserPath(this.Path);

if (!File.Exists(filePath))
{
throw new FileNotFoundException(
string.Format(
Resources.FileNotFound,
this.Path));
filePath));
;
}

var filePath = this.Path;

RecoveryPlan recoveryPlan = null;

using (var file = new StreamReader(filePath))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public override void ExecuteSiteRecoveryCmdlet()
{
base.ExecuteSiteRecoveryCmdlet();

Path = this.ResolveUserPath(Path);

if (this.ShouldProcess(
"Vault Setting file",
VerbsData.Import))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public override void ExecuteCmdlet()
{ VaultParams.VaultName, vaultName },
{ VaultParams.ResourceGroupName, resourceGroupName },
{ RestoreBackupItemParams.RecoveryPoint, RecoveryPoint },
{ RecoveryPointParams.FileDownloadLocation, Path }
{ RecoveryPointParams.FileDownloadLocation, ResolveUserPath(Path) }
}, ServiceClientAdapter);

IPsBackupProvider psBackupProvider = providerManager.GetProviderInstance(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ private void GetSiteRecoveryCredentials()
string fileName = this.GenerateFileName();

string filePath = string.IsNullOrEmpty(this.Path) ? Utilities.GetDefaultPath() : this.Path;
filePath = ResolveUserPath(filePath);

// Generate file.
if (RecoveryServicesClient.getVaultAuthType(this.Vault.ResourceGroupName, this.Vault.Name) == 0)
Expand Down Expand Up @@ -262,6 +263,7 @@ private string GenerateFileName()
public void GetAzureRMRecoveryServicesVaultBackupCredentials()
{
string targetLocation = string.IsNullOrEmpty(this.Path) ? Utilities.GetDefaultPath() : this.Path;
targetLocation = ResolveUserPath(targetLocation);
if (!Directory.Exists(targetLocation))
{
throw new ArgumentException(Resources.VaultCredPathException);
Expand Down
Loading