Skip to content

Commit d210014

Browse files
committed
Merge branch 'develop'
update main codebase
2 parents cf222b7 + 3dd0c8b commit d210014

File tree

2,534 files changed

+45803
-294213
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,534 files changed

+45803
-294213
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: Publish to PowerShell Gallery
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
PublishMonkeyToGallery:
9+
runs-on: windows-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
- name: Publish
13+
shell: powershell
14+
env:
15+
NUGET_KEY: ${{ secrets.PSGALLERY }}
16+
run: |
17+
$remove = @('.git', '.github', '.gitignore', 'docs', 'mkdocs.yml')
18+
Write-Output "INFO: Preparing Windows-based GitHub runner for publishing module to the PowerShell Gallery."
19+
Write-Output "INFO: Setting the PowerShell Gallery as a trusted repository."
20+
Set-PSRepository psgallery -InstallationPolicy trusted
21+
Write-Output "INFO: Locating module manifest in '$env:GITHUB_WORKSPACE'."
22+
$moduleManifest = Get-ChildItem -Path $env:GITHUB_WORKSPACE -Filter *.psd1
23+
If ($moduleManifest) {
24+
Write-Output ("SUCCESS: Manifest {0} found in {1}." -f $moduleManifest.FullName, $env:GITHUB_WORKSPACE)
25+
} Else {
26+
Write-Output ("FAILURE: Manifest not found in {0}." -f $env:GITHUB_WORKSPACE)
27+
}
28+
If ($moduleManifest.Name -match '^(.*)\.psd1$') {
29+
$moduleName = $Matches[1]
30+
Write-Output "SUCCESS: Determining module name from manifest file name '$moduleName'."
31+
} Else {
32+
Write-Error "FAILED: Determining module name from manifest file name '$moduleName'."
33+
}
34+
$manifest = Test-ModuleManifest -Path $moduleManifest.FullName
35+
$prerelease = $manifest.PrivateData.PSData['Prerelease']
36+
If ($prerelease -and $prerelease.StartsWith('-')){
37+
$version = ("{0}{1}" -f $manifest.version,$prerelease)
38+
}
39+
Else{
40+
$version = ("{0}-{1}" -f $manifest.version,$prerelease)
41+
}
42+
$modulePath = Join-Path -Path $env:RUNNER_TEMP -ChildPath $moduleName
43+
$createModulePath = New-Item -Path $modulePath -ItemType Directory -Force
44+
If ($createModulePath) {
45+
Write-Output "SUCCESS: Creating staging path '$modulePath'."
46+
} Else {
47+
Write-Error "FAILED: Creating staging path '$modulePath'."
48+
}
49+
Write-Output "INFO: Setting location to the GitHub workspace at '$env:GITHUB_WORKSPACE'."
50+
Set-Location $env:GITHUB_WORKSPACE
51+
Write-Output "INFO: Publishing module to the PowerShell Gallery."
52+
Get-ChildItem -Force | Where-Object { $_.Name -notin $remove } | Copy-Item -Destination $modulePath -Recurse
53+
#Get-ChildItem -Depth 5 -Path $modulePath | Format-Table -AutoSize
54+
$moduleManifest_ = Join-Path -Path $modulePath -ChildPath ("{0}.psd1" -f $moduleName)
55+
If (Test-Path -Path $moduleManifest_) {
56+
#Check if module is already loaded
57+
If($prerelease){
58+
$module = Find-Module -Name $moduleName -RequiredVersion ("{0}" -f $version) -AllowPrerelease -ErrorAction Ignore
59+
}
60+
Else{
61+
$module = Find-Module -Name $moduleName -RequiredVersion ("{0}" -f $version) -ErrorAction Ignore
62+
}
63+
If($null -eq $module){
64+
Publish-Module -Path $modulePath -NuGetApiKey $env:NUGET_KEY -Force
65+
Start-Sleep -Seconds 30
66+
If($prerelease){
67+
$module = Find-Module -Name $moduleName -RequiredVersion ("{0}" -f $version) -AllowPrerelease
68+
}
69+
Else{
70+
$module = Find-Module -Name $moduleName -RequiredVersion ("{0}" -f $version)
71+
}
72+
If ($module) {
73+
Write-Output "SUCCESS: Publishing module '$moduleName' version '$version' to PowerShell Gallery."
74+
}
75+
Else {
76+
Write-Error "FAILED: Publishing module '$moduleName' version '$version' to PowerShell Gallery."
77+
}
78+
}
79+
Else{
80+
Write-Output "SUCCESS: Module '$moduleName' version '$version' is already available in PowerShell Gallery."
81+
}
82+
} Else {
83+
Write-Error "FAILED: Module manifest file not found at path '$moduleManifest_'."
84+
}

.github/workflows/release.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Create Release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
jobs:
8+
monkeyversion:
9+
name: Get Monkey365 version
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
- name: Get current version
17+
id: monkey365version
18+
shell: pwsh
19+
run: |
20+
$manifest = Test-ModuleManifest -Path "./monkey365.psd1"
21+
$prerelease = $manifest.PrivateData.PSData['Prerelease']
22+
If ($prerelease -and $prerelease.StartsWith('-')){
23+
$version = ("{0}{1}" -f $manifest.version,$prerelease)
24+
}
25+
else{
26+
$version = ("{0}-{1}" -f $manifest.version,$prerelease)
27+
}
28+
$releaseName = ("Monkey365 v{0}" -f $version)
29+
"monkey365version=$version" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
30+
"releasename=$releaseName" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
31+
- name: Get current date
32+
id: date
33+
run: echo "today=$(date +'%Y-%m-%d_%H%M%S')" >> $GITHUB_OUTPUT
34+
- name: Set release
35+
id: release_message
36+
run: |
37+
echo "message=Thanks for follow [Monkey365](https://github.com/silverhack/monkey365)!." >> $GITHUB_ENV
38+
- name: Create Release
39+
id: create_release
40+
uses: comnoco/[email protected]
41+
env:
42+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
43+
with:
44+
tag_name: ${{ steps.monkey365version.outputs.monkey365version }}
45+
release_name: ${{ steps.monkey365version.outputs.releasename }}
46+
body: ${{ steps.release_message.outputs.message }}
47+
draft: true
48+
prerelease: false
49+
# Create a zip of the folder
50+
- name: Create ZIP file of the folder
51+
if: steps.create_release.outcome == 'success'
52+
run: |
53+
mkdir -p build
54+
git archive --format zip --output ./build/monkey365.zip main
55+
gh release upload ${{ steps.monkey365version.outputs.monkey365version }} ./build/monkey365.zip
56+
sha256sum ./build/monkey365.zip | awk '{print $1}' > ./build/monkey365.zip.sha256
57+
gh release upload ${{ steps.monkey365version.outputs.monkey365version }} ./build/monkey365.zip.sha256
58+
sha512sum ./build/monkey365.zip | awk '{print $1}' > ./build/monkey365.zip.sha512
59+
gh release upload ${{ steps.monkey365version.outputs.monkey365version }} ./build/monkey365.zip.sha512
60+
env:
61+
GITHUB_TOKEN: ${{ github.TOKEN }}

.github/workflows/psa.yml renamed to .github/workflows/scriptanalyzer.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Scan Code with PSScriptAnalyzer
1+
name: Scan Monkey365 with PSScriptAnalyzer
22

33
on:
44
# Triggers the workflow on push or pull request events but only for the develop branch
@@ -9,12 +9,12 @@ on:
99

1010
jobs:
1111
psscriptanalyzer_job:
12-
name: PsScriptAnalyzer Scan Job
12+
name: PsScriptAnalyzer Monkey365 Scan Job
1313
runs-on: ubuntu-latest
1414
steps:
1515
- name: Checkout code
1616
uses: actions/checkout@v2
17-
- name: Run PsScriptAnalyzer
17+
- name: Run ScriptAnalyzer
1818
uses: ./
1919
with:
2020
path: .\

Invoke-Monkey365.ps1

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -521,18 +521,14 @@ Function Invoke-Monkey365{
521521
Write-Error $_
522522
}
523523
Finally{
524-
#Remove Report variable
525-
if($null -ne (Get-Variable -Name Report -Scope Script -ErrorAction Ignore)){
526-
Remove-Variable -Name Report -Scope Script -Force
527-
}
528-
#Remove Report variable
529-
if($null -ne (Get-Variable -Name returnData -Scope Script -ErrorAction Ignore)){
530-
Remove-Variable -Name returnData -Scope Script -Force
531-
}
524+
#Remove OutFolder variable
525+
Remove-Variable -Name OutFolder -Scope Script -Force -ErrorAction Ignore
526+
#Remove returnData variable
527+
Remove-Variable -Name returnData -Scope Script -Force -ErrorAction Ignore
528+
#Remove LogQueue
529+
Remove-Variable -Name MonkeyLogQueue -Scope Global -ErrorAction Ignore -Force
532530
#collect garbage
533531
[System.GC]::GetTotalMemory($true) | out-null
534532
}
535533
}
536534
}
537-
538-

README.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
<a href="https://github.com/silverhack/monkey365"><img alt="ScriptAnalyzer" src="https://github.com/silverhack/monkey365/actions/workflows/psa.yml/badge.svg"></a>
88
<a href="https://github.com/silverhack/monkey365"><img alt="Lines" src="https://img.shields.io/tokei/lines/github/silverhack/monkey365"></a>
99
<a href="https://twitter.com/tr1ana"><img alt="Twitter" src="https://img.shields.io/twitter/follow/tr1ana?style=social"></a>
10+
[![latest PsGallery version](https://img.shields.io/powershellgallery/v/monkey365.svg?label=latest+version)](https://www.powershellgallery.com/packages/monkey365)
11+
[![Downloads](https://img.shields.io/powershellgallery/dt/monkey365.svg?label=downloads)](https://www.powershellgallery.com/packages/monkey365)
12+
![GitHub Downloads](https://img.shields.io/github/downloads/silverhack/monkey365/total)
1013
</p>
1114

1215
<p
@@ -19,7 +22,29 @@ Monkey365 is a collector-based PowerShell module that can be used to review the
1922

2023
# Installation
2124

22-
You can either download the latest zip by clicking [this link](https://github.com/silverhack/monkey365/archive/refs/heads/main.zip) or download Monkey365 by cloning the [repository](https://github.com/silverhack/monkey365.git):
25+
## PowerShell Gallery
26+
27+
You can install Monkey365 using the built-in `Install-Module` command. The examples below will install Monkey365 in your <a href="https://learn.microsoft.com/en-us/powershell/module/powershellget/install-module?view=powershellget-3.x#-scope" target="_blank">installation scope</a> depending on your PowerShell version. You can control this using the `-Scope <AllUsers/CurrentUser>` parameter.
28+
29+
``` powershell
30+
Install-Module -Name monkey365 -Scope CurrentUser
31+
```
32+
33+
To install a beta version, you can use the following command:
34+
35+
``` powershell
36+
Install-Module -Name monkey365 -Scope CurrentUser -AllowPrerelease
37+
```
38+
39+
To update monkey365:
40+
41+
``` powershell
42+
Update-Module -Name monkey365 -Scope CurrentUser
43+
```
44+
45+
## GitHub
46+
47+
You can download the latest release by clicking [here](https://github.com/silverhack/monkey365/releases). Once downloaded, you must extract the file and extract the files to a suitable directory.
2348

2449
Once downloaded, you must extract the files to a suitable directory. Once you have unzipped the zip file, you can use the PowerShell V3 Unblock-File cmdlet to unblock files:
2550

action.yml

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,17 @@ runs:
5757
- name: Run PSScriptAnalyzer
5858
shell: pwsh
5959
run: |
60-
$PSA_args = [ordered]@{ Path = '${{ inputs.path }}'; }
61-
if(![string]::IsNullOrEmpty('${{ inputs.customRulePath }}')) { $PSA_args.add('CustomRulePath', @(${{ inputs.customRulePath }})) }
62-
if(![string]::IsNullOrEmpty('${{ inputs.recurseCustomRulePath }}')) { $PSA_args.add('RecurseCustomRulePath', $true) }
63-
if(![string]::IsNullOrEmpty('${{ inputs.excludeRule }}')) { $PSA_args.add('ExcludeRule', @(${{ inputs.excludeRule }})) }
64-
if(![string]::IsNullOrEmpty('${{ inputs.includeDefaultRules }}') -and '${{ inputs.includeDefaultRules }}' -ne 'false') { $PSA_args.add('IncludeDefaultRules', $true) }
65-
if(![string]::IsNullOrEmpty('${{ inputs.includeRule }}')) { $PSA_args.add('IncludeRule', @(${{ inputs.includeRule }})) }
66-
if(![string]::IsNullOrEmpty('${{ inputs.severity }}')) { $PSA_args.add('Severity', @(${{ inputs.severity }})) }
67-
if(![string]::IsNullOrEmpty('${{ inputs.recurse }}') -and '${{ inputs.includeDefaultRules }}' -ne 'false') { $PSA_args.add('Recurse', $true) }
68-
if(![string]::IsNullOrEmpty('${{ inputs.fix }}')) { $PSA_args.add('Fix', $true) }
69-
if(![string]::IsNullOrEmpty('${{ inputs.enableExit }}')) { $PSA_args.add('EnableExit', $true) }
70-
if(![string]::IsNullOrEmpty('${{ inputs.settings }}')) { $PSA_args.add('Settings', '${{ inputs.settings }}') }
71-
[System.Void](Invoke-ScriptAnalyzer @PSA_args -Outvariable issues)
72-
$errors = $issues.Where({($_.Severity -eq 'Error') -or ($_.Severity -eq 'ParseError')})
73-
$warnings = $issues.Where({$_.Severity -eq 'Warning'})
74-
$info = $issues.Where({$_.Severity -eq 'Information'})
60+
$ExcludeDirs = @('pipelines','docs','rules','tests')
61+
$files = Get-ChildItem -Path ${{ inputs.path }} -Recurse | Where-Object {$_.FullName -notmatch ($ExcludeDirs -join '|')}
62+
$ScriptAnalyzer = @{
63+
Config = @{IncludeDefaultRules = $true;}
64+
Rules = Get-ScriptAnalyzerRule
65+
}
66+
$Config = $ScriptAnalyzer.Config
67+
$ScriptAnalyzer.Results = $files | Invoke-ScriptAnalyzer @Config
68+
$errors = $ScriptAnalyzer.Results.Where({($_.Severity -eq 'Error') -or ($_.Severity -eq 'ParseError')})
69+
$warnings = $ScriptAnalyzer.Results.Where({$_.Severity -eq 'Warning'})
70+
$info = $ScriptAnalyzer.Results.Where({$_.Severity -eq 'Information'})
7571
if($errors){
7672
foreach ($e in $errors){
7773
$message = ("file={0},line={1},message{2}" -f $e.ScriptName,$e.Line,$e.Message)

assets.zip

-14.6 MB
Binary file not shown.

build.ps1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,3 @@ $param = @{
7878
Write-information @param
7979
#Start process
8080
Start-Process docker -ArgumentList $buildArgs -NoNewWindow -Wait
81-

collectors/azure/APIM/Get-MonkeyAZAPIM.ps1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,3 @@ function Get-MonkeyAZAPIM {
131131

132132

133133

134-

collectors/azure/alerts/securityalerts/Get-MonkeyAzSecurityAlert.ps1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,3 @@ function Get-MonkeyAzSecurityAlert {
138138

139139

140140

141-

0 commit comments

Comments
 (0)