Skip to content
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
12 changes: 10 additions & 2 deletions src/Accounts/Accounts.Test/EnvironmentCmdletTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
using Microsoft.Azure.Commands.Common.Authentication.Models;
using Microsoft.Azure.Commands.Common.Authentication.ResourceManager;
using Microsoft.Azure.Commands.Profile;
using Microsoft.Azure.Commands.Profile.Models;
using Microsoft.Azure.Commands.Profile.Utilities;
using Microsoft.Azure.Commands.ResourceManager.Common;
Expand Down Expand Up @@ -61,7 +60,7 @@ public void AddsAzureEnvironment()
var cmdlet = new AddAzureRMEnvironmentCommand()
{
CommandRuntime = commandRuntimeMock.Object,
Name = "Katal",
Name = "Katal"
};
var dict =new Dictionary<string, object>
{
Expand All @@ -74,6 +73,7 @@ public void AddsAzureEnvironment()
};

cmdlet.SetBoundParameters(dict);
cmdlet.SetParameterSet("Name");
cmdlet.InvokeBeginProcessing();
cmdlet.ExecuteCmdlet();
cmdlet.InvokeEndProcessing();
Expand Down Expand Up @@ -189,6 +189,7 @@ public void AddsEnvironmentMultipleTimes()
dict["PublishSettingsFileUrl"] = "http://microsoft.com";
dict["EnableAdfsAuthentication"] = true;
cmdlet.SetBoundParameters(dict);
cmdlet.SetParameterSet("Name");

cmdlet.InvokeBeginProcessing();
cmdlet.ExecuteCmdlet();
Expand All @@ -211,6 +212,7 @@ public void AddsEnvironmentMultipleTimes()
dict.Clear();
dict["EnableAdfsAuthentication"] = true;
cmdlet2.SetBoundParameters(dict);
cmdlet2.SetParameterSet("Name");

cmdlet2.InvokeBeginProcessing();
cmdlet2.ExecuteCmdlet();
Expand All @@ -229,6 +231,7 @@ public void AddsEnvironmentMultipleTimes()
};
dict.Clear();
cmdlet3.SetBoundParameters(dict);
cmdlet3.SetParameterSet("Name");

cmdlet3.InvokeBeginProcessing();
cmdlet3.ExecuteCmdlet();
Expand Down Expand Up @@ -257,6 +260,7 @@ public void AddsEnvironmentWithMinimumInformation()
dict["EnableAdfsAuthentication"] = true;
dict["PublishSettingsFileUrl"] = "http://microsoft.com";
cmdlet.SetBoundParameters(dict);
cmdlet.SetParameterSet("Name");
cmdlet.InvokeBeginProcessing();
cmdlet.ExecuteCmdlet();
cmdlet.InvokeEndProcessing();
Expand Down Expand Up @@ -337,6 +341,7 @@ public void AddsEnvironmentWithStorageEndpoint()
StorageEndpoint = "core.windows.net",
};

cmdlet.SetParameterSet("Name");
cmdlet.InvokeBeginProcessing();
cmdlet.ExecuteCmdlet();
cmdlet.InvokeEndProcessing();
Expand Down Expand Up @@ -412,6 +417,7 @@ public void CanCreateEnvironmentWithAllProperties()
dict["AzureSynapseAnalyticsEndpointResourceId"] = "AzureSynapseAnalyticsEndpointResourceId";
dict["AzureSynapseAnalyticsEndpointSuffix"] = "https://AzureSynapseAnalytics";
cmdlet.SetBoundParameters(dict);
cmdlet.SetParameterSet("Name");

cmdlet.InvokeBeginProcessing();
cmdlet.ExecuteCmdlet();
Expand Down Expand Up @@ -487,6 +493,8 @@ public void CreateEnvironmentWithTrailingSlashInActiveDirectory()
var dict = new Dictionary<string, object>();
dict["ActiveDirectoryEndpoint"] = "https://ActiveDirectoryEndpoint/";
cmdlet.SetBoundParameters(dict);
cmdlet.SetParameterSet("Name");

SetupConfirmation(commandRuntimeMock);
cmdlet.InvokeBeginProcessing();
cmdlet.ExecuteCmdlet();
Expand Down
8 changes: 8 additions & 0 deletions src/Accounts/Accounts/Accounts.generated.format.ps1xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
<Alignment>Left</Alignment>
<Label>ActiveDirectory Authority</Label>
</TableColumnHeader>
<TableColumnHeader>
<Alignment>Left</Alignment>
<Label>Type</Label>
</TableColumnHeader>
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
Expand All @@ -36,6 +40,10 @@
<Alignment>Left</Alignment>
<PropertyName>ActiveDirectoryAuthority</PropertyName>
</TableColumnItem>
<TableColumnItem>
<Alignment>Left</Alignment>
<PropertyName>Type</PropertyName>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
Expand Down
3 changes: 2 additions & 1 deletion src/Accounts/Accounts/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
- Additional information about change #1
-->
## Upcoming Release
* Update preloaded assemblies [#12024,#11976]
* Supported discovering environment setting by default and adding environment via `Add-AzEnvironment`
* Update preloaded assemblies [#12024], [#11976]
* Updated Azure.Core assembly
* Fixed an issue that may cause `Connect-AzAccount` to fail in multi-threaded execution [#11201]

Expand Down
81 changes: 64 additions & 17 deletions src/Accounts/Accounts/Environment/AddAzureRMEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,9 @@
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
using Microsoft.Azure.Commands.Common.Authentication.Models;
using Microsoft.Azure.Commands.Profile.Common;
using Microsoft.Azure.Commands.Profile.Models;
using Microsoft.Azure.Commands.Profile.Utilities;
using Microsoft.Azure.Commands.ResourceManager.Common;
using Microsoft.WindowsAzure.Commands.Common;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using System;
using System.Globalization;
Expand All @@ -41,14 +38,16 @@ public class AddAzureRMEnvironmentCommand : AzureContextModificationCmdlet

private const string MetadataParameterSet = "ARMEndpoint";
private const string EnvironmentPropertiesParameterSet = "Name";
private const string DiscoveryParameterSet = "Discovery";

public EnvironmentHelper EnvHelper
{
get { return this.envHelper; }
set { this.envHelper = value != null ? value : new EnvironmentHelper(); }
}

[Parameter(Position = 0, Mandatory = true, ValueFromPipelineByPropertyName = true)]
[Parameter(ParameterSetName = EnvironmentPropertiesParameterSet, Position = 0, Mandatory = true, ValueFromPipelineByPropertyName = true)]
[Parameter(ParameterSetName = MetadataParameterSet, Position = 0, Mandatory = true, ValueFromPipelineByPropertyName = true)]
public string Name { get; set; }

[Parameter(ParameterSetName = EnvironmentPropertiesParameterSet, Position = 1, Mandatory = false, ValueFromPipelineByPropertyName = true)]
Expand Down Expand Up @@ -131,7 +130,9 @@ public EnvironmentHelper EnvHelper
[Alias("GraphEndpointResourceId", "GraphResourceId")]
public string GraphAudience { get; set; }

[Parameter(Position = 19, Mandatory = false, ValueFromPipelineByPropertyName = true,
[Parameter(ParameterSetName = EnvironmentPropertiesParameterSet, Position = 19, Mandatory = false, ValueFromPipelineByPropertyName = true,
HelpMessage = "The audience for tokens authenticating with the AD Data Lake services Endpoint.")]
[Parameter(ParameterSetName = MetadataParameterSet, Position = 19, Mandatory = false, ValueFromPipelineByPropertyName = true,
HelpMessage = "The audience for tokens authenticating with the AD Data Lake services Endpoint.")]
[Alias("DataLakeEndpointResourceId", "DataLakeResourceId")]
public string DataLakeAudience
Expand All @@ -146,43 +147,70 @@ public string DataLakeAudience
}
}

[Parameter(Position = 20, Mandatory = false, ValueFromPipelineByPropertyName = true,
[Parameter(ParameterSetName = EnvironmentPropertiesParameterSet, Position = 20, Mandatory = false, ValueFromPipelineByPropertyName = true,
HelpMessage = "The resource identifier of the Azure Batch service that is the recipient of the requested token.")]
[Parameter(ParameterSetName = MetadataParameterSet, Position = 20, Mandatory = false, ValueFromPipelineByPropertyName = true,
HelpMessage = "The resource identifier of the Azure Batch service that is the recipient of the requested token.")]
[Alias("BatchResourceId", "BatchAudience")]
public string BatchEndpointResourceId { get; set; }

[Parameter(Position = 21, Mandatory = false, ValueFromPipelineByPropertyName = true,
[Parameter(ParameterSetName = EnvironmentPropertiesParameterSet, Position = 21, Mandatory = false, ValueFromPipelineByPropertyName = true,
HelpMessage = "The audience for tokens authenticating with the Azure Log Analytics API.")]
[Parameter(ParameterSetName = MetadataParameterSet, Position = 21, Mandatory = false, ValueFromPipelineByPropertyName = true,
HelpMessage = "The audience for tokens authenticating with the Azure Log Analytics API.")]
public string AzureOperationalInsightsEndpointResourceId { get; set; }

[Parameter(Position = 22, Mandatory = false, ValueFromPipelineByPropertyName = true,
[Parameter(ParameterSetName = EnvironmentPropertiesParameterSet, Position = 22, Mandatory = false, ValueFromPipelineByPropertyName = true,
HelpMessage = "The endpoint to use when communicating with the Azure Log Analytics API.")]
[Parameter(ParameterSetName = MetadataParameterSet, Position = 22, Mandatory = false, ValueFromPipelineByPropertyName = true,
HelpMessage = "The endpoint to use when communicating with the Azure Log Analytics API.")]
public string AzureOperationalInsightsEndpoint { get; set; }

[Parameter(Mandatory = false,
[Parameter(ParameterSetName = EnvironmentPropertiesParameterSet, Mandatory = false,
HelpMessage = "The endpoint to use when communicating with the Azure Log Analytics API.")]
[Parameter(ParameterSetName = MetadataParameterSet, Mandatory = false,
HelpMessage = "The endpoint to use when communicating with the Azure Log Analytics API.")]
public string AzureAnalysisServicesEndpointSuffix { get; set; }

[Parameter(Mandatory = false,
[Parameter(ParameterSetName = EnvironmentPropertiesParameterSet, Mandatory = false,
HelpMessage = "The resource identifier of the Azure Analysis Services resource.")]
[Parameter(ParameterSetName = MetadataParameterSet, Mandatory = false,
HelpMessage = "The resource identifier of the Azure Analysis Services resource.")]
public string AzureAnalysisServicesEndpointResourceId { get; set; }

[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true,
[Parameter(ParameterSetName = EnvironmentPropertiesParameterSet, Mandatory = false, ValueFromPipelineByPropertyName = true,
HelpMessage = "Dns suffix of Azure Attestation service.")]
[Parameter(ParameterSetName = MetadataParameterSet, Mandatory = false, ValueFromPipelineByPropertyName = true,
HelpMessage = "Dns suffix of Azure Attestation service.")]
public string AzureAttestationServiceEndpointSuffix { get; set; }

[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true,
[Parameter(ParameterSetName = EnvironmentPropertiesParameterSet, Mandatory = false, ValueFromPipelineByPropertyName = true,
HelpMessage = "The resource identifier of the Azure Attestation service that is the recipient of the requested token.")]
[Parameter(ParameterSetName = MetadataParameterSet, Mandatory = false, ValueFromPipelineByPropertyName = true,
HelpMessage = "The resource identifier of the Azure Attestation service that is the recipient of the requested token.")]
public string AzureAttestationServiceEndpointResourceId { get; set; }

[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true,
[Parameter(ParameterSetName = EnvironmentPropertiesParameterSet, Mandatory = false, ValueFromPipelineByPropertyName = true,
HelpMessage = "Dns suffix of Azure Synapse Analytics.")]
[Parameter(ParameterSetName = MetadataParameterSet, Mandatory = false, ValueFromPipelineByPropertyName = true,
HelpMessage = "Dns suffix of Azure Synapse Analytics.")]
public string AzureSynapseAnalyticsEndpointSuffix { get; set; }

[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true,
[Parameter(ParameterSetName = EnvironmentPropertiesParameterSet, Mandatory = false, ValueFromPipelineByPropertyName = true,
HelpMessage = "The resource identifier of the Azure Synapse Analytics that is the recipient of the requested token.")]
[Parameter(ParameterSetName = MetadataParameterSet, Mandatory = false, ValueFromPipelineByPropertyName = true,
HelpMessage = "The resource identifier of the Azure Synapse Analytics that is the recipient of the requested token.")]
public string AzureSynapseAnalyticsEndpointResourceId { get; set; }

[Parameter(ParameterSetName = DiscoveryParameterSet, Mandatory = true,
HelpMessage = "Discovers environments via default or configured endpoint.")]
public SwitchParameter AutoDiscover { get; set; }

[Parameter(ParameterSetName = DiscoveryParameterSet, Mandatory = false,
HelpMessage = "Specifies URI of the internet resource to fetch environments.")]
public Uri Uri { get; set; }


protected override void BeginProcessing()
{
// do not call begin processing there is no context needed for this cmdlet
Expand All @@ -196,7 +224,7 @@ public override void ExecuteCmdlet()
if (AzureEnvironment.PublicEnvironments.Keys.Any((k) => string.Equals(k, Name, StringComparison.CurrentCultureIgnoreCase)))
{
throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture,
"Cannot add built-in environment {0}.", Name));
"Cannot add built-in or discovered environment {0}.", Name));
}

if (this.ParameterSetName.Equals(MetadataParameterSet, StringComparison.Ordinal))
Expand All @@ -212,7 +240,10 @@ public override void ExecuteCmdlet()
IAzureEnvironment newEnvironment;
if (!defProfile.TryGetEnvironment(this.Name, out newEnvironment))
{
newEnvironment = new AzureEnvironment { Name = this.Name };
newEnvironment = new AzureEnvironment {
Name = this.Name,
Type = AzureEnvironment.TypeUserDefined
};
}

if (publicEnvironment.Key == null)
Expand Down Expand Up @@ -267,7 +298,7 @@ public override void ExecuteCmdlet()
WriteObject(new PSAzureEnvironment(client.AddOrSetEnvironment(newEnvironment)));
});
}
else
else if (this.ParameterSetName.Equals(EnvironmentPropertiesParameterSet, StringComparison.Ordinal))
{
ModifyContext((profile, profileClient) =>
{
Expand Down Expand Up @@ -344,6 +375,22 @@ public override void ExecuteCmdlet()
}
});
}
else
{
AzureEnvironment.DiscoverEnvironments(Uri?.ToString(), this.WriteDebug, this.WriteWarning);
ModifyContext((profile, profileClient) =>
{
foreach (var env in profile.EnvironmentTable.Where(i => (i.Value is AzureEnvironment environment) && AzureEnvironment.TypeDiscovered.Equals(environment.Type)).ToList())
{
profile.EnvironmentTable.Remove(env.Key);
}
foreach (var env in AzureEnvironment.PublicEnvironments.Values)
{
profile.EnvironmentTable[env.Name] = env;
WriteObject(new PSAzureEnvironment(env));
}
});
}
});

}
Expand Down
12 changes: 6 additions & 6 deletions src/Accounts/Accounts/Environment/SetAzureRMEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,10 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Commands.Common.Authentication;
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
using Microsoft.Azure.Commands.Common.Authentication.Models;
using Microsoft.Azure.Commands.Common.Authentication.ResourceManager;
using Microsoft.Azure.Commands.Profile.Common;
using Microsoft.Azure.Commands.Profile.Models;
using Microsoft.Azure.Commands.Profile.Utilities;
using Microsoft.Azure.Commands.ResourceManager.Common;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using System;
using System.Globalization;
Expand Down Expand Up @@ -198,7 +194,7 @@ public override void ExecuteCmdlet()
if (AzureEnvironment.PublicEnvironments.Keys.Any((k) => string.Equals(k, Name, StringComparison.CurrentCultureIgnoreCase)))
{
throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture,
"Cannot change built-in environment {0}.", Name));
"Cannot change built-in or discovered environment {0}.", Name));
}

if (this.ParameterSetName.Equals(MetadataParameterSet, StringComparison.Ordinal))
Expand All @@ -214,7 +210,11 @@ public override void ExecuteCmdlet()
IAzureEnvironment newEnvironment;
if (!defProfile.TryGetEnvironment(this.Name, out newEnvironment))
{
newEnvironment = new AzureEnvironment { Name = this.Name };
newEnvironment = new AzureEnvironment
{
Name = this.Name,
Type = AzureEnvironment.TypeUserDefined
};
}

if (publicEnvironment.Key == null)
Expand Down
Loading