public ValueTask <GeneratedText> GenerateTextAsync( TextGenerationConfiguration configuration, EndpointAuthentication authentication, CancellationToken cancellationToken) { return(_serviceClient.PostAsync <TextGenerationConfigurationDto, GeneratedText>( ServiceName, $"{RoutePrefix}/generate", authentication, TextGenerationConfigurationDto.ToDto(configuration), cancellationToken)); }
public async ValueTask <string?> GetRealtimeAuthValueAsync(string token) { var result = await _client.PostAsync <object, string?>( _serviceName, "api/realtime-auth/validate", EndpointAuthentication.FromClientCredentials( new ClientCredentials("realtime-auth", "secret", new[] { "realtime-auth", "service" })), new { token = token }, default) .ConfigureAwait(false); return(result); }
public async ValueTask <T> GetAsync <T>(string serviceName, string endpoint, EndpointAuthentication endpointAuthentication, CancellationToken cancellationToken) { if (!_serviceAddresses.ContainsKey(serviceName)) { throw new InvalidOperationException("Service is not registered in service discovery."); } var uri = $"{_serviceAddresses[serviceName]}/{endpoint}"; var endpointAuthenticationType = endpointAuthentication.AuthenticationType; var accessToken = endpointAuthenticationType switch { EndpointAuthenticationType.Profile => await _profileTokenService.GetProfileAccessTokenAsync(cancellationToken).ConfigureAwait(false), EndpointAuthenticationType.Service => endpointAuthentication.Credentials == null ? await _serviceTokenService.GetServiceAccessTokenAsync(cancellationToken).ConfigureAwait(false) : await _serviceTokenService.GetServiceAccessTokenAsync(endpointAuthentication.Credentials, cancellationToken).ConfigureAwait(false), _ => null }; try { using var message = new HttpRequestMessage(HttpMethod.Get, uri); using var httpClient = _httpClientFactory.CreateClient(); return(await httpClient.SendMessageAsync <T>(message, accessToken, cancellationToken) .ConfigureAwait(false)); } catch (HttpRequestException exception) { // TODO: Consider placing it in some other place of code, like IHttpClient. // TODO: Fix the issue that if endpoint return STRUCT - we return default value when it's not found! // TODO: What if URL is incorrect - it shouldn't return default value. // TODO: If object is valueobject - we cannot return default value. We always need to return NULL. // Consider wrapping response in some kind of Result object. if (exception.StatusCode == HttpStatusCode.NotFound) { return(default !);