ConvertToNBRedactedBody
SYNOPSIS
Returns a copy of a request body that is safe to write to the verbose stream.
SYNTAX
ConvertToNBRedactedBody [[-Body] <Object>] [[-Depth] <Int32>] [-ProgressAction <ActionPreference>]
[<CommonParameters>]
DESCRIPTION
Builds a deep copy of the body in which the value of every field whose name looks sensitive is replaced by 'REDACTED'. The original body is never modified - it still has to be sent to NetBox.
A field is sensitive when its name contains one of: secret, passw (password, passwd), passphrase, key, token, psk, credential, community (SNMP), header. 'header' is there for a webhook's additional_headers, which is a plain string field that routinely carries an 'Authorization: Bearer ...' line. Matching is by name only and errs on the side of masking too much: a masked field costs a little debugging comfort, a logged credential costs a rotation.
Dictionaries are walked by their entries. That is the whole point of this helper: $hashtable.PSObject.Properties does NOT enumerate the entries of a hashtable, it enumerates the .NET members of the Hashtable type (Keys, Values, SyncRoot, Count, ...). Redacting "by property" therefore masked 'Keys' and then logged every value in clear text through 'Values' and 'SyncRoot'.
Nested dictionaries, PSCustomObjects and arrays are handled recursively, so a secret inside e.g. a data source's 'parameters' or inside 'custom_fields' is masked as well.
EXAMPLES
EXAMPLE 1
ConvertToNBRedactedBody -Body @{ username = 'alice'; password = 'hunter2' } | ConvertTo-Json -Compress
{"username":"alice","password":"REDACTED"}
PARAMETERS
-Body
The request body: a hashtable / ordered dictionary, a PSCustomObject, an array of those, or a scalar.
Type: Object
Parameter Sets: (All)
Aliases:
Required: False
Position: 1
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-Depth
Current recursion depth. Internal; callers leave it at 0.
Type: Int32
Parameter Sets: (All)
Aliases:
Required: False
Position: 2
Default value: 0
Accept pipeline input: False
Accept wildcard characters: False
-ProgressAction
{{ Fill ProgressAction Description }}
Type: ActionPreference
Parameter Sets: (All)
Aliases: proga
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
INPUTS
OUTPUTS
System.Collections.Specialized.OrderedDictionary
System.Object[]
System.String
System.Object
NOTES
Internal helper, used by InvokeNetboxRequest for the "BODY:" verbose line.