blob: e8034fc91b0a7eaeb2633a2dd066753a2c54a540 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
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);
}
}
|