Skip to content

[Subscription RP] New-AzureRmSubscription #5803

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 19 commits into from
Apr 11, 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 @@ -689,6 +689,18 @@ public void RemoveAllSpCredentials(string spObjectId)
PatchSpPasswordCredentials(spObjectId, passwordCredentials: null);
}

public string GetObjectIdFromUPN(string upn)
{
var odataQueryFilter = new Rest.Azure.OData.ODataQuery<User>(s => s.UserPrincipalName == upn);
var user = GraphClient.Users.List(odataQueryFilter.ToString()).SingleOrDefault();
if (user == null)
{
throw new InvalidOperationException(String.Format(ProjectResources.UserWithUPNDoesntExist, upn));
}

return user.ObjectId;
}

public string GetObjectIdFromSPN(string spn)
{
var odataQueryFilter = new Rest.Azure.OData.ODataQuery<ServicePrincipal>(s => s.ServicePrincipalNames.Contains(spn));
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,7 @@
<data name="ServicePrincipalWithSPNDoesntExist" xml:space="preserve">
<value>Service principal with SPN '{0}' does not exist.</value>
</data>
<data name="UserWithUPNDoesntExist" xml:space="preserve">
<value>User with UPN '{0}' does not exist.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ NestedModules = @('.\Microsoft.Azure.Commands.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 = 'Get-AzureRmSubscriptionDefinition',
'New-AzureRmSubscriptionDefinition'
CmdletsToExport = 'New-AzureRmSubscription'

# Variables to export from this module
# VariablesToExport = @()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ NestedModules = @('.\Microsoft.Azure.Commands.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 = 'Get-AzureRmSubscriptionDefinition',
'New-AzureRmSubscriptionDefinition'
CmdletsToExport = 'New-AzureRmSubscription'

# Variables to export from this module
# VariablesToExport = @()
Expand All @@ -96,7 +95,7 @@ PrivateData = @{
PSData = @{

# Tags applied to this module. These help with module discovery in online galleries.
Tags = 'Azure','ARM','Subscription','SubscriptionDefinition'
Tags = 'Azure','ARM','Subscription'

# A URL to the license for this module.
LicenseUri = 'https://aka.ms/azps-license'
Expand Down
3 changes: 1 addition & 2 deletions src/ResourceManager/Subscription/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
- Additional information about change #1
-->
## Current Release

## Version 0.1.2
* New cmdlet New-AzureRmSubscription to enable subscription creation under a specific EA enrollment account.
* Updated to the latest version of the Azure ClientRuntime

## Version 0.1.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
</Reference>
<Reference Include="Microsoft.Azure.Management.Subscription, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Subscription.1.0.0-preview\lib\net452\Microsoft.Azure.Management.Subscription.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Subscription.1.1.0-preview\lib\net452\Microsoft.Azure.Management.Subscription.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.ResourceManager, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
Expand Down Expand Up @@ -132,22 +132,16 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ScenarioTests\SubscriptionDefinitionTests.cs" />
<Compile Include="ScenarioTests\SubscriptionTests.cs" />
<Compile Include="ScenarioTests\TestController.cs" />
</ItemGroup>
<ItemGroup>
<None Include="MSSharedLibKey.snk" />
<None Include="packages.config" />
<None Include="ScenarioTests\SubscriptionDefinitionTests.ps1">
<None Include="ScenarioTests\SubscriptionTests.ps1">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Subscription.Test.ScenarioTests.SubscriptionDefinitionTests\TestGetSubscriptionDefinitionByName.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Subscription.Test.ScenarioTests.SubscriptionDefinitionTests\TestListSubscriptionDefinitions.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Subscription.Test.ScenarioTests.SubscriptionDefinitionTests\TestNewSubscriptionDefinition.json">
<None Include="SessionRecords\Subscription.Test.ScenarioTests.SubscriptionTests\TestNewSubscription.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@
namespace Subscription.Test.ScenarioTests
{
/// <summary>
/// The following tests require four subscription definitions to be created manually at this time. This can
/// be done by calling New-AzureRmSubscriptionDefinition. At this time, this can only be done when your tenant is
/// whitelisted by Microsoft.
/// The following tests require four subscriptions to be created manually. This can be done by
/// calling New-AzureRmSubscription. At this time, this can only be done by EA customers.
/// </summary>
public class SubscriptionDefinitionTests
public class SubscriptionTests
{
private XunitTracingInterceptor _logger;

public SubscriptionDefinitionTests(Xunit.Abstractions.ITestOutputHelper output)
public SubscriptionTests(Xunit.Abstractions.ITestOutputHelper output)
{
_logger = new XunitTracingInterceptor(output);
XunitTracingInterceptor.AddToContext(_logger);
Expand All @@ -38,22 +37,9 @@ public SubscriptionDefinitionTests(Xunit.Abstractions.ITestOutputHelper output)

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

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestGetSubscriptionDefinitionByName()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-GetSubscriptionDefinitionByName");
}
[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestNewSubscriptionDefinition()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-NewSubscriptionDefinition");
TestController.NewInstance.RunPowerShellTest(_logger, "Test-NewSubscription");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# ----------------------------------------------------------------------------------
#
# 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.
# ----------------------------------------------------------------------------------

<#
.SYNOPSIS
Create subscription
#>
function Test-NewSubscription
{
# $accounts = Get-AzureRmEnrollmentAccount
$accounts = @(@{ ObjectId = "cdf813b6-bdc2-4df5-b150-00ccfd7580e2" })

# Verify the caller has at least one enrollment account.
Assert-True { $accounts.Count -gt 0 }

$myNewSubName = GetAssetName

$newSub = New-AzureRmSubscription -EnrollmentAccountObjectId $accounts[0].ObjectId -Name $myNewSubName -OfferType MS-AZR-0017P

Assert-AreEqual $myNewSubName $newSub.Name
Assert-NotNull $newSub.SubscriptionId
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
using Microsoft.Azure.Gallery;
using Microsoft.Azure.Management.Authorization;
using Microsoft.Azure.Management.Resources;
using Microsoft.Azure.Subscriptions;
using Microsoft.Azure.Test;
using Microsoft.Azure.Test.HttpRecorder;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
Expand All @@ -26,7 +25,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using SubscriptionDefinitionClient = Microsoft.Azure.Management.Subscription.SubscriptionDefinitionsClient;
using TestBase = Microsoft.Azure.Test.TestBase;
using TestEnvironmentFactory = Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestEnvironmentFactory;
using TestUtilities = Microsoft.Azure.Test.TestUtilities;
Expand All @@ -41,14 +39,14 @@ public class TestController : RMTestBase

public ResourceManagementClient ResourceManagementClient { get; private set; }

public SubscriptionClient SubscriptionClient { get; private set; }
public Microsoft.Azure.Subscriptions.SubscriptionClient OldSubscriptionClient { get; private set; }

public Microsoft.Azure.Management.Subscription.SubscriptionClient SubscriptionClient { get; private set; }

public GalleryClient GalleryClient { get; private set; }

public AuthorizationManagementClient AuthorizationManagementClient { get; private set; }

public SubscriptionDefinitionClient SubscriptionDefinitionClient { get; private set; }


public static TestController NewInstance
{
get
Expand All @@ -65,17 +63,17 @@ protected TestController()
protected void SetupManagementClients(MockContext context)
{
ResourceManagementClient = GetResourceManagementClient();
SubscriptionClient = GetSubscriptionClient();
OldSubscriptionClient = GetOldSubscriptionClient();
SubscriptionClient = GetSubscriptionClient(context);
GalleryClient = GetGalleryClient();
AuthorizationManagementClient = GetAuthorizationManagementClient();
SubscriptionDefinitionClient = GetSubscriptionDefinitionManagementClient(context);


_helper.SetupManagementClients(
ResourceManagementClient,
OldSubscriptionClient,
SubscriptionClient,
GalleryClient,
AuthorizationManagementClient,
SubscriptionDefinitionClient);
AuthorizationManagementClient);
}

public void RunPowerShellTest(ServiceManagemenet.Common.Models.XunitTracingInterceptor logger, params string[] scripts)
Expand Down Expand Up @@ -166,19 +164,19 @@ private AuthorizationManagementClient GetAuthorizationManagementClient()
return TestBase.GetServiceClient<AuthorizationManagementClient>(_csmTestFactory);
}

private SubscriptionClient GetSubscriptionClient()
private Microsoft.Azure.Subscriptions.SubscriptionClient GetOldSubscriptionClient()
{
return TestBase.GetServiceClient<SubscriptionClient>(_csmTestFactory);
return TestBase.GetServiceClient<Microsoft.Azure.Subscriptions.SubscriptionClient>(_csmTestFactory);
}

private GalleryClient GetGalleryClient()
private Microsoft.Azure.Management.Subscription.SubscriptionClient GetSubscriptionClient(MockContext context)
{
return TestBase.GetServiceClient<GalleryClient>(_csmTestFactory);
return context.GetServiceClient<Microsoft.Azure.Management.Subscription.SubscriptionClient>(TestEnvironmentFactory.GetTestEnvironment());
}

private SubscriptionDefinitionClient GetSubscriptionDefinitionManagementClient(MockContext context)
private GalleryClient GetGalleryClient()
{
return context.GetServiceClient<SubscriptionDefinitionClient>(TestEnvironmentFactory.GetTestEnvironment());
return TestBase.GetServiceClient<GalleryClient>(_csmTestFactory);
}
}
}
Loading