CyOpticsPackages.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<#
.SYNOPSIS
    Gets a list of all packages from the console.
 
.PARAMETER API
    Optional. API Handle (use only when not using session scope).
#>

function Get-CyPackagesList {
    Param (
        [parameter(Mandatory=$false)]
        [CylanceAPIHandle]$API = $GlobalCyAPIHandle,
        [parameter(Mandatory=$false)]
        [String]$UpdatedByLogin,
        [parameter(Mandatory=$false)]
        [int]$Timeout,
        [parameter(Mandatory=$false)]
        [ValidateSet ("custom", "cylance")]
        [String]$Category,
        [parameter(Mandatory=$false)]
        [ValidateSet ("started", "success", "failed", "timeout")]
        [string]$Status,
        [parameter(Mandatory=$false)]
        [ValidateSet ("packageId", "uploadedOn", "uploadedBy.id", "uploadedBy.login", "size", "status", "timeout", "packageDescriptor.name")]
        [string]$Sort
    )

    $params = @{}

    if (![String]::IsNullOrEmpty($Status)) {
        $params.status = $Status
    }

    if (![String]::IsNullOrEmpty($UpdatedByLogin)) {
        $params.'updatedBy.Login' = $UpdatedByLogin
    }

    if (![String]::IsNullOrEmpty($Category)) {
        $params.category = $Category
    }

    if (![String]::IsNullOrEmpty($DetectedOn)) {
        $params.detected_on = $DetectedOn
    }

    if (0 -ne $Timeout) {
        $params.timeout = $Timeout
    }

    if (![String]::IsNullOrEmpty($Sort)) {
        $params.sort = $Sort
    }

    Read-CyData -API $API -Uri "$($API.BaseUrl)/packages/v2" -QueryParams $params
}