Skip to content
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

Warning JSON is truncated... after creating a file #605

Open
icabraja opened this issue Aug 11, 2024 · 1 comment
Open

Warning JSON is truncated... after creating a file #605

icabraja opened this issue Aug 11, 2024 · 1 comment
Labels
question ❔ Further information is requested

Comments

@icabraja
Copy link

icabraja commented Aug 11, 2024

I have created a page for adding my PXE deployments in the queue and everything works fine. Now I need to create a log file with new deployment but for some reason when I add

New-Item -ItemType File -Force -Path "$PSScriptRoot\public\logs\deployment\$($WebEvent.Data.MACAddress).log"

and click the button to add the deployment in the queue I get a warning in the console:

 WARNING: Resulting JSON is truncated as serialization has exceeded the set depth of 10

The page hangs, file gets created but button animation is in the loop and modal windows doesn't popup. Commenting out "New-Item", everything works fine. Here is a page snippet. Some data is redacted.

New-PodeWebCard -Name "Add deployment" -Content @(
    New-PodeWebForm -Name "Add PXE Deployment" -SubmitText "Add Deployment" -ShowReset -ResetText "Reset Form" -Content @(
        New-PodeWebTextbox -Name "Hostname" -DisplayName "Host Name" -Required -Width 500px -PrependIcon "desktop-classic" -HelpText "Hostname must follow REDACTED naming convention"
        New-PodeWebTextbox -Name "MACAddress" -DisplayName "MAC Address" -Required -Width 500px -PrependIcon "lan" -HelpText "MAC address needs to be in hypen format: aa-bb-cc-11-22-33"
        New-PodeWebLine
    ) -ScriptBlock {
        $DBPath = (Get-PodeConfig).DBPath
        $DBQuery = "SELECT MACAddress, IPAddress, Hostname FROM Deployments"
        $DBData = Invoke-SqliteQuery -Query $DBQuery -DataSource $DBPath
        $Hostname = $WebEvent.Data.Hostname.ToUpper()
        $MACAddress = $WebEvent.Data.MACAddress.ToUpper()

        $invalid = $false

        if ($Hostname -notmatch "^(REDACTED-|READECTED-)[A-Z]{4}-[0-9]{2}$") {
            Out-PodeWebValidation -Name "Hostname" -Message "Invalid Hostname format."
            $invalid = $true
        }
        if ($MACAddress -notmatch "^(([A-F0-9]{2}[-]){5}[A-F0-9]{2})$") {
            Out-PodeWebValidation -Name "MACAddress" -Message "Invalid MAC address or format. MAC address must be entered in hyphen format."
            $invalid = $true
        }
        if ($MACAddress -eq $DBData.MACAddress) {
            Out-PodeWebValidation -Name "MACAddress" -Message "MAC address already exists in deployment."
            $invalid = $true
        }
        if ($Hostname -eq $DBData.Hostname) {
            Out-PodeWebValidation -Name "Hostname" -Message "Hostname already exists in deployment."
            $invalid = $true
        }
        if ($invalid) {

            return
        }

        $DBPath = (Get-PodeConfig).DBPath
        $DBQuery = "SELECT AESKey, AESIV FROM Security"
        $DBData = Invoke-SqliteQuery -Query $DBQuery -DataSource $DBPath

        $EncryptUsername = Invoke-AESStringEncrypt -PlainTextString "$($WebEvent.Auth.User.Domain)\$($WebEvent.Auth.User.Username)" -Key $DBData.AESKey -InitVector $DBData.AESIV
        $PlainPassword = ConvertFrom-SecureString -SecureString $WebEvent.Auth.User.Credential.Password -AsPlainText
        $EncryptPassword = Invoke-AESStringEncrypt -PlainTextString $PlainPassword -Key $DBData.AESKey -InitVector $DBData.AESIV
        Clear-Variable -Name "PlainPassword"

        $DBPath = (Get-PodeConfig).DBPath
        $DBQuery = "INSERT INTO Deployments (MACAddress, Hostname, IPAddress, Username, Password, DeployStatus, VNCStatus) VALUES ('$MACAddress', '$Hostname', 'Waiting on PE', '$EncryptUsername', '$EncryptPassword', 'Waiting on PE', 'Waiting on PE')"
        Invoke-SqliteQuery -Query $DBQuery -DataSource $DBPath
        Show-PodeWebModal -Name "Add PXE Deployment"
        Sync-PodeWebTable -Name "PXE Deployment Status"
        Reset-PodeWebForm -Name "Add PXE Deployment"
        New-LogEntry -LogLevel '[INFO]' -LogLine "Deployment added to the queue by $($WebEvent.Auth.User.Username)" -Hostname "$Hostname" -MACAddress "$MACAddress" -LogFile "deployment.log"
        New-Item -ItemType File -Force -Path "$PSScriptRoot\public\logs\deployment\$($WebEvent.Data.MACAddress).log"
    }
)

New-PodeWebModal -Name "Add PXE Deployment" -DisplayName "Add PXE Deployment" -Icon "server-plus" -Content @(
    New-PodeWebAlert -Type Success -Content @(
        New-PodeWebText -Value "Deployment successfully added."
    )
)

EDIT

Tried with piping empty string to Out-FiIe, empty string with redirect operator and finally Set-Content with empty string as a -Value, they all worked. Bug maybe?

@icabraja icabraja added the question ❔ Further information is requested label Aug 11, 2024
@Badgerati
Copy link
Owner

Hi @icabraja,

It's because New-Item returns a value, and this is being returned from the scriptblock to Pode.Web which tries to parse it as an "Action".

If you pipe or set the value to null that should remove the warning :)

ie:

$null = New-Item -ItemType File -Force -Path "$PSScriptRoot\public\logs\deployment\$($WebEvent.Data.MACAddress).log"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question ❔ Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants