ThePoShWolf/Curl2PS

ConvertTo-IRM does not return a valid Invoke-RestMethod statement for cUrl command passed

Closed this issue · 2 comments

This curl command updates an specific end-point with build details. The end-point is a REST API of a JIRA plugin from a company called Apwide(https://www.apwide.com/).

curl command

curl -X PUT "http://10.83.65.4:8080/rest/apwide/tem/1.1/deployment?application
=PegaADB%2FVBD%2FDecision%20Engine%20-%20OutboundPega7%2C%20Marketing&category=RSIT03" -H "accept: application/json" -H "authorization: Basic Z2FsYXh5OmdhbGF4eQ==" -H "Co
ntent-Type: application/json" -d "{ "versionName": "PEP2.8.5_20200309_01-22-10", "versionId": "PEP2.8.5"}"

Expected Behavior

The script should generate the correct statement.

Current Behavior

ConvertTo-IRM -CurlCommand 'curl -X PUT "http://10.83.65.4:8080/rest/apwide/tem/1.1/deployment?application
=PegaADB%2FVBD%2FDecision%20Engine%20-%20OutboundPega7%2C%20Marketing&category=RSIT03" -H "accept: application/json" -H "authorization: Basic Z2FsYXh5OmdhbGF4eQ==" -H "Co
ntent-Type: application/json" -d "{ "versionName": "PEP2.8.5_20200309_01-22-10", "versionId": "PEP2.8.5"}"' -String
Invoke-RestMethod -Uri http://10.83.65.4:8080/rest/apwide/tem/1.1/deployment -Method PUT -Headers @{

}

Possible Solution

Steps to Reproduce (for bugs)

Context

I am unable to progress further with the plugin if I am unable to correctly generate this Invoke-Restmethod statement.

Your Environment

> $PSVersionTable
PS C:\Users\GILLB1\OneDrive - AA PLC\PowerShell\Curl2PS-master> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.17134.858
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.17134.858
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1


PS C:\Users\GILLB1\OneDrive - AA PLC\PowerShell\Curl2PS-master>
> Get-Module Curl2PS
PS C:\Users\GILLB1\OneDrive - AA PLC\PowerShell\Curl2PS-master> Get-Module Curl2PS

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     0.0.2      Curl2PS                             {ConvertTo-IRM, Get-CurlCommand, Get-URLData}

Installation output:

PS C:\Users\GILLB1\OneDrive - AA PLC\PowerShell\Curl2PS-master> Install-Module Curl2PS
Install-Module : Administrator rights are required to install modules in 'C:\Program Files\WindowsPowerShell\Modules'. Log on to the computer with an account that has
Administrator rights, and then try again, or install 'C:\Users\GILLB1\OneDrive - AA PLC\WindowsPowerShell\Modules' by adding "-Scope CurrentUser" to your command. You
can also try running the Windows PowerShell session with elevated rights (Run as Administrator).
At line:1 char:1

  • Install-Module Curl2PS
  •   + CategoryInfo          : InvalidArgument: (:) [Install-Module], ArgumentException
      + FullyQualifiedErrorId : InstallModuleNeedsCurrentUserScopeParameterForNonAdminUser,Install-Module
    
    

PS C:\Users\GILLB1\OneDrive - AA PLC\PowerShell\Curl2PS-master> Install-Module Curl2PS -Scope CurrentUser

NuGet provider is required to continue
PowerShellGet requires NuGet provider version '2.8.5.201' or newer to interact with NuGet-based repositories. The NuGet provider must be available in 'C:\Program
Files\PackageManagement\ProviderAssemblies' or 'C:\Users\GILLB1\AppData\Local\PackageManagement\ProviderAssemblies'. You can also install the NuGet provider by running
'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force'. Do you want PowerShellGet to install and import the NuGet provider now?
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): Y

Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its InstallationPolicy value by running the Set-PSRepository cmdlet.
Are you sure you want to install the modules from 'PSGallery'?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"): A

Thank you for the issue, I'll take a look. I apparently didn't have notifications set up on this repository, so my apologies for the sluggish response.

I've tested this is the just released v0.0.3 of Curl2PS and it works after removing the linebreaks.

Here's the modified string:

curl -X PUT "http://10.83.65.4:8080/rest/apwide/tem/1.1/deployment?application=PegaADB%2FVBD%2FDecision%20Engine%20-%20OutboundPega7%2C%20Marketing&category=RSIT03" -H "accept: application/json" -H "authorization: Basic Z2FsYXh5OmdhbGF4eQ==" -H "Content-Type: application/json" -d "{ "versionName": "PEP2.8.5_20200309_01-22-10", "versionId": "PEP2.8.5"}"

Assign it to $str and then:

ConvertTo-IRM $str -String

And you should get the correct output:

Invoke-RestMethod -Uri 'http://10.83.65.4:8080/rest/apwide/tem/1.1/deployment?application=PegaADB/VBD/Decision Engine - OutboundPega7, Marketing&category=RSIT03' -Method PUT -Body '"{ "versionName": "PEP2.8.5_20200309_01-22-10", "versionId": "PEP2.8.5"}"' -Verbose:$false -Headers @{
    'authorization' = 'Basic Z2FsYXh5OmdhbGF4eQ=='
    'Content-Type' = 'application/json'
    'accept' = 'application/json'
}