appsec/New-AppSecConfigurationVersion.ps1
function New-AppSecConfigurationVersion { Param( [Parameter(ParameterSetName="name", Mandatory=$true)] [string] $ConfigName, [Parameter(ParameterSetName="id", Mandatory=$true)] [string] $ConfigID, [Parameter(Mandatory=$true)] [string] $CreateFromVersion, [Parameter(Mandatory=$false)] [switch] $UpdateRules, [Parameter(Mandatory=$false)] [string] $EdgeRCFile = '~\.edgerc', [Parameter(Mandatory=$false)] [string] $Section = 'default', [Parameter(Mandatory=$false)] [string] $AccountSwitchKey ) 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") } } $Path = "/appsec/v1/configs/$ConfigID/versions?accountSwitchKey=$AccountSwitchKey" if($CreateFromVersion.ToLower() -eq 'latest'){ $CreateFromVersion = (List-AppSecConfigurationVersions -ConfigID $ConfigID -PageSize 1 -EdgeRCFile $EdgeRCFile -Section $Section -AccountSwitchKey $AccountSwitchKey).version } $BodyObj = @{ createFromVersion = $CreateFromVersion ruleUpdate = $UpdateRules.IsPresent } $Body = $BodyObj | ConvertTo-Json -Depth 100 try { $Result = Invoke-AkamaiRestMethod -Method POST -Path $Path -Body $Body -EdgeRCFile $EdgeRCFile -Section $Section return $Result } catch { throw $_.Exception } } |