TheJumpCloud / support

Public scripts and examples for managing JumpCloud managed systems and service endpoints
268 stars 153 forks source link

Allow general URL to import JCCommands from. -- receiving '400: Invalid request' #472

Open flybyray opened 1 year ago

flybyray commented 1 year ago

'The URL of the JumpCloud command to import into a JumpCloud tenant.' see https://github.com/TheJumpCloud/support/blob/a3ddab05d800d56e3fc90aa8a40889fd72cee03e/PowerShell/JumpCloud%20Module/Public/Commands/Import-JCCommand.ps1#L4

command:

Import-JCCommand -URL "http://localhost:9000/JumpCloud_Commands/Mac%20Commands/Mac%20-%20List%20additional%20routes%20from%20vpn.md"

error and stacktrace:

Invoke-WebRequest: /home/username/.local/share/powershell/Modules/JumpCloud/2.2.0/Private/NestedFunctions/New-JCCommandFromURL.ps1:20
Line |
  20 |  … UrlInvoke = Invoke-WebRequest -Uri $rawUrl -UseBasicParsing -UserAgen …
     |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | 400: Invalid request
InvalidOperation: /home/username/.local/share/powershell/Modules/JumpCloud/2.2.0/Private/NestedFunctions/New-JCCommandFromURL.ps1:24
Line |
  24 |          $Name = $content[0].Groups[2].Value #Name
     |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Cannot index into a null array.
InvalidOperation: /home/username/.local/share/powershell/Modules/JumpCloud/2.2.0/Private/NestedFunctions/New-JCCommandFromURL.ps1:25
Line |
  25 |          $commandType = $content[1].Groups[2].Value #CommandType
     |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Cannot index into a null array.
InvalidOperation: /home/username/.local/share/powershell/Modules/JumpCloud/2.2.0/Private/NestedFunctions/New-JCCommandFromURL.ps1:26
Line |
  26 |          $Command = $content[2].Groups[3].Value #Command
     |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Cannot index into a null array.

reason:

https://github.com/TheJumpCloud/support/blob/a3ddab05d800d56e3fc90aa8a40889fd72cee03e/PowerShell/JumpCloud%20Module/Private/NestedFunctions/New-JCCommandFromURL.ps1#L17-L18

URL is transformed and not a general URL is expected as described by help text.

Could you allow to import JC Commands from different URLs?

flybyray commented 1 year ago

Apply patch as workarround.

patch -p1 /home/username/.local/share/powershell/Modules/JumpCloud/2.2.0/Private/NestedFunctions/New-JCCommandFromURL.ps1 < <(curl -fsSL https://github.com/flybyray/support/commit/73c5fbc4d13b871ce472ecbe43266fb2d988218f.patch)

replace /home/username/.local/share/powershell/Modules/JumpCloud/2.2.0/Private/NestedFunctions/New-JCCommandFromURL.ps1 with the correct path.