in src/Microsoft.Azure.Relay/ManagementOperations.cs [22:63]
public static async Task<TEntityDescription> GetAsync<TEntityDescription>(
Uri resourceUri, TokenProvider tokenProvider, CancellationToken cancellationToken)
{
Fx.Assert(resourceUri != null, "resourceUri is required");
Fx.Assert(tokenProvider != null, "tokenProvider is required");
var httpClient = new HttpClient();
try
{
httpClient.BaseAddress = CreateManagementUri(resourceUri);
httpClient.DefaultRequestHeaders.Add("X-PROCESS-AT", "ServiceBus");
var token = await tokenProvider.GetTokenAsync(resourceUri.AbsoluteUri, TokenDuration).ConfigureAwait(false);
httpClient.DefaultRequestHeaders.Add("Authorization", token.TokenString);
var httpResponse = await httpClient.GetAsync(string.Empty, cancellationToken).ConfigureAwait(false);
if (httpResponse.IsSuccessStatusCode)
{
if (IsFeedContentType(httpResponse))
{
// REST management operations will return an atom feed for unknown paths
throw new EndpointNotFoundException(resourceUri.AbsolutePath.TrimStart('/'));
}
using (var stream = await httpResponse.Content.ReadAsStreamAsync().ConfigureAwait(false))
{
return DeserializeFromAtomEntry<TEntityDescription>(stream);
}
}
else
{
throw RelayEventSource.Log.ThrowingException(await CreateExceptionForFailedResponseAsync(httpResponse).ConfigureAwait(false));
}
}
catch (Exception exception) when (!WebSocketExceptionHelper.IsRelayContract(exception))
{
throw RelayEventSource.Log.ThrowingException(WebSocketExceptionHelper.ConvertToRelayContract(exception, null));
}
finally
{
httpClient.Dispose();
}
}