public virtual ElasticsearchClientOption Execute(string connectionString) { var tokens = new DbConnectionStringBuilder() { ConnectionString = connectionString }; var option = new ElasticsearchClientOption(connectionString) { Hostname = tokens.TryGet(Hostname, out string host) ? host : throw new ArgumentException("Hostname is mandatory for an Elasticsearch connection string"), Port = tokens.Get(Port, 9200) }; if (tokens.TryGet(Username, out string username) ^ tokens.TryGet(Password, out string password)) { throw new ArgumentException("username and password must be both filled or none of them must be filled"); } option.Username = username; option.Password = password; return(option); } }
internal static bool TryGetPassword(string connectionString, out string key, out string password) { try { var csb = new DbConnectionStringBuilder(); csb.ConnectionString = connectionString; return(csb.TryGet(new[] { "password", "pwd", "secret", "key" }, out key, out password)); } catch { key = null; password = null; return(false); } }