diff options
| author | Jake Mannens <jake@asger.xyz> | 2023-08-25 15:47:14 +1000 |
|---|---|---|
| committer | Jake Mannens <jake@asger.xyz> | 2026-05-06 04:21:54 +1000 |
| commit | 7984d2ecd4bdba7061429f98fdfae88f44f4a358 (patch) | |
| tree | 70dcda52dbd0cd955a1857442ceb0e0ae1f189b2 /ConnectSession.cs | |
v0.13av0.13a
Diffstat (limited to 'ConnectSession.cs')
| -rw-r--r-- | ConnectSession.cs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/ConnectSession.cs b/ConnectSession.cs new file mode 100644 index 0000000..7590408 --- /dev/null +++ b/ConnectSession.cs @@ -0,0 +1,36 @@ +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)); + } + + WriteVerbose($"Successfully logged in to {Host}"); + WriteObject(session); + } +} |
