44using Seq . Api ;
55using 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
139Usage:
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+ }
0 commit comments