Skip to content

Instantly share code, notes, and snippets.

@mbrownnycnyc
Last active July 17, 2020 16:21
Show Gist options
  • Save mbrownnycnyc/0c73972f4c4c6bd81fd55b3268bf9481 to your computer and use it in GitHub Desktop.
Save mbrownnycnyc/0c73972f4c4c6bd81fd55b3268bf9481 to your computer and use it in GitHub Desktop.
$body = @{
"username" = "[email protected]"
"password" = "password"
}
$LoginResponse = Invoke-WebRequest 'https://api.splunk.com/2.0/rest/login/splunk' -SessionVariable 'Session' -Body $Body -Method 'POST'
$Session
$headers = @{
"Authorization" = "bearer $(($loginresponse.content | convertfrom-json).data.token)"
"Cache-Control" = "no-cache"
}
<#
# submit a request to appinspect
$form = @{
"app_package" = "/path/to/splunk/app.tgz"
}
#supported in powershell > v6.x
$apprequestid = Invoke-WebRequest "https://appinspect.splunk.com/v1/app/validate" -headers $headers -form $form -Method 'POST'
#>
#submit a request to appinspect API for cloud
#https://get-powershellblog.blogspot.com/2017/09/multipartform-data-support-for-invoke.html
# https://www.powershellgallery.com/packages/PSBolts/0.5.0.37/Content/Public%5CInvoke-MultipartFormDataUpload.ps1
Add-Type -AssemblyName System.Net.Http
$multipartContent = [System.Net.Http.MultipartFormDataContent]::new()
$stringHeader = [System.Net.Http.Headers.ContentDispositionHeaderValue]::new("form-data")
$stringHeader.Name = "included_tags"
$StringContent = [System.Net.Http.StringContent]::new("cloud")
$StringContent.Headers.ContentDisposition = $stringHeader
$multipartContent.Add($stringContent)
$multipartFile = dir "C:\Users\Matt\Desktop\cisco-firepower-estreamer-encore-add-on-for-splunk_368.tgz"
Add-Type -AssemblyName System.Web
$mimeType = [System.Web.MimeMapping]::GetMimeMapping($multipartFile)
if ($mimeType) {
$ContentType = $mimeType
} else {
$ContentType = "application/octet-stream"
}
$FileStream = [System.IO.FileStream]::new($multipartFile, [System.IO.FileMode]::Open)
$fileHeader = [System.Net.Http.Headers.ContentDispositionHeaderValue]::new("form-data")
$fileHeader.Name = "app_package"
$fileHeader.FileName = "$multipartfile.name"
$fileContent = [System.Net.Http.StreamContent]::new($FileStream)
$fileContent.Headers.ContentDisposition = $fileHeader
$fileContent.Headers.ContentType = New-Object System.Net.Http.Headers.MediaTypeHeaderValue $ContentType
$multipartContent.Add($fileContent)
$filestream.close()
Invoke-WebRequest -uri "https://appinspect.splunk.com/v1/app/validate" -headers $headers -body $multipartContent -Method 'POST'
<#
$body = @{
"app_package" = $filecontent
"included_tags" = "cloud"
}
#>
#supported in powershell > v6.x
$cloudapprequestid = Invoke-WebRequest "https://appinspect.splunk.com/v1/app/validate" -headers $headers -form $form -Method 'POST'
#obtain result status
$resultstatus = Invoke-WebRequest "https://appinspect.splunk.com/v1/app/validate/status/$($cloudapprequestid)" -headers $headers -form $form -Method 'POST'
#obtain result status in html
$resultreportheader - $headers.add("content-type","text/html")
# or $resultreportheader - $headers.add("content-type","application/json")
$resultstatus = Invoke-WebRequest "https://appinspect.splunk.com/v1/app/report/$($cloudapprequestid)" -headers $resultreportheader -form $form -Method 'POST'```````````
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment