Using C# I can delete Azure Batch Pools and Jobs using Client ID and Client Secret - but currently we want to delete them by using Azure Functions using Managed Identity. Here is my current code:
internal async Task<string> GetAuthenticationTokenAsync()
{
var authContext = new AuthenticationContext(AuthorityUri);
var authResult = await authContext.AcquireTokenAsync(BatchResourceUri, new ClientCredential(BatchCredentials["ClientId"], BatchCredentials["ClientKey"])).ConfigureAwait(false);
return authResult.AccessToken;
}
Task<string> TokenProvider() => GetAuthenticationTokenAsync();
using (var Batch = BatchClient.Open(new BatchTokenCredentials(BatchCredentials["BatchAccountURL"], TokenProvider)))
{
var CloudPools = Batch.PoolOperations.ListPools();
var JobList = Batch.JobOperations.ListJobs();
foreach (var pool in CloudPools)
{
pool.DeleteAsync();
}
foreach (var job in JobList)
{
job.DeleteAsync();
}
}
I see that in msdn social that there is no support for MSI currently in Azure Batch, so is there any alternative to just delete the Azure Batch Pools and Jobs ?
note: if it is not possible in C#, I am comfortable using Rest API or PowerShell also for deleting the pools and jobs of the batch account