|
10 | 10 | steps: |
11 | 11 | - uses: actions/checkout@v3 |
12 | 12 |
|
| 13 | + - name: Modify web.config files in all apps |
| 14 | + shell: pwsh |
| 15 | + run: | |
| 16 | + $webConfigPaths = @( |
| 17 | + "${{ github.workspace }}\AdminUI\LearningHub.Nhs.AdminUI\web.config", |
| 18 | + "${{ github.workspace }}\WebAPI\LearningHub.Nhs.Api\web.config", |
| 19 | + "${{ github.workspace }}\LearningHub.Nhs.WebUI\web.config" |
| 20 | + ) |
| 21 | +
|
| 22 | + foreach ($path in $webConfigPaths) { |
| 23 | + if (Test-Path $path) { |
| 24 | + Write-Host "Modifying $path" |
| 25 | + [xml]$config = Get-Content $path |
| 26 | + |
| 27 | + if (-not $config.configuration.'system.webServer') { |
| 28 | + $systemWebServer = $config.CreateElement("system.webServer") |
| 29 | + $config.configuration.AppendChild($systemWebServer) | Out-Null |
| 30 | + } else { |
| 31 | + $systemWebServer = $config.configuration.'system.webServer' |
| 32 | + } |
| 33 | + |
| 34 | + if (-not $systemWebServer.httpProtocol) { |
| 35 | + $httpProtocol = $config.CreateElement("httpProtocol") |
| 36 | + $systemWebServer.AppendChild($httpProtocol) | Out-Null |
| 37 | + } else { |
| 38 | + $httpProtocol = $systemWebServer.httpProtocol |
| 39 | + } |
| 40 | + |
| 41 | + if (-not $httpProtocol.customHeaders) { |
| 42 | + $customHeaders = $config.CreateElement("customHeaders") |
| 43 | + $httpProtocol.AppendChild($customHeaders) | Out-Null |
| 44 | + } else { |
| 45 | + $customHeaders = $httpProtocol.customHeaders |
| 46 | + } |
| 47 | + |
| 48 | + foreach ($name in @("X-Powered-By", "Server")) { |
| 49 | + $removeNode = $config.CreateElement("remove") |
| 50 | + $removeNode.SetAttribute("name", $name) |
| 51 | + $customHeaders.AppendChild($removeNode) | Out-Null |
| 52 | + } |
| 53 | + |
| 54 | + if (-not $systemWebServer.security) { |
| 55 | + $security = $config.CreateElement("security") |
| 56 | + $systemWebServer.AppendChild($security) | Out-Null |
| 57 | + } else { |
| 58 | + $security = $systemWebServer.security |
| 59 | + } |
| 60 | + |
| 61 | + if (-not $security.requestFiltering) { |
| 62 | + $requestFiltering = $config.CreateElement("requestFiltering") |
| 63 | + $requestFiltering.SetAttribute("removeServerHeader", "true") |
| 64 | + $security.AppendChild($requestFiltering) | Out-Null |
| 65 | + } |
| 66 | + |
| 67 | + $config.Save($path) |
| 68 | + } else { |
| 69 | + Write-Host "File not found: $path" |
| 70 | + } |
| 71 | + } |
| 72 | + |
13 | 73 | - name: Setup .NET Core SDK 8.0 |
14 | 74 | uses: actions/setup-dotnet@v3 |
15 | 75 | with: |
|
0 commit comments