Skip to content

[App Service]: Added support to use Id for Restore-AzDeletedWebApp. #12256

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 6 commits into from
Jun 28, 2020
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
47 changes: 46 additions & 1 deletion src/Websites/Websites.Test/ScenarioTests/WebAppSlotTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -405,13 +405,16 @@ function Test-SetWebAppSlot
{
# Setup
$rgname = Get-ResourceGroupName
$rgname1 = Get-ResourceGroupName
$appname = Get-WebsiteName
$location = Get-Location
$slotname = "staging"
$planName1 = Get-WebHostPlanName
$planName2 = Get-WebHostPlanName
$planName2 = Get-WebHostPlanName
$planName3 = Get-WebHostPlanName
$tier1 = "Standard"
$tier2 = "Standard"
$tier3 = "Standard"
$apiversion = "2015-08-01"
$resourceType = "Microsoft.Web/sites"
$numberOfWorkers = 2
Expand All @@ -420,8 +423,10 @@ function Test-SetWebAppSlot
{
#Setup
New-AzResourceGroup -Name $rgname -Location $location
New-AzResourceGroup -Name $rgname1 -Location $location
$serverFarm1 = New-AzAppServicePlan -ResourceGroupName $rgname -Name $planName1 -Location $location -Tier $tier1
$serverFarm2 = New-AzAppServicePlan -ResourceGroupName $rgname -Name $planName2 -Location $location -Tier $tier2
$serverFarm3 = New-AzAppServicePlan -ResourceGroupName $rgname1 -Name $planName3 -Location $location -Tier $tier3

# Create new web app
$webApp = New-AzWebApp -ResourceGroupName $rgname -Name $appname -Location $location -AppServicePlan $planName1
Expand Down Expand Up @@ -495,6 +500,45 @@ function Test-SetWebAppSlot
}

Assert-AreEqual $numberOfWorkers $slot.SiteConfig.NumberOfWorkers

#Set-AzWebAppSlot errors on operations for App Services not in the same resource group as the App Service Plan
#setup

$app1 = Get-WebsiteName

# Create new web app
$webApp = New-AzWebApp -ResourceGroupName $rgname1 -Name $app1 -Location $location -AppServicePlan $planName3

# Assert
Assert-AreEqual $app1 $webApp.Name

# Create deployment slot
$slot = New-AzWebAppSlot -ResourceGroupName $rgname1 -Name $app1 -Slot $slotname -AppServicePlan $planName3
$appWithSlotName = "$app1/$slotname"

# Assert
Assert-AreEqual $appWithSlotName $slot.Name
Assert-Null $webApp.Identity
Assert-AreEqual "AllAllowed" $slot.SiteConfig.FtpsState

# Get the deployment slot

$slot = Get-AzWebAppSlot -ResourceGroupName $rgname1 -Name $app1 -Slot $slotName

# Set config properties
$slot.SiteConfig.HttpLoggingEnabled = $true
$slot.SiteConfig.RequestTracingEnabled = $true
$slot.SiteConfig.FtpsState = "FtpsOnly"
$slot.SiteConfig.MinTlsVersion = "1.0"

$slot = $slot | Set-AzWebAppSlot

# Assert
Assert-AreEqual $appWithSlotName $slot.Name
Assert-AreEqual $true $slot.SiteConfig.HttpLoggingEnabled
Assert-AreEqual $true $slot.SiteConfig.RequestTracingEnabled
Assert-AreEqual "FtpsOnly" $slot.SiteConfig.FtpsState
Assert-AreEqual "1.0" $slot.SiteConfig.MinTlsVersion
}
finally
{
Expand All @@ -504,6 +548,7 @@ function Test-SetWebAppSlot
Remove-AzAppServicePlan -ResourceGroupName $rgname -Name $planName1 -Force
Remove-AzAppServicePlan -ResourceGroupName $rgname -Name $planName2 -Force
Remove-AzResourceGroup -Name $rgname -Force
Remove-AzResourceGroup -Name $rgname1 -Force
}
}

Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/Websites/Websites/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
* Fixed bug to get SiteConfig when -Name is not given for Get-AzWebApp
* Added a support to create ASP for Linux Apps
* Added exceptions for clone across resource groups
* Added support to perform operations for Slots not in the same resource group as the App Service Plan
* Added support to use Id for Restore-AzDeletedWebApp.

## Version 1.9.0
* Fixed typo on help of `Update-AzWebAppAccessRestrictionConfig`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace Microsoft.Azure.Commands.WebApps.Cmdlets.WebApps
{
public class PSAzureDeletedWebApp
{
public string Id { get; private set; }
public int DeletedSiteId { get; set; }

public string SubscriptionId { get; set; }
Expand All @@ -35,6 +36,7 @@ public class PSAzureDeletedWebApp

public PSAzureDeletedWebApp(DeletedSite ds, string subscriptionId)
{
Id = ds.Id;
DeletedSiteId = ds.DeletedSiteId.Value;
DeletionTime = DateTime.Parse(ds.DeletedTimestamp, System.Globalization.CultureInfo.InvariantCulture);
SubscriptionId = subscriptionId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public class RestoreAzureDeletedWebApp : WebAppBaseClientCmdLet
[Parameter(ParameterSetName = FromDeletedResourceNameParameterSet, Mandatory = false, HelpMessage = "The location of the deleted Azure Web App.")]
public string Location { get; set; }

[Parameter(ParameterSetName = FromDeletedResourceNameParameterSet, Mandatory = false, HelpMessage = "The Resource ID of the deleted web app.")]
public string DeletedId { get; set; }

[Parameter(Mandatory = false, HelpMessage = "The resource group containing the new Azure Web App.")]
public string TargetResourceGroupName { get; set; }

Expand Down Expand Up @@ -77,7 +80,7 @@ public override void ExecuteCmdlet()
{
base.ExecuteCmdlet();

string deletedSiteId = GetDeletedSiteResourceId();
string deletedSiteId = string.IsNullOrEmpty(DeletedId) ? GetDeletedSiteResourceId() : DeletedId;
ResolveTargetParameters();

DeletedAppRestoreRequest restoreReq = new DeletedAppRestoreRequest()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ public override void ExecuteCmdlet()

CmdletHelpers.TryParseAppServicePlanMetadataFromResourceId(WebApp.ServerFarmId, out rg, out servicePlanName);
WebApp.AzureStoragePath = null; // the API to update site Object doesn't have the AzureStorage Path property
WebsitesClient.UpdateWebApp(ResourceGroupName, location, Name, Slot, servicePlanName, WebApp);
WebsitesClient.UpdateWebApp(ResourceGroupName, location, Name, Slot, servicePlanName, WebApp,rg);
WebsitesClient.AddCustomHostNames(ResourceGroupName, location, Name, WebApp.HostNames.ToArray(), Slot);
break;
}
Expand Down
31 changes: 27 additions & 4 deletions src/Websites/Websites/help/Restore-AzDeletedWebApp.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ Restores a deleted web app to a new or existing web app.
### FromDeletedResourceName (Default)
```
Restore-AzDeletedWebApp [-ResourceGroupName] <String> [-Name] <String> [[-Slot] <String>] [-Location <String>]
[-TargetResourceGroupName <String>] [-TargetName <String>] [-TargetSlot <String>]
[-DeletedId <String>] [-TargetResourceGroupName <String>] [-TargetName <String>] [-TargetSlot <String>]
[-TargetAppServicePlanName <String>] [-RestoreContentOnly] [-UseDisasterRecovery] [-Force] [-AsJob]
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
```

### FromDeletedApp
```
Restore-AzDeletedWebApp [-TargetResourceGroupName <String>] [-TargetName <String>] [-TargetSlot <String>]
[-TargetAppServicePlanName <String>] [-RestoreContentOnly] [-UseDisasterRecovery] [-Force] [-AsJob]
[-DefaultProfile <IAzureContextContainer>] [-InputObject] <PSAzureDeletedWebApp> [-WhatIf] [-Confirm]
Restore-AzDeletedWebApp [-TargetResourceGroupName <String>] [-DeletedId <String>] [-TargetName <String>]
[-TargetSlot <String>] [-TargetAppServicePlanName <String>] [-RestoreContentOnly] [-UseDisasterRecovery]
[-Force] [-AsJob] [-DefaultProfile <IAzureContextContainer>] [-InputObject] <PSAzureDeletedWebApp>
[-WhatIf] [-Confirm]
[<CommonParameters>]
```

Expand All @@ -49,6 +50,13 @@ Restores the Staging slot of a deleted app named ContosoApp belonging to the res

###Example 3
```powershell
PS C:\> Restore-AzDeletedWebApp -ResourceGroupName Default-Web-WestUS -Name ContosoApp -DeletedId /subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Web/locations/location/deletedSites/1234 -TargetAppServicePlanName ContosoPlan
```

In case there are 2 deleted apps with same name(ContosoApp), then we get details of both the sites and restore the app named ContosoRestore with the app of our choice by calling restore with Id.

###Example 4
```powershell
PS C:\> $deletedSite = Get-AzDeletedWebApp -ResourceGroupName Default-Web-WestUS -Name ContosoApp
PS C:\> Restore-AzDeletedWebApp -TargetResourceGroupName Default-Web-EastUS -TargetName ContosoRestore -TargetAppServicePlanName ContosoPlan -InputObject $deletedSite[0]
```
Expand Down Expand Up @@ -87,6 +95,21 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -DeletedId
The Id of the deleted Azure Web App.

```yaml
Type: System.String
Parameter Sets: FromDeletedResourceName
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Force
Do the restore without prompting for confirmation.

Expand Down