/// <summary> /// Resolves a single component connection. If connections are configured to be /// retrieved from Discovery service it finds a IDiscovery and resolves the connection there. /// </summary> /// <param name="correlationId">(optional) transaction id to trace execution through call chain.</param> /// <returns>resolved connection.</returns> public async Task <ConnectionParams> ResolveAsync(string correlationId) { var connection = await _connectionResolver.ResolveAsync(correlationId); ValidateConnection(correlationId, connection); UpdateConnection(connection); return(connection); }
/// <summary> /// Resolves a single component connection. If connections are configured to be /// retrieved from Discovery service it finds a IDiscovery and resolves the connection there. /// </summary> /// <param name="correlationId">(optional) transaction id to trace execution through call chain.</param> /// <returns>resolved connection.</returns> public async Task <ConnectionParams> ResolveAsync(string correlationId) { var connection = await _connectionResolver.ResolveAsync(correlationId); var credential = await _credentialResolver.LookupAsync(correlationId); ValidateConnection(correlationId, connection, credential); UpdateConnection(connection, credential); return(connection); }
public void TestResolve() { var connectionParams = _connectionResolver.ResolveAsync("correlationId").Result; Assert.Equal(connectionParams.Get("protocol"), "http"); Assert.Equal(connectionParams.Get("host"), "localhost"); Assert.Equal(connectionParams.Get("port"), "3000"); var restConfigDiscovery = ConfigParams.FromTuples( "connection.protocol", "http", "connection.host", "localhost", "connection.port", 3000, "connection.discovery_key", "Discovery key value" ); IReferences references = new References(); _connectionResolver = new ConnectionResolver(restConfigDiscovery, references); try { _connectionResolver.ResolveAsync("correlationId").Wait(); } catch (Exception ex) { Assert.IsType <ConfigException>(ex.InnerException); } }
protected ConfigParams PerformReadConfig(string correlationId) { try { var connection = _connectionResolver.ResolveAsync(correlationId).Result; var credential = _credentialResolver.LookupAsync(correlationId).Result; KeyVaultClient _client = new KeyVaultClient(connection, credential); var secrets = _client.GetSecretsAsync().Result; var result = new ConfigParams(); foreach (var entry in secrets) { var key = entry.Key.Replace('-', '.'); var value = entry.Value; result[key] = value; } return(result); } catch (Exception ex) { throw new ArgumentException("Failed to load config from KeyVault", ex); } }
/// <summary> /// Resolves connection and credental parameters and generates a single AWSConnectionParams value. /// </summary> /// <param name="correlationId">(optional) transaction id to trace execution through call chain.</param> /// <returns>AWSConnectionParams value</returns> public async Task <AwsConnectionParams> ResolveAsync(string correlationId) { var result = new AwsConnectionParams(); var connection = await _connectionResolver.ResolveAsync(correlationId); result.Append(connection); var credential = await _credentialResolver.LookupAsync(correlationId); result.Append(credential); // Force ARN parsing result.Arn = result.Arn; // Perform validation var err = result.Validate(correlationId); if (err != null) { throw err; } return(result); }
public async virtual Task OpenAsync(string correlationId) { var connection = await _connectionResolver.ResolveAsync(correlationId); var credential = await _credentialResolver.LookupAsync(correlationId); await OpenAsync(correlationId, connection, credential); }
public async Task OpenAsync(string correlationId) { var connection = await _connectionResolver.ResolveAsync(correlationId); if (connection == null) { throw new ConfigException(correlationId, "NO_CONNECTION", "Connection is not configured"); } ConfigurationOptions options; var uri = connection.Uri; if (!string.IsNullOrEmpty(uri)) { options = ConfigurationOptions.Parse(uri); } else { var host = connection.Host ?? "localhost"; var port = connection.Port != 0 ? connection.Port : 6379; options = new ConfigurationOptions(); options.EndPoints.Add(host, port); } var credential = await _credentialResolver.LookupAsync(correlationId); if (credential != null && !string.IsNullOrEmpty(credential.Password)) { options.Password = credential.Password; } options.ConnectTimeout = _connectTimeout; options.ResponseTimeout = _retryTimeout; options.ConnectRetry = _retries; _client = await ConnectionMultiplexer.ConnectAsync(options); _database = _client.GetDatabase(); }