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
|
# List published policy bundles ================================================
# Execution Entrypoint +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Write-Host "List of Published IaC Policy Bundles in Artifactory" -ForegroundColor Yellow
# Step 1: Fetch JFRO token -----------------------------------------------------
if (-not $env:JFRO_TOKEN) {
Write-Host "missing env var: JFRO_TOKEN" -ForegroundColor Red
exit 1
}
# Step 2: Fetch published bundles ----------------------------------------------
$base = "https://hcassc.jfrog.io/artifactory"
$headers = @{ Authorization = "Bearer $($env:JFRO_TOKEN)" }
$query = @'
items.find({"repo":"iac-generic-tooling-local","path":"policies","name":{"$match":"*.tar.gz"}}).include("repo","path","name","created","modified")
'@
try {
$results = Invoke-RestMethod `
-Uri "$base/api/search/aql" `
-Method Post `
-Headers $headers `
-ContentType "text/plain" `
-Body $query
}
catch {
Write-Host "failed to query jfrog artifactory: $($_.Exception.Message)" -ForegroundColor Red
exit 1
}
# Step 3: Print results --------------------------------------------------------
Write-Host "`nFound $($results.results.Count) published policy bundle(s)`n"
$results.results | Sort-Object modified -Descending | ForEach-Object {
$ts = [System.DateTime]::ParseExact($_.modified, "MM/dd/yyyy HH:mm:ss", $null).ToString("yyyy-MM-dd HH:mm:ss UTC")
Write-Host " - $($_.path)/$($_.name) (updated: $ts)"
}
|