DescribeRuleGroup TCL Example
load ./chilkat.dll
# This example requires the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
set rest [new_CkRest]
set authAws [new_CkAuthAws]
CkAuthAws_put_AccessKey $authAws "AWS_ACCESS_KEY"
CkAuthAws_put_SecretKey $authAws "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.)
CkAuthAws_put_Region $authAws "us-west-2"
CkAuthAws_put_ServiceName $authAws "network-firewall"
# SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
CkRest_SetAuthAws $rest $authAws
# URL: https://network-firewall.us-west-2.amazonaws.com/
# Use the same region as specified above.
set success [CkRest_Connect $rest "network-firewall.us-west-2.amazonaws.com" 443 1 1]
if {$success != 1} then {
puts "ConnectFailReason: [CkRest_get_ConnectFailReason $rest]"
puts [CkRest_lastErrorText $rest]
delete_CkRest $rest
delete_CkAuthAws $authAws
exit
}
# 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
set json [new_CkJsonObject]
CkJsonObject_UpdateString $json "RuleGroupArn" "string"
CkJsonObject_UpdateString $json "RuleGroupName" "string"
CkJsonObject_UpdateString $json "Type" "string"
# The JSON request body created by the above code:
# {
# "RuleGroupArn": "string",
# "RuleGroupName": "string",
# "Type": "string"
# }
CkRest_AddHeader $rest "Content-Type" "application/x-amz-json-1.0"
CkRest_AddHeader $rest "X-Amz-Target" "NetworkFirewall_20201112.DescribeRuleGroup"
set sbRequestBody [new_CkStringBuilder]
CkJsonObject_EmitSb $json $sbRequestBody
set sbResponseBody [new_CkStringBuilder]
set success [CkRest_FullRequestSb $rest "POST" "/" $sbRequestBody $sbResponseBody]
if {$success != 1} then {
puts [CkRest_lastErrorText $rest]
delete_CkRest $rest
delete_CkAuthAws $authAws
delete_CkJsonObject $json
delete_CkStringBuilder $sbRequestBody
delete_CkStringBuilder $sbResponseBody
exit
}
set respStatusCode [CkRest_get_ResponseStatusCode $rest]
puts "response status code = $respStatusCode"
if {$respStatusCode != 200} then {
puts "Response Header:"
puts [CkRest_responseHeader $rest]
puts "Response Body:"
puts [CkStringBuilder_getAsString $sbResponseBody]
delete_CkRest $rest
delete_CkAuthAws $authAws
delete_CkJsonObject $json
delete_CkStringBuilder $sbRequestBody
delete_CkStringBuilder $sbResponseBody
exit
}
set jResp [new_CkJsonObject]
CkJsonObject_LoadSb $jResp $sbResponseBody
# 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
set GeneratedRulesType [CkJsonObject_stringOf $jResp "RuleGroup.RulesSource.RulesSourceList.GeneratedRulesType"]
set RulesString [CkJsonObject_stringOf $jResp "RuleGroup.RulesSource.RulesString"]
set RuleOrder [CkJsonObject_stringOf $jResp "RuleGroup.StatefulRuleOptions.RuleOrder"]
set Capacity [CkJsonObject_IntOf $jResp "RuleGroupResponse.Capacity"]
set ConsumedCapacity [CkJsonObject_IntOf $jResp "RuleGroupResponse.ConsumedCapacity"]
set Description [CkJsonObject_stringOf $jResp "RuleGroupResponse.Description"]
set KeyId [CkJsonObject_stringOf $jResp "RuleGroupResponse.EncryptionConfiguration.KeyId"]
set v_Type [CkJsonObject_stringOf $jResp "RuleGroupResponse.EncryptionConfiguration.Type"]
set LastModifiedTime [CkJsonObject_IntOf $jResp "RuleGroupResponse.LastModifiedTime"]
set NumberOfAssociations [CkJsonObject_IntOf $jResp "RuleGroupResponse.NumberOfAssociations"]
set RuleGroupArn [CkJsonObject_stringOf $jResp "RuleGroupResponse.RuleGroupArn"]
set RuleGroupId [CkJsonObject_stringOf $jResp "RuleGroupResponse.RuleGroupId"]
set RuleGroupName [CkJsonObject_stringOf $jResp "RuleGroupResponse.RuleGroupName"]
set RuleGroupStatus [CkJsonObject_stringOf $jResp "RuleGroupResponse.RuleGroupStatus"]
set SnsTopic [CkJsonObject_stringOf $jResp "RuleGroupResponse.SnsTopic"]
set SourceArn [CkJsonObject_stringOf $jResp "RuleGroupResponse.SourceMetadata.SourceArn"]
set SourceUpdateToken [CkJsonObject_stringOf $jResp "RuleGroupResponse.SourceMetadata.SourceUpdateToken"]
set RuleGroupResponseType [CkJsonObject_stringOf $jResp "RuleGroupResponse.Type"]
set UpdateToken [CkJsonObject_stringOf $jResp "UpdateToken"]
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "RuleGroup.RulesSource.RulesSourceList.Targets"]
while {$i < $count_i} {
CkJsonObject_put_I $jResp $i
set strVal [CkJsonObject_stringOf $jResp "RuleGroup.RulesSource.RulesSourceList.Targets[i]"]
set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "RuleGroup.RulesSource.RulesSourceList.TargetTypes"]
while {$i < $count_i} {
CkJsonObject_put_I $jResp $i
set strVal [CkJsonObject_stringOf $jResp "RuleGroup.RulesSource.RulesSourceList.TargetTypes[i]"]
set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "RuleGroup.RulesSource.StatefulRules"]
while {$i < $count_i} {
CkJsonObject_put_I $jResp $i
set Action [CkJsonObject_stringOf $jResp "RuleGroup.RulesSource.StatefulRules[i].Action"]
set Destination [CkJsonObject_stringOf $jResp "RuleGroup.RulesSource.StatefulRules[i].Header.Destination"]
set DestinationPort [CkJsonObject_stringOf $jResp "RuleGroup.RulesSource.StatefulRules[i].Header.DestinationPort"]
set Direction [CkJsonObject_stringOf $jResp "RuleGroup.RulesSource.StatefulRules[i].Header.Direction"]
set Protocol [CkJsonObject_stringOf $jResp "RuleGroup.RulesSource.StatefulRules[i].Header.Protocol"]
set Source [CkJsonObject_stringOf $jResp "RuleGroup.RulesSource.StatefulRules[i].Header.Source"]
set SourcePort [CkJsonObject_stringOf $jResp "RuleGroup.RulesSource.StatefulRules[i].Header.SourcePort"]
set j 0
set count_j [CkJsonObject_SizeOfArray $jResp "RuleGroup.RulesSource.StatefulRules[i].RuleOptions"]
while {$j < $count_j} {
CkJsonObject_put_J $jResp $j
set Keyword [CkJsonObject_stringOf $jResp "RuleGroup.RulesSource.StatefulRules[i].RuleOptions[j].Keyword"]
set k 0
set count_k [CkJsonObject_SizeOfArray $jResp "RuleGroup.RulesSource.StatefulRules[i].RuleOptions[j].Settings"]
while {$k < $count_k} {
CkJsonObject_put_K $jResp $k
set strVal [CkJsonObject_stringOf $jResp "RuleGroup.RulesSource.StatefulRules[i].RuleOptions[j].Settings[k]"]
set k [expr $k + 1]
}
set j [expr $j + 1]
}
set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "RuleGroup.RulesSource.StatelessRulesAndCustomActions.CustomActions"]
while {$i < $count_i} {
CkJsonObject_put_I $jResp $i
set ActionName [CkJsonObject_stringOf $jResp "RuleGroup.RulesSource.StatelessRulesAndCustomActions.CustomActions[i].ActionName"]
set j 0
set count_j [CkJsonObject_SizeOfArray $jResp "RuleGroup.RulesSource.StatelessRulesAndCustomActions.CustomActions[i].ActionDefinition.PublishMetricAction.Dimensions"]
while {$j < $count_j} {
CkJsonObject_put_J $jResp $j
set Value [CkJsonObject_stringOf $jResp "RuleGroup.RulesSource.StatelessRulesAndCustomActions.CustomActions[i].ActionDefinition.PublishMetricAction.Dimensions[j].Value"]
set j [expr $j + 1]
}
set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules"]
while {$i < $count_i} {
CkJsonObject_put_I $jResp $i
set Priority [CkJsonObject_IntOf $jResp "RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].Priority"]
set j 0
set count_j [CkJsonObject_SizeOfArray $jResp "RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.Actions"]
while {$j < $count_j} {
CkJsonObject_put_J $jResp $j
set strVal [CkJsonObject_stringOf $jResp "RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.Actions[j]"]
set j [expr $j + 1]
}
set j 0
set count_j [CkJsonObject_SizeOfArray $jResp "RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.DestinationPorts"]
while {$j < $count_j} {
CkJsonObject_put_J $jResp $j
set FromPort [CkJsonObject_IntOf $jResp "RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.DestinationPorts[j].FromPort"]
set ToPort [CkJsonObject_IntOf $jResp "RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.DestinationPorts[j].ToPort"]
set j [expr $j + 1]
}
set j 0
set count_j [CkJsonObject_SizeOfArray $jResp "RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.Destinations"]
while {$j < $count_j} {
CkJsonObject_put_J $jResp $j
set AddressDefinition [CkJsonObject_stringOf $jResp "RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.Destinations[j].AddressDefinition"]
set j [expr $j + 1]
}
set j 0
set count_j [CkJsonObject_SizeOfArray $jResp "RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.Protocols"]
while {$j < $count_j} {
CkJsonObject_put_J $jResp $j
set intVal [CkJsonObject_IntOf $jResp "RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.Protocols[j]"]
set j [expr $j + 1]
}
set j 0
set count_j [CkJsonObject_SizeOfArray $jResp "RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.SourcePorts"]
while {$j < $count_j} {
CkJsonObject_put_J $jResp $j
set FromPort [CkJsonObject_IntOf $jResp "RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.SourcePorts[j].FromPort"]
set ToPort [CkJsonObject_IntOf $jResp "RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.SourcePorts[j].ToPort"]
set j [expr $j + 1]
}
set j 0
set count_j [CkJsonObject_SizeOfArray $jResp "RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.Sources"]
while {$j < $count_j} {
CkJsonObject_put_J $jResp $j
set AddressDefinition [CkJsonObject_stringOf $jResp "RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.Sources[j].AddressDefinition"]
set j [expr $j + 1]
}
set j 0
set count_j [CkJsonObject_SizeOfArray $jResp "RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.TCPFlags"]
while {$j < $count_j} {
CkJsonObject_put_J $jResp $j
set k 0
set count_k [CkJsonObject_SizeOfArray $jResp "RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.TCPFlags[j].Flags"]
while {$k < $count_k} {
CkJsonObject_put_K $jResp $k
set strVal [CkJsonObject_stringOf $jResp "RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.TCPFlags[j].Flags[k]"]
set k [expr $k + 1]
}
set k 0
set count_k [CkJsonObject_SizeOfArray $jResp "RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.TCPFlags[j].Masks"]
while {$k < $count_k} {
CkJsonObject_put_K $jResp $k
set strVal [CkJsonObject_stringOf $jResp "RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.TCPFlags[j].Masks[k]"]
set k [expr $k + 1]
}
set j [expr $j + 1]
}
set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "RuleGroup.RuleVariables.IPSets.string.Definition"]
while {$i < $count_i} {
CkJsonObject_put_I $jResp $i
set strVal [CkJsonObject_stringOf $jResp "RuleGroup.RuleVariables.IPSets.string.Definition[i]"]
set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "RuleGroup.RuleVariables.PortSets.string.Definition"]
while {$i < $count_i} {
CkJsonObject_put_I $jResp $i
set strVal [CkJsonObject_stringOf $jResp "RuleGroup.RuleVariables.PortSets.string.Definition[i]"]
set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "RuleGroupResponse.Tags"]
while {$i < $count_i} {
CkJsonObject_put_I $jResp $i
set Key [CkJsonObject_stringOf $jResp "RuleGroupResponse.Tags[i].Key"]
set Value [CkJsonObject_stringOf $jResp "RuleGroupResponse.Tags[i].Value"]
set i [expr $i + 1]
}
# A sample JSON response body parsed by the above code:
# {
# "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"
# }
# },
# "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"
# }
delete_CkRest $rest
delete_CkAuthAws $authAws
delete_CkJsonObject $json
delete_CkStringBuilder $sbRequestBody
delete_CkStringBuilder $sbResponseBody
delete_CkJsonObject $jResp