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
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class AzureEnvironment : IAzureEnvironment
AzureDataLakeStoreFileSystemEndpointSuffix = AzureEnvironmentConstants.AzureDataLakeStoreFileSystemEndpointSuffix,
GraphEndpointResourceId = AzureEnvironmentConstants.AzureGraphEndpoint,
DataLakeEndpointResourceId = AzureEnvironmentConstants.AzureDataLakeServiceEndpointResourceId,
BatchEndpointResourceId = AzureEnvironmentConstants.BatchEndpointResourceId,
AdTenant = "Common"
}
},
Expand All @@ -77,6 +78,7 @@ public class AzureEnvironment : IAzureEnvironment
AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix = null,
AzureDataLakeStoreFileSystemEndpointSuffix = null,
GraphEndpointResourceId = AzureEnvironmentConstants.ChinaGraphEndpoint,
BatchEndpointResourceId = AzureEnvironmentConstants.ChinaBatchEndpointResourceId,
AdTenant = "Common"
}
},
Expand All @@ -101,6 +103,7 @@ public class AzureEnvironment : IAzureEnvironment
AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix = null,
AzureDataLakeStoreFileSystemEndpointSuffix = null,
GraphEndpointResourceId = AzureEnvironmentConstants.USGovernmentGraphEndpoint,
BatchEndpointResourceId = AzureEnvironmentConstants.USGovernmentBatchEndpointResourceId,
AdTenant = "Common"
}
},
Expand All @@ -125,6 +128,7 @@ public class AzureEnvironment : IAzureEnvironment
AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix = null,
AzureDataLakeStoreFileSystemEndpointSuffix = null,
GraphEndpointResourceId = AzureEnvironmentConstants.GermanGraphEndpoint,
BatchEndpointResourceId = AzureEnvironmentConstants.GermanBatchEndpointResourceId,
AdTenant = "Common"
}
}
Expand Down Expand Up @@ -228,6 +232,11 @@ public AzureEnvironment(IAzureEnvironment other)
/// </summary>
public string DataLakeEndpointResourceId { get; set; }

/// <summary>
/// The token audience required for communicating with the Batch service in this enviornment
/// </summary>
public string BatchEndpointResourceId { get; set; }

/// <summary>
/// The domain name suffix for Azure DataLake Catalog and Job services created in this environment
/// </summary>
Expand Down Expand Up @@ -275,7 +284,8 @@ public static class Endpoint
ManagementPortalUrl = "ManagementPortalUrl",
AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix = "AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix",
AzureDataLakeStoreFileSystemEndpointSuffix = "AzureDataLakeStoreFileSystemEndpointSuffix",
DataLakeEndpointResourceId = "DataLakeEndpointResourceId";
DataLakeEndpointResourceId = "DataLakeEndpointResourceId",
BatchEndpointResourceId = "BatchEndpointResourceId";

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,10 @@ public static class AzureEnvironmentConstants
/// The token audience for authorizing DataLake requests
/// </summary>
public const string AzureDataLakeServiceEndpointResourceId = "https://datalake.azure.net";

public const string BatchEndpointResourceId = "https://batch.core.windows.net/";
public const string ChinaBatchEndpointResourceId = "https://batch.chinacloudapi.cn/";
public const string USGovernmentBatchEndpointResourceId = "https://batch.core.usgovcloudapi.net/";
public const string GermanBatchEndpointResourceId = "https://batch.cloudapi.de/";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public static bool TryGetEndpointUrl(this IAzureEnvironment environment, string
case AzureEnvironment.Endpoint.DataLakeEndpointResourceId:
endpoint = new Uri(environment.DataLakeEndpointResourceId);
break;
case AzureEnvironment.Endpoint.BatchEndpointResourceId:
endpoint = new Uri(environment.BatchEndpointResourceId);
break;
default:
result = false;
break;
Expand Down Expand Up @@ -138,6 +141,9 @@ public static bool TryGetEndpointString(this IAzureEnvironment environment, stri
case AzureEnvironment.Endpoint.ServiceManagement:
propertyValue = environment.ServiceManagementUrl;
break;
case AzureEnvironment.Endpoint.BatchEndpointResourceId:
propertyValue = environment.BatchEndpointResourceId;
break;
default:
break;
}
Expand Down Expand Up @@ -226,6 +232,9 @@ public static void SetEndpoint(this IAzureEnvironment environment, string endpoi
case AzureEnvironment.Endpoint.DataLakeEndpointResourceId:
environment.DataLakeEndpointResourceId = propertyValue;
break;
case AzureEnvironment.Endpoint.BatchEndpointResourceId:
environment.BatchEndpointResourceId = propertyValue;
break;
case AzureEnvironment.Endpoint.ActiveDirectory:
environment.ActiveDirectoryAuthority = propertyValue;
break;
Expand Down Expand Up @@ -440,6 +449,10 @@ public static void CopyFrom(this IAzureEnvironment environment, IAzureEnvironmen
environment.AzureKeyVaultServiceEndpointResourceId =
other.AzureKeyVaultServiceEndpointResourceId;
}
if (other.IsEndpointSet(AzureEnvironment.Endpoint.BatchEndpointResourceId))
{
environment.BatchEndpointResourceId = other.BatchEndpointResourceId;
}

environment.VersionProfiles.Clear();
foreach (var profile in other.VersionProfiles)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ public interface IAzureEnvironment : IExtensibleModel
/// </summary>
string DataLakeEndpointResourceId { get; set; }

/// <summary>
/// The token audience required to authenticate with the Azure Batch service
/// </summary>
string BatchEndpointResourceId { get; set; }

/// <summary>
/// The domain name suffix for Azure DataLake Catalog and Job services
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public PSAzureEnvironment(PSObject other)
AzureDataLakeStoreFileSystemEndpointSuffix = other.GetProperty<string>(nameof(AzureDataLakeStoreFileSystemEndpointSuffix));
AzureKeyVaultDnsSuffix = other.GetProperty<string>(nameof(AzureKeyVaultDnsSuffix));
AzureKeyVaultServiceEndpointResourceId = other.GetProperty<string>(nameof(AzureKeyVaultServiceEndpointResourceId));
BatchEndpointResourceId = other.GetProperty<string>(nameof(BatchEndpointResourceId));
DataLakeEndpointResourceId = other.GetProperty<string>(nameof(DataLakeEndpointResourceId));
GalleryUrl = other.GetProperty<string>(nameof(GalleryUrl));
GraphEndpointResourceId = other.GetProperty<string>(nameof(GraphEndpointResourceId));
Expand Down Expand Up @@ -227,6 +228,11 @@ public bool OnPremise

public IDictionary<string, string> ExtendedProperties { get; } = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);

/// <summary>
/// Gets or sets the Azure Batch AD resource ID.
/// </summary>
public string BatchEndpointResourceId { get; set; }

/// <summary>
/// Determine equality of two PSAzureEnvironment instances.
/// </summary>
Expand All @@ -253,7 +259,8 @@ public override bool Equals(object obj)
&& SqlDatabaseDnsSuffix == other.SqlDatabaseDnsSuffix
&& AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix == other.AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix
&& AzureDataLakeStoreFileSystemEndpointSuffix == other.AzureDataLakeStoreFileSystemEndpointSuffix
&& TrafficManagerDnsSuffix == other.TrafficManagerDnsSuffix;
&& TrafficManagerDnsSuffix == other.TrafficManagerDnsSuffix
&& BatchEndpointResourceId == other.BatchEndpointResourceId;
}

return false;
Expand Down
2 changes: 2 additions & 0 deletions src/ResourceManager/Profile/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
- Clear-AzureRmDefault
- Use this cmdlet to remove the current default resource group
- ```Clear-AzureRmDefault -ResourceGroup```
- Add-AzureRmEnvironment and Set-AzureRmEnvironment
- Add the BatchAudience parameter, which allows you to specify the Azure Batch Active Directory audience to use when acquiring authentication tokens for the Batch service.

## Version 3.4.1
* LocationCompleterAttribute added and available for cmdlets which use the -Location parameter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,7 @@ public void SavingProfileWorks()
""AzureKeyVaultServiceEndpointResourceId"": null,
""GraphEndpointResourceId"": null,
""DataLakeEndpointResourceId"": null,
""BatchEndpointResourceId"": null,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add in tests that verify this value - we have tests that check the output type, and tests that check the value that is saved in the context

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I have updated the TypeConversionTests as well (I hadn't realized they were there earlier).

Can you point me to the test classes/methods for any other tests which I should update?

""AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix"": null,
""AzureDataLakeStoreFileSystemEndpointSuffix"": null,
""AdTenant"": null,
Expand Down Expand Up @@ -784,6 +785,7 @@ public void SavingProfileWorks()
""AzureKeyVaultServiceEndpointResourceId"": null,
""GraphEndpointResourceId"": null,
""DataLakeEndpointResourceId"": null,
""BatchEndpointResourceId"": null,
""AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix"": null,
""AzureDataLakeStoreFileSystemEndpointSuffix"": null,
""AdTenant"": null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,8 @@ public void CanCreateEnvironmentWithAllProperties()
StorageEndpoint = "https://StorageEndpoint",
SqlDatabaseDnsSuffix = "SqlDatabaseDnsSuffix",
TrafficManagerDnsSuffix = "TrafficManagerDnsSuffix",
GraphAudience = "GaraphAudience"
GraphAudience = "GaraphAudience",
BatchEndpointResourceId = "BatchResourceId"
};

var dict = new Dictionary<string, object>();
Expand All @@ -390,6 +391,7 @@ public void CanCreateEnvironmentWithAllProperties()
dict["SqlDatabaseDnsSuffix"] = "SqlDatabaseDnsSuffix";
dict["TrafficManagerDnsSuffix"] = "TrafficManagerDnsSuffix";
dict["GraphAudience"] = "GaraphAudience";
dict["BatchEndpointResourceId"] = "BatchResourceId";
cmdlet.SetBoundParameters(dict);

cmdlet.InvokeBeginProcessing();
Expand All @@ -413,6 +415,7 @@ public void CanCreateEnvironmentWithAllProperties()
Assert.Equal(cmdlet.SqlDatabaseDnsSuffix, actual.SqlDatabaseDnsSuffix);
Assert.Equal(cmdlet.TrafficManagerDnsSuffix, actual.TrafficManagerDnsSuffix);
Assert.Equal(cmdlet.GraphAudience, actual.GraphEndpointResourceId);
Assert.Equal(cmdlet.BatchEndpointResourceId, actual.BatchEndpointResourceId);
commandRuntimeMock.Verify(f => f.WriteObject(It.IsAny<PSAzureEnvironment>()), Times.Once());
IAzureEnvironment env = AzureRmProfileProvider.Instance.Profile.GetEnvironment("KaTaL");
Assert.Equal(env.Name, cmdlet.Name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public void CanConvertNullEnvironments()
Assert.Null(environment.SqlDatabaseDnsSuffix);
Assert.Null(environment.StorageEndpointSuffix);
Assert.Null(environment.TrafficManagerDnsSuffix);
Assert.Null(environment.BatchEndpointResourceId);
}

[Theory]
Expand All @@ -64,19 +65,19 @@ public void CanConvertNullEnvironments()
"https://graph.windows.net", "https://graph.windows.net/", "https://manage.windowsazure.com",
"https://manage.windowsazure.com/publishsettings", "https://management.azure.com",
"https://management.core.windows.net", ".sql.azure.com", ".core.windows.net",
".trafficmanager.windows.net")]
".trafficmanager.windows.net", "https://batch.core.windows.net")]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void CanConvertValidEnvironments(string name, bool onPremise, string activeDirectory, string serviceResource,
string adTenant, string dataLakeJobs, string dataLakeFiles, string kvDnsSuffix,
string kvResource, string gallery, string graph, string graphResource, string portal,
string publishSettings, string resourceManager, string serviceManagement,
string sqlSuffix, string storageSuffix, string trafficManagerSuffix)
string sqlSuffix, string storageSuffix, string trafficManagerSuffix, string batchResource)
{
AzureEnvironment azEnvironment = CreateEnvironment(name, onPremise, activeDirectory,
serviceResource, adTenant, dataLakeJobs, dataLakeFiles, kvDnsSuffix,
kvResource, gallery, graph, graphResource, portal, publishSettings,
resourceManager, serviceManagement, sqlSuffix, storageSuffix,
trafficManagerSuffix);
trafficManagerSuffix, batchResource);
var environment = (PSAzureEnvironment)azEnvironment;
Assert.NotNull(environment);
CheckEndpoint(AzureEnvironment.Endpoint.ActiveDirectory, azEnvironment,
Expand Down Expand Up @@ -113,6 +114,8 @@ public void CanConvertValidEnvironments(string name, bool onPremise, string acti
environment.StorageEndpointSuffix);
CheckEndpoint(AzureEnvironment.Endpoint.TrafficManagerDnsSuffix, azEnvironment,
environment.TrafficManagerDnsSuffix);
CheckEndpoint(AzureEnvironment.Endpoint.BatchEndpointResourceId, azEnvironment,
environment.BatchEndpointResourceId);
Assert.Equal(azEnvironment.Name, environment.Name);
Assert.Equal(azEnvironment.OnPremise, environment.EnableAdfsAuthentication);
}
Expand Down Expand Up @@ -144,6 +147,7 @@ public void CanConvertNullPSEnvironments()
Assert.False(environment.IsEndpointSet(AzureEnvironment.Endpoint.SqlDatabaseDnsSuffix));
Assert.False(environment.IsEndpointSet(AzureEnvironment.Endpoint.StorageEndpointSuffix));
Assert.False(environment.IsEndpointSet(AzureEnvironment.Endpoint.TrafficManagerDnsSuffix));
Assert.False(environment.IsEndpointSet(AzureEnvironment.Endpoint.BatchEndpointResourceId));
}
[Theory]
[InlineData("TestAll", true, "https://login.microsoftonline.com", "https://management.core.windows.net/",
Expand All @@ -152,13 +156,13 @@ public void CanConvertNullPSEnvironments()
"https://graph.windows.net", "https://graph.windows.net/", "https://manage.windowsazure.com",
"https://manage.windowsazure.com/publishsettings", "https://management.azure.com",
"https://management.core.windows.net", ".sql.azure.com", ".core.windows.net",
".trafficmanager.windows.net")]
".trafficmanager.windows.net", "https://batch.core.windows.net")]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void CanConvertValidPSEnvironments(string name, bool onPremise, string activeDirectory, string serviceResource,
string adTenant, string dataLakeJobs, string dataLakeFiles, string kvDnsSuffix,
string kvResource, string gallery, string graph, string graphResource, string portal,
string publishSettings, string resourceManager, string serviceManagement,
string sqlSuffix, string storageSuffix, string trafficManagerSuffix)
string sqlSuffix, string storageSuffix, string trafficManagerSuffix, string batchResource)
{
PSAzureEnvironment environment = new PSAzureEnvironment
{
Expand All @@ -180,7 +184,8 @@ public void CanConvertValidPSEnvironments(string name, bool onPremise, string ac
ServiceManagementUrl = serviceManagement,
SqlDatabaseDnsSuffix = sqlSuffix,
StorageEndpointSuffix = storageSuffix,
TrafficManagerDnsSuffix = trafficManagerSuffix
TrafficManagerDnsSuffix = trafficManagerSuffix,
BatchEndpointResourceId = batchResource
};
var azEnvironment = (AzureEnvironment)environment;
Assert.NotNull(environment);
Expand Down Expand Up @@ -218,6 +223,8 @@ public void CanConvertValidPSEnvironments(string name, bool onPremise, string ac
environment.StorageEndpointSuffix);
CheckEndpoint(AzureEnvironment.Endpoint.TrafficManagerDnsSuffix, azEnvironment,
environment.TrafficManagerDnsSuffix);
CheckEndpoint(AzureEnvironment.Endpoint.BatchEndpointResourceId, azEnvironment,
environment.BatchEndpointResourceId);
Assert.Equal(azEnvironment.Name, environment.Name);
Assert.Equal(azEnvironment.OnPremise, environment.EnableAdfsAuthentication);
}
Expand All @@ -227,7 +234,7 @@ private AzureEnvironment CreateEnvironment(string name, bool onPremise, string a
string adTenant, string dataLakeJobs, string dataLakeFiles, string kvDnsSuffix,
string kvResource, string gallery, string graph, string graphResource, string portal,
string publishSettings, string resourceManager, string serviceManagement,
string sqlSuffix, string storageSuffix, string trafficManagerSuffix)
string sqlSuffix, string storageSuffix, string trafficManagerSuffix, string batchResource)
{
var environment = new AzureEnvironment() { Name = name, OnPremise = onPremise };
SetEndpoint(AzureEnvironment.Endpoint.ActiveDirectory, environment, activeDirectory);
Expand Down Expand Up @@ -263,7 +270,8 @@ private AzureEnvironment CreateEnvironment(string name, bool onPremise, string a
storageSuffix);
CheckEndpoint(AzureEnvironment.Endpoint.TrafficManagerDnsSuffix, environment,
trafficManagerSuffix);

CheckEndpoint(AzureEnvironment.Endpoint.BatchEndpointResourceId, environment,
batchResource);
return environment;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ public string DataLakeAudience
}
}

[Parameter(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; }

protected override void BeginProcessing()
{
// do not call begin processing there is no context needed for this cmdlet
Expand Down Expand Up @@ -285,6 +290,8 @@ public override void ExecuteCmdlet()
nameof(GraphAudience));
SetEndpointIfBound(newEnvironment, AzureEnvironment.Endpoint.DataLakeEndpointResourceId,
nameof(DataLakeAudience));
SetEndpointIfBound(newEnvironment, AzureEnvironment.Endpoint.BatchEndpointResourceId,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, I think you will also need to change the constructors and type conversion operators for PSAzureEnvinronment to include this value. If you add this value into existing test validation overt these types, you'll see the code you need to change.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was already done I think, right? I made the change to PSAzureEnvironment(PSObject other) already, and to Equals in PSAzureEnvironment - Did I need to do something else too?

nameof(BatchEndpointResourceId));
WriteObject(new PSAzureEnvironment(profileClient.AddOrSetEnvironment(newEnvironment)));
}
});
Expand Down
Loading