using HyperBooru.ApiClient; using System.Management.Automation; namespace HyperBooru.PowerShell; [Alias("cchbs")] [Cmdlet(VerbsCommunications.Connect, "HyperBooruSession")] public class ConnectSessionCmdlet : PSCmdlet { [Parameter(Mandatory = true, Position = 0)] public Uri BaseUrl { get; set; } [Parameter(Mandatory = true, Position = 1)] public PSCredential Credential { get; set; } [Parameter(Position = 2)] public SwitchParameter SkipCertificateCheck { get; set; } protected override void BeginProcessing() { var session = new HBSession(BaseUrl, SkipCertificateCheck); try { session.LoginAsync(Credential.UserName, Credential.GetNetworkCredential().Password) .GetAwaiter() .GetResult(); } catch(Exception e) { ThrowTerminatingError(new( exception: e, errorId: "LoginError", errorCategory: ErrorCategory.AuthenticationError, targetObject: null)); } SessionCmdlet.GlobalSession = session; WriteVerbose($"Successfully logged in to {Host}"); WriteObject(session); } }