Skip to content

Feat/get resource log category #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 50 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
e9bd332
Add ResourceLogCategory class and unit tests
fslef Mar 27, 2024
e7b6443
Bump gittools/actions from 0.9.15 to 1.1.1 (#5)
dependabot[bot] Mar 27, 2024
819a764
Bump actions/download-artifact from 3 to 4 (#7)
dependabot[bot] Mar 27, 2024
2cca178
Bump actions/upload-artifact from 3 to 4 (#6)
dependabot[bot] Mar 27, 2024
2e67f97
Bump actions/checkout from 3 to 4 (#4)
dependabot[bot] Mar 27, 2024
73b527d
Bump codecov/codecov-action from 4.0.1 to 4.1.1 (#3)
dependabot[bot] Mar 27, 2024
3e4fb14
Refactor ResourceType to ResourceLogCategory
fslef Mar 27, 2024
5bed922
Add unit test for ResourceLogCategory class
fslef Mar 27, 2024
5d8368a
Add 'ResourceLogCategory' Class
fslef Mar 28, 2024
9ef102a
Add 'ResourceLogCategory' Class
fslef Mar 28, 2024
6f8174a
Remove ResourceLogCategory test file
fslef Mar 28, 2024
c922479
Add 'ResourceLogCategory' Class
fslef Mar 28, 2024
f226a22
Refactor ResourceLogCategory class constructors and add unit tests
fslef Mar 28, 2024
ac4b696
Add unit test template for <ClassName> class
fslef Mar 28, 2024
522b0dd
Refactor ResourceLogCategory.tests.ps1
fslef Mar 28, 2024
e35ddd3
Update CodeCoverageThreshold to 60%
fslef Mar 28, 2024
46e2a67
Addes Az.Monitor in RequiredModules
fslef Mar 28, 2024
32a797d
Added Az.Accounts and Az.Resources as required modules
fslef Mar 28, 2024
6635fbf
Mock Get-AzResource function to return predefined results for testing
fslef Mar 28, 2024
e291a5b
Add parameter filter to ResourceLogCategory.tests.ps1
fslef Mar 28, 2024
d8ea625
Refactor ResourceLogCategory.tests.ps1 file
fslef Mar 28, 2024
153f63d
Remove unnecessary parameter filter in ResourceLogCategory.tests.ps1
fslef Mar 28, 2024
f19d47f
Refactored Get-AzResource mock in ResourceLogCategory.tests.ps1
fslef Mar 28, 2024
948bfe5
Mock Get-AzDiagnosticSettingCategory command in ResourceLogCategory.t…
fslef Mar 28, 2024
a853e44
Refactor ResourceLogCategory.tests.ps1 to use 'CyberShell' module
fslef Mar 28, 2024
1bc49cc
Add -Verifiable flag to Get-AzResource calls in ResourceLogCategory.t…
fslef Mar 28, 2024
eabe8dd
Refactor ResourceLogCategory.tests.ps1 to remove unnecessary module n…
fslef Mar 28, 2024
f27cc3e
Remove unnecessary parameter in ResourceLogCategory.tests.ps1
fslef Mar 28, 2024
373ff87
Add unit tests for ResourceLogCategory class
fslef Mar 28, 2024
7706a89
Refactor ResourceLogCategory.tests.ps1
fslef Mar 28, 2024
65f3cd8
Add mock for Get-AzContext command
fslef Mar 28, 2024
d34a0b7
Fix module import in ResourceLogCategory.tests.ps1
fslef Mar 28, 2024
b4f7b2f
Remove unnecessary parameters in mock functions
fslef Mar 28, 2024
7658a02
Remove parameter validation in ResourceLogCategory.tests.ps1
fslef Mar 28, 2024
9eb9266
Remove unnecessary modules from RequiredModules.psd1
fslef Mar 28, 2024
dd56b1e
Remove parameter validation in ResourceLogCategory.tests.ps1
fslef Mar 28, 2024
e0a0b2e
Update CodeCoverageThreshold in build.yaml
fslef Mar 28, 2024
44d8678
Add Connect-AzAccount to ResourceLogCategory.tests.ps1
fslef Mar 29, 2024
fb982b5
Add latest Az modules
fslef Mar 29, 2024
bc876ea
Add simulated Azure context for testing
fslef Mar 29, 2024
8bb827d
Add UnitQuality tag to <ClassName> Class Unit Tests
fslef Mar 29, 2024
ddeae63
Refactor unit tests for ResourceLogCategory class
fslef Mar 29, 2024
e2bbb15
Add UnitQuality to Pester exclusion in build.yaml
fslef Mar 29, 2024
6bfaae0
Refactor azureProfile object creation
fslef Mar 29, 2024
0048d1c
Remove unit test template file
fslef Apr 2, 2024
1221148
Fix tags in module.tests.ps1
fslef Apr 2, 2024
f0231ec
Delete ResourceLogCategory class
fslef Apr 2, 2024
0bfc643
Refactor ListOfLogCategory class for better resource management
fslef Apr 8, 2024
35f2b4b
Add LogCategoryObj class for managing log categories
fslef Apr 8, 2024
a4be02c
Add Get-CsLogCategory function for retrieving Azure resources and the…
fslef Apr 8, 2024
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
42 changes: 21 additions & 21 deletions .github/workflows/deploy-module.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v0.9.15
uses: gittools/actions/gitversion/setup@v1.1.1
with:
versionSpec: 5.x
- name: Evaluate Next Version
uses: gittools/actions/gitversion/execute@v0.9.15
uses: gittools/actions/gitversion/execute@v1.1.1
with:
configFilePath: GitVersion.yml
- name: Build & Package Module
Expand All @@ -45,7 +45,7 @@ jobs:
env:
ModuleVersion: ${{ env.gitVersion.NuGetVersionV2 }}
- name: Publish Build Artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: ${{ env.buildArtifactName }}
path: ${{ env.buildFolderName }}/
Expand All @@ -55,19 +55,19 @@ jobs:
needs: Build_Stage_Package_Module
steps:
- name: Checkout Code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download Build Artifact
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: ${{ env.buildArtifactName }}
path: ${{ env.buildFolderName }}
- name: Run Tests
shell: pwsh
run: ./build.ps1 -tasks test
- name: Publish Test Artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
path: ${{ env.buildFolderName }}/${{ env.testResultFolderName }}/
name: CodeCoverageLinux
Expand All @@ -78,19 +78,19 @@ jobs:
needs: Build_Stage_Package_Module
steps:
- name: Checkout Code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download Build Artifact
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: ${{ env.buildArtifactName }}
path: ${{ env.buildFolderName }}
- name: Run Tests
shell: pwsh
run: ./build.ps1 -tasks test
- name: Publish Test Artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
path: ${{ env.buildFolderName }}/${{ env.testResultFolderName }}/
name: CodeCoverageWinPS7
Expand All @@ -101,19 +101,19 @@ jobs:
needs: Build_Stage_Package_Module
steps:
- name: Checkout Code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download Build Artifact
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: ${{ env.buildArtifactName }}
path: ${{ env.buildFolderName }}
- name: Run Tests
shell: pwsh
run: ./build.ps1 -tasks test
- name: Publish Test Artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
path: ${{ env.buildFolderName }}/${{ env.testResultFolderName }}/
name: CodeCoverageMacOS
Expand All @@ -129,25 +129,25 @@ jobs:
- Test_Stage_test_macos
steps:
# - name: Checkout Code
# uses: actions/checkout@v3
# uses: actions/checkout@v4
# with:
# fetch-depth: 0
# - name: Download Test Artifacts
# uses: actions/download-artifact@v3
# uses: actions/download-artifact@v4
# with:
# path: ${{ env.buildFolderName }}/${{ env.testResultFolderName }}/
- name: Download Test Artifact macOS
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: CodeCoverageMacOS
path: ${{ env.buildFolderName }}/${{ env.testResultFolderName }}/CodeCoverageMacOS/
- name: Download Test Artifact Linux
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: CodeCoverageLinux
path: ${{ env.buildFolderName }}/${{ env.testResultFolderName }}/CodeCoverageLinux/
- name: Download Test Artifact Windows (PS7)
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: CodeCoverageWinPS7
path: ${{ env.buildFolderName }}/${{ env.testResultFolderName }}/CodeCoverageWinPS7/
Expand All @@ -173,7 +173,7 @@ jobs:
nunit_files: ${{ env.buildFolderName }}/${{ env.testResultFolderName }}/CodeCoverageWinPS7/NUnit*.xml
check_name: WinPS71 Test Results
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4.0.1
uses: codecov/codecov-action@v4.1.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: CyberShell-App/CyberShell
Expand All @@ -189,11 +189,11 @@ jobs:
if: github.ref == 'refs/heads/main'
steps:
- name: Checkout Code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download Build Artifact
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: ${{ env.buildArtifactName }}
path: ${{ env.buildFolderName }}
Expand Down
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Powershell module initialization using the excellent [Sampler](https://github.com/gaelcolas/Sampler).


- Add 'ResourceLogCategory' Class
21 changes: 11 additions & 10 deletions RequiredModules.psd1
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
@{
PSDependOptions = @{
PSDependOptions = @{
AddToPath = $true
Target = 'output\RequiredModules'
Parameters = @{
Repository = 'PSGallery'
}
}

InvokeBuild = 'latest'
PSScriptAnalyzer = 'latest'
Pester = 'latest'
ModuleBuilder = 'latest'
ChangelogManagement = 'latest'
Sampler = 'latest'
'Sampler.GitHubTasks' = 'latest'


InvokeBuild = 'latest'
PSScriptAnalyzer = 'latest'
Pester = 'latest'
ModuleBuilder = 'latest'
ChangelogManagement = 'latest'
Sampler = 'latest'
'Sampler.GitHubTasks' = 'latest'
'Az.Accounts' = 'latest'
'Az.Monitor' = 'latest'
'Az.Resources' = 'latest'
}

1 change: 1 addition & 0 deletions build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ Pester:
# - helpQuality
# - FunctionalQuality
# - TestQuality
- UnitQuality
Tag:
CodeCoverageThreshold: 0 # Set to 0 to bypass
#CodeCoverageOutputFile: JaCoCo_$OsShortName.xml
Expand Down
90 changes: 90 additions & 0 deletions src/Classes/002 LogCategory-list.ps1.old
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#dotsource the corresponding object class
class ListOfLogCategory {
# Static property to hold the list of resources
static [System.Collections.Generic.List[LogCategoryObj]] $Resources

# Static method to initialize the list of resources. Called in the other
# static methods to avoid needing to explicit initialize the value.
static [void] Initialize() { [ListOfLogCategory]::Initialize($false) }

# Initialize the list of resources.
static [bool] Initialize([bool]$force) {
if ([ListOfLogCategory]::Resources.Count -gt 0 -and -not $force) {
return $false
}
[ListOfLogCategory]::Resources = [System.Collections.Generic.List[LogCategoryObj]]::new()
return $true
}

# Ensure the LogCategoryObj is valid for the list.
static [void] Validate([LogCategoryObj]$Resource) {
$Prefix = 'Resource validation failed: Resource must be defined with the ContainerId, ResourceTypeName, and SourceType properties, but'
if ($null -eq $Resource) { throw "$Prefix was null" }
if ([string]::IsNullOrEmpty($Resource.ContainerId)) {
throw "$Prefix ContainerId wasn't defined"
}
if ([string]::IsNullOrEmpty($Resource.ResourceTypeName)) {
throw "$Prefix ResourceTypeName wasn't defined"
}
if ([string]::IsNullOrEmpty($Resource.SourceType)) {
throw "$Prefix SourceType wasn't defined"
}
}

# Static methods to manage the list of LogCategoryObj.
# Add a LogCategoryObj if it's not already in the list.
static [void] Add([LogCategoryObj]$Resource) {
[ListOfLogCategory]::Initialize()
[ListOfLogCategory]::Validate($Resource)
$FindPredicate = {
param([LogCategoryObj]$r)
$r.ContainerId -eq $Resource.ContainerId -and
$r.ResourceTypeName -eq $Resource.ResourceTypeName -and
$r.SourceType -eq $Resource.SourceType
}.GetNewClosure()
if ([ListOfLogCategory]::Resources.Find($FindPredicate)) {
throw "Resource with ContainerId '$Resource.ContainerId', ResourceTypeName '$Resource.ResourceTypeName', and SourceType '$Resource.SourceType' already in list"
}
[ListOfLogCategory]::Resources.Add($Resource)
}

# Clear the list of LogCategoryObj.
static [void] Clear() {
[ListOfLogCategory]::Initialize()
[ListOfLogCategory]::Resources.Clear()
}

# Method to find the first LogCategoryObj that matches the given criteria.
# This method stops searching as soon as it finds a match, so it's more efficient for large lists.
# However, it will not alert you to duplicate entries.
static [LogCategoryObj] Find([scriptblock]$Predicate) {
[ListOfLogCategory]::Initialize()
return [ListOfLogCategory]::Resources.Find($Predicate)
}

# Method to find all LogCategoryObjs that match the given criteria.
# This method searches the entire list and returns all matches.
# Use this method when you need to find all matches, or when you need to check for duplicates.
static [LogCategoryObj[]] FindAll([scriptblock]$Predicate) {
[ListOfLogCategory]::Initialize()
return [ListOfLogCategory]::Resources.FindAll($Predicate)
}

# Remove a LogCategoryObj from the list.
static [void] Remove([LogCategoryObj]$Resource) {
[ListOfLogCategory]::Initialize()
[ListOfLogCategory]::Resources.Remove($Resource)
}

# Remove a LogCategoryObj from the list by property and value.
static [void] RemoveBy([string]$Property, [string]$Value) {
[ListOfLogCategory]::Initialize()
$Index = [ListOfLogCategory]::Resources.FindIndex({
param($r)
$r.$Property -eq $Value
}.GetNewClosure())
if ($Index -ge 0) {
[ListOfLogCategory]::Resources.RemoveAt($Index)
}
}
}
Loading