Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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 @@ -41,5 +41,19 @@ public void TestNewSubscription()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-NewSubscription");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestUpdateRenameSubscription()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-UpdateRenameSubscription");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestUpdateCancelSubscription()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-UpdateCancelSubscription");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,21 @@ function Test-NewSubscription
Assert-AreEqual $myNewSubName $newSub.Name
Assert-NotNull $newSub.SubscriptionId
}

function Test-UpdateRenameSubscription
{
$subId = "21cba39d-cbbc-487f-9749-43c5c960f269"

$updateSub = Update-AzSubscription -SubscriptionId $subId -Action "Rename" -Name "RenameFromPowershell"

Assert-NotNull updateSub.SubscriptionId
}

function Test-UpdateCancelSubscription
{
$subId = "21cba39d-cbbc-487f-9749-43c5c960f269"

$updateSub = Update-AzSubscription -SubscriptionId $subId -Action "Cancel"

Assert-NotNull updateSub.SubscriptionId
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
"Entries": [
{
"RequestUri": "/subscriptions/21cba39d-cbbc-487f-9749-43c5c960f269/providers/Microsoft.Subscription/cancel?api-version=2019-10-01-preview",
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvMjFjYmEzOWQtY2JiYy00ODdmLTk3NDktNDNjNWM5NjBmMjY5L3Byb3ZpZGVycy9NaWNyb3NvZnQuU3Vic2NyaXB0aW9uL2NhbmNlbD9hcGktdmVyc2lvbj0yMDE5LTEwLTAxLXByZXZpZXc=",
"RequestMethod": "POST",
"RequestBody": "",
"RequestHeaders": {
"x-ms-client-request-id": [
"2dfb692e-f389-4264-ae26-bb79e7c64574"
],
"Accept-Language": [
"en-US"
],
"User-Agent": [
"FxVersion/4.6.27817.03",
"OSName/Windows",
"OSVersion/Microsoft.Windows.10.0.18363.",
"Microsoft.Azure.Management.Subscription.SubscriptionClient/1.1.4.0"
]
},
"ResponseHeaders": {
"Cache-Control": [
"no-cache"
],
"Pragma": [
"no-cache"
],
"Vary": [
"Accept-Encoding"
],
"x-ms-ratelimit-remaining-subscription-writes": [
"1199"
],
"x-ms-correlation-request-id": [
"0b8fdd49-96e1-424b-a0d1-725451e072bc"
],
"request-id": [
"0b8fdd49-96e1-424b-a0d1-725451e072bc"
],
"x-gsm": [
"1.0.0.0"
],
"X-Content-Type-Options": [
"nosniff"
],
"Server": [
"Microsoft-IIS/10.0"
],
"X-AspNet-Version": [
"4.0.30319"
],
"X-Powered-By": [
"ASP.NET"
],
"x-ms-request-id": [
"0b8fdd49-96e1-424b-a0d1-725451e072bc"
],
"x-ms-routing-request-id": [
"WESTUS:20200619T225218Z:0b8fdd49-96e1-424b-a0d1-725451e072bc"
],
"Strict-Transport-Security": [
"max-age=31536000; includeSubDomains"
],
"Date": [
"Fri, 19 Jun 2020 22:52:17 GMT"
],
"Content-Length": [
"57"
],
"Content-Type": [
"application/json; charset=utf-8"
],
"Expires": [
"-1"
]
},
"ResponseBody": "{\r\n \"subscriptionId\": \"21cba39d-cbbc-487f-9749-43c5c960f269\"\r\n}",
"StatusCode": 200
}
],
"Names": {},
"Variables": {
"SubscriptionId": "21cba39d-cbbc-487f-9749-43c5c960f269"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
{
"Entries": [
{
"RequestUri": "/subscriptions/21cba39d-cbbc-487f-9749-43c5c960f269/providers/Microsoft.Subscription/rename?api-version=2019-10-01-preview",
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvMjFjYmEzOWQtY2JiYy00ODdmLTk3NDktNDNjNWM5NjBmMjY5L3Byb3ZpZGVycy9NaWNyb3NvZnQuU3Vic2NyaXB0aW9uL3JlbmFtZT9hcGktdmVyc2lvbj0yMDE5LTEwLTAxLXByZXZpZXc=",
"RequestMethod": "POST",
"RequestBody": "{\r\n \"subscriptionName\": \"RenameFromPowershell\"\r\n}",
"RequestHeaders": {
"x-ms-client-request-id": [
"07b39a23-6005-465f-adf2-c088d0ab601d"
],
"Accept-Language": [
"en-US"
],
"User-Agent": [
"FxVersion/4.6.27817.03",
"OSName/Windows",
"OSVersion/Microsoft.Windows.10.0.18363.",
"Microsoft.Azure.Management.Subscription.SubscriptionClient/1.1.4.0"
],
"Content-Type": [
"application/json; charset=utf-8"
],
"Content-Length": [
"50"
]
},
"ResponseHeaders": {
"Cache-Control": [
"no-cache"
],
"Pragma": [
"no-cache"
],
"Vary": [
"Accept-Encoding"
],
"x-ms-ratelimit-remaining-subscription-writes": [
"1199"
],
"x-ms-correlation-request-id": [
"aa0d95c5-3b21-4ee4-97d0-91fb5a735293"
],
"request-id": [
"aa0d95c5-3b21-4ee4-97d0-91fb5a735293"
],
"x-gsm": [
"1.0.0.0"
],
"X-Content-Type-Options": [
"nosniff"
],
"Server": [
"Microsoft-IIS/10.0"
],
"X-AspNet-Version": [
"4.0.30319"
],
"X-Powered-By": [
"ASP.NET"
],
"x-ms-request-id": [
"aa0d95c5-3b21-4ee4-97d0-91fb5a735293"
],
"x-ms-routing-request-id": [
"WESTUS:20200619T224730Z:aa0d95c5-3b21-4ee4-97d0-91fb5a735293"
],
"Strict-Transport-Security": [
"max-age=31536000; includeSubDomains"
],
"Date": [
"Fri, 19 Jun 2020 22:47:29 GMT"
],
"Content-Length": [
"57"
],
"Content-Type": [
"application/json; charset=utf-8"
],
"Expires": [
"-1"
]
},
"ResponseBody": "{\r\n \"subscriptionId\": \"21cba39d-cbbc-487f-9749-43c5c960f269\"\r\n}",
"StatusCode": 200
}
],
"Names": {},
"Variables": {
"SubscriptionId": "21cba39d-cbbc-487f-9749-43c5c960f269"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.Subscription" Version="1.1.1-preview" />
<PackageReference Include="Microsoft.Azure.Management.Subscription" Version="1.1.4-preview" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/Subscription/Subscription/Az.Subscription.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ NestedModules = @('Microsoft.Azure.PowerShell.Cmdlets.Subscription.dll')
FunctionsToExport = @()

# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
CmdletsToExport = 'New-AzSubscription'
CmdletsToExport = 'New-AzSubscription','Update-AzSubscription'

# Variables to export from this module
# VariablesToExport = @()
Expand Down
19 changes: 12 additions & 7 deletions src/Subscription/Subscription/Cmdlets/NewAzureRmSubscription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,20 @@ public override void ExecuteCmdlet()
{
if (this.ShouldProcess(target: this.Name, action: "Create subscription"))
{
var owners = this.ResolveObjectIds(this.OwnerObjectId, this.OwnerApplicationId, this.OwnerSignInName).Select(id => new AdPrincipal() { ObjectId = id }).ToArray();
SubscriptionCreationResult result = new SubscriptionCreationResult();

var owners = this
.ResolveObjectIds(this.OwnerObjectId, this.OwnerApplicationId, this.OwnerSignInName)
.Select(id => new AdPrincipal() { ObjectId = id }).ToArray();

// Create the subscription.
var result = this.SubscriptionClient.SubscriptionFactory.CreateSubscriptionInEnrollmentAccount(EnrollmentAccountObjectId, new SubscriptionCreationParameters()
{
DisplayName = this.Name,
OfferType = this.OfferType,
Owners = owners
});
result = this.SubscriptionClient.Subscription.CreateSubscriptionInEnrollmentAccount(
EnrollmentAccountObjectId, new SubscriptionCreationParameters()
{
DisplayName = this.Name,
OfferType = this.OfferType,
Owners = owners
});

// Write output.
var createdSubscription = new AzureSubscription()
Expand Down
84 changes: 84 additions & 0 deletions src/Subscription/Subscription/Cmdlets/UpdateAzureRmSubscription.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using System.Management.Automation;
using Microsoft.Azure.Commands.Common.Authentication;
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
using Microsoft.Azure.Commands.ResourceManager.Common;
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using Microsoft.Azure.Commands.Subscription.Models;
using Microsoft.Azure.Management.Subscription;
using Microsoft.Azure.Management.Subscription.Models;

namespace Microsoft.Azure.Commands.Subscription.Cmdlets
{
[Cmdlet("Update", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "Subscription", SupportsShouldProcess =
true), OutputType(typeof(PSAzureSubscription))]
public class UpdateAzureRmSubscription : AzureRmLongRunningCmdlet
{
private ISubscriptionClient _subscriptionClient;

/// <summary>
/// Gets or sets the subscription client.
/// </summary>
public ISubscriptionClient SubscriptionClient
{
get
{
return _subscriptionClient ??
(_subscriptionClient =
AzureSession.Instance.ClientFactory.CreateArmClient<SubscriptionClient>(DefaultContext,
AzureEnvironment.Endpoint.ResourceManager));
}
set { _subscriptionClient = value; }
}

[Parameter(Mandatory = true, HelpMessage = "Subscription Id to update")]
public string SubscriptionId { get; set; }

[Parameter(Mandatory = true, HelpMessage = "Action to perform on subscription")]
[PSArgumentCompleter("Cancel", "Enable", "Rename")]
public string Action { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Name of the subscription")]
public string Name { get; set; }

public override void ExecuteCmdlet()
{
if (this.ShouldProcess(target: this.SubscriptionId, action: "Update subscription"))
{
// Updates the subscription.

if (Action == "Cancel")
{
var result = this.SubscriptionClient.Subscription.Cancel(SubscriptionId);
WriteObject(result);
}
else if (Action == "Enable")
{
var result = this.SubscriptionClient.Subscription.Enable(SubscriptionId);
WriteObject(result);
}
else
{
var result = this.SubscriptionClient.Subscription.Rename(SubscriptionId, new SubscriptionName()
{
SubscriptionNameProperty = Name
});
WriteObject(result);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,14 @@
ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
}

Register-ArgumentCompleter -CommandName Update-AzSubscription -ParameterName Action -ScriptBlock {
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)

$values = "Cancel", "Rename", "Enable"
$values |
ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
}
2 changes: 1 addition & 1 deletion src/Subscription/Subscription/Subscription.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.Subscription" Version="1.1.1-preview" />
<PackageReference Include="Microsoft.Azure.Management.Subscription" Version="1.1.4-preview" />
</ItemGroup>

</Project>
5 changes: 4 additions & 1 deletion src/Subscription/Subscription/help/Az.Subscription.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
---
Module Name: Az.Subscription
Module Guid: 8074e741-0979-4b4e-8f9b-7243f213d98a
Download Help Link: https://docs.microsoft.com/en-us/powershell/module/az.subscription
Expand All @@ -14,3 +14,6 @@ The topics in this section document the Azure PowerShell cmdlets for Azure Subsc
### [New-AzSubscription](New-AzSubscription.md)
Creates an Azure subscription.

### [Update-AzSubscription](Update-AzSubscription.md)
Updates the Azure subscription

Loading