Elasticsearch configuration now uses a Uri

Also fixed default setup wizard option not working

Fixes #1599
This commit is contained in:
Jordan Dominion
2023-07-15 09:39:15 -04:00
parent d8aa9ae37e
commit 2091ce06e7
5 changed files with 25 additions and 16 deletions
@@ -1,4 +1,6 @@
namespace Tgstation.Server.Host.Configuration
using System;
namespace Tgstation.Server.Host.Configuration
{
/// <summary>
/// Configuration options pertaining to elasticsearch log storage.
@@ -18,7 +20,7 @@
/// <summary>
/// The host of the elasticsearch endpoint.
/// </summary>
public string Host { get; set; }
public Uri Host { get; set; }
/// <summary>
/// Username for elasticsearch.
@@ -196,11 +196,7 @@ namespace Tgstation.Server.Host.Core
rollOnFileSizeLimit: true);
},
elasticsearchConfiguration.Enable
? new ElasticsearchSinkOptions(
new Uri(
String.IsNullOrWhiteSpace(elasticsearchConfiguration.Host)
? throw new InvalidOperationException($"Missing {ElasticsearchConfiguration.Section}:{nameof(elasticsearchConfiguration.Host)}!")
: elasticsearchConfiguration.Host))
? new ElasticsearchSinkOptions(elasticsearchConfiguration.Host ?? throw new InvalidOperationException($"Missing {ElasticsearchConfiguration.Section}:{nameof(elasticsearchConfiguration.Host)}!"))
{
// Yes I know this means they cannot use a self signed cert unless they also have authentication, but lets be real here
// No one is going to be doing one of those but not the other
@@ -790,11 +790,17 @@ namespace Tgstation.Server.Host.Setup
do
{
await console.WriteAsync("ElasticSearch server endpoint (Include protocol and port, leave blank for http://127.0.0.1:9200): ", false, cancellationToken);
elasticsearchConfiguration.Host = await console.ReadLineAsync(false, cancellationToken);
if (!String.IsNullOrWhiteSpace(elasticsearchConfiguration.Host))
var hostString = await console.ReadLineAsync(false, cancellationToken);
if (String.IsNullOrWhiteSpace(hostString))
hostString = "http://127.0.0.1:9200";
if (Uri.TryCreate(hostString, UriKind.Absolute, out var host))
{
elasticsearchConfiguration.Host = host;
break;
}
await console.WriteAsync("Invalid URI!", true, cancellationToken);
}
while (true);
@@ -803,9 +809,7 @@ namespace Tgstation.Server.Host.Setup
await console.WriteAsync("Enter Elasticsearch username: ", false, cancellationToken);
elasticsearchConfiguration.Username = await console.ReadLineAsync(false, cancellationToken);
if (!String.IsNullOrWhiteSpace(elasticsearchConfiguration.Username))
{
break;
}
}
while (true);
@@ -814,9 +818,7 @@ namespace Tgstation.Server.Host.Setup
await console.WriteAsync("Enter password: ", false, cancellationToken);
elasticsearchConfiguration.Password = await console.ReadLineAsync(true, cancellationToken);
if (!String.IsNullOrWhiteSpace(elasticsearchConfiguration.Username))
{
break;
}
}
while (true);
}