Skip to content

Commit

Permalink
Merge pull request #122 from datalust/dev
Browse files Browse the repository at this point in the history
2023.3.0 Release
  • Loading branch information
nblumhardt authored Jul 7, 2023
2 parents 0d3fe79 + 003a365 commit 4658702
Show file tree
Hide file tree
Showing 12 changed files with 221 additions and 278 deletions.
121 changes: 55 additions & 66 deletions example/SeqEnableAAD/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
using Seq.Api;
using Seq.Api.Model.Settings;

namespace SeqEnableAAD
{
class Program
{
const string Usage = @"seq-enable-aad: enable authentication on your Seq server (for initial setup of a new Seq server only).
const string usage = @"seq-enable-aad: enable authentication on your Seq server (for initial setup of a new Seq server only).
Usage:
seq-enable-aad.exe <server> --uname=<un> --tenantid=<tid> --clientid=<cid> --clientkey=<ckey> [--authority=<a>]
Expand All @@ -21,71 +17,64 @@ class Program
--clientid=<cid> Client ID.
--clientkey=<ckey> Client key.
--authority=<a> Authority (optional, defaults to 'login.windows.net').
";
static void Main(string[] args)
{
Task.Run(async () =>
{
try
{
var arguments = new Docopt().Apply(Usage, args, version: "Seq Enable AAD 0.1", exit: true);
";

var server = arguments["<server>"].ToString();
var username = Normalize(arguments["--uname"]);
var tenantId = Normalize(arguments["--tenantid"]);
var clientId = Normalize(arguments["--clientid"]);
var clientKey = Normalize(arguments["--clientkey"]);
var authority = Normalize(arguments["--authority"]);
try
{
var arguments = new Docopt().Apply(usage, args, version: "Seq Enable AAD 0.1", exit: true)!;

await Run(server, username, tenantId, clientId, clientKey, authority);
}
catch (Exception ex)
{
Console.ForegroundColor = ConsoleColor.White;
Console.BackgroundColor = ConsoleColor.Red;
Console.WriteLine("seq-enable-aad: {0}", ex);
Console.ResetColor();
Environment.Exit(-1);
}
}).Wait();
}

static string Normalize(ValueObject v)
{
if (v == null) return null;
var s = v.ToString();
return string.IsNullOrWhiteSpace(s) ? null : s;
}
var server = arguments["<server>"].ToString();
var username = Normalize(arguments["--uname"]);
var tenantId = Normalize(arguments["--tenantid"]);
var clientId = Normalize(arguments["--clientid"]);
var clientKey = Normalize(arguments["--clientkey"]);
var authority = Normalize(arguments["--authority"]);

await Run(server, username, tenantId, clientId, clientKey, authority);
}
catch (Exception ex)
{
Console.ForegroundColor = ConsoleColor.White;
Console.BackgroundColor = ConsoleColor.Red;
Console.WriteLine("seq-enable-aad: {0}", ex);
Console.ResetColor();
Environment.Exit(-1);
}

static async Task Run(string server, string username, string tenantId, string clientId, string clientKey, string authority="login.windows.net")
{
var connection = new SeqConnection(server);
static string? Normalize(ValueObject? v)
{
if (v == null) return null;
var s = v.ToString();
return string.IsNullOrWhiteSpace(s) ? null : s;
}

static async Task Run(string server, string? username, string? tenantId, string? clientId, string? clientKey, string? authority="login.windows.net")
{
var connection = new SeqConnection(server);

var user = await connection.Users.FindCurrentAsync();
var provider = await connection.Settings.FindNamedAsync(SettingName.AuthenticationProvider);
var cid = await connection.Settings.FindNamedAsync(SettingName.AzureADClientId);
var ckey = await connection.Settings.FindNamedAsync(SettingName.AzureADClientKey);
var aut = await connection.Settings.FindNamedAsync(SettingName.AzureADAuthority);
var tid = await connection.Settings.FindNamedAsync(SettingName.AzureADTenantId);
var user = await connection.Users.FindCurrentAsync();
var provider = await connection.Settings.FindNamedAsync(SettingName.AuthenticationProvider);
var cid = await connection.Settings.FindNamedAsync(SettingName.AzureADClientId);
var ckey = await connection.Settings.FindNamedAsync(SettingName.AzureADClientKey);
var aut = await connection.Settings.FindNamedAsync(SettingName.AzureADAuthority);
var tid = await connection.Settings.FindNamedAsync(SettingName.AzureADTenantId);

user.Username = username;
provider.Value = "Azure Active Directory";
cid.Value = clientId;
ckey.Value = clientKey;
tid.Value = tenantId;
aut.Value = authority;
user.Username = username;
provider.Value = "Azure Active Directory";
cid.Value = clientId;
ckey.Value = clientKey;
tid.Value = tenantId;
aut.Value = authority;

await connection.Users.UpdateAsync(user);
await connection.Settings.UpdateAsync(cid);
await connection.Settings.UpdateAsync(ckey);
await connection.Settings.UpdateAsync(tid);
await connection.Settings.UpdateAsync(aut);
await connection.Users.UpdateAsync(user);
await connection.Settings.UpdateAsync(cid);
await connection.Settings.UpdateAsync(ckey);
await connection.Settings.UpdateAsync(tid);
await connection.Settings.UpdateAsync(aut);

await connection.Settings.UpdateAsync(provider); // needs to go before IsAuthenticationEnabled but after the other settings

var iae = await connection.Settings.FindNamedAsync(SettingName.IsAuthenticationEnabled);
iae.Value = true;
await connection.Settings.UpdateAsync(iae); // this update needs to happen last, as enabling auth will lock this connection out
}
}
}
await connection.Settings.UpdateAsync(provider); // needs to go before IsAuthenticationEnabled but after the other settings

var iae = await connection.Settings.FindNamedAsync(SettingName.IsAuthenticationEnabled);
iae.Value = true;
await connection.Settings.UpdateAsync(iae); // this update needs to happen last, as enabling auth will lock this connection out
}
7 changes: 4 additions & 3 deletions example/SeqEnableAAD/SeqEnableAAD.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>SeqEnableAuth</RootNamespace>
<TargetFramework>net6.0</TargetFramework>
<AssemblyName>seq-enable-aad</AssemblyName>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="docopt.net" Version="0.6.1.9" />
<PackageReference Include="docopt.net" Version="0.8.1" />
</ItemGroup>

<ItemGroup>
Expand Down
78 changes: 33 additions & 45 deletions example/SeqQuery/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
using DocoptNet;
using Seq.Api;

namespace SeqQuery
{
class Program
{
const string Usage = @"seq-query: run Seq SQL queries from your console.
const string usage = @"seq-query: run Seq SQL queries from your console.
Usage:
seq-query.exe <server> <query> [--apikey=<k>] [--from=<f>] [--to=<t>]
Expand All @@ -21,50 +17,42 @@ class Program
";

static void Main(string[] args)
{
Task.Run(async () =>
{
try
{
var arguments = new Docopt().Apply(Usage, args, version: "Seq Query 0.1", exit: true);
try
{
var arguments = new Docopt().Apply(usage, args, version: "Seq Query 0.1", exit: true)!;

var server = arguments["<server>"].ToString();
var query = Normalize(arguments["<query>"]);
var apiKey = Normalize(arguments["--apikey"]);
var from = Normalize(arguments["--from"]);
var to = Normalize(arguments["--to"]);
var server = arguments["<server>"].ToString();
var query = Normalize(arguments["<query>"]);
var apiKey = Normalize(arguments["--apikey"]);
var from = Normalize(arguments["--from"]);
var to = Normalize(arguments["--to"]);

await Run(server, apiKey, query, from, to);
}
catch (Exception ex)
{
Console.ForegroundColor = ConsoleColor.White;
Console.BackgroundColor = ConsoleColor.Red;
Console.WriteLine("seq-query: {0}", ex);
Console.ResetColor();
Environment.Exit(-1);
}
}).Wait();
}
await Run(server, apiKey, query, from, to);
}
catch (Exception ex)
{
Console.ForegroundColor = ConsoleColor.White;
Console.BackgroundColor = ConsoleColor.Red;
Console.WriteLine("seq-query: {0}", ex);
Console.ResetColor();
Environment.Exit(-1);
}

static string Normalize(ValueObject v)
{
if (v == null) return null;
var s = v.ToString();
return string.IsNullOrWhiteSpace(s) ? null : s;
}
static string? Normalize(ValueObject? v)
{
if (v == null) return null;
var s = v.ToString();
return string.IsNullOrWhiteSpace(s) ? null : s;
}

static async Task Run(string server, string apiKey, string query, string from, string to)
{
var connection = new SeqConnection(server, apiKey);
static async Task Run(string server, string? apiKey, string? query, string? from, string? to)
{
var connection = new SeqConnection(server, apiKey);

var now = DateTime.UtcNow;
var rangeStartUtc = from != null ? DateTime.Parse(from) : now - TimeSpan.FromDays(1);
DateTime? rangeEndUtc = to != null ? DateTime.Parse(to) : now;
var now = DateTime.UtcNow;
var rangeStartUtc = from != null ? DateTime.Parse(from) : now - TimeSpan.FromDays(1);
DateTime? rangeEndUtc = to != null ? DateTime.Parse(to) : now;

var result = await connection.Data.QueryCsvAsync(query, rangeStartUtc, rangeEndUtc);
Console.WriteLine(result);
}
}
var result = await connection.Data.QueryCsvAsync(query, rangeStartUtc, rangeEndUtc);
Console.WriteLine(result);
}
7 changes: 4 additions & 3 deletions example/SeqQuery/SeqQuery.csproj
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net461;netcoreapp2.2</TargetFrameworks>
<AssemblyName>seq-query</AssemblyName>
<TargetFramework>net6.0</TargetFramework>
<OutputType>Exe</OutputType>
<AssemblyName>seq-query</AssemblyName>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Seq.Api\Seq.Api.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="docopt.net" Version="0.6.1.9" />
<PackageReference Include="docopt.net" Version="0.8.1" />
</ItemGroup>

</Project>
Loading

0 comments on commit 4658702

Please sign in to comment.