Skip to content

Commit

Permalink
Audit event tweaks and sample report
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-peterson committed Oct 16, 2023
1 parent fd5b4fc commit a04a943
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 4 deletions.
47 changes: 47 additions & 0 deletions examples/membership_audit.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
function Get-GitlabMembershipReport {
param(
[string]
[Parameter(Mandatory, Position=0)]
$GroupName,

[string]
[Parameter(Mandatory)]
$StartDate,

[string]
[Parameter()]
$EndDate
)

$Group = Get-GitlabGroup $GroupName

$CurrentMembership = $Group | Get-GitlabGroupMember
$AuditRequest = @{
GroupId = $Group.Id
All = $true
FetchAuthors = $true
After = $StartDate
}
if ($EndDate) {
Before = $EndDate
}

Write-Host "Current membership of '$GroupName' on $(Get-Date):"
$CurrentMembership | Foreach-Object {
[PSCustomObject]@{
'User' = $_.Name
'Access' = $_.AccessLevelFriendly
'Granted On' = $_.CreatedAt
}
} | Format-Markdown
Write-Host "`nChanges to membership since $StartDate`:"
Get-GitlabAuditEvent @AuditRequest |
Where-Object { $_.Details.add -eq 'user_access' -or $_.Details.remove -eq 'user_access' -or $_.Details.change -eq 'access_level' } |
ForEach-Object {
[PSCustomObject]@{
Timestamp = $_.CreatedAt
User = $_.Author.Name
Action = $_.Summary
}
} | Format-Markdown
}
2 changes: 1 addition & 1 deletion src/GitlabCli/AuditEvents.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function Get-GitlabAuditEvent {
$After,

[Parameter()]
[int]
[uint]
$MaxPages = $global:GitlabGetProjectDefaultPages,

[Parameter()]
Expand Down
4 changes: 2 additions & 2 deletions src/GitlabCli/GitlabCli.psd1
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
@{
ModuleVersion = '1.104.0'
ModuleVersion = '1.104.1'

PrivateData = @{
PSData = @{
LicenseUri = 'https://github.com/chris-peterson/pwsh-gitlab/blob/main/LICENSE'
ProjectUri = 'https://github.com/chris-peterson/pwsh-gitlab'
ReleaseNotes = 'Upsert protected branches, minor usability improvements'
ReleaseNotes = 'Audit event tweaks'
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/GitlabCli/Types.ps1xml
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,11 @@
if ($Details.add) {
"Added $($Details.add) ($($Details.target_details)) in $($Details.entity_path)"
} elseif ($Details.remove) {
"Removed $($Details.remove) ($($Details.target_details)) in $($Details.entity_path)"
if ($Details.reason) {
"Removed '$($Details.target_details)' ($($Details.reason))"
} else {
"Removed $($Details.remove) ($($Details.target_details)) in $($Details.entity_path)"
}
} elseif ($Details.change) {
"Changed $($Details.change) ($($Details.target_details)) from $($Details.from) to $($Details.to) in $($Details.entity_path)"
} elseif ($Details.custom_message) {
Expand Down

0 comments on commit a04a943

Please sign in to comment.