"$fxv#0": "function Set-AzureAgentlessOptions {\n [CmdletBinding()]\n param (\n [Parameter(Mandatory, ValueFromPipeline)]\n [Guid[]]$Subscriptions,\n [Parameter(Mandatory)]\n [string]$DatadogSite,\n [Parameter(Mandatory, HelpMessage = \"Datadog API Key\")]\n [ValidatePattern(\"^[0-9a-f]{32}$\")]\n [string]$APIKey,\n [Parameter(Mandatory, HelpMessage = \"Datadog Application Key\")]\n [ValidatePattern(\"^[0-9a-f]{40}$\")]\n [string]$ApplicationKey\n )\n begin {\n $url = \"https://api.${DatadogSite}/api/v2/agentless_scanning/accounts/azure\"\n $headers = @{\n \"Content-Type\" = \"application/vnd.api+json\"\n \"DD-API-KEY\" = $APIKey\n \"DD-APPLICATION-KEY\" = $ApplicationKey\n \"Dd-Call-Source\" = \"arm-agentless\"\n }\n }\n process {\n $subscription_id = $_.ToString()\n $body = @{\n \"data\" = @{\n \"id\" = $subscription_id\n \"type\" = \"azure_scan_options\"\n \"attributes\" = @{\n \"vuln_containers_os\" = $true\n \"vuln_host_os\" = $true\n }\n }\n } | ConvertTo-Json\n\n $result = Invoke-RestMethod -Method POST -Uri $url -Headers $headers -Body $body -SkipHttpErrorCheck -StatusCodeVariable status\n if ($status -eq 409) {\n # Subscription already exists; update it instead\n $result = Invoke-RestMethod -Method PATCH -Uri \"${url}/${subscription_id}\" -Headers $headers -Body $body -SkipHttpErrorCheck -StatusCodeVariable status\n }\n if ($status -ge 200 -and $status -lt 300) {\n Write-Output \"Successfully enabled Agentless Scanning for subscription ${subscription_id}\"\n }\n else {\n Write-Error \"Failed to enable Agentless Scanning for subscription ${subscription_id}: $(ConvertTo-Json -Compress $result)\"\n }\n }\n}\n\nfunction Convert-ScopeToSubscriptionId {\n [CmdletBinding()]\n param (\n [Parameter(Mandatory, ValueFromPipeline)]\n [string[]]$Scopes\n )\n process {\n $scope = $_.Trim()\n if ($scope -match '^/subscriptions/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})(/|$)') {\n return $Matches[1]\n }\n Write-Warning \"Ignoring scope: $scope\"\n }\n}\n\n${env:SCAN_SCOPES} |\nConvertFrom-Json |\nConvert-ScopeToSubscriptionId |\nSort-Object |\nGet-Unique |\nSet-AzureAgentlessOptions -APIKey ${env:DD_API_KEY} -ApplicationKey ${env:DD_APP_KEY} -DatadogSite ${env:DD_SITE}\n",
0 commit comments