Skip to content

Add Graph Audience to environment cmdlets (Issue #1956) [#115822457] #1990

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 1 commit into from
Mar 23, 2016
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 @@ -166,14 +166,21 @@
<Compile Include="Models\MemoryDataStore.cs" />
<Compile Include="Models\XmlProfileSerializer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Resources.Designer.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Utilities\DictionaryExtensions.cs" />
<Compile Include="Utilities\FileUtilities.cs" />
<Compile Include="Utilities\JsonUtilities.cs" />
<Compile Include="Utilities\XmlUtilities.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Properties\Resources.resx" />
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,24 @@ private AdalConfiguration GetAdalConfiguration(AzureEnvironment environment, str
{
throw new ArgumentNullException("environment");
}

var adEndpoint = environment.Endpoints[AzureEnvironment.Endpoint.ActiveDirectory];
if (string.IsNullOrWhiteSpace(adEndpoint))
{
throw new ArgumentOutOfRangeException("environment", string.Format("No Active Directory endpoint specified for environment '{0}'", environment.Name));
}

var audience = environment.Endpoints[resourceId];
if (string.IsNullOrWhiteSpace(audience))
{
string message = Resources.InvalidManagementTokenAudience;
if (resourceId == AzureEnvironment.Endpoint.GraphEndpointResourceId)
{
message = Resources.InvalidGraphTokenAudience;
}

throw new ArgumentOutOfRangeException("environment", string.Format(message, environment.Name));
}

return new AdalConfiguration
{
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 @@ -300,4 +300,10 @@
<data name="UnsupportedCredentialType" xml:space="preserve">
<value>Certificate authentication is not supported for account type {0}.</value>
</data>
<data name="InvalidGraphTokenAudience" xml:space="preserve">
<value>No value was specified for the token audience for the graph endpoint in environment '{0}'. Please use Set-AzureRmEnvironment -Name {0} -GraphAudience token-audience-value</value>
</data>
<data name="InvalidManagementTokenAudience" xml:space="preserve">
<value>No value was specified for the token audience for the management endpoint in environment '{0}'. Please use Set-AzureRmEnvironment -Name {0} -ActiveDirectoryServiceEndpointResourceId token-audience-value</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ public void CanCreateEnvironmentWithAllProperties()
ServiceEndpoint = "ServiceEndpoint",
StorageEndpoint = "StorageEndpoint",
SqlDatabaseDnsSuffix = "SqlDatabaseDnsSuffix",
TrafficManagerDnsSuffix = "TrafficManagerDnsSuffix"
TrafficManagerDnsSuffix = "TrafficManagerDnsSuffix",
GraphAudience = "GaraphAudience"
};

cmdlet.InvokeBeginProcessing();
Expand All @@ -216,6 +217,7 @@ public void CanCreateEnvironmentWithAllProperties()
Assert.Equal(cmdlet.StorageEndpoint, actual.StorageEndpointSuffix);
Assert.Equal(cmdlet.SqlDatabaseDnsSuffix, actual.SqlDatabaseDnsSuffix);
Assert.Equal( cmdlet.TrafficManagerDnsSuffix , actual.TrafficManagerDnsSuffix);
Assert.Equal( cmdlet.GraphAudience , actual.GraphEndpointResourceId);
commandRuntimeMock.Verify(f => f.WriteObject(It.IsAny<PSAzureEnvironment>()), Times.Once());
AzureEnvironment env = AzureRmProfileProvider.Instance.Profile.Environments["KaTaL"];
Assert.Equal(env.Name, cmdlet.Name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,12 @@ public class AddAzureRMEnvironmentCommand : AzureRMCmdlet
HelpMessage = "The default tenant for this environment.")]
public string AdTenant { get; set; }

protected override void BeginProcessing()
[Parameter(Position = 18, Mandatory = false, ValueFromPipelineByPropertyName = true,
HelpMessage = "The audience for tokens authenticating with the AD Graph Endpoint.")]
[Alias("GraphEndpointResourceId", "GraphResourceId")]
public string GraphAudience { get; set; }

protected override void BeginProcessing()
{
// do not call begin processing there is no context needed for this cmdlet
}
Expand Down Expand Up @@ -129,7 +134,8 @@ public override void ExecuteCmdlet()
newEnvironment.Endpoints[AzureEnvironment.Endpoint.AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix] = AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix;
newEnvironment.Endpoints[AzureEnvironment.Endpoint.AzureDataLakeStoreFileSystemEndpointSuffix] = AzureDataLakeStoreFileSystemEndpointSuffix;
newEnvironment.Endpoints[AzureEnvironment.Endpoint.AdTenant] = AdTenant;
WriteObject((PSAzureEnvironment)profileClient.AddOrSetEnvironment(newEnvironment));
newEnvironment.Endpoints[AzureEnvironment.Endpoint.GraphEndpointResourceId] = GraphAudience;
WriteObject((PSAzureEnvironment)profileClient.AddOrSetEnvironment(newEnvironment));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,12 @@ public class SetAzureRMEnvironmentCommand : AzureRMCmdlet
HelpMessage = "The default tenant for this environment.")]
public string AdTenant { get; set; }

protected override void BeginProcessing()
[Parameter(Position = 18, Mandatory = false, ValueFromPipelineByPropertyName = true,
HelpMessage = "The audience for tokens authenticating with the AD Graph Endpoint.")]
[Alias("GraphEndpointResourceId", "GraphResourceId")]
public string GraphAudience { get; set; }

protected override void BeginProcessing()
{
// do not call begin processing there is no context needed for this cmdlet
}
Expand Down Expand Up @@ -139,7 +144,7 @@ public override void ExecuteCmdlet()
SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix, AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix);
SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.AzureDataLakeStoreFileSystemEndpointSuffix, AzureDataLakeStoreFileSystemEndpointSuffix);
SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.AdTenant, AdTenant);

SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.GraphEndpointResourceId, GraphAudience);
profileClient.AddOrSetEnvironment(newEnvironment);

WriteObject((PSAzureEnvironment)newEnvironment);
Expand Down