CreateRuleGroup autoit Example
; This example requires the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
$oRest = ObjCreate("Chilkat_9_5_0.Rest")
Local $bSuccess
$oAuthAws = ObjCreate("Chilkat_9_5_0.AuthAws")
$oAuthAws.AccessKey = "AWS_ACCESS_KEY"
$oAuthAws.SecretKey = "AWS_SECRET_KEY"
; Don't forget to change the region to your particular region. (Also make the same change in the call to Connect below.)
$oAuthAws.Region = "us-west-2"
$oAuthAws.ServiceName = "network-firewall"
; SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
$oRest.SetAuthAws($oAuthAws)
; URL: https://network-firewall.us-west-2.amazonaws.com/
; Use the same region as specified above.
$bSuccess = $oRest.Connect("network-firewall.us-west-2.amazonaws.com",443,True,True)
If ($bSuccess <> True) Then
ConsoleWrite("ConnectFailReason: " & $oRest.ConnectFailReason & @CRLF)
ConsoleWrite($oRest.LastErrorText & @CRLF)
Exit
EndIf
; The following code creates the JSON request body.
; The JSON created by this code is shown below.
; Use this online tool to generate code from sample JSON:
; Generate Code to Create JSON
$oJson = ObjCreate("Chilkat_9_5_0.JsonObject")
$oJson.UpdateInt("Capacity",123)
$oJson.UpdateString("Description","string")
$oJson.UpdateInt("DryRun",123)
$oJson.UpdateString("EncryptionConfiguration.KeyId","string")
$oJson.UpdateString("EncryptionConfiguration.Type","string")
$oJson.UpdateString("RuleGroup.RulesSource.RulesSourceList.GeneratedRulesType","string")
$oJson.UpdateString("RuleGroup.RulesSource.RulesSourceList.Targets[0]","string")
$oJson.UpdateString("RuleGroup.RulesSource.RulesSourceList.TargetTypes[0]","string")
$oJson.UpdateString("RuleGroup.RulesSource.RulesString","string")
$oJson.UpdateString("RuleGroup.RulesSource.StatefulRules[0].Action","string")
$oJson.UpdateString("RuleGroup.RulesSource.StatefulRules[0].Header.Destination","string")
$oJson.UpdateString("RuleGroup.RulesSource.StatefulRules[0].Header.DestinationPort","string")
$oJson.UpdateString("RuleGroup.RulesSource.StatefulRules[0].Header.Direction","string")
$oJson.UpdateString("RuleGroup.RulesSource.StatefulRules[0].Header.Protocol","string")
$oJson.UpdateString("RuleGroup.RulesSource.StatefulRules[0].Header.Source","string")
$oJson.UpdateString("RuleGroup.RulesSource.StatefulRules[0].Header.SourcePort","string")
$oJson.UpdateString("RuleGroup.RulesSource.StatefulRules[0].RuleOptions[0].Keyword","string")
$oJson.UpdateString("RuleGroup.RulesSource.StatefulRules[0].RuleOptions[0].Settings[0]","string")
$oJson.UpdateString("RuleGroup.RulesSource.StatelessRulesAndCustomActions.CustomActions[0].ActionDefinition.PublishMetricAction.Dimensions[0].Value","string")
$oJson.UpdateString("RuleGroup.RulesSource.StatelessRulesAndCustomActions.CustomActions[0].ActionName","string")
$oJson.UpdateInt("RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[0].Priority",123)
$oJson.UpdateString("RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[0].RuleDefinition.Actions[0]","string")
$oJson.UpdateInt("RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[0].RuleDefinition.MatchAttributes.DestinationPorts[0].FromPort",123)
$oJson.UpdateInt("RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[0].RuleDefinition.MatchAttributes.DestinationPorts[0].ToPort",123)
$oJson.UpdateString("RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[0].RuleDefinition.MatchAttributes.Destinations[0].AddressDefinition","string")
ERROR: Undefined variable(number)
$oJson.UpdateInt("RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[0].RuleDefinition.MatchAttributes.Protocols[0]",ERROR: Undefined variable(number)
)
$oJson.UpdateInt("RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[0].RuleDefinition.MatchAttributes.SourcePorts[0].FromPort",123)
$oJson.UpdateInt("RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[0].RuleDefinition.MatchAttributes.SourcePorts[0].ToPort",123)
$oJson.UpdateString("RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[0].RuleDefinition.MatchAttributes.Sources[0].AddressDefinition","string")
$oJson.UpdateString("RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[0].RuleDefinition.MatchAttributes.TCPFlags[0].Flags[0]","string")
$oJson.UpdateString("RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[0].RuleDefinition.MatchAttributes.TCPFlags[0].Masks[0]","string")
$oJson.UpdateString("RuleGroup.RuleVariables.IPSets.string.Definition[0]","string")
$oJson.UpdateString("RuleGroup.RuleVariables.PortSets.string.Definition[0]","string")
$oJson.UpdateString("RuleGroup.StatefulRuleOptions.RuleOrder","string")
$oJson.UpdateString("RuleGroupName","string")
$oJson.UpdateString("Rules","string")
$oJson.UpdateString("SourceMetadata.SourceArn","string")
$oJson.UpdateString("SourceMetadata.SourceUpdateToken","string")
$oJson.UpdateString("Tags[0].Key","string")
$oJson.UpdateString("Tags[0].Value","string")
$oJson.UpdateString("Type","string")
; The JSON request body created by the above code:
; {
; "Capacity": number,
; "Description": "string",
; "DryRun": boolean,
; "EncryptionConfiguration": {
; "KeyId": "string",
; "Type": "string"
; },
; "RuleGroup": {
; "RulesSource": {
; "RulesSourceList": {
; "GeneratedRulesType": "string",
; "Targets": [
; "string"
; ],
; "TargetTypes": [
; "string"
; ]
; },
; "RulesString": "string",
; "StatefulRules": [
; {
; "Action": "string",
; "Header": {
; "Destination": "string",
; "DestinationPort": "string",
; "Direction": "string",
; "Protocol": "string",
; "Source": "string",
; "SourcePort": "string"
; },
; "RuleOptions": [
; {
; "Keyword": "string",
; "Settings": [
; "string"
; ]
; }
; ]
; }
; ],
; "StatelessRulesAndCustomActions": {
; "CustomActions": [
; {
; "ActionDefinition": {
; "PublishMetricAction": {
; "Dimensions": [
; {
; "Value": "string"
; }
; ]
; }
; },
; "ActionName": "string"
; }
; ],
; "StatelessRules": [
; {
; "Priority": number,
; "RuleDefinition": {
; "Actions": [
; "string"
; ],
; "MatchAttributes": {
; "DestinationPorts": [
; {
; "FromPort": number,
; "ToPort": number
; }
; ],
; "Destinations": [
; {
; "AddressDefinition": "string"
; }
; ],
; "Protocols": [
; number
; ],
; "SourcePorts": [
; {
; "FromPort": number,
; "ToPort": number
; }
; ],
; "Sources": [
; {
; "AddressDefinition": "string"
; }
; ],
; "TCPFlags": [
; {
; "Flags": [
; "string"
; ],
; "Masks": [
; "string"
; ]
; }
; ]
; }
; }
; }
; ]
; }
; },
; "RuleVariables": {
; "IPSets": {
; "string": {
; "Definition": [
; "string"
; ]
; }
; },
; "PortSets": {
; "string": {
; "Definition": [
; "string"
; ]
; }
; }
; },
; "StatefulRuleOptions": {
; "RuleOrder": "string"
; }
; },
; "RuleGroupName": "string",
; "Rules": "string",
; "SourceMetadata": {
; "SourceArn": "string",
; "SourceUpdateToken": "string"
; },
; "Tags": [
; {
; "Key": "string",
; "Value": "string"
; }
; ],
; "Type": "string"
; }
$oRest.AddHeader("Content-Type","application/x-amz-json-1.0")
$oRest.AddHeader("X-Amz-Target","NetworkFirewall_20201112.CreateRuleGroup")
$oSbRequestBody = ObjCreate("Chilkat_9_5_0.StringBuilder")
$oJson.EmitSb($oSbRequestBody)
$oSbResponseBody = ObjCreate("Chilkat_9_5_0.StringBuilder")
$bSuccess = $oRest.FullRequestSb("POST","/",$oSbRequestBody,$oSbResponseBody)
If ($bSuccess <> True) Then
ConsoleWrite($oRest.LastErrorText & @CRLF)
Exit
EndIf
Local $iRespStatusCode = $oRest.ResponseStatusCode
ConsoleWrite("response status code = " & $iRespStatusCode & @CRLF)
If ($iRespStatusCode <> 200) Then
ConsoleWrite("Response Header:" & @CRLF)
ConsoleWrite($oRest.ResponseHeader & @CRLF)
ConsoleWrite("Response Body:" & @CRLF)
ConsoleWrite($oSbResponseBody.GetAsString() & @CRLF)
Exit
EndIf
$oJResp = ObjCreate("Chilkat_9_5_0.JsonObject")
$oJResp.LoadSb($oSbResponseBody)
; The following code parses the JSON response.
; A sample JSON response is shown below the sample code.
; Use this online tool to generate parsing code from sample JSON:
; Generate Parsing Code from JSON
Local $sKey
Local $sValue
Local $iCapacity = $oJResp.IntOf("RuleGroupResponse.Capacity")
Local $iConsumedCapacity = $oJResp.IntOf("RuleGroupResponse.ConsumedCapacity")
Local $sDescription = $oJResp.StringOf("RuleGroupResponse.Description")
Local $sKeyId = $oJResp.StringOf("RuleGroupResponse.EncryptionConfiguration.KeyId")
Local $sV_Type = $oJResp.StringOf("RuleGroupResponse.EncryptionConfiguration.Type")
Local $iLastModifiedTime = $oJResp.IntOf("RuleGroupResponse.LastModifiedTime")
Local $iNumberOfAssociations = $oJResp.IntOf("RuleGroupResponse.NumberOfAssociations")
Local $sRuleGroupArn = $oJResp.StringOf("RuleGroupResponse.RuleGroupArn")
Local $sRuleGroupId = $oJResp.StringOf("RuleGroupResponse.RuleGroupId")
Local $sRuleGroupName = $oJResp.StringOf("RuleGroupResponse.RuleGroupName")
Local $sRuleGroupStatus = $oJResp.StringOf("RuleGroupResponse.RuleGroupStatus")
Local $sSnsTopic = $oJResp.StringOf("RuleGroupResponse.SnsTopic")
Local $sSourceArn = $oJResp.StringOf("RuleGroupResponse.SourceMetadata.SourceArn")
Local $sSourceUpdateToken = $oJResp.StringOf("RuleGroupResponse.SourceMetadata.SourceUpdateToken")
Local $sRuleGroupResponseType = $oJResp.StringOf("RuleGroupResponse.Type")
Local $sUpdateToken = $oJResp.StringOf("UpdateToken")
Local $i = 0
Local $iCount_i = $oJResp.SizeOfArray("RuleGroupResponse.Tags")
While $i < $iCount_i
$oJResp.I = $i
$sKey = $oJResp.StringOf("RuleGroupResponse.Tags[i].Key")
$sValue = $oJResp.StringOf("RuleGroupResponse.Tags[i].Value")
$i = $i + 1
Wend
; A sample JSON response body parsed by the above code:
; {
; "RuleGroupResponse": {
; "Capacity": number,
; "ConsumedCapacity": number,
; "Description": "string",
; "EncryptionConfiguration": {
; "KeyId": "string",
; "Type": "string"
; },
; "LastModifiedTime": number,
; "NumberOfAssociations": number,
; "RuleGroupArn": "string",
; "RuleGroupId": "string",
; "RuleGroupName": "string",
; "RuleGroupStatus": "string",
; "SnsTopic": "string",
; "SourceMetadata": {
; "SourceArn": "string",
; "SourceUpdateToken": "string"
; },
; "Tags": [
; {
; "Key": "string",
; "Value": "string"
; }
; ],
; "Type": "string"
; },
; "UpdateToken": "string"
; }