Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ seqcli config -k connection.serverUrl -v https://your-seq-server
seqcli config -k connection.apiKey -v your-api-key
```

The API key will be stored in your `SeqCli.json` configuration file; on Windows, this is encrypted using DPAPI; on Mac/Linux the key is currently stored in plain text. As an alternative to storing the API key in configuration, it can be passed to each command via the `--apikey=` argument.
The API key will be stored in your `SeqCli.json` (or `SEQCLI_CONFIG_FILE`) configuration file; on Windows, this is encrypted using DPAPI; on Mac/Linux the key is currently stored in plain text. As an alternative to storing the API key in configuration, it can be passed to each command via the `--apikey=` argument.

`seqcli` is also available as a Docker container under [`datalust/seqcli`](https://store.docker.com/community/images/datalust/seqcli):

Expand Down Expand Up @@ -113,7 +113,7 @@ seqcli help apikey
- [`appinstance remove`](#appinstance-remove) — Remove an app instance from the server.
- [`appinstance update`](#appinstance-update) — Update an existing app instance.
- [`bench`](#bench) — Measure query performance.
- [`config`](#config) — View and set fields in the `SeqCli.json` file; run with no arguments to list all fields.
- [`config`](#config) — View and set fields in the `SeqCli.json` (or `SEQCLI_CONFIG_PATH`) file; run with no arguments to list all fields.
- `dashboard`
- [`dashboard list`](#dashboard-list) — List dashboards.
- [`dashboard remove`](#dashboard-remove) — Remove a dashboard from the server.
Expand Down Expand Up @@ -491,7 +491,7 @@ Measure query performance.

### `config`

View and set fields in the `SeqCli.json` file; run with no arguments to list all fields.
View and set fields in the default `SeqCli.json` or environment-specified `SEQCLI_CONFIG_FILE` file; run with no arguments to list all fields.

| Option | Description |
| ------ | ----------- |
Expand Down
8 changes: 4 additions & 4 deletions src/SeqCli/Cli/Commands/ConfigCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

namespace SeqCli.Cli.Commands;

[Command("config", "View and set fields in the `SeqCli.json` file; run with no arguments to list all fields")]
[Command("config", "View and set fields in the default `SeqCli.json` or environment-specified `SEQCLI_CONFIG_FILE` file; run with no arguments to list all fields")]
class ConfigCommand : Command
{
string? _key, _value;
Expand All @@ -44,21 +44,21 @@ protected override Task<int> Run()

try
{
var config = SeqCliConfig.ReadFromFile(RuntimeConfigurationLoader.DefaultConfigFilename);
var config = SeqCliConfig.ReadFromFile(RuntimeConfigurationLoader.SeqCliConfigFilename());

if (_key != null)
{
if (_clear)
{
verb = "clear";
KeyValueSettings.Clear(config, _key);
SeqCliConfig.WriteToFile(config, RuntimeConfigurationLoader.DefaultConfigFilename);
SeqCliConfig.WriteToFile(config, RuntimeConfigurationLoader.SeqCliConfigFilename());
}
else if (_value != null)
{
verb = "update";
KeyValueSettings.Set(config, _key, _value);
SeqCliConfig.WriteToFile(config, RuntimeConfigurationLoader.DefaultConfigFilename);
SeqCliConfig.WriteToFile(config, RuntimeConfigurationLoader.SeqCliConfigFilename());
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions src/SeqCli/Cli/Commands/Profile/CreateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ int RunSync()

try
{
var config = SeqCliConfig.ReadFromFile(RuntimeConfigurationLoader.DefaultConfigFilename);
var config = SeqCliConfig.ReadFromFile(RuntimeConfigurationLoader.SeqCliConfigFilename());
config.Profiles[_name] = new SeqCliConnectionConfig { ServerUrl = _url, ApiKey = _apiKey };
SeqCliConfig.WriteToFile(config, RuntimeConfigurationLoader.DefaultConfigFilename);
SeqCliConfig.WriteToFile(config, RuntimeConfigurationLoader.SeqCliConfigFilename());
return 0;
}
catch (Exception ex)
Expand Down
4 changes: 2 additions & 2 deletions src/SeqCli/Cli/Commands/Profile/RemoveCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ int RunSync()

try
{
var config = SeqCliConfig.ReadFromFile(RuntimeConfigurationLoader.DefaultConfigFilename);
var config = SeqCliConfig.ReadFromFile(RuntimeConfigurationLoader.SeqCliConfigFilename());
if (!config.Profiles.Remove(_name))
{
Log.Error("No profile with name {ProfileName} was found", _name);
return 1;
}

SeqCliConfig.WriteToFile(config, RuntimeConfigurationLoader.DefaultConfigFilename);
SeqCliConfig.WriteToFile(config, RuntimeConfigurationLoader.SeqCliConfigFilename());

return 0;
}
Expand Down
23 changes: 17 additions & 6 deletions src/SeqCli/Config/RuntimeConfigurationLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,28 @@ static class RuntimeConfigurationLoader
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "SeqCli.json");

const string DefaultEnvironmentVariablePrefix = "SEQCLI_";

/// <summary>
/// This is the method to use when loading configuration for runtime use. It will read the default configuration
/// file, if any, and apply overrides from the environment.
/// </summary>
public static SeqCliConfig Load()
{
var config = SeqCliConfig.ReadFromFile(DefaultConfigFilename);
var config = SeqCliConfig.ReadFromFile(SeqCliConfigFilename());

EnvironmentOverrides.Apply(DefaultEnvironmentVariablePrefix, config);

return config;
}
}
}

public static string SeqCliConfigFilename()
{
var customConfigFilename = Environment.GetEnvironmentVariable("SEQCLI_CONFIG_FILE");
if (!string.IsNullOrEmpty(customConfigFilename))
{
return customConfigFilename;
}

return DefaultConfigFilename;
}
}
30 changes: 30 additions & 0 deletions test/SeqCli.Tests/Config/ConfigFileLocationTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.IO;
using SeqCli.Config;
using Xunit;

namespace SeqCli.Tests.Config;

public class ConfigFileLocationTests
{
[Fact]
public void DefaultConfigFilename()
{
var configFile = RuntimeConfigurationLoader.SeqCliConfigFilename();

Assert.Equal(configFile, RuntimeConfigurationLoader.DefaultConfigFilename);
}

[Fact]
public void EnvironmentOverridenConfigFilename()
{
var tempConfigFile = Path.GetTempFileName();
Environment.SetEnvironmentVariable("SEQCLI_CONFIG_FILE", tempConfigFile);
var configFile = RuntimeConfigurationLoader.SeqCliConfigFilename();
// Clean up immediately to avoid affecting environment for other tests
// TODO: Or better move to public void Dispose() ?
Environment.SetEnvironmentVariable("SEQCLI_CONFIG_FILE", null);

Assert.Equal(tempConfigFile, configFile);
}
}