summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJake Mannens <jake@asger.xyz>2026-05-08 01:28:31 +1000
committerJake Mannens <jake@asger.xyz>2026-05-08 01:28:31 +1000
commit8ef09f9fed656bacc3a25e790796e9f144a5fac8 (patch)
treedb940e9fe93eaf7cb226037d8d7ab1b1f6704c78
parent7984d2ecd4bdba7061429f98fdfae88f44f4a358 (diff)
v0.14av0.14a
-rw-r--r--GetUser.cs26
-rw-r--r--NewUser.cs26
-rw-r--r--PowerShell.csproj2
-rw-r--r--RemoveUser.cs20
-rw-r--r--SetUser.cs38
-rw-r--r--Util.cs17
6 files changed, 128 insertions, 1 deletions
diff --git a/GetUser.cs b/GetUser.cs
new file mode 100644
index 0000000..63c5af7
--- /dev/null
+++ b/GetUser.cs
@@ -0,0 +1,26 @@
+using HyperBooru.ApiClient;
+using System.Management.Automation;
+
+namespace HyperBooru.PowerShell;
+
+[Alias("ghbu")]
+[Cmdlet(VerbsCommon.Get, "HyperBooruUser")]
+public class GetUserCmdlet : PSCmdlet {
+ [Parameter(Position = 0, Mandatory = true)]
+ public HBSession Session { get; set; }
+
+ [Parameter(Position = 1)]
+ public Guid? UserId { get; set; }
+
+ protected override void ProcessRecord() {
+ ApiModels.User[] users;
+
+ if(UserId is not null)
+ users = [ Session.User.GetUserAsync((Guid) UserId).GetAwaiter().GetResult() ];
+ else
+ users = Session.User.GetAllUsersAsync().GetAwaiter().GetResult();
+
+ foreach(var u in users)
+ WriteObject(u);
+ }
+}
diff --git a/NewUser.cs b/NewUser.cs
new file mode 100644
index 0000000..7b9ab07
--- /dev/null
+++ b/NewUser.cs
@@ -0,0 +1,26 @@
+using HyperBooru.ApiClient;
+using System.Management.Automation;
+using System.Security;
+
+namespace HyperBooru.PowerShell;
+
+[Alias("nhbu")]
+[Cmdlet(VerbsCommon.New, "HyperBooruUser")]
+public class NewUserCmdlet : PSCmdlet {
+ [Parameter(Position = 0, Mandatory = true)]
+ public HBSession Session { get; set; }
+
+ [Parameter(Position = 1, Mandatory = true)]
+ public string Username { get; set; }
+
+ [Parameter(Position = 2, Mandatory = true)]
+ public SecureString Password { get; set; }
+
+ protected override void ProcessRecord() {
+ var user = Session.User.CreateUserAsync(Username, Password.ToInsecureString())
+ .GetAwaiter()
+ .GetResult();
+
+ WriteObject(user);
+ }
+}
diff --git a/PowerShell.csproj b/PowerShell.csproj
index 188674f..ba0a927 100644
--- a/PowerShell.csproj
+++ b/PowerShell.csproj
@@ -9,7 +9,7 @@
<FileVersion>$(AssemblyVersion)</FileVersion>
<AssemblyTitle>HyperBooru.PowerShell</AssemblyTitle>
<Authors>Jake Mannens</Authors>
- <Version>0.13-alpha</Version>
+ <Version>0.14-alpha</Version>
</PropertyGroup>
<ItemGroup>
diff --git a/RemoveUser.cs b/RemoveUser.cs
new file mode 100644
index 0000000..0e28675
--- /dev/null
+++ b/RemoveUser.cs
@@ -0,0 +1,20 @@
+using HyperBooru.ApiClient;
+using System.Management.Automation;
+
+namespace HyperBooru.PowerShell;
+
+[Alias("rhbu")]
+[Cmdlet(VerbsCommon.Remove, "HyperBooruUser")]
+public class RemoveUserCmdlet : PSCmdlet {
+ [Parameter(Position = 0, Mandatory = true)]
+ public HBSession Session { get; set; }
+
+ [Parameter(Position = 1, Mandatory = true)]
+ public Guid UserId { get; set; }
+
+ protected override void ProcessRecord() {
+ Session.User.DeleteUserAsync(UserId)
+ .GetAwaiter()
+ .GetResult();
+ }
+}
diff --git a/SetUser.cs b/SetUser.cs
new file mode 100644
index 0000000..93af581
--- /dev/null
+++ b/SetUser.cs
@@ -0,0 +1,38 @@
+using HyperBooru.ApiClient;
+using System.Management.Automation;
+using System.Security;
+
+namespace HyperBooru.PowerShell;
+
+[Alias("shbu")]
+[Cmdlet(VerbsCommon.Set, "HyperBooruUser")]
+public class SetUserCmdlet : PSCmdlet {
+ [Parameter(Position = 0, Mandatory = true)]
+ public HBSession Session { get; set; }
+
+ [Parameter(Position = 1, Mandatory = true)]
+ public Guid UserId { get; set; }
+
+ [Parameter(Position = 2)]
+ public string? Username { get; set; }
+
+ [Parameter(Position = 3)]
+ public SecureString? Password { get; set; }
+
+ protected override void ProcessRecord() {
+ if(Username is null && Password is null) {
+ ThrowTerminatingError(new(
+ new ArgumentException("Both Username and Password cannot be null"),
+ "ArgumentException",
+ ErrorCategory.InvalidArgument,
+ null));
+ return;
+ }
+
+ var user = Session.User.UpdateUserAsync(UserId, Username, Password?.ToInsecureString())
+ .GetAwaiter()
+ .GetResult();
+
+ WriteObject(user);
+ }
+}
diff --git a/Util.cs b/Util.cs
new file mode 100644
index 0000000..9f261ee
--- /dev/null
+++ b/Util.cs
@@ -0,0 +1,17 @@
+using System.Runtime.InteropServices;
+using System.Security;
+
+namespace HyperBooru.PowerShell;
+
+internal static class Util {
+ internal static string ToInsecureString(this SecureString x) {
+ IntPtr rawString = IntPtr.Zero;
+ try {
+ rawString = Marshal.SecureStringToBSTR(x);
+ return Marshal.PtrToStringBSTR(rawString);
+ } finally {
+ if(rawString != IntPtr.Zero)
+ Marshal.FreeBSTR(rawString);
+ }
+ }
+}