Skip to content

Commit

Permalink
Modify functions to pass all test cmd line argument test cases except…
Browse files Browse the repository at this point in the history
… test cases 8 - 10
  • Loading branch information
jonnybottles committed Jan 14, 2025
1 parent 0c41e1a commit 49dab29
Show file tree
Hide file tree
Showing 4 changed files with 298 additions and 267 deletions.
88 changes: 75 additions & 13 deletions Hawk/functions/Tenant/Start-HawkTenantInvestigation.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -100,37 +100,99 @@
param (
[DateTime]$StartDate,
[DateTime]$EndDate,
[ValidateRange(1, 365)]
[int]$DaysToLookBack,
[string]$FilePath,
[switch]$SkipUpdate,
[switch]$NonInteractive
)


# begin {
# # Validate parameters if in non-interactive mode
# if ($NonInteractive) {


# # if ($NonInteractive) {

# # Write-Output "ENTERING COMMAND LINE INTERFACE NON INTERACTIVE MODE"

# # # Check if DaysToLookBack is valid before calling the conversion function
# # if ($DaysToLookBack -ne $null -and $DaysToLookBack -ge 1 -and $DaysToLookBack -le 365) {
# # $ConvertedDates = Convert-HawkDaysToDates -DaysToLookBack $DaysToLookBack
# # $StartDate = $ConvertedDates.StartDate
# # $EndDate = $ConvertedDates.EndDate
# # }

# # }
# # if ($NonInteractive) {

# # Write-Output "ENTERING COMMAND LINE INTERFACE NON INTERACTIVE MODE"

# # # Check if DaysToLookBack is valid before calling the conversion function
# # if ($DaysToLookBack -ne $null -and $DaysToLookBack -ge 1 -and $DaysToLookBack -le 365) {
# # $ConvertedDates = Convert-HawkDaysToDates -DaysToLookBack $DaysToLookBack
# # $StartDate = $ConvertedDates.StartDate
# # $EndDate = $ConvertedDates.EndDate
# # }

# # }


# $validation = Test-HawkInvestigationParameter -StartDate $StartDate -EndDate $EndDate `
# -DaysToLookBack $DaysToLookBack -FilePath $FilePath -NonInteractive

# if (-not $validation.IsValid) {
# foreach ($error in $validation.ErrorMessages) {
# Stop-PSFFunction -Message $error -EnableException $true
# }
# }


# try {
# # Initialize with provided parameters
# Initialize-HawkGlobalObject -StartDate $StartDate -EndDate $EndDate -DaysToLookBack $DaysToLookBack `
# -FilePath $FilePath -SkipUpdate:$SkipUpdate -NonInteractive:$NonInteractive
# }
# catch {
# Stop-PSFFunction -Message "Failed to initialize Hawk: $_" -EnableException $true
# }
# }

# }


begin {
# Validate parameters if in non-interactive mode
if ($NonInteractive) {
$validation = Test-HawkInvestigationParameter -StartDate $StartDate -EndDate $EndDate `
# If DaysToLookBack is specified, convert it first
if ($PSBoundParameters.ContainsKey('DaysToLookBack') -and $DaysToLookBack -ge 1 -and $DaysToLookBack -le 365) {
$convertedDates = Convert-HawkDaysToDate -DaysToLookBack $DaysToLookBack
$StartDate = $convertedDates.StartDate
$EndDate = $convertedDates.EndDate
}

# Now call validation with updated StartDate/EndDate
$validation = Test-HawkInvestigationParameter `
-StartDate $StartDate -EndDate $EndDate `
-DaysToLookBack $DaysToLookBack -FilePath $FilePath -NonInteractive

if (-not $validation.IsValid) {
foreach ($error in $validation.ErrorMessages) {
Stop-PSFFunction -Message $error -EnableException $true
}
}
}

try {
# Initialize with provided parameters
Initialize-HawkGlobalObject -StartDate $StartDate -EndDate $EndDate -DaysToLookBack $DaysToLookBack `
-FilePath $FilePath -SkipUpdate:$SkipUpdate -NonInteractive:$NonInteractive
}
catch {
Stop-PSFFunction -Message "Failed to initialize Hawk: $_" -EnableException $true

try {
Initialize-HawkGlobalObject -StartDate $StartDate -EndDate $EndDate `
-DaysToLookBack $DaysToLookBack -FilePath $FilePath `
-SkipUpdate:$SkipUpdate -NonInteractive:$NonInteractive
}
catch {
Stop-PSFFunction -Message "Failed to initialize Hawk: $_" -EnableException $true
}
}
}


process {

if (Test-PSFFunctionInterrupt) { return }
Expand Down
2 changes: 1 addition & 1 deletion Hawk/internal/functions/Convert-HawkDaysToDate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Function Convert-HawkDaysToDate {

# Calculate the dates
$startDate = (Get-Date).ToUniversalTime().AddDays(-$DaysToLookBack).Date
$endDate = (Get-Date).ToUniversalTime().AddDays(1).Date
$endDate = (Get-Date).ToUniversalTime().Date

# Return the dates as a PSCustomObject
[PSCustomObject]@{
Expand Down
Loading

0 comments on commit 49dab29

Please sign in to comment.