Skip to content
Merged
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
84 changes: 60 additions & 24 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,60 @@
- name: PowerShell Security Scan
shell: pwsh
run: |
$psFiles = Get-ChildItem -Path . -Include *.ps1,*.psm1 -Recurse -File |
Select-Object -ExpandProperty FullName

if ($psFiles) {

$results = Invoke-ScriptAnalyzer -Path $psFiles -Severity Error,Warning |
Where-Object { $_.RuleName -like "*Security*" }

if ($results) {
$results | Format-Table
Write-Host "::error title=Security Scan::Potential security issues found in PowerShell scripts."
throw "Security issues detected by PSScriptAnalyzer"
}
else {
Write-Host "::notice title=Security Scan::No common security issues found in PowerShell scripts."
}

}
else {
Write-Host "::notice title=Security Scan::No PowerShell files found."
}
name: Continuous Integration

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:

jobs:
pester-test:
name: Run Pester Tests
runs-on: windows-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Run Pester tests
shell: pwsh
run: |
$results = Invoke-Pester -Path ./tests/Project.Tests.ps1 -PassThru
if ($results.FailedCount -gt 0) {
throw "Pester tests failed with $($results.FailedCount) errors."
}

security-scan:
name: PowerShell Security Scan
runs-on: windows-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install PSScriptAnalyzer
shell: pwsh
run: |
Set-PSRepository PSGallery -InstallationPolicy Trusted
Install-Module PSScriptAnalyzer -Force -Scope CurrentUser

- name: Run PowerShell Security Scan
shell: pwsh
run: |
$psFiles = Get-ChildItem -Path . -Include *.ps1,*.psm1 -Recurse -File |
Select-Object -ExpandProperty FullName

if ($psFiles) {
$results = Invoke-ScriptAnalyzer -Path $psFiles -Severity Error,Warning |
Where-Object { $_.RuleName -like "*Security*" }

if ($results) {
$results | Format-Table
Write-Host "::error title=Security Scan::Potential security issues found in PowerShell scripts."
throw "Security issues detected by PSScriptAnalyzer"
}
else {
Write-Host "::notice title=Security Scan::No common security issues found in PowerShell scripts."
}
}
else {
Write-Host "::notice title=Security Scan::No PowerShell files found."
}
7 changes: 2 additions & 5 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ on:
jobs:

analyze:
name: CodeQL JavaScript/TypeScript Scan
name: CodeQL Security Scan
runs-on: ubuntu-latest

permissions:
Expand All @@ -26,7 +26,7 @@ jobs:
strategy:
fail-fast: false
matrix:
language: ['javascript-typescript']
language: ['javascript-typescript', 'python']

timeout-minutes: 30

Expand Down Expand Up @@ -70,12 +70,10 @@ jobs:
- name: Run PowerShell Security Scan
shell: pwsh
run: |
# Find PowerShell files and convert to string paths
$psFiles = Get-ChildItem -Path . -Include *.ps1,*.psm1 -Recurse -File |
Select-Object -ExpandProperty FullName

if ($psFiles) {

$results = Invoke-ScriptAnalyzer -Path $psFiles -Severity Error,Warning |
Where-Object { $_.RuleName -like "*Security*" }

Expand All @@ -87,7 +85,6 @@ jobs:
else {
Write-Host "::notice title=Security Scan::No common security issues found in PowerShell scripts."
}

}
else {
Write-Host "::notice title=Security Scan::No PowerShell files found."
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/powershell-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ jobs:

- name: Install PSScriptAnalyzer
shell: pwsh
run: Install-Module PSScriptAnalyzer -Force -Scope CurrentUser
run: |
Set-PSRepository PSGallery -InstallationPolicy Trusted
Install-Module PSScriptAnalyzer -Force -Scope CurrentUser

- name: Run Security Scan
shell: pwsh
Expand All @@ -30,4 +32,4 @@ jobs:
throw "Security issues detected by PSScriptAnalyzer"
} else {
Write-Host "::notice title=Security Scan::No common security issues found."
}
}
13 changes: 5 additions & 8 deletions .github/workflows/powershell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
branches: [ "main" ]
schedule:
- cron: '38 9 * * 5'
workflow_dispatch:

permissions:
contents: read
Expand All @@ -29,16 +30,12 @@ jobs:
- name: Run PSScriptAnalyzer
shell: pwsh
run: |
# Determine repo root path based on OS
if ($IsWindows) {
$scanPath = ".\"
} else {
$scanPath = "."
}
# Ensure repository is trusted for smooth module installation
Set-PSRepository PSGallery -InstallationPolicy Trusted
Install-Module PSScriptAnalyzer -Force -Scope CurrentUser

# Run PSScriptAnalyzer
Install-Module PSScriptAnalyzer -Force -Scope CurrentUser
$results = Invoke-ScriptAnalyzer -Path $scanPath -Recurse -Severity Error,Warning `
$results = Invoke-ScriptAnalyzer -Path . -Recurse -Severity Error,Warning `
| Where-Object { $_.RuleName -like "*Security*" }

if ($results) {
Expand Down
34 changes: 2 additions & 32 deletions webhooks/listener.ps1
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
<<<<<<< HEAD
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingWriteHost", "")]
# =============================================
# System Automation Hub - Webhook Listener
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingWriteHost", "")]
# =============================================
=======
# =============================================
# System Automation Hub - Webhook Listener
# =============================================
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingWriteHost", "")]
param()

>>>>>>> origin/remote-control-bridge-12936344523257638862
$port = 9000
$endpoint = "http://localhost:$port/"

Expand All @@ -24,24 +17,18 @@ $listener.Prefixes.Add($endpoint)

try {
$listener.Start()
<<<<<<< HEAD
Write-Host "🚀 Listener started on $endpoint" -ForegroundColor Cyan
Write-Host "Press Ctrl+C to stop.`n" -ForegroundColor DarkGray

Write-Host "💡 To test locally, run:" -ForegroundColor Green
Write-Host "curl -X POST $endpoint -d '{""test"": ""hello""}' -H 'Content-Type: application/json'" -ForegroundColor DarkGray
Write-Host "curl -X POST $endpoint -d '{\"test\": \"hello\"}' -H 'Content-Type: application/json'" -ForegroundColor DarkGray
Write-Host "`nWaiting for events..." -ForegroundColor Cyan
=======
Write-Host "🚀 Listener started on $endpoint"
Write-Host "Press Ctrl+C to stop.`n"
>>>>>>> origin/remote-control-bridge-12936344523257638862

while ($listener.IsListening) {
$context = $listener.GetContext()
$request = $context.Request
$response = $context.Response

<<<<<<< HEAD
$timestamp = Get-Date -Format 'HH:mm:ss'
$method = $request.HttpMethod
$remote = $request.RemoteEndPoint
Expand All @@ -55,15 +42,11 @@ try {
Write-Host "$method " -ForegroundColor Yellow -NoNewline
Write-Host "from " -ForegroundColor Gray -NoNewline
Write-Host "$remote" -ForegroundColor White
=======
Write-Host "[$(Get-Date -Format 'HH:mm:ss')] Received $($request.HttpMethod) request from $($request.RemoteEndPoint)"
>>>>>>> origin/remote-control-bridge-12936344523257638862

# Read body if available
if ($request.HasEntityBody) {
$reader = New-Object System.IO.StreamReader($request.InputStream, [System.Text.Encoding]::UTF8)
$body = $reader.ReadToEnd()
<<<<<<< HEAD

try {
if ($request.ContentType -match "application/json") {
Expand All @@ -79,32 +62,19 @@ try {
Write-Host "Payload (Raw):" -ForegroundColor Cyan
Write-Host $body -ForegroundColor DarkGray
}
=======
Write-Host "Payload: $body"
>>>>>>> origin/remote-control-bridge-12936344523257638862
}

# Simple response
$buffer = [System.Text.Encoding]::UTF8.GetBytes("System Automation Hub: Event Received")
$response.ContentLength64 = $buffer.Length
$response.OutputStream.Write($buffer, 0, $buffer.Length)
$response.Close()
<<<<<<< HEAD
Write-Host "Done.`n" -ForegroundColor DarkGray
}
} catch {
Write-Host "❌ Error: $($_.Exception.Message)" -ForegroundColor Red
=======
}
} catch {
Write-Host "❌ Error: $($_.Exception.Message)"
>>>>>>> origin/remote-control-bridge-12936344523257638862
} finally {
if ($null -ne $listener) {
$listener.Stop()
}
<<<<<<< HEAD
}
=======
}
>>>>>>> origin/remote-control-bridge-12936344523257638862
Loading