Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add seqcli setting names|show|set|clear commands #299

Merged
merged 7 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/SeqCli/Apps/Definitions/AppDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#nullable enable

using System.Collections.Generic;
using Newtonsoft.Json;

Expand Down
2 changes: 0 additions & 2 deletions src/SeqCli/Apps/Definitions/AppMetadataReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
using System.Reflection;
using Seq.Apps;

#nullable enable

namespace SeqCli.Apps.Definitions;

static class AppMetadataReader
Expand Down
2 changes: 0 additions & 2 deletions src/SeqCli/Apps/Definitions/AppSettingDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

using Newtonsoft.Json;

#nullable enable

namespace SeqCli.Apps.Definitions;

// ReSharper disable all
Expand Down
2 changes: 0 additions & 2 deletions src/SeqCli/Cli/CommandLineHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
using Serilog.Core;
using Serilog.Events;

#nullable enable

namespace SeqCli.Cli;

class CommandLineHost
Expand Down
2 changes: 0 additions & 2 deletions src/SeqCli/Cli/Commands/App/InstallCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
using SeqCli.Util;
using Serilog;

#nullable enable

namespace SeqCli.Cli.Commands.App;

[Command("app", "install", "Install an app package",
Expand Down
2 changes: 0 additions & 2 deletions src/SeqCli/Cli/Commands/App/UpdateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
using SeqCli.Util;
using Serilog;

#nullable enable

namespace SeqCli.Cli.Commands.App;

[Command("app", "update", "Update an installed app package",
Expand Down
2 changes: 0 additions & 2 deletions src/SeqCli/Cli/Commands/Bench/BenchCase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#nullable enable

namespace SeqCli.Cli.Commands.Bench;

// ReSharper disable ClassNeverInstantiated.Global AutoPropertyCanBeMadeGetOnly.Global UnusedAutoPropertyAccessor.Global
Expand Down
1 change: 0 additions & 1 deletion src/SeqCli/Cli/Commands/Bench/BenchCaseTimings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down
1 change: 0 additions & 1 deletion src/SeqCli/Cli/Commands/Bench/BenchCasesCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#nullable enable
using System.Collections.Generic;

namespace SeqCli.Cli.Commands.Bench;
Expand Down
2 changes: 0 additions & 2 deletions src/SeqCli/Cli/Commands/Bench/BenchCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#nullable enable

using System;
using System.IO;
using System.Linq;
Expand Down
2 changes: 0 additions & 2 deletions src/SeqCli/Cli/Commands/License/ApplyCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

// ReSharper disable once UnusedType.Global

#nullable enable

namespace SeqCli.Cli.Commands.License;

[Command("license", "apply", "Apply a license to the Seq server",
Expand Down
18 changes: 15 additions & 3 deletions src/SeqCli/Cli/Commands/Node/DemoteCommand.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
using System;
// Copyright Datalust Pty Ltd and Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using System.Linq;
using System.Threading.Tasks;
using Seq.Api.Model.Cluster;
using SeqCli.Cli.Features;
using SeqCli.Connection;
using Serilog;

#nullable enable

namespace SeqCli.Cli.Commands.Node;

[Command("node", "demote", "Begin demotion of the current leader node",
Expand Down
18 changes: 15 additions & 3 deletions src/SeqCli/Cli/Commands/Node/HealthCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
using System;
// Copyright Datalust Pty Ltd and Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
Expand All @@ -7,8 +21,6 @@
using SeqCli.Util;
using Serilog;

#nullable enable

namespace SeqCli.Cli.Commands.Node;

[Command("node", "health",
Expand Down
2 changes: 0 additions & 2 deletions src/SeqCli/Cli/Commands/Node/ListCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
using SeqCli.Config;
using SeqCli.Connection;

#nullable enable

namespace SeqCli.Cli.Commands.Node;

[Command("node", "list", "List nodes in the Seq cluster",
Expand Down
2 changes: 0 additions & 2 deletions src/SeqCli/Cli/Commands/SearchCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
using Serilog.Parsing;
// ReSharper disable UnusedType.Global

#nullable enable

namespace SeqCli.Cli.Commands;

[Command("search", "Retrieve log events that match a given filter",
Expand Down
48 changes: 48 additions & 0 deletions src/SeqCli/Cli/Commands/Settings/ClearCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright Datalust Pty Ltd and Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using System.Threading.Tasks;
using SeqCli.Cli.Features;
using SeqCli.Connection;

namespace SeqCli.Cli.Commands.Settings;

[Command("setting", "clear", "Clear a runtime-configurable server setting")]
class ClearCommand: Command
{
readonly SeqConnectionFactory _connectionFactory;

readonly ConnectionFeature _connection;
readonly SettingNameFeature _name;

public ClearCommand(SeqConnectionFactory connectionFactory)
{
_connectionFactory = connectionFactory ?? throw new ArgumentNullException(nameof(connectionFactory));

_name = Enable<SettingNameFeature>();
_connection = Enable<ConnectionFeature>();
}

protected override async Task<int> Run()
{
var connection = _connectionFactory.Connect(_connection);

var setting = await connection.Settings.FindNamedAsync(_name.Name);
setting.Value = null;
await connection.Settings.UpdateAsync(setting);

return 0;
}
}
34 changes: 34 additions & 0 deletions src/SeqCli/Cli/Commands/Settings/NamesCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright Datalust Pty Ltd and Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using System.Linq;
using System.Threading.Tasks;
using Seq.Api.Model.Settings;

namespace SeqCli.Cli.Commands.Settings;

[Command("setting", "names", "Print the names of all supported settings")]
class NamesCommand: Command
{
protected override Task<int> Run(string[] unrecognized)
{
foreach (var name in Enum.GetNames(typeof(SettingName)).Order())
{
Console.WriteLine(name);
}

return Task.FromResult(0);
}
}
80 changes: 80 additions & 0 deletions src/SeqCli/Cli/Commands/Settings/SetCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Copyright Datalust Pty Ltd and Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using System.Threading.Tasks;
using SeqCli.Cli.Features;
using SeqCli.Connection;
using Serilog;

namespace SeqCli.Cli.Commands.Settings;

[Command("setting", "set", "Change a runtime-configurable server setting")]
class SetCommand: Command
{
readonly SeqConnectionFactory _connectionFactory;

readonly ConnectionFeature _connection;
readonly SettingNameFeature _name;

string? _value;
bool _valueSpecified, _readValueFromStdin;

public SetCommand(SeqConnectionFactory connectionFactory)
{
_connectionFactory = connectionFactory ?? throw new ArgumentNullException(nameof(connectionFactory));

_name = Enable<SettingNameFeature>();

Options.Add("v|value=",
"The setting value, comma-separated if multiple values are accepted",
v =>
{
// Not normalized; some settings might include leading/trailing whitespace.
_valueSpecified = true;
_value = v;
});

Options.Add("value-stdin",
"Read the value from `STDIN`",
_ => _readValueFromStdin = true);

_connection = Enable<ConnectionFeature>();
}

protected override async Task<int> Run()
{
if (!_valueSpecified && !_readValueFromStdin)
{
Log.Error("A value must be supplied with either `--value=VALUE` or `--value-stdin`.");
return 1;
}

var connection = _connectionFactory.Connect(_connection);

var setting = await connection.Settings.FindNamedAsync(_name.Name);
setting.Value = ReadValue();
await connection.Settings.UpdateAsync(setting);

return 0;
}

string? ReadValue()
{
if (_readValueFromStdin)
return Console.In.ReadToEnd().TrimEnd('\r', '\n');

return _value;
}
}
52 changes: 52 additions & 0 deletions src/SeqCli/Cli/Commands/Settings/ShowCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright Datalust Pty Ltd and Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using System.Globalization;
using System.Threading.Tasks;
using SeqCli.Cli.Features;
using SeqCli.Connection;

namespace SeqCli.Cli.Commands.Settings;

[Command("setting", "show", "Print the current value of a runtime-configurable server setting")]
class ShowCommand: Command
{
readonly SeqConnectionFactory _connectionFactory;

readonly ConnectionFeature _connection;
readonly SettingNameFeature _name;

public ShowCommand(SeqConnectionFactory connectionFactory)
{
_connectionFactory = connectionFactory ?? throw new ArgumentNullException(nameof(connectionFactory));

_name = Enable<SettingNameFeature>();
_connection = Enable<ConnectionFeature>();
}

protected override async Task<int> Run()
{
var connection = _connectionFactory.Connect(_connection);

var setting = await connection.Settings.FindNamedAsync(_name.Name);

if (setting.Value != null)
{
Console.Write(setting.Value is IFormattable f ? f.ToString(null, CultureInfo.InvariantCulture) : setting.Value.ToString());
}

return 0;
}
}
Loading