Skip to content

Fix for New-AzureRmRoleAssignment and Remove-AzureRmRoleAssignment fo… #7228

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 5 commits into from
Sep 13, 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
3 changes: 2 additions & 1 deletion src/StackAdmin/Dns/Commands.Dns/Commands.Dns.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="Models\DnsClient.cs" />
<Compile Include="Models\DoubleFetchHandler.cs" />
<Compile Include="Models\DnsBaseCmdlet.cs" />
<Compile Include="Models\DnsRecordSet.cs" />
<Compile Include="Models\DnsZone.cs" />
Expand Down Expand Up @@ -108,4 +109,4 @@
</ItemGroup>
<Copy SourceFiles="@(MarkdownFiles)" DestinationFolder="$(OutputPath)\help\" ContinueOnError="false" />
</Target>
</Project>
</Project>
24 changes: 19 additions & 5 deletions src/StackAdmin/Dns/Commands.Dns/Models/DnsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using System.Linq;
using ProjectResources = Microsoft.Azure.Commands.Dns.Properties.Resources;
using Sdk = Microsoft.Azure.Management.Dns.Models;
using System.Net.Http;

namespace Microsoft.Azure.Commands.Dns.Models
{
Expand Down Expand Up @@ -51,8 +52,21 @@ public class DnsClient
};

public DnsClient(IAzureContext context)
: this(AzureSession.Instance.ClientFactory.CreateArmClient<DnsManagementClient>(context, AzureEnvironment.Endpoint.ResourceManager))
{
// Factories
var authFactory = AzureSession.Instance.AuthenticationFactory;
var clientFactory = AzureSession.Instance.ClientFactory;

var endpoint = AzureEnvironment.Endpoint.ResourceManager;

// Get parameters
var handler = new DelegatingHandler[] { new DoubleFetchHandler() };
var creds = authFactory.GetServiceClientCredentials(context, endpoint);
var baseUri = context.Environment.GetEndpointAsUri(endpoint);

// Construct client
this.DnsManagementClient = clientFactory.CreateCustomArmClient<DnsManagementClient>(baseUri, creds, handler);
this.DnsManagementClient.SubscriptionId = context.Subscription.Id.ToString();
}

public DnsClient(IDnsManagementClient managementClient)
Expand Down Expand Up @@ -127,9 +141,9 @@ public List<DnsZone> ListDnsZonesInResourceGroup(string resourceGroupName)
}
else
{
getResponse = this.DnsManagementClient.Zones.ListInResourceGroup(resourceGroupName);
getResponse = this.DnsManagementClient.Zones.ListInResourceGroup(resourceGroupName);
}

results.AddRange(getResponse.Select(ToDnsZone));
} while (getResponse != null && getResponse.NextPageLink != null);

Expand Down Expand Up @@ -204,7 +218,7 @@ private RecordSet ConstructRecordSetPropeties(string recordSetName, RecordType r
}
else
{
FillEmptyRecordsForType( properties, recordType);
FillEmptyRecordsForType( properties, recordType);
}
return properties;
}
Expand Down Expand Up @@ -354,7 +368,7 @@ public List<DnsRecordSet> ListRecordSets(string zoneName, string resourceGroupNa
}

results.AddRange(listResponse.Select(recordSet => GetPowerShellRecordSet(zoneName, resourceGroupName, recordSet)));

} while (listResponse != null && listResponse.NextPageLink != null);

return results;
Expand Down
43 changes: 43 additions & 0 deletions src/StackAdmin/Dns/Commands.Dns/Models/DoubleFetchHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// ----------------------------------------------------------------------------------
//
// 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;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;

namespace Microsoft.Azure.Commands.Dns.Models
{
public class DoubleFetchHandler : DelegatingHandler, ICloneable
{
public object Clone() {
return new DoubleFetchHandler();
}

protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) {

return base.SendAsync(request, cancellationToken).ContinueWith<HttpResponseMessage>(response =>
{
var result = response.Result;
if (result.Headers.Contains("Location") && result.Headers.Contains("Azure-AsyncOperation"))
{
result.Headers.Remove("Location");
}

return result;
});
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,25 @@ public List<PSRoleDefinition> FilterRoleDefinitionsByCustom(string scope, bool s
public PSRoleAssignment CreateRoleAssignment(FilterRoleAssignmentsOptions parameters)
{
Guid principalId = ActiveDirectoryClient.GetObjectId(parameters.ADObjectFilter);
string principalIdStr = null;

if (principalId == Guid.Empty)
{
principalIdStr = ActiveDirectoryClient.GetAdfsObjectId(parameters.ADObjectFilter);
}
else
{
principalIdStr = principalId.ToString();
}

Guid roleAssignmentId = RoleAssignmentNames.Count == 0 ? Guid.NewGuid() : RoleAssignmentNames.Dequeue();
string scope = parameters.Scope;
string roleDefinitionId = !string.IsNullOrEmpty(parameters.RoleDefinitionName)
? AuthorizationHelper.ConstructFullyQualifiedRoleDefinitionIdFromScopeAndIdAsGuid(scope, GetSingleRoleDefinitionByName(parameters.RoleDefinitionName, scope).Id)
: AuthorizationHelper.ConstructFullyQualifiedRoleDefinitionIdFromScopeAndIdAsGuid(scope, parameters.RoleDefinitionId);
var createProperties = new RoleAssignmentProperties
{
PrincipalId = principalId.ToString(),
PrincipalId = principalIdStr,
RoleDefinitionId = roleDefinitionId
};
var createParameters = new RoleAssignmentCreateParameters(createProperties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public override void ExecuteCmdlet()
ADObjectFilter = new ADObjectFilterOptions
{
UPN = SignInName,
Id = ObjectId.ToString(),
Id = ObjectId,
SPN = ServicePrincipalName
},
ResourceIdentifier = new ResourceIdentifier()
Expand Down
2 changes: 1 addition & 1 deletion tools/CleanupBuild.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ foreach($RMPath in $resourceManagerPaths)
$removedScripts = Get-ChildItem -Path "$($RMFolder.FullName)\StartupScripts" -Filter "*.ps1" | where { $_.FullName -ne $scriptName }
$removedScripts | % { Write-Verbose "Removing $($_.FullName)"; Remove-Item $_.FullName -Force }
}
$removedPsd1 = Get-ChildItem -Path "$($RMFolder.FullName)" -Filter "*.psd1" -Recurse | where { $_.FullName -ne "$($RMFolder.FullName)$([IO.Path]::DirectorySeparatorChar)$($RMFolder.Name).psd1" }
$removedPsd1 = Get-ChildItem -Path "$($RMFolder.FullName)" -Filter "*.psd1" | where { $_.FullName -ne "$($RMFolder.FullName)$([IO.Path]::DirectorySeparatorChar)$($RMFolder.Name).psd1" }
$removedPsd1 | % { Write-Verbose "Removing $($_.FullName)"; Remove-Item $_.FullName -Force }
}
}
14 changes: 3 additions & 11 deletions tools/Modules/Run-UnitTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,9 @@ if ($Scope -in $AzureScopes) {

if ($Scope -in $StackScopes) {

# Download and add AzureRM.Profile 3.4.1 to PSModulePath
[System.String]$SavePath = (Join-Path -Path $PSScriptRoot -ChildPath "tmp")
if (-not(Test-Path $SavePath)) {
New-Item -Path $SavePath -ItemType Directory -Force | Out-Null
Save-Module -Name AzureRM.Profile -RequiredVersion 3.4.1 -Repository PSGallery -Path $SavePath | Out-Null
Save-Module -Name AzureRM.Resources -RequiredVersion 4.4.1 -Repository PSGallery -Path $SavePath | Out-Null
}

$oldModulePath = $env:PSModulePath.Clone()
[Environment]::SetEnvironmentVariable("PSModulePath","$env:PSModulePath;$SavePath")
$ARMRoot = "$PSScriptRoot\..\..\src\Stack\$BuildConfig\ResourceManager\AzureResourceManager"
Import-Module "$ARMRoot\AzureRM.Profile\AzureRM.Profile.psd1"
Import-Module "$ARMRoot\AzureRM.Resources\AzureRM.Resources.psd1";

# All admin modules
$AllStackModules = @(
Expand All @@ -151,6 +144,5 @@ if ($Scope -in $StackScopes) {
[System.String[]]$ModulesToTest = $AllStackModules | Where-Object { !($_ -in $IgnoredStackModules) }
Test-Stack -BuildConfig $BuildConfig -Modules $ModulesToTest

[Environment]::SetEnvironmentVariable("PSModulePath",$oldModulePath)
}