-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
64 lines (62 loc) · 2.57 KB
/
Copy pathProgram.cs
File metadata and controls
64 lines (62 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NServiceKit.CacheAccess;
using NServiceKit.CacheAccess.Providers;
using NServiceKit.Configuration;
using NServiceKit.Logging;
using NServiceKit.ServiceInterface;
using NServiceKit.ServiceInterface.Admin;
using NServiceKit.ServiceInterface.Auth;
using NServiceKit.ServiceInterface.Providers;
using NServiceKit.Text;
namespace Repository {
public static class Program {
public static void Main(string[] args) {
var appSettings = new AppSettings();
LogManager.LogFactory = new NServiceKit.Logging.Support.Logging.ConsoleLogFactory();
var userRepository = new InMemoryAuthRepository();
var adminPassword = appSettings.GetString("adminPassword");
if (args.Length >= 1) {
adminPassword = args[0];
}
if (adminPassword != null) {
var newUser = userRepository.CreateUserAuth(new UserAuth {
UserName = "admin",
}, adminPassword);
userRepository.SaveUserAuth(newUser);
Console.WriteLine("Admin account added from settings.");
}
var port = appSettings.Get<int>("port", 3000);
if (args.Length >= 2) {
port = Int32.Parse(args[1]);
}
using (var host = new AppHost()) {
host.PreRequestFilters.Insert(0, (httpReq, httpRes) => {
httpReq.UseBufferedStream = true;
});
host.Config.DebugMode = true;
host.Plugins.Add(new AuthFeature(createSession, new IAuthProvider[] { new BasicAuthProvider() }, "/builds"));
host.Plugins.Add(new RequestLogsFeature() { RequiredRoles = new string[0] });
host.Container.Register<ICacheClient>(new MemoryCacheClient());
host.Container.Register<IUserAuthRepository>(userRepository);
{
host.Init();
host.Start($"http://*:{port}/");
Console.WriteLine($"Listening on port {port}.");
Console.WriteLine("Press Q to exit.");
var shouldExit = false;
do {
shouldExit = Console.ReadKey(true).Key == ConsoleKey.Q;
} while (!shouldExit);
host.Stop();
}
}
}
private static IAuthSession createSession() {
return new AuthUserSession();
}
}
}