Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(scoop-virustotal): Adopt Resolve-ManifestInformation #232

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@
- E:/Install/Shovel/customManifest.yml # Even local manifest support. Use with caution in controlled environment!
```

- **scoop-virustotal**: Rename parameter `no-depends` (`-n`) to `independent` (`-i`) for consistency with other commands
- **scoop-virustotal**:
- Rename parameter `no-depends` (`-n`) to `independent` (`-i`) for consistency with other commands
- Adopt `Resolve-ManifestObject` to support remote manifests/local manifests/archived manifests lookups
- Yaml typed manifests are also supported
- Consider debug mode enabled only when the `debug` config option or `SCOOP_DEBUG` is valid boolean value (`$true`, `$false`, `1`, `0`, `true`, `false`)
- Prevent multiple evaluations of debug mode check
- Respect `NO_JUNCTIONS` config when resolving helper utilities
Expand Down
46 changes: 32 additions & 14 deletions libexec/scoop-virustotal.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
@('help', 'scoop_help'),
@('Helpers', 'New-IssuePrompt'),
@('Dependencies', 'Resolve-DependsProperty'),
@('depends', 'script_deps'),
@('VirusTotal', 'Search-VirusTotal')
) | ForEach-Object {
if (!([bool] (Get-Command $_[1] -ErrorAction 'Ignore'))) {
Expand All @@ -54,49 +53,68 @@ if (!$VT_API_KEY) { Stop-ScoopExecution -Message 'Virustotal API Key is required
$DoScan = $Options.scan -or $Options.s
$Independent = $Options.independent -or $Options.i
$Architecture = Resolve-ArchitectureParameter -Architecture $Options.a, $Options.arch
$toInstall = @{
'Failed' = @()
'Resolved' = @()
}

# Buildup all installed applications
if ($Applications -eq '*') {
$Applications = installed_apps $false
$Applications += installed_apps $true
}

if (!$Independent) { $Applications = install_order $Applications $Architecture }
# Properly resolve all dependencies and applications
if ($Independent) {
foreach ($a in $Applications) {
$ar = $null
try {
$ar = Resolve-ManifestInformation -ApplicationQuery $a
} catch {
++$Problems
Write-UserMessage -Message "$($_.Exception.Message)" -Err
continue
}

$toInstall.Resolved += $ar
}
} else {
$toInstall = Resolve-MultipleApplicationDependency -Applications $Applications -Architecture $Architecture -IncludeInstalled
}

foreach ($app in $toInstall.Resolved) {
$appName = $app.ApplicationName
$manifest = $app.ManifestObject

foreach ($app in $Applications) {
# TODO: Adopt Resolve-ManifestInformation
# TOOD: Fix URL/local manifest installations
# Should it take installed manifest or remote manifest?
$manifest, $bucket = find_manifest $app
if (!$manifest) {
$ExitCode = $ExitCode -bor $VT_ERR.NoInfo
Write-UserMessage -Message "${app}: manifest not found" -Err
Write-UserMessage -Message "${appName}: manifest not found" -Err
continue
}

foreach ($url in (url $manifest $Architecture)) {
$hash = hash_for_url $manifest $url $Architecture

if (!$hash) {
Write-UserMessage -Message "${app}: Cannot find hash for $url" -Warning
Write-UserMessage -Message "${appName}: Cannot find hash for '$url'" -Warning
# TODO: Adopt if ($Download) {}
continue
# TODO: Adopt $Options.download
}

try {
$ExitCode = $ExitCode -bor (Search-VirusTotal $hash $app)
$ExitCode = $ExitCode -bor (Search-VirusTotal $hash $appName)
} catch {
$ExitCode = $ExitCode -bor $VT_ERR.Exception

if ($_.Exception.Message -like '*(404)*') {
Submit-ToVirusTotal -Url $url -App $app -DoScan:$DoScan
Submit-ToVirusTotal -Url $url -App $appName -DoScan:$DoScan
} else {
if ($_.Exception.Message -match '\(204|429\)') {
Write-UserMessage -Message "${app}: VirusTotal request failed: $($_.Exception.Message)"
Write-UserMessage -Message "${appName}: VirusTotal request failed: $($_.Exception.Message)"
$ExitCode = 3
continue
}
Write-UserMessage -Message "${app}: VirusTotal request failed: $($_.Exception.Message)"
Write-UserMessage -Message "${appName}: VirusTotal request failed: $($_.Exception.Message)"
}
}
}
Expand Down