Skip to content

Commit b3d6299

Browse files
committed
Merge branch 'dev' of https://github.com/Azure/azure-powershell into dev
2 parents c2e61c9 + 6095e51 commit b3d6299

File tree

262 files changed

+3423
-1876
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

262 files changed

+3423
-1876
lines changed

src/Common/Commands.Common/AzureDataCmdlet.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,25 @@ protected override void PromptForDataCollectionProfileIfNotExists()
117117
protected override void InitializeQosEvent()
118118
{
119119
}
120+
121+
/// <summary>
122+
/// Guards execution of the given action using ShouldProcess and ShouldContinue. The optional
123+
/// useSHouldContinue predicate determines whether SHouldContinue should be called for this
124+
/// particular action (e.g. a resource is being overwritten). By default, both
125+
/// ShouldProcess and ShouldContinue will be executed. Cmdlets that use this method overload
126+
/// must have a force parameter.
127+
/// </summary>
128+
/// <param name="force">Do not ask for confirmation</param>
129+
/// <param name="continueMessage">Message to describe the action</param>
130+
/// <param name="processMessage">Message to prompt after the active is performed.</param>
131+
/// <param name="target">The target name.</param>
132+
/// <param name="action">The action code</param>
133+
protected override void ConfirmAction(bool force, string continueMessage, string processMessage, string target,
134+
Action action)
135+
{
136+
ConfirmAction(force, continueMessage, processMessage, target, action, () => true);
137+
}
138+
139+
120140
}
121141
}

src/Common/Commands.Common/AzurePSCmdlet.cs

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -506,21 +506,23 @@ protected void LogQosEvent()
506506
}
507507

508508
/// <summary>
509-
/// Asks for confirmation before executing the action.
509+
/// Guards execution of the given action using ShouldProcess and ShouldContinue. This is a legacy
510+
/// version forcompatibility with older RDFE cmdlets.
510511
/// </summary>
511512
/// <param name="force">Do not ask for confirmation</param>
512-
/// <param name="actionMessage">Message to describe the action</param>
513+
/// <param name="continueMessage">Message to describe the action</param>
513514
/// <param name="processMessage">Message to prompt after the active is performed.</param>
514515
/// <param name="target">The target name.</param>
515516
/// <param name="action">The action code</param>
516-
protected void ConfirmAction(bool force, string actionMessage, string processMessage, string target, Action action)
517+
protected virtual void ConfirmAction(bool force, string continueMessage, string processMessage, string target,
518+
Action action)
517519
{
518520
if (_qosEvent != null)
519521
{
520522
_qosEvent.PauseQoSTimer();
521523
}
522524

523-
if (force || ShouldContinue(actionMessage, ""))
525+
if (force || ShouldContinue(continueMessage, ""))
524526
{
525527
if (ShouldProcess(target, processMessage))
526528
{
@@ -533,6 +535,68 @@ protected void ConfirmAction(bool force, string actionMessage, string processMes
533535
}
534536
}
535537

538+
/// <summary>
539+
/// Guards execution of the given action using ShouldProcess and ShouldContinue. The optional
540+
/// useSHouldContinue predicate determines whether SHouldContinue should be called for this
541+
/// particular action (e.g. a resource is being overwritten). By default, both
542+
/// ShouldProcess and ShouldContinue will be executed. Cmdlets that use this method overload
543+
/// must have a force parameter.
544+
/// </summary>
545+
/// <param name="force">Do not ask for confirmation</param>
546+
/// <param name="continueMessage">Message to describe the action</param>
547+
/// <param name="processMessage">Message to prompt after the active is performed.</param>
548+
/// <param name="target">The target name.</param>
549+
/// <param name="action">The action code</param>
550+
/// <param name="useShouldContinue">A predicate indicating whether ShouldContinue should be invoked for thsi action</param>
551+
protected virtual void ConfirmAction(bool force, string continueMessage, string processMessage, string target, Action action, Func<bool> useShouldContinue)
552+
{
553+
if (null == useShouldContinue)
554+
{
555+
useShouldContinue = () => true;
556+
}
557+
if (_qosEvent != null)
558+
{
559+
_qosEvent.PauseQoSTimer();
560+
}
561+
562+
if (ShouldProcess(target, processMessage))
563+
{
564+
if (force || !useShouldContinue() || ShouldContinue(continueMessage, ""))
565+
{
566+
if (_qosEvent != null)
567+
{
568+
_qosEvent.ResumeQosTimer();
569+
}
570+
action();
571+
}
572+
}
573+
}
574+
575+
/// <summary>
576+
/// Prompt for confirmation depending on the ConfirmLevel. By default No confirmation prompt
577+
/// occurs unless ConfirmLevel >= $ConfirmPreference. Guarding the actions of a cmdlet with this
578+
/// method will enable the cmdlet to support -WhatIf and -Confirm parameters.
579+
/// </summary>
580+
/// <param name="processMessage">The change being made to the resource</param>
581+
/// <param name="target">The resource that is being changed</param>
582+
/// <param name="action">The action to perform if confirmed</param>
583+
protected virtual void ConfirmAction(string processMessage, string target, Action action)
584+
{
585+
if (_qosEvent != null)
586+
{
587+
_qosEvent.PauseQoSTimer();
588+
}
589+
590+
if (ShouldProcess(target, processMessage))
591+
{
592+
if (_qosEvent != null)
593+
{
594+
_qosEvent.ResumeQosTimer();
595+
}
596+
action();
597+
}
598+
}
599+
536600
public virtual void ExecuteCmdlet()
537601
{
538602
// Do nothing.

src/ResourceManager/ApiManagement/Commands.ApiManagement.ServiceManagement/Commands/AzureApiManagementRemoveCmdletBase.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14+
15+
using System;
16+
1417
namespace Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Commands
1518
{
1619
using Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Properties;
@@ -28,6 +31,7 @@ abstract public class AzureApiManagementRemoveCmdletBase : AzureApiManagementCmd
2831
ValueFromPipelineByPropertyName = true,
2932
Mandatory = false,
3033
HelpMessage = "Forces delete operation (prevents confirmation dialog). This parameter is optional. Default value is false.")]
34+
[Obsolete("Force parameter will be removed in an upcoming release", false)]
3135
public SwitchParameter Force { get; set; }
3236

3337
public abstract string ActionWarning { get; }
@@ -36,8 +40,7 @@ abstract public class AzureApiManagementRemoveCmdletBase : AzureApiManagementCmd
3640

3741
public override void ExecuteApiManagementCmdlet()
3842
{
39-
if (!Force.IsPresent &&
40-
!ShouldProcess(
43+
if (!ShouldProcess(
4144
ActionDescription,
4245
ActionWarning,
4346
Resources.ShouldProcessCaption))

src/ResourceManager/ApiManagement/Commands.ApiManagement.ServiceManagement/Commands/ExportAzureApiManagementApi.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ namespace Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Commands
2222
using System.Management.Automation;
2323
using System.Text;
2424

25-
[Cmdlet(VerbsData.Export, Constants.ApiManagementApi, DefaultParameterSetName = ExportContentToPipeline)]
25+
[Cmdlet(VerbsData.Export, Constants.ApiManagementApi, DefaultParameterSetName = ExportContentToPipeline,
26+
SupportsShouldProcess = true)]
2627
[OutputType(typeof(string))]
2728
public class ExportAzureApiManagementApi : AzureApiManagementCmdletBase
2829
{
@@ -93,12 +94,9 @@ public override void ExecuteApiManagementCmdlet()
9394
var actionWarning = string.Format(CultureInfo.CurrentCulture, Resources.ApiExportWarning, SaveAs);
9495

9596
// Do nothing if force is not specified and user cancelled the operation
96-
if (File.Exists(SaveAs) &&
97-
!Force.IsPresent &&
98-
!ShouldProcess(
99-
actionDescription,
100-
actionWarning,
101-
Resources.ShouldProcessCaption))
97+
if (!ShouldProcess(ApiId,
98+
actionDescription) || (File.Exists(SaveAs) &&
99+
!Force.IsPresent && !ShouldContinue(actionWarning, Resources.ShouldProcessCaption)))
102100
{
103101
if (PassThru)
104102
{

src/ResourceManager/ApiManagement/Commands.ApiManagement.ServiceManagement/Commands/GetAzureApiManagementCertificate.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ namespace Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Commands
1919
using System.Collections.Generic;
2020
using System.Management.Automation;
2121

22-
[Cmdlet(VerbsCommon.Get, Constants.ApiManagementCertificate, DefaultParameterSetName = GetAll)]
22+
[Cmdlet(VerbsCommon.Get, Constants.ApiManagementCertificate, DefaultParameterSetName = GetAll,
23+
SupportsShouldProcess= true)]
2324
[OutputType(typeof(IList<PsApiManagementCertificate>), ParameterSetName = new[] { GetAll })]
2425
[OutputType(typeof(PsApiManagementCertificate), ParameterSetName = new[] { GetById })]
2526
public class GetAzureApiManagementCertificate : AzureApiManagementCmdletBase

src/ResourceManager/ApiManagement/Commands.ApiManagement.ServiceManagement/Commands/GetAzureApiManagementPolicy.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ namespace Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Commands
2222
using System.Management.Automation;
2323
using System.Text;
2424

25-
[Cmdlet(VerbsCommon.Get, Constants.ApiManagementPolicy, DefaultParameterSetName = TenantLevel)]
25+
[Cmdlet(VerbsCommon.Get, Constants.ApiManagementPolicy, DefaultParameterSetName = TenantLevel,
26+
SupportsShouldProcess = true)]
2627
[OutputType(typeof(string))]
2728
public class GetAzureApiManagementPolicy : AzureApiManagementCmdletBase
2829
{
@@ -125,12 +126,11 @@ public override void ExecuteApiManagementCmdlet()
125126
var actionWarning = string.Format(CultureInfo.CurrentCulture, Resources.SavePolicyWarning, SaveAs);
126127

127128
// Do nothing if force is not specified and user cancelled the operation
128-
if (File.Exists(SaveAs) &&
129+
if (!ShouldProcess(ApiId, actionDescription) || (File.Exists(SaveAs) &&
129130
!Force.IsPresent &&
130-
!ShouldProcess(
131-
actionDescription,
131+
!ShouldContinue(
132132
actionWarning,
133-
Resources.ShouldProcessCaption))
133+
Resources.ShouldProcessCaption)))
134134
{
135135
return;
136136
}

src/ResourceManager/ApiManagement/Commands.ApiManagement.ServiceManagement/Commands/PublishAzureApiManagementTenantConfiguration.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Commands
2020
using System;
2121
using System.Management.Automation;
2222

23-
[Cmdlet(VerbsData.Publish, Constants.ApiManagementTenantGitConfiguration)]
23+
[Cmdlet(VerbsData.Publish, Constants.ApiManagementTenantGitConfiguration, SupportsShouldProcess = true)]
2424
[OutputType(typeof(PsApiManagementOperationResult))]
2525
public class PublishAzureApiManagementTenantConfiguration : AzureApiManagementCmdletBase
2626
{
@@ -75,10 +75,9 @@ public override void ExecuteApiManagementCmdlet()
7575
else
7676
{
7777
// confirm with user before pushing the update.
78-
if (!Force.IsPresent &&
79-
!ShouldProcess(
80-
Resources.PublishTenantConfigurationDescription,
78+
if (!ShouldProcess(
8179
Resources.PublishTenantConfigurationDescription,
80+
Resources.PublishTenantConfigurationWarning,
8281
Resources.ShouldProcessCaption))
8382
{
8483
return;

src/ResourceManager/ApiManagement/Commands.ApiManagement.ServiceManagement/Commands/RemoveAzureApiManagementApi.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Commands
2020
using System.Globalization;
2121
using System.Management.Automation;
2222

23-
[Cmdlet(VerbsCommon.Remove, Constants.ApiManagementApi)]
23+
[Cmdlet(VerbsCommon.Remove, Constants.ApiManagementApi, SupportsShouldProcess = true)]
2424
[OutputType(typeof(bool))]
2525
public class RemoveAzureApiManagementApi : AzureApiManagementCmdletBase
2626
{
@@ -42,6 +42,7 @@ public class RemoveAzureApiManagementApi : AzureApiManagementCmdletBase
4242
ValueFromPipelineByPropertyName = true,
4343
Mandatory = false,
4444
HelpMessage = "Forces delete operation (prevents confirmation dialog). This parameter is optional.")]
45+
[Obsolete("Force parameter will be removed in an upcoming release", false)]
4546
public SwitchParameter Force { get; set; }
4647

4748
[Parameter(
@@ -56,8 +57,7 @@ public override void ExecuteApiManagementCmdlet()
5657
var actionWarning = string.Format(CultureInfo.CurrentCulture, Resources.ApiRemoveWarning, ApiId);
5758

5859
// Do nothing if force is not specified and user cancelled the operation
59-
if (!Force.IsPresent &&
60-
!ShouldProcess(
60+
if (!ShouldProcess(
6161
actionDescription,
6262
actionWarning,
6363
Resources.ShouldProcessCaption))

src/ResourceManager/ApiManagement/Commands.ApiManagement.ServiceManagement/Commands/RemoveAzureApiManagementAuthorizationServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Commands
2020
using System.Globalization;
2121
using System.Management.Automation;
2222

23-
[Cmdlet(VerbsCommon.Remove, Constants.ApiManagementAuthorizationServer)]
23+
[Cmdlet(VerbsCommon.Remove, Constants.ApiManagementAuthorizationServer, SupportsShouldProcess = true)]
2424
[OutputType(typeof(bool))]
2525
public class RemoveAzureApiManagementAuthorizationServer : AzureApiManagementRemoveCmdletBase
2626
{

src/ResourceManager/ApiManagement/Commands.ApiManagement.ServiceManagement/Commands/RemoveAzureApiManagementCertificate.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Commands
2020
using System.Globalization;
2121
using System.Management.Automation;
2222

23-
[Cmdlet(VerbsCommon.Remove, Constants.ApiManagementCertificate)]
23+
[Cmdlet(VerbsCommon.Remove, Constants.ApiManagementCertificate, SupportsShouldProcess = true)]
2424
[OutputType(typeof(bool))]
2525
public class RemoveAzureApiManagementCertificate : AzureApiManagementRemoveCmdletBase
2626
{

src/ResourceManager/ApiManagement/Commands.ApiManagement.ServiceManagement/Commands/RemoveAzureApiManagementGroup.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Commands
2020
using System.Globalization;
2121
using System.Management.Automation;
2222

23-
[Cmdlet(VerbsCommon.Remove, Constants.ApiManagementGroup)]
23+
[Cmdlet(VerbsCommon.Remove, Constants.ApiManagementGroup, SupportsShouldProcess = true)]
2424
[OutputType(typeof(bool))]
2525
public class RemoveAzureApiManagementGroup : AzureApiManagementCmdletBase
2626
{
@@ -48,6 +48,7 @@ public class RemoveAzureApiManagementGroup : AzureApiManagementCmdletBase
4848
ValueFromPipelineByPropertyName = true,
4949
Mandatory = false,
5050
HelpMessage = "Forces delete operation (prevents confirmation dialog). This parameter is optional. Default value is false.")]
51+
[Obsolete("Force parameter will be removed in an upcoming release", false)]
5152
public SwitchParameter Force { get; set; }
5253

5354
public override void ExecuteApiManagementCmdlet()
@@ -56,8 +57,7 @@ public override void ExecuteApiManagementCmdlet()
5657
var actionWarning = string.Format(CultureInfo.CurrentCulture, Resources.GroupRemoveWarning, GroupId);
5758

5859
// Do nothing if force is not specified and user cancelled the operation
59-
if (!Force.IsPresent &&
60-
!ShouldProcess(
60+
if (!ShouldProcess(
6161
actionDescription,
6262
actionWarning,
6363
Resources.ShouldProcessCaption))

src/ResourceManager/ApiManagement/Commands.ApiManagement.ServiceManagement/Commands/RemoveAzureApiManagementLogger.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Commands
2020
using System.Globalization;
2121
using System.Management.Automation;
2222

23-
[Cmdlet(VerbsCommon.Remove, Constants.ApiManagementLogger)]
23+
[Cmdlet(VerbsCommon.Remove, Constants.ApiManagementLogger, SupportsShouldProcess = true)]
2424
[OutputType(typeof(bool))]
2525
public class RemoveAzureApiManagementLogger : AzureApiManagementCmdletBase
2626
{
@@ -48,6 +48,7 @@ public class RemoveAzureApiManagementLogger : AzureApiManagementCmdletBase
4848
ValueFromPipelineByPropertyName = true,
4949
Mandatory = false,
5050
HelpMessage = "Forces delete operation (prevents confirmation dialog). This parameter is optional. Default value is false.")]
51+
[Obsolete("Force parameter will be removed in an upcoming release", false)]
5152
public SwitchParameter Force { get; set; }
5253

5354
public override void ExecuteApiManagementCmdlet()
@@ -56,8 +57,7 @@ public override void ExecuteApiManagementCmdlet()
5657
var actionWarning = string.Format(CultureInfo.CurrentCulture, Resources.LoggerRemoveWarning, LoggerId);
5758

5859
// Do nothing if force is not specified and user cancelled the operation
59-
if (!Force.IsPresent &&
60-
!ShouldProcess(
60+
if (!ShouldProcess(
6161
actionDescription,
6262
actionWarning,
6363
Resources.ShouldProcessCaption))

src/ResourceManager/ApiManagement/Commands.ApiManagement.ServiceManagement/Commands/RemoveAzureApiManagementOpenIdConnectProvider.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Commands
2020
using System.Globalization;
2121
using System.Management.Automation;
2222

23-
[Cmdlet(VerbsCommon.Remove, Constants.ApiManagementOpenIdConnectProvider)]
23+
[Cmdlet(VerbsCommon.Remove, Constants.ApiManagementOpenIdConnectProvider, SupportsShouldProcess = true)]
2424
[OutputType(typeof(bool))]
2525
public class RemoveAzureApiManagementOpenIdConnectProvider : AzureApiManagementCmdletBase
2626
{
@@ -48,6 +48,7 @@ public class RemoveAzureApiManagementOpenIdConnectProvider : AzureApiManagementC
4848
ValueFromPipelineByPropertyName = true,
4949
Mandatory = false,
5050
HelpMessage = "Forces delete operation (prevents confirmation dialog). This parameter is optional. Default value is false.")]
51+
[Obsolete("Force parameter will be removed in an upcoming release", false)]
5152
public SwitchParameter Force { get; set; }
5253

5354
public override void ExecuteApiManagementCmdlet()
@@ -56,8 +57,7 @@ public override void ExecuteApiManagementCmdlet()
5657
var actionWarning = string.Format(CultureInfo.CurrentCulture, Resources.OpenIdConnectProviderRemoveWarning, OpenIdConnectProviderId);
5758

5859
// Do nothing if force is not specified and user cancelled the operation
59-
if (!Force.IsPresent &&
60-
!ShouldProcess(
60+
if (!ShouldProcess(
6161
actionDescription,
6262
actionWarning,
6363
Resources.ShouldProcessCaption))

src/ResourceManager/ApiManagement/Commands.ApiManagement.ServiceManagement/Commands/RemoveAzureApiManagementOperation.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Commands
2020
using System.Globalization;
2121
using System.Management.Automation;
2222

23-
[Cmdlet(VerbsCommon.Remove, Constants.ApiManagementOperation)]
23+
[Cmdlet(VerbsCommon.Remove, Constants.ApiManagementOperation, SupportsShouldProcess = true)]
2424
[OutputType(typeof(bool))]
2525
public class RemoveAzureApiManagementOperation : AzureApiManagementCmdletBase
2626
{
@@ -49,6 +49,7 @@ public class RemoveAzureApiManagementOperation : AzureApiManagementCmdletBase
4949
ValueFromPipelineByPropertyName = true,
5050
Mandatory = false,
5151
HelpMessage = "Forces delete operation (prevents confirmation dialog). This parameter is optional.")]
52+
[Obsolete("Force parameter will be removed in an upcoming release", false)]
5253
public SwitchParameter Force { get; set; }
5354

5455
[Parameter(
@@ -63,8 +64,7 @@ public override void ExecuteApiManagementCmdlet()
6364
var actionWarning = string.Format(CultureInfo.CurrentCulture, Resources.OperationRemoveWarning, OperationId, ApiId);
6465

6566
// Do nothing if force is not specified and user cancelled the operation
66-
if (!Force.IsPresent &&
67-
!ShouldProcess(
67+
if (!ShouldProcess(
6868
actionDescription,
6969
actionWarning,
7070
Resources.ShouldProcessCaption))

0 commit comments

Comments
 (0)