Module/Rule.FileContent/Convert/FileContentType/Methods.OracleJRE.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
#region Method Functions
<#
    .SYNOPSIS
        Parses the rawString from the rule to retrieve the Key name and Value
        for OracleJRE STIGs
    .DESCRIPTION
        The FileContentType is used to extend filter and parse logic for different
        FileContentRules without modifing existing filtering and parsing logic
    .PARAMETER MatchResult
        The list of items to filter and parse
#>

function Get-FilteredItem
{
    [CmdletBinding()]
    [OutputType([psobject])]
    param
    (
        [Parameter(Mandatory = $true)]
        [AllowNull()]
        [AllowEmptyString()]
        [psobject]
        $MatchResult
    )

        $lineResult = $matchResult.Matches | Where-Object -FilterScript {$PSItem.Value -match '=' -or $PSItem.Value -match '.locked' -or $PSItem.Value -match '.mandatory'}
        if ($lineResult)
        {
            return Get-ParsedItem -LineResult $lineResult
        }
        else
        {
            return $null
        }
}

<#
    .SYNOPSIS
        Applies the specific parsing strategy for a specific FileContentType
    .DESCRIPTION
        The FileContentType is used to extend filter and parse logic for different
        FileContentRules without modifing existing filtering and parsing logic
    .PARAMETER LineResult
        The specific line item to parse
#>

function Get-ParsedItem
{
    [CmdletBinding()]
    [OutputType([pscustomobject])]
    param
    (
        [Parameter(Mandatory = $true)]
        [AllowNull()]
        [AllowEmptyString()]
        [psobject]
        $LineResult
    )
    
    $setting = @()
    $settingNoQuotes = $lineResult[0].Value -replace $regexToRemove, ""
    if ($lineResult[0].Value -match '=')
    {
        $setting = $settingNoQuotes.Split('=') | ForEach-Object {
            New-Object PSObject -Property @{Value=$_}
        }
    }

    if ($lineResult[0].Value -match '.locked' -or $lineResult[0].Value -match '.mandatory')
    {
        $setting = @($settingNoQuotes, 'true') | ForEach-Object {
            New-Object PSObject -Property @{Value=$_}
        }
    }
    return $setting
}