jpsider / RestPS

Simple ReST Framework for Powershell
MIT License
114 stars 31 forks source link

Issue running through the preliminary steps #73

Closed Goghtime closed 1 year ago

Goghtime commented 1 year ago

First off, great project if there is a better place to ask a question as dumb as im about to ask, please direct me to the right place.

I was running through the basic outline you've provided and encounter an issue in the newest couple of versions. I'm not sure what i'm over looking.

currently using the defaults 'RestPSLocalRoot' within C:\RestPS Invoke-DeployRestPS -LocalDir 'C:\RestPS'

Start your first Endpoint, no problem.

Open a second console as admin. Run the provided input

$RestMethodParams = @{
            Uri = 'http://localhost:8080/process?name=powershell'
            Method = 'Get'
            UseBasicParsing = $true
        }
Invoke-RestMethod @RestMethodParams

I get the following error:

. : The term 'c:/RestPS/endPoints/GET/Invoke-GetProcess.ps1
c:/RestPS/endPoints/GET/Invoke-BasicChallenge.ps1' is not recognized as the name of a cmdlet,
function, script file, or operable program. Check the spelling of the name, or if a path was
included, verify that the path is correct and try again.
At C:\Program Files\WindowsPowerShell\Modules\RestPS\7.0.48\RestPS.psm1:142 char:32
+             $CommandReturn = . $RequestCommand -RequestArgs $RequestA ...

    + CategoryInfo          : ObjectNotFound: (c:/RestPS/endPo...icChallenge.ps1:String) [], Comma
   ndNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

What am I over looking, the log file doesn't provide any insight and I tired modifying RestPSroutes.json "RequestCommand" parameter to include an & or a -file without much luck.

Any thoughts?

Goghtime commented 1 year ago

Follow-up seems like the issue I'm having is when calling a script like the example provides. Running a command doesn't seem to be an issue.

jpsider commented 1 year ago

Can you post your json file and your startup line?

Goghtime commented 1 year ago
[
  {
    "RequestType": "GET",
    "RequestURL": "/proc",
    "RequestCommand": "Get-Process -ProcessName PowerShell -ErrorAction SilentlyContinue | Select-Object -Property ProcessName,Id -ErrorAction SilentlyContinue"
  },
  {
    "RequestType": "GET",
    "RequestURL": "/endpoint/status",
    "RequestCommand": "return 1"
  },
  {
    "RequestType": "GET",
    "RequestURL": "/endpoint/routes",
    "RequestCommand": "c:/RestPS/endPoints/GET/Invoke-GetRoutes.ps1"
  },
  {
    "RequestType": "GET",
    "RequestURL": "/process",
    "RequestCommand": "c:/RestPS/endPoints/GET/Invoke-GetProcess.ps1"
  },
  {
    "RequestType": "GET",
    "RequestURL": "/process",
    "RequestCommand": "c:/RestPS/endPoints/GET/Invoke-BasicChallenge.ps1"
  },
  {
    "RequestType": "PUT",
    "RequestURL": "/Service",
    "RequestCommand": "c:/RestPS/endPoints/PUT/Invoke-GetProcess.ps1"
  },
  {
    "RequestType": "POST",
    "RequestURL": "/data",
    "RequestCommand": "c:/RestPS/endPoints/POST/Invoke-GetProcess.ps1"
  },
  {
    "RequestType": "DELETE",
    "RequestURL": "/data",
    "RequestCommand": "c:/RestPS/endPoints/DELETE/Invoke-GetProcess.ps1"
  }
]
$RestPSparams = @{
            RoutesFilePath = 'C:\RestPS\endpoints\RestPSRoutes.json'
            Port = '8080'
        }
Start-RestPSListener @RestPSparams

I've not changed anything from the standard deployment as of yet - just working through the example.

jpsider commented 1 year ago

I think the issue is that there are 2 entries for a 'get' call on the '/process' path.

Remove the 2nd one and see if that works better.

Goghtime commented 1 year ago

That worked. So simple, sorry about that.

seems like the default 'RestPSRoutes.json has this two entries for get /process.

https://github.com/jpsider/RestPS/blob/master/RestPS/endpoints/RestPSRoutes.json

I also downloaded from the Gallery the following versions, looks like the entry was introduced in 7.0.46 https://www.powershellgallery.com/packages/RestPS/7.0.46/Content/endpoints%5CRestPSRoutes.json

Anyhow - thanks again.

jpsider commented 1 year ago

Cool!

I'll update it and push a fix out!

jpsider commented 1 year ago

New version was deployed today with the fix.