Compare commits
4 Commits
d2cba1fb34
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 1974f36b24 | |||
| a75c952f45 | |||
| be1e2041ff | |||
| e237a248ca |
+1
-1
Submodule ModeusSchedule.MSAuth updated: 5b906d6d07...89316e247f
@@ -23,10 +23,9 @@
|
||||
- `employees.json` для локального индекса сотрудников;
|
||||
- `keys/` для ключей Data Protection;
|
||||
- `Plugins/` для загружаемых плагинов.
|
||||
4. Настраивает логирование в консоль, а при наличии `TG_CHAT_ID` и `TG_TOKEN` ещё и отправку ошибок в Telegram.
|
||||
5. Подключает Sentry, Swagger, Prometheus, rate limiter, API key auth и OpenID Connect через `Microsoft.Identity.Web`.
|
||||
6. Загружает все плагины `*.plugin.dll` из `data/Plugins` в отдельном `AssemblyLoadContext`.
|
||||
7. Инициализирует Quartz-задачи:
|
||||
4. Подключает Sentry, Swagger, Prometheus, rate limiter, API key auth и OpenID Connect через `Microsoft.Identity.Web`.
|
||||
5. Загружает все плагины `*.plugin.dll` из `data/Plugins` в отдельном `AssemblyLoadContext`.
|
||||
6. Инициализирует Quartz-задачи:
|
||||
- обновление JWT;
|
||||
- обновление локального списка сотрудников;
|
||||
- цепочку, при которой после успешного обновления JWT сразу запускается обновление сотрудников.
|
||||
@@ -180,8 +179,6 @@ MVC-контроллеры из плагинов тоже подключаютс
|
||||
| `PERMIT_LIMIT` | Нет | `40` | код | Лимит запросов в окне rate limiter |
|
||||
| `TIME_LIMIT` | Нет | `10` | код | Длина окна rate limiter в секундах |
|
||||
| `TZ` | Нет | `Europe/Moscow` | код | Таймзона для запросов к`Modeus` и генерации `ICS` |
|
||||
| `TG_CHAT_ID` | Нет | нет | код | Chat ID для Telegram-логирования |
|
||||
| `TG_TOKEN` | Нет | нет | код | Bot token для Telegram-логирования |
|
||||
| `Sentry:Dsn` | Нет | пустая строка | код | DSN для Sentry |
|
||||
|
||||
### Переменные для Microsoft / Azure AD
|
||||
@@ -214,7 +211,6 @@ MVC-контроллеры из плагинов тоже подключаютс
|
||||
- нужен `TOKEN` или рабочий `AUTH_URL`, чтобы ходить в `Modeus`;
|
||||
- нужен `API_KEY`, если вы хотите использовать `GET /api/schedule/getguid`;
|
||||
- нужны `AzureAd:*`, если используется `GET /api/sfedu/guid`;
|
||||
- нужны `TG_CHAT_ID` и `TG_TOKEN`, если хотите логирование в Telegram;
|
||||
- нужен `Sentry:Dsn`, если хотите отправлять ошибки и трейсы в Sentry.
|
||||
|
||||
## Пример `.env`
|
||||
|
||||
@@ -11,10 +11,6 @@ public static class AppConsts
|
||||
public const string ModeusUrlEnv = "MODEUS_URL";
|
||||
public const string ModeusDefaultUrl = "https://sfedu.modeus.org/";
|
||||
|
||||
// Telegram
|
||||
public const string TgChatIdEnv = "TG_CHAT_ID";
|
||||
public const string TgTokenEnv = "TG_TOKEN";
|
||||
|
||||
// RateLimiter
|
||||
public const string PermitLimitEnv = "PERMIT_LIMIT";
|
||||
public const string TimeLimitEnv = "TIME_LIMIT";
|
||||
|
||||
@@ -18,7 +18,6 @@ using SfeduSchedule.Jobs;
|
||||
using SfeduSchedule.Logging;
|
||||
using SfeduSchedule.Middleware;
|
||||
using SfeduSchedule.Services;
|
||||
using X.Extensions.Logging.Telegram.Extensions;
|
||||
using IPNetwork = Microsoft.AspNetCore.HttpOverrides.IPNetwork;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
@@ -59,26 +58,6 @@ builder.Logging.AddConsole(options => options.FormatterName = "CustomConsoleForm
|
||||
.AddConsoleFormatter<ConsoleFormatter, ConsoleFormatterOptions>();
|
||||
|
||||
builder.Logging.AddFilter("Quartz", LogLevel.Warning);
|
||||
if (!string.IsNullOrEmpty(configuration[AppConsts.TgChatIdEnv]) && !string.IsNullOrEmpty(configuration[AppConsts.TgTokenEnv]))
|
||||
builder.Logging.AddTelegram(options =>
|
||||
{
|
||||
options.FormatterConfiguration = new X.Extensions.Logging.Telegram.Base.Configuration.FormatterConfiguration
|
||||
{
|
||||
IncludeException = true,
|
||||
IncludeProperties = true,
|
||||
};
|
||||
options.ChatId = configuration[AppConsts.TgChatIdEnv]!;
|
||||
options.AccessToken = configuration[AppConsts.TgTokenEnv]!;
|
||||
options.FormatterConfiguration.UseEmoji = true;
|
||||
options.FormatterConfiguration.ReadableApplicationName = "Modeus Schedule Proxy";
|
||||
options.LogLevel = new Dictionary<string, LogLevel>
|
||||
{
|
||||
{ "Default", LogLevel.Error },
|
||||
{ "SfeduSchedule.Jobs.UpdateJwtJob", LogLevel.Information },
|
||||
{ "Program", LogLevel.Information },
|
||||
{ "Quartz", LogLevel.Warning }
|
||||
};
|
||||
});
|
||||
#endregion
|
||||
|
||||
builder.WebHost.UseSentry(options =>
|
||||
|
||||
@@ -3,7 +3,7 @@ using System.Text.Json;
|
||||
|
||||
namespace SfeduSchedule.Services;
|
||||
|
||||
public class ModeusEmployeeService(ISchedulerFactory schedulerFactory)
|
||||
public class ModeusEmployeeService
|
||||
: IHostedService
|
||||
{
|
||||
private Dictionary<string, (string, List<string>)> _employees = []; // ФИО (ИД, Список должностей)
|
||||
@@ -18,14 +18,14 @@ public class ModeusEmployeeService(ISchedulerFactory schedulerFactory)
|
||||
.OrderBy(e => e.Key)
|
||||
.Take(size)
|
||||
.ToDictionary(e => e.Key, e => e.Value);
|
||||
|
||||
|
||||
return _employees
|
||||
.Where(e => e.Key.Contains(fullname, StringComparison.OrdinalIgnoreCase))
|
||||
.OrderBy(e => e.Key)
|
||||
.Take(size)
|
||||
.ToDictionary(e => e.Key, e => e.Value);
|
||||
}
|
||||
|
||||
|
||||
public bool IsInitialized()
|
||||
{
|
||||
return _employees.Count > 0;
|
||||
@@ -70,7 +70,7 @@ public class ModeusEmployeeService(ISchedulerFactory schedulerFactory)
|
||||
|
||||
private async Task LoadEmployeesFromDisk()
|
||||
{
|
||||
|
||||
|
||||
if (File.Exists(_employeesFilePath))
|
||||
{
|
||||
var json = await File.ReadAllTextAsync(_employeesFilePath);
|
||||
|
||||
@@ -233,21 +233,22 @@ public class ModeusService(
|
||||
}
|
||||
}
|
||||
|
||||
var position = (e.GroupName ?? string.Empty).Trim();
|
||||
|
||||
static string FormatDateRange(string? dateIn, string? dateOut)
|
||||
{
|
||||
var start = (dateIn ?? string.Empty).Trim();
|
||||
if (string.IsNullOrEmpty(start)) start = "?";
|
||||
|
||||
var end = (dateOut ?? string.Empty).Trim();
|
||||
if (string.IsNullOrEmpty(end)) end = "по наст.вр.";
|
||||
|
||||
return $"{start}–{end}";
|
||||
}
|
||||
|
||||
var dateRange = FormatDateRange(e.DateIn, e.DateOut);
|
||||
var positionWithDates = string.IsNullOrEmpty(position) ? $"({dateRange})" : $"{position} ({dateRange})";
|
||||
// Отключено так как информация нигде не используется
|
||||
// var position = (e.GroupName ?? string.Empty).Trim();
|
||||
//
|
||||
// static string FormatDateRange(string? dateIn, string? dateOut)
|
||||
// {
|
||||
// var start = (dateIn ?? string.Empty).Trim();
|
||||
// if (string.IsNullOrEmpty(start)) start = "?";
|
||||
//
|
||||
// var end = (dateOut ?? string.Empty).Trim();
|
||||
// if (string.IsNullOrEmpty(end)) end = "по наст.вр.";
|
||||
//
|
||||
// return $"{start}–{end}";
|
||||
// }
|
||||
//
|
||||
// var dateRange = FormatDateRange(e.DateIn, e.DateOut);
|
||||
// var positionWithDates = string.IsNullOrEmpty(position) ? $"({dateRange})" : $"{position} ({dateRange})"; // Место работы с датой
|
||||
|
||||
if (!grouped.TryGetValue(fullName, out var entry))
|
||||
{
|
||||
@@ -260,11 +261,11 @@ public class ModeusService(
|
||||
entry.PersonId = personId;
|
||||
}
|
||||
}
|
||||
|
||||
if (!entry.Positions.Contains(positionWithDates))
|
||||
{
|
||||
entry.Positions.Add(positionWithDates);
|
||||
}
|
||||
|
||||
// if (!entry.Positions.Contains(positionWithDates))
|
||||
// {
|
||||
// entry.Positions.Add(positionWithDates);
|
||||
// }
|
||||
|
||||
grouped[fullName] = entry;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
<PackageReference Include="Sentry.AspNetCore" Version="6.1.0"/>
|
||||
<PackageReference Include="Sentry.Profiling" Version="6.1.0"/>
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.6"/>
|
||||
<PackageReference Include="X.Extensions.Logging.Telegram" Version="2.0.2"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -11,8 +11,6 @@ services:
|
||||
- AzureAd:ClientSecret=
|
||||
- AzureAd:Domain=sfedu.onmicrosoft.com
|
||||
- AzureAd:CallbackPath=/signin-oidc
|
||||
- TG_CHAT_ID=${TG_CHAT_ID}
|
||||
- TG_TOKEN=${TG_TOKEN}
|
||||
- API_KEY=${API_KEY}
|
||||
# - TOKEN=${TOKEN}
|
||||
- AUTH_URL=${AUTH_URL}
|
||||
|
||||
@@ -11,8 +11,6 @@ services:
|
||||
- AzureAd:ClientSecret=
|
||||
- AzureAd:Domain=sfedu.onmicrosoft.com
|
||||
- AzureAd:CallbackPath=/signin-oidc
|
||||
- TG_CHAT_ID=${TG_CHAT_ID}
|
||||
- TG_TOKEN=${TG_TOKEN}
|
||||
- API_KEY=${API_KEY}
|
||||
# - TOKEN=${TOKEN}
|
||||
- AUTH_URL=${AUTH_URL}
|
||||
|
||||
Reference in New Issue
Block a user