refactor!: rename Titano to Chronos and move CI and releases to Gitea (#6)
CI / Build and test (push) Successful in 8m14s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 7s
Release / Build, test and publish (push) Successful in 13m19s
CI / PostgreSQL 16 integration (push) Successful in 4m49s
CI / PostgreSQL 17 integration (push) Successful in 5m28s
CI / Docker image (push) Successful in 53s
Release / Server image (push) Failing after 10s
CI / Build and test (push) Successful in 8m14s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 7s
Release / Build, test and publish (push) Successful in 13m19s
CI / PostgreSQL 16 integration (push) Successful in 4m49s
CI / PostgreSQL 17 integration (push) Successful in 5m28s
CI / Docker image (push) Successful in 53s
Release / Server image (push) Failing after 10s
The owner renamed the product and moved the repository to the self-hosted Gitea (https://gitea.encke-hake.ts.net/BalboSoft/Chronos) for more control, and asked for Actions and a first automatic release with the server package and the Windows exe (docs/requests/2026-10-23-chronos-gitea.md). - Chronos everywhere: a byte-exact rename of contents and paths, then a per-language review of the forms the old name's ending had dictated. - Gitea instead of GitHub: the update check, licence, issue and support links read ChronosReleasesUrl; the update check takes the highest stable version, offers a pre-release build its final release and reports a repository it cannot see as a failed check. EULA, security policy and Gitea issue forms live at the repository root. - Gitea Actions for the Linux act_runner (.gitea/workflows): CI, release, nightly image and performance gates in the .NET SDK container with git checkout and the system SQLite. The release cross-compiles the Windows programs, checks their icon, version and DPI manifest, packs installers and zips, publishes the Gitea release and pushes the server image (REGISTRY_TOKEN). Windows-only tests run in an opt-in job on a Windows runner (WINDOWS_RUNNER). - New Chronos.Tools commands: zip, gitea-release, postgres-ci (replaces the docker-exec script, which Gitea's service containers do not allow; the throw-away server runs without durability) and pe-check. - Timed tests take their budget from TestTiming (CHRONOS_TEST_TIME_FACTOR, 3 on the shared runner; the weekly performance gates keep theirs). BREAKING CHANGE: programs, settings, data folders, file types, environment variables and the Docker image use the new name; nothing is migrated from Titano, which never had a release. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
This commit was merged in pull request #6.
This commit is contained in:
1 parent
c99842cc86
commit
f2b58522b9
1801 files changed
+11804
-10676
No files matched your search
@@ -0,0 +1,305 @@
|
||||
using System.Diagnostics;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text.Json;
|
||||
using Chronos.Protocol;
|
||||
using Chronos.Protocol.Client;
|
||||
|
||||
namespace Chronos.App.Server;
|
||||
|
||||
/// <summary>The calls the connection makes; implemented over <see cref="ChronosClient"/>, faked in tests.</summary>
|
||||
public interface IServerApi : IDisposable
|
||||
{
|
||||
Uri BaseAddress { get; }
|
||||
|
||||
/// <summary>Bearer token sent with every request.</summary>
|
||||
string? Token { get; set; }
|
||||
|
||||
/// <summary>Throws <see cref="UntrustedCertificateException"/> while the certificate is neither valid nor trusted.</summary>
|
||||
Task<ServerInfo> GetInfoAsync(CancellationToken ct);
|
||||
|
||||
Task<LoginResponse> LoginAsync(string username, string password, CancellationToken ct);
|
||||
|
||||
Task<UserDto> MeAsync(CancellationToken ct);
|
||||
|
||||
Task LogoutAsync(CancellationToken ct);
|
||||
}
|
||||
|
||||
/// <summary>Creates API clients pinned to the certificates the user trusts.</summary>
|
||||
public interface IServerApiFactory
|
||||
{
|
||||
IServerApi Create(Uri baseAddress, IReadOnlyCollection<string> trustedFingerprints);
|
||||
}
|
||||
|
||||
/// <summary>Certificates trusted on first use (persisted in the settings).</summary>
|
||||
public interface ITrustStore
|
||||
{
|
||||
IReadOnlyCollection<string> Fingerprints { get; }
|
||||
|
||||
void Trust(string server, string fingerprint);
|
||||
}
|
||||
|
||||
/// <summary>Where the connection stands (BRIEF §12.7).</summary>
|
||||
public enum ConnectStep
|
||||
{
|
||||
/// <summary>Nothing started, or signed out.</summary>
|
||||
Idle,
|
||||
|
||||
/// <summary>Reading the server's identity (no credentials are sent).</summary>
|
||||
Probing,
|
||||
|
||||
/// <summary>The certificate is self-signed and unknown: the user must confirm its fingerprint first.</summary>
|
||||
AwaitingTrust,
|
||||
|
||||
/// <summary>The server is identified and trusted: the login form may send the password.</summary>
|
||||
AwaitingCredentials,
|
||||
|
||||
SigningIn,
|
||||
Connected,
|
||||
Failed,
|
||||
}
|
||||
|
||||
/// <summary>Why the last step failed.</summary>
|
||||
public enum ConnectError
|
||||
{
|
||||
None,
|
||||
InvalidAddress,
|
||||
Unreachable,
|
||||
NotChronos,
|
||||
Untrusted,
|
||||
BadCredentials,
|
||||
|
||||
/// <summary>A saved session was rejected (expired or revoked token); sign in again.</summary>
|
||||
SessionExpired,
|
||||
|
||||
/// <summary>The certificate differs from the trusted one; the saved session was dropped.</summary>
|
||||
CertificateChanged,
|
||||
Failed,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Trust-on-first-use connection state machine, mirroring the uploader: the server's identity is read first
|
||||
/// (<c>GET server/info</c>, which needs no credentials); a self-signed certificate that is not trusted yet stops the
|
||||
/// flow at <see cref="ConnectStep.AwaitingTrust"/> until the user confirms its fingerprint; only then can
|
||||
/// <see cref="SignInAsync"/> send the password. A saved token is restored the same way, and a changed certificate
|
||||
/// never reuses it. Not thread-safe; drive it from the UI.
|
||||
/// </summary>
|
||||
public sealed class ConnectFlow(IServerApiFactory factory, ITrustStore trust) : IDisposable
|
||||
{
|
||||
private IServerApi? _api;
|
||||
|
||||
public ConnectStep Step { get; private set; } = ConnectStep.Idle;
|
||||
public ConnectError Error { get; private set; }
|
||||
|
||||
/// <summary>Normalised API base ("https://nas.local:8443/").</summary>
|
||||
public Uri? Address { get; private set; }
|
||||
|
||||
/// <summary>The fingerprint waiting for the user's decision.</summary>
|
||||
public string? PendingFingerprint { get; private set; }
|
||||
|
||||
public ServerInfo? Info { get; private set; }
|
||||
public UserDto? User { get; private set; }
|
||||
|
||||
/// <summary>Round trip of the identity request.</summary>
|
||||
public TimeSpan? Latency { get; private set; }
|
||||
|
||||
/// <summary>The token of the signed-in session (store it encrypted).</summary>
|
||||
public string? Token => Step == ConnectStep.Connected ? _api?.Token : null;
|
||||
|
||||
/// <summary>The signed-in client, for the screens that talk to the server.</summary>
|
||||
public IServerApi? Api => Step == ConnectStep.Connected ? _api : null;
|
||||
|
||||
/// <summary>Raised after every step change.</summary>
|
||||
public event EventHandler? Changed;
|
||||
|
||||
/// <summary>Identifies the server at <paramref name="address"/>: ends in AwaitingTrust, AwaitingCredentials or Failed.</summary>
|
||||
public async Task<ConnectStep> ProbeAsync(string address, CancellationToken ct = default)
|
||||
{
|
||||
Reset();
|
||||
if (!ServerAddress.TryParse(address, out var uri)) return Fail(ConnectError.InvalidAddress);
|
||||
Address = uri;
|
||||
return await IdentifyAsync(ct);
|
||||
}
|
||||
|
||||
/// <summary>The user's answer to the fingerprint question; trusting it identifies the server again.</summary>
|
||||
public async Task<ConnectStep> ConfirmTrustAsync(bool trusted, CancellationToken ct = default)
|
||||
{
|
||||
if (Step != ConnectStep.AwaitingTrust || PendingFingerprint is null || Address is null) return Step;
|
||||
if (!trusted) return Fail(ConnectError.Untrusted);
|
||||
trust.Trust(ServerAddress.Display(Address), PendingFingerprint);
|
||||
PendingFingerprint = null;
|
||||
return await IdentifyAsync(ct);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends the credentials; only possible once the server is identified and trusted. An answer that arrives after the
|
||||
/// flow moved on (disconnected, or connecting elsewhere) changes nothing.
|
||||
/// </summary>
|
||||
public async Task<ConnectStep> SignInAsync(string username, string password, CancellationToken ct = default)
|
||||
{
|
||||
if (Step is not (ConnectStep.AwaitingCredentials or ConnectStep.SigningIn) || _api is not { } api) return Step;
|
||||
if (string.IsNullOrWhiteSpace(username)) return Retry(ConnectError.BadCredentials);
|
||||
Set(ConnectStep.SigningIn, ConnectError.None);
|
||||
try
|
||||
{
|
||||
var login = await api.LoginAsync(username.Trim(), password, ct);
|
||||
if (!ReferenceEquals(api, _api)) return Step;
|
||||
if (login.Token is null) return Retry(ConnectError.BadCredentials);
|
||||
// ChronosClient keeps the token itself; set it explicitly so every IServerApi behaves the same.
|
||||
api.Token = login.Token;
|
||||
User = login.User;
|
||||
return Set(ConnectStep.Connected, ConnectError.None);
|
||||
}
|
||||
catch (Exception ex) when (Classify(ex, ct) is { } error)
|
||||
{
|
||||
if (!ReferenceEquals(api, _api)) return Step;
|
||||
return error is ConnectError.BadCredentials ? Retry(error) : Fail(error);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Resumes a saved session: Connected, or AwaitingCredentials/AwaitingTrust when it cannot be reused.</summary>
|
||||
public async Task<ConnectStep> RestoreAsync(string address, string token, CancellationToken ct = default)
|
||||
{
|
||||
Reset();
|
||||
if (!ServerAddress.TryParse(address, out var uri)) return Fail(ConnectError.InvalidAddress);
|
||||
Address = uri;
|
||||
if (await IdentifyAsync(ct) != ConnectStep.AwaitingCredentials)
|
||||
{
|
||||
// Never resend a token to a server whose certificate is no longer the trusted one.
|
||||
if (Step == ConnectStep.AwaitingTrust) Error = ConnectError.CertificateChanged;
|
||||
Changed?.Invoke(this, EventArgs.Empty);
|
||||
return Step;
|
||||
}
|
||||
_api!.Token = token;
|
||||
try
|
||||
{
|
||||
User = await _api.MeAsync(ct);
|
||||
return Set(ConnectStep.Connected, ConnectError.None);
|
||||
}
|
||||
catch (Exception ex) when (Classify(ex, ct) is { } error)
|
||||
{
|
||||
_api.Token = null;
|
||||
return error is ConnectError.BadCredentials ? Retry(ConnectError.SessionExpired) : Fail(error);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Ends the session on the server (best effort) and forgets it here.</summary>
|
||||
public async Task SignOutAsync()
|
||||
{
|
||||
if (_api is { Token: not null } api)
|
||||
{
|
||||
try
|
||||
{
|
||||
using var timeout = new CancellationTokenSource(TimeSpan.FromSeconds(5));
|
||||
await api.LogoutAsync(timeout.Token);
|
||||
}
|
||||
catch (Exception ex) when (ex is HttpRequestException or ChronosApiException or OperationCanceledException or UntrustedCertificateException)
|
||||
{
|
||||
// The token is forgotten locally either way.
|
||||
}
|
||||
}
|
||||
Reset();
|
||||
Changed?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
/// <summary>Drops the connection without signing out (the saved token stays valid).</summary>
|
||||
public void Disconnect()
|
||||
{
|
||||
Reset();
|
||||
Changed?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
public void Dispose() => Reset();
|
||||
|
||||
private async Task<ConnectStep> IdentifyAsync(CancellationToken ct)
|
||||
{
|
||||
Set(ConnectStep.Probing, ConnectError.None);
|
||||
_api?.Dispose();
|
||||
_api = factory.Create(Address!, trust.Fingerprints);
|
||||
try
|
||||
{
|
||||
var clock = Stopwatch.StartNew();
|
||||
Info = await _api.GetInfoAsync(ct);
|
||||
Latency = clock.Elapsed;
|
||||
return Set(ConnectStep.AwaitingCredentials, ConnectError.None);
|
||||
}
|
||||
catch (UntrustedCertificateException untrusted)
|
||||
{
|
||||
PendingFingerprint = untrusted.Fingerprint;
|
||||
return Set(ConnectStep.AwaitingTrust, ConnectError.None);
|
||||
}
|
||||
catch (Exception ex) when (Classify(ex, ct) is { } error)
|
||||
{
|
||||
return Fail(error);
|
||||
}
|
||||
}
|
||||
|
||||
private void Reset()
|
||||
{
|
||||
_api?.Dispose();
|
||||
_api = null;
|
||||
Step = ConnectStep.Idle;
|
||||
Error = ConnectError.None;
|
||||
Address = null;
|
||||
PendingFingerprint = null;
|
||||
Info = null;
|
||||
User = null;
|
||||
Latency = null;
|
||||
}
|
||||
|
||||
private ConnectStep Set(ConnectStep step, ConnectError error)
|
||||
{
|
||||
Step = step;
|
||||
Error = error;
|
||||
Changed?.Invoke(this, EventArgs.Empty);
|
||||
return step;
|
||||
}
|
||||
|
||||
/// <summary>Back to the login form with an error (wrong password, expired session).</summary>
|
||||
private ConnectStep Retry(ConnectError error) => Set(ConnectStep.AwaitingCredentials, error);
|
||||
|
||||
private ConnectStep Fail(ConnectError error)
|
||||
{
|
||||
_api?.Dispose();
|
||||
_api = null;
|
||||
return Set(ConnectStep.Failed, error);
|
||||
}
|
||||
|
||||
/// <summary>Expected failures as an error code; null lets unexpected exceptions propagate.</summary>
|
||||
internal static ConnectError? Classify(Exception ex, CancellationToken ct) => ex switch
|
||||
{
|
||||
UntrustedCertificateException => ConnectError.Untrusted,
|
||||
ChronosApiException { Status: HttpStatusCode.Unauthorized or HttpStatusCode.Forbidden } => ConnectError.BadCredentials,
|
||||
ChronosApiException { Status: HttpStatusCode.NotFound } => ConnectError.NotChronos,
|
||||
ChronosApiException api when api.IsTransient => ConnectError.Unreachable,
|
||||
ChronosApiException => ConnectError.Failed,
|
||||
JsonException or NotSupportedException => ConnectError.NotChronos,
|
||||
HttpRequestException => ConnectError.Unreachable,
|
||||
OperationCanceledException when !ct.IsCancellationRequested => ConnectError.Unreachable,
|
||||
_ => null,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>Server addresses as typed in the address field.</summary>
|
||||
public static class ServerAddress
|
||||
{
|
||||
/// <summary>Accepts "nas.local:8443" (https assumed) or a full http(s) URL; the result is the API base, ending with "/".</summary>
|
||||
public static bool TryParse(string? text, out Uri uri)
|
||||
{
|
||||
uri = null!;
|
||||
if (string.IsNullOrWhiteSpace(text)) return false;
|
||||
var trimmed = text.Trim();
|
||||
if (!trimmed.Contains("://", StringComparison.Ordinal)) trimmed = "https://" + trimmed;
|
||||
if (!Uri.TryCreate(trimmed, UriKind.Absolute, out var parsed) || parsed.Scheme is not ("https" or "http") || parsed.Host.Length == 0) return false;
|
||||
var builder = new UriBuilder(parsed) { Query = string.Empty, Fragment = string.Empty };
|
||||
if (!builder.Path.EndsWith('/')) builder.Path += "/";
|
||||
uri = builder.Uri;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>The address as shown in the field: the base URL without its trailing slash.</summary>
|
||||
public static string Display(Uri uri) => uri.ToString().TrimEnd('/');
|
||||
|
||||
/// <summary>Same, for stored text.</summary>
|
||||
public static string Display(string? address) => address?.TrimEnd('/') ?? string.Empty;
|
||||
}
|
||||
Reference in new issue
Block a user