public static BlobServiceClient CreateClient(string connectionString, System.Net.Http.IHttpClientFactory http = null) { var clientOptions = new BlobClientOptions { // notes: no options for this in new API, there is GeoRedundantSecondaryUri, but we do not have second URI // LocationMode = LocationMode.PrimaryThenSecondary, // notes: next hash check is not recreated, either is is buildint or should be done manually // DisableContentMD5Validation = false, // controls whether or not the Storage Client will validate that MD5 hash on download Diagnostics = { IsDistributedTracingEnabled = true, IsLoggingEnabled = true }, Retry = { NetworkTimeout = TimeSpan.FromSeconds(120), Delay = TimeSpan.FromSeconds(2), MaxDelay = TimeSpan.FromSeconds(20), Mode = RetryMode.Exponential }, }; if (http != null) { var client = http.CreateClient("Blob"); client.Timeout = TimeSpan.FromSeconds(720); clientOptions.Transport = new HttpClientTransport(client); } // is on per HTTP call basis, not per blob // clientOptions.AddPolicy(new HttpPipelinePolicy(), HttpPipelinePosition.PerCall) return(new BlobServiceClient(connectionString, clientOptions)); }
public async Task <IEnumerable <ClaimDto> > GetAsync(IIdentity identity, IEnumerable <IKeyValueSettings> settings, object parameter) { var result = new List <ClaimDto>(); if (null == identity) { Logger.Technical.From <ClaimsProxy>().Error($"A null identity was received. No Claims will be generated.").Log(); return(result); } if (null == settings || settings.Count() == 0) { Logger.Technical.From <ClaimsProxy>().Error($"We need token settings to call the backend.").Log(); return(result); } if (!settings.Any(s => s.Values.ContainsKey(TokenKeys.AuthenticationTypeKey) && s.Values[TokenKeys.AuthenticationTypeKey].Equals(identity.AuthenticationType))) { Logger.Technical.From <ClaimsProxy>().Debug($"Skip fetching claims, no setting found for authentication type {identity.AuthenticationType}."); return(result); } try { // Check before the url and application name is defined! if (String.IsNullOrWhiteSpace(_url)) { // no override rule, use the standard endpoint defined. _url = settings.First().Values[TokenKeys.RootServiceUrlKey].TrimEnd('/') + "/api/claims"; } else { _url = String.Format(_url, _applicationName); } Logger.Technical.From <ClaimsProxy>().System($"Call back-end service for authorization, endpoint = {_url}.").Log(); IPlatformParameters platformParameters = parameter is IPlatformParameters parameters ? parameters : null; // Check if we need to do something before calling the backend like force the start of a vpn. Network.Handler.OnCalling?.Invoke(new Uri(_url)); // call the backend service! var client = _httpClientFactory.CreateClient("ClaimsProxy"); var response = await client.GetAsync(_url); if (response.IsSuccessStatusCode) { Logger.Technical.From <ClaimsProxy>().System($"Call service {_url} succeeds.").Log(); String responseString = await response.Content.ReadAsStringAsync(); // Add the claims. result.AddRange(_jsonSerializer.ReadObject <IEnumerable <ClaimDto> >(responseString)); Logger.Technical.From <ClaimsProxy>().System($"{result.Count} claim(s) received.").Log(); } else { Logger.Technical.From <ClaimsProxy>().Error($"Call service {_url} gives error status ${response.StatusCode}.").Log(); } } catch (Exception exception) { Exception inner = exception.InnerException; while (null != inner) { Logger.Technical.From <ClaimsProxy>().Exception(inner).Log(); inner = inner.InnerException; } Logger.Technical.From <ClaimsProxy>().Exception(exception).Log(); } return(result); }