Skip to content

Commit 003a365

Browse files
authored
Merge pull request #121 from nblumhardt/v2023-3
Update for Seq 2023.3
2 parents f25945d + 48bceda commit 003a365

File tree

12 files changed

+221
-278
lines changed

12 files changed

+221
-278
lines changed

example/SeqEnableAAD/Program.cs

Lines changed: 55 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44
using Seq.Api;
55
using Seq.Api.Model.Settings;
66

7-
namespace SeqEnableAAD
8-
{
9-
class Program
10-
{
11-
const string Usage = @"seq-enable-aad: enable authentication on your Seq server (for initial setup of a new Seq server only).
7+
const string usage = @"seq-enable-aad: enable authentication on your Seq server (for initial setup of a new Seq server only).
128
139
Usage:
1410
seq-enable-aad.exe <server> --uname=<un> --tenantid=<tid> --clientid=<cid> --clientkey=<ckey> [--authority=<a>]
@@ -21,71 +17,64 @@ class Program
2117
--clientid=<cid> Client ID.
2218
--clientkey=<ckey> Client key.
2319
--authority=<a> Authority (optional, defaults to 'login.windows.net').
24-
";
25-
static void Main(string[] args)
26-
{
27-
Task.Run(async () =>
28-
{
29-
try
30-
{
31-
var arguments = new Docopt().Apply(Usage, args, version: "Seq Enable AAD 0.1", exit: true);
20+
";
3221

33-
var server = arguments["<server>"].ToString();
34-
var username = Normalize(arguments["--uname"]);
35-
var tenantId = Normalize(arguments["--tenantid"]);
36-
var clientId = Normalize(arguments["--clientid"]);
37-
var clientKey = Normalize(arguments["--clientkey"]);
38-
var authority = Normalize(arguments["--authority"]);
22+
try
23+
{
24+
var arguments = new Docopt().Apply(usage, args, version: "Seq Enable AAD 0.1", exit: true)!;
3925

40-
await Run(server, username, tenantId, clientId, clientKey, authority);
41-
}
42-
catch (Exception ex)
43-
{
44-
Console.ForegroundColor = ConsoleColor.White;
45-
Console.BackgroundColor = ConsoleColor.Red;
46-
Console.WriteLine("seq-enable-aad: {0}", ex);
47-
Console.ResetColor();
48-
Environment.Exit(-1);
49-
}
50-
}).Wait();
51-
}
52-
53-
static string Normalize(ValueObject v)
54-
{
55-
if (v == null) return null;
56-
var s = v.ToString();
57-
return string.IsNullOrWhiteSpace(s) ? null : s;
58-
}
26+
var server = arguments["<server>"].ToString();
27+
var username = Normalize(arguments["--uname"]);
28+
var tenantId = Normalize(arguments["--tenantid"]);
29+
var clientId = Normalize(arguments["--clientid"]);
30+
var clientKey = Normalize(arguments["--clientkey"]);
31+
var authority = Normalize(arguments["--authority"]);
32+
33+
await Run(server, username, tenantId, clientId, clientKey, authority);
34+
}
35+
catch (Exception ex)
36+
{
37+
Console.ForegroundColor = ConsoleColor.White;
38+
Console.BackgroundColor = ConsoleColor.Red;
39+
Console.WriteLine("seq-enable-aad: {0}", ex);
40+
Console.ResetColor();
41+
Environment.Exit(-1);
42+
}
5943

60-
static async Task Run(string server, string username, string tenantId, string clientId, string clientKey, string authority="login.windows.net")
61-
{
62-
var connection = new SeqConnection(server);
44+
static string? Normalize(ValueObject? v)
45+
{
46+
if (v == null) return null;
47+
var s = v.ToString();
48+
return string.IsNullOrWhiteSpace(s) ? null : s;
49+
}
50+
51+
static async Task Run(string server, string? username, string? tenantId, string? clientId, string? clientKey, string? authority="login.windows.net")
52+
{
53+
var connection = new SeqConnection(server);
6354

64-
var user = await connection.Users.FindCurrentAsync();
65-
var provider = await connection.Settings.FindNamedAsync(SettingName.AuthenticationProvider);
66-
var cid = await connection.Settings.FindNamedAsync(SettingName.AzureADClientId);
67-
var ckey = await connection.Settings.FindNamedAsync(SettingName.AzureADClientKey);
68-
var aut = await connection.Settings.FindNamedAsync(SettingName.AzureADAuthority);
69-
var tid = await connection.Settings.FindNamedAsync(SettingName.AzureADTenantId);
55+
var user = await connection.Users.FindCurrentAsync();
56+
var provider = await connection.Settings.FindNamedAsync(SettingName.AuthenticationProvider);
57+
var cid = await connection.Settings.FindNamedAsync(SettingName.AzureADClientId);
58+
var ckey = await connection.Settings.FindNamedAsync(SettingName.AzureADClientKey);
59+
var aut = await connection.Settings.FindNamedAsync(SettingName.AzureADAuthority);
60+
var tid = await connection.Settings.FindNamedAsync(SettingName.AzureADTenantId);
7061

71-
user.Username = username;
72-
provider.Value = "Azure Active Directory";
73-
cid.Value = clientId;
74-
ckey.Value = clientKey;
75-
tid.Value = tenantId;
76-
aut.Value = authority;
62+
user.Username = username;
63+
provider.Value = "Azure Active Directory";
64+
cid.Value = clientId;
65+
ckey.Value = clientKey;
66+
tid.Value = tenantId;
67+
aut.Value = authority;
7768

78-
await connection.Users.UpdateAsync(user);
79-
await connection.Settings.UpdateAsync(cid);
80-
await connection.Settings.UpdateAsync(ckey);
81-
await connection.Settings.UpdateAsync(tid);
82-
await connection.Settings.UpdateAsync(aut);
69+
await connection.Users.UpdateAsync(user);
70+
await connection.Settings.UpdateAsync(cid);
71+
await connection.Settings.UpdateAsync(ckey);
72+
await connection.Settings.UpdateAsync(tid);
73+
await connection.Settings.UpdateAsync(aut);
8374

84-
await connection.Settings.UpdateAsync(provider); // needs to go before IsAuthenticationEnabled but after the other settings
85-
86-
var iae = await connection.Settings.FindNamedAsync(SettingName.IsAuthenticationEnabled);
87-
iae.Value = true;
88-
await connection.Settings.UpdateAsync(iae); // this update needs to happen last, as enabling auth will lock this connection out
89-
}
90-
}
91-
}
75+
await connection.Settings.UpdateAsync(provider); // needs to go before IsAuthenticationEnabled but after the other settings
76+
77+
var iae = await connection.Settings.FindNamedAsync(SettingName.IsAuthenticationEnabled);
78+
iae.Value = true;
79+
await connection.Settings.UpdateAsync(iae); // this update needs to happen last, as enabling auth will lock this connection out
80+
}

example/SeqEnableAAD/SeqEnableAAD.csproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>netcoreapp3.1</TargetFramework>
6-
<RootNamespace>SeqEnableAuth</RootNamespace>
5+
<TargetFramework>net6.0</TargetFramework>
6+
<AssemblyName>seq-enable-aad</AssemblyName>
7+
<Nullable>enable</Nullable>
78
</PropertyGroup>
89

910
<ItemGroup>
10-
<PackageReference Include="docopt.net" Version="0.6.1.9" />
11+
<PackageReference Include="docopt.net" Version="0.8.1" />
1112
</ItemGroup>
1213

1314
<ItemGroup>

example/SeqQuery/Program.cs

Lines changed: 33 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@
33
using DocoptNet;
44
using Seq.Api;
55

6-
namespace SeqQuery
7-
{
8-
class Program
9-
{
10-
const string Usage = @"seq-query: run Seq SQL queries from your console.
6+
const string usage = @"seq-query: run Seq SQL queries from your console.
117
128
Usage:
139
seq-query.exe <server> <query> [--apikey=<k>] [--from=<f>] [--to=<t>]
@@ -21,50 +17,42 @@ class Program
2117
2218
";
2319

24-
static void Main(string[] args)
25-
{
26-
Task.Run(async () =>
27-
{
28-
try
29-
{
30-
var arguments = new Docopt().Apply(Usage, args, version: "Seq Query 0.1", exit: true);
20+
try
21+
{
22+
var arguments = new Docopt().Apply(usage, args, version: "Seq Query 0.1", exit: true)!;
3123

32-
var server = arguments["<server>"].ToString();
33-
var query = Normalize(arguments["<query>"]);
34-
var apiKey = Normalize(arguments["--apikey"]);
35-
var from = Normalize(arguments["--from"]);
36-
var to = Normalize(arguments["--to"]);
24+
var server = arguments["<server>"].ToString();
25+
var query = Normalize(arguments["<query>"]);
26+
var apiKey = Normalize(arguments["--apikey"]);
27+
var from = Normalize(arguments["--from"]);
28+
var to = Normalize(arguments["--to"]);
3729

38-
await Run(server, apiKey, query, from, to);
39-
}
40-
catch (Exception ex)
41-
{
42-
Console.ForegroundColor = ConsoleColor.White;
43-
Console.BackgroundColor = ConsoleColor.Red;
44-
Console.WriteLine("seq-query: {0}", ex);
45-
Console.ResetColor();
46-
Environment.Exit(-1);
47-
}
48-
}).Wait();
49-
}
30+
await Run(server, apiKey, query, from, to);
31+
}
32+
catch (Exception ex)
33+
{
34+
Console.ForegroundColor = ConsoleColor.White;
35+
Console.BackgroundColor = ConsoleColor.Red;
36+
Console.WriteLine("seq-query: {0}", ex);
37+
Console.ResetColor();
38+
Environment.Exit(-1);
39+
}
5040

51-
static string Normalize(ValueObject v)
52-
{
53-
if (v == null) return null;
54-
var s = v.ToString();
55-
return string.IsNullOrWhiteSpace(s) ? null : s;
56-
}
41+
static string? Normalize(ValueObject? v)
42+
{
43+
if (v == null) return null;
44+
var s = v.ToString();
45+
return string.IsNullOrWhiteSpace(s) ? null : s;
46+
}
5747

58-
static async Task Run(string server, string apiKey, string query, string from, string to)
59-
{
60-
var connection = new SeqConnection(server, apiKey);
48+
static async Task Run(string server, string? apiKey, string? query, string? from, string? to)
49+
{
50+
var connection = new SeqConnection(server, apiKey);
6151

62-
var now = DateTime.UtcNow;
63-
var rangeStartUtc = from != null ? DateTime.Parse(from) : now - TimeSpan.FromDays(1);
64-
DateTime? rangeEndUtc = to != null ? DateTime.Parse(to) : now;
52+
var now = DateTime.UtcNow;
53+
var rangeStartUtc = from != null ? DateTime.Parse(from) : now - TimeSpan.FromDays(1);
54+
DateTime? rangeEndUtc = to != null ? DateTime.Parse(to) : now;
6555

66-
var result = await connection.Data.QueryCsvAsync(query, rangeStartUtc, rangeEndUtc);
67-
Console.WriteLine(result);
68-
}
69-
}
56+
var result = await connection.Data.QueryCsvAsync(query, rangeStartUtc, rangeEndUtc);
57+
Console.WriteLine(result);
7058
}

example/SeqQuery/SeqQuery.csproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net461;netcoreapp2.2</TargetFrameworks>
5-
<AssemblyName>seq-query</AssemblyName>
4+
<TargetFramework>net6.0</TargetFramework>
65
<OutputType>Exe</OutputType>
6+
<AssemblyName>seq-query</AssemblyName>
7+
<Nullable>enable</Nullable>
78
</PropertyGroup>
89

910
<ItemGroup>
1011
<ProjectReference Include="..\..\src\Seq.Api\Seq.Api.csproj" />
1112
</ItemGroup>
1213

1314
<ItemGroup>
14-
<PackageReference Include="docopt.net" Version="0.6.1.9" />
15+
<PackageReference Include="docopt.net" Version="0.8.1" />
1516
</ItemGroup>
1617

1718
</Project>

0 commit comments

Comments
 (0)