diff options
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); + } +} |
