appsec/Set-AppSecCustomRule.ps1
function Set-AppSecCustomRule { Param( [Parameter(ParameterSetName="name", Mandatory=$true)] [string] $ConfigName, [Parameter(ParameterSetName="id", Mandatory=$true)] [string] $ConfigID, [Parameter(Mandatory=$true)] [string] $RuleID, [Parameter(Mandatory=$false, ValueFromPipeline=$true)] [object] $Rule, [Parameter(Mandatory=$false)] [string] $Body, [Parameter(Mandatory=$false)] [string] $EdgeRCFile = '~\.edgerc', [Parameter(Mandatory=$false)] [string] $Section = 'default', [Parameter(Mandatory=$false)] [string] $AccountSwitchKey ) begin{} process{ if($ConfigName){ $Config = List-AppSecConfigurations -EdgeRCFile $EdgeRCFile -Section $Section -AccountSwitchKey $AccountSwitchKey | where {$_.name -eq $ConfigName} if($Config){ $ConfigID = $Config.id } else{ throw("Security config '$ConfigName' not found") } } if($Rule){ $Body = $Rule | ConvertTo-Json -Depth 100 } $Path = "/appsec/v1/configs/$ConfigID/custom-rules/$RuleID`?accountSwitchKey=$AccountSwitchKey" try { $Result = Invoke-AkamaiRestMethod -Method PUT -Path $Path -Body $Body -EdgeRCFile $EdgeRCFile -Section $Section return $Result } catch { throw $_.Exception } } end{} } |