mirror of
https://dev.azure.com/effectory/Survey%20Software/_git/Cloud%20Engineering
synced 2026-02-27 18:52:18 +01:00
New Snyk overview
This commit is contained in:
59
Powershell/Lists/Snyk/SnykOverview.ps1
Normal file
59
Powershell/Lists/Snyk/SnykOverview.ps1
Normal file
@@ -0,0 +1,59 @@
|
||||
$access_token = Get-AzKeyVaultSecret -VaultName "consoleapp" -Name "SnykKey" -AsPlainText
|
||||
$head = @{ Authorization ="$access_token" }
|
||||
$version = "2023-08-29%7Ebeta"
|
||||
$ofs = ', '
|
||||
|
||||
[string] $date = Get-Date -Format "yyyy-MM-dd HHmm"
|
||||
$fileName = ".\$date snyk projects.csv"
|
||||
|
||||
class SnykOverview {
|
||||
[string] $OrganisationId = ""
|
||||
[string] $OrganisationName = ""
|
||||
[string] $GroupId = ""
|
||||
[string] $OrganisationSlug = ""
|
||||
[string] $ProjectId = ""
|
||||
[string] $ProjectRepo = ""
|
||||
[string] $ProjectName = ""
|
||||
[string] $ProjectType = ""
|
||||
[string] $ProjectCreateDate = ""
|
||||
[string] $ProjectTargetFile = ""
|
||||
[string] $ProjectTargetRunTime = ""
|
||||
}
|
||||
|
||||
[SnykOverview[]]$Result = @()
|
||||
|
||||
$organisationUrl = "https://api.snyk.io/rest/orgs?version=$version"
|
||||
$organisationResponse = Invoke-RestMethod -Uri $organisationUrl -Method GET -Headers $head
|
||||
|
||||
foreach ($organisation in $organisationResponse.data)
|
||||
{
|
||||
$organisationId = $organisation.id
|
||||
|
||||
$projectUrl = "https://api.snyk.io/rest/orgs/$organisationId/projects?version=$version&limit=100"
|
||||
$projectResponse = Invoke-RestMethod -Uri $projectUrl -Method GET -Headers $head
|
||||
|
||||
foreach ($project in $projectResponse.data)
|
||||
{
|
||||
$projectName = $project.attributes.name
|
||||
|
||||
[SnykOverview] $SnykOverview = [SnykOverview]::new()
|
||||
|
||||
$SnykOverview.OrganisationId = $organisationId
|
||||
$SnykOverview.OrganisationName = $organisation.attributes.name
|
||||
$SnykOverview.GroupId = $organisation.attributes.group_id
|
||||
$SnykOverview.OrganisationSlug = $organisation.attributes.slug
|
||||
$SnykOverview.ProjectId = $project.id
|
||||
$SnykOverview.ProjectRepo = $projectName.Split(":")[0]
|
||||
$SnykOverview.ProjectName = $projectName.Split(":")[1]
|
||||
$SnykOverview.ProjectType = $project.attributes.type
|
||||
$SnykOverview.ProjectCreateDate = $project.attributes.created
|
||||
$SnykOverview.ProjectTargetFile = $project.attributes.target_file
|
||||
$SnykOverview.ProjectTargetRunTime = $project.attributes.target_runtime
|
||||
|
||||
$Result += $SnykOverview
|
||||
}
|
||||
}
|
||||
|
||||
$Result | Export-Csv -Path $fileName -NoTypeInformation -Force
|
||||
|
||||
$Result | Format-Table
|
||||
Reference in New Issue
Block a user