Chilkat Online Tools

DescribeRuleGroup DataFlex Example

AWS Network Firewall

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoRest
    Boolean iSuccess
    Variant vAuthAws
    Handle hoAuthAws
    Handle hoJson
    Variant vSbRequestBody
    Handle hoSbRequestBody
    Variant vSbResponseBody
    Handle hoSbResponseBody
    Integer iRespStatusCode
    Handle hoJResp
    String sStrVal
    String sAction
    String sDestination
    String sDestinationPort
    String sDirection
    String sProtocol
    String sSource
    String sSourcePort
    Integer j
    Integer iCount_j
    String sKeyword
    Integer k
    Integer iCount_k
    String sActionName
    String sValue
    Integer iPriority
    Integer iFromPort
    Integer iToPort
    String sAddressDefinition
    Integer iIntVal
    String sKey
    String sGeneratedRulesType
    String sRulesString
    String sRuleOrder
    Integer iCapacity
    Integer iConsumedCapacity
    String sDescription
    String sKeyId
    String sV_Type
    Integer iLastModifiedTime
    Integer iNumberOfAssociations
    String sRuleGroupArn
    String sRuleGroupId
    String sRuleGroupName
    String sRuleGroupStatus
    String sSnsTopic
    String sSourceArn
    String sSourceUpdateToken
    String sRuleGroupResponseType
    String sUpdateToken
    Integer i
    Integer iCount_i
    String sTemp1
    Integer iTemp1

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    Get Create (RefClass(cComChilkatRest)) To hoRest
    If (Not(IsComObjectCreated(hoRest))) Begin
        Send CreateComObject of hoRest
    End

    Get Create (RefClass(cComChilkatAuthAws)) To hoAuthAws
    If (Not(IsComObjectCreated(hoAuthAws))) Begin
        Send CreateComObject of hoAuthAws
    End
    Set ComAccessKey Of hoAuthAws To "AWS_ACCESS_KEY"
    Set ComSecretKey Of hoAuthAws To "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.)
    Set ComRegion Of hoAuthAws To "us-west-2"
    Set ComServiceName Of hoAuthAws To "network-firewall"
    // SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    Get pvComObject of hoAuthAws to vAuthAws
    Get ComSetAuthAws Of hoRest vAuthAws To iSuccess

    // URL: https://network-firewall.us-west-2.amazonaws.com/
    // Use the same region as specified above.
    Get ComConnect Of hoRest "network-firewall.us-west-2.amazonaws.com" 443 True True To iSuccess
    If (iSuccess <> True) Begin
        Get ComConnectFailReason Of hoRest To iTemp1
        Showln "ConnectFailReason: " iTemp1
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // 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

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get ComUpdateString Of hoJson "RuleGroupArn" "string" To iSuccess
    Get ComUpdateString Of hoJson "RuleGroupName" "string" To iSuccess
    Get ComUpdateString Of hoJson "Type" "string" To iSuccess

    // The JSON request body created by the above code:

    // {
    //   "RuleGroupArn": "string",
    //   "RuleGroupName": "string",
    //   "Type": "string"
    // }

    Get ComAddHeader Of hoRest "Content-Type" "application/x-amz-json-1.0" To iSuccess
    Get ComAddHeader Of hoRest "X-Amz-Target" "NetworkFirewall_20201112.DescribeRuleGroup" To iSuccess

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbRequestBody
    If (Not(IsComObjectCreated(hoSbRequestBody))) Begin
        Send CreateComObject of hoSbRequestBody
    End
    Get pvComObject of hoSbRequestBody to vSbRequestBody
    Get ComEmitSb Of hoJson vSbRequestBody To iSuccess
    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
    If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
        Send CreateComObject of hoSbResponseBody
    End
    Get pvComObject of hoSbRequestBody to vSbRequestBody
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComFullRequestSb Of hoRest "POST" "/" vSbRequestBody vSbResponseBody To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComResponseStatusCode Of hoRest To iRespStatusCode
    Showln "response status code = " iRespStatusCode
    If (iRespStatusCode <> 200) Begin
        Showln "Response Header:"
        Get ComResponseHeader Of hoRest To sTemp1
        Showln sTemp1
        Showln "Response Body:"
        Get ComGetAsString Of hoSbResponseBody To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatJsonObject)) To hoJResp
    If (Not(IsComObjectCreated(hoJResp))) Begin
        Send CreateComObject of hoJResp
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComLoadSb Of hoJResp vSbResponseBody To iSuccess

    // 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

    Get ComStringOf Of hoJResp "RuleGroup.RulesSource.RulesSourceList.GeneratedRulesType" To sGeneratedRulesType
    Get ComStringOf Of hoJResp "RuleGroup.RulesSource.RulesString" To sRulesString
    Get ComStringOf Of hoJResp "RuleGroup.StatefulRuleOptions.RuleOrder" To sRuleOrder
    Get ComIntOf Of hoJResp "RuleGroupResponse.Capacity" To iCapacity
    Get ComIntOf Of hoJResp "RuleGroupResponse.ConsumedCapacity" To iConsumedCapacity
    Get ComStringOf Of hoJResp "RuleGroupResponse.Description" To sDescription
    Get ComStringOf Of hoJResp "RuleGroupResponse.EncryptionConfiguration.KeyId" To sKeyId
    Get ComStringOf Of hoJResp "RuleGroupResponse.EncryptionConfiguration.Type" To sV_Type
    Get ComIntOf Of hoJResp "RuleGroupResponse.LastModifiedTime" To iLastModifiedTime
    Get ComIntOf Of hoJResp "RuleGroupResponse.NumberOfAssociations" To iNumberOfAssociations
    Get ComStringOf Of hoJResp "RuleGroupResponse.RuleGroupArn" To sRuleGroupArn
    Get ComStringOf Of hoJResp "RuleGroupResponse.RuleGroupId" To sRuleGroupId
    Get ComStringOf Of hoJResp "RuleGroupResponse.RuleGroupName" To sRuleGroupName
    Get ComStringOf Of hoJResp "RuleGroupResponse.RuleGroupStatus" To sRuleGroupStatus
    Get ComStringOf Of hoJResp "RuleGroupResponse.SnsTopic" To sSnsTopic
    Get ComStringOf Of hoJResp "RuleGroupResponse.SourceMetadata.SourceArn" To sSourceArn
    Get ComStringOf Of hoJResp "RuleGroupResponse.SourceMetadata.SourceUpdateToken" To sSourceUpdateToken
    Get ComStringOf Of hoJResp "RuleGroupResponse.Type" To sRuleGroupResponseType
    Get ComStringOf Of hoJResp "UpdateToken" To sUpdateToken
    Move 0 To i
    Get ComSizeOfArray Of hoJResp "RuleGroup.RulesSource.RulesSourceList.Targets" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "RuleGroup.RulesSource.RulesSourceList.Targets[i]" To sStrVal
        Move (i + 1) To i
    Loop

    Move 0 To i
    Get ComSizeOfArray Of hoJResp "RuleGroup.RulesSource.RulesSourceList.TargetTypes" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "RuleGroup.RulesSource.RulesSourceList.TargetTypes[i]" To sStrVal
        Move (i + 1) To i
    Loop

    Move 0 To i
    Get ComSizeOfArray Of hoJResp "RuleGroup.RulesSource.StatefulRules" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "RuleGroup.RulesSource.StatefulRules[i].Action" To sAction
        Get ComStringOf Of hoJResp "RuleGroup.RulesSource.StatefulRules[i].Header.Destination" To sDestination
        Get ComStringOf Of hoJResp "RuleGroup.RulesSource.StatefulRules[i].Header.DestinationPort" To sDestinationPort
        Get ComStringOf Of hoJResp "RuleGroup.RulesSource.StatefulRules[i].Header.Direction" To sDirection
        Get ComStringOf Of hoJResp "RuleGroup.RulesSource.StatefulRules[i].Header.Protocol" To sProtocol
        Get ComStringOf Of hoJResp "RuleGroup.RulesSource.StatefulRules[i].Header.Source" To sSource
        Get ComStringOf Of hoJResp "RuleGroup.RulesSource.StatefulRules[i].Header.SourcePort" To sSourcePort
        Move 0 To j
        Get ComSizeOfArray Of hoJResp "RuleGroup.RulesSource.StatefulRules[i].RuleOptions" To iCount_j
        While (j < iCount_j)
            Set ComJ Of hoJResp To j
            Get ComStringOf Of hoJResp "RuleGroup.RulesSource.StatefulRules[i].RuleOptions[j].Keyword" To sKeyword
            Move 0 To k
            Get ComSizeOfArray Of hoJResp "RuleGroup.RulesSource.StatefulRules[i].RuleOptions[j].Settings" To iCount_k
            While (k < iCount_k)
                Set ComK Of hoJResp To k
                Get ComStringOf Of hoJResp "RuleGroup.RulesSource.StatefulRules[i].RuleOptions[j].Settings[k]" To sStrVal
                Move (k + 1) To k
            Loop

            Move (j + 1) To j
        Loop

        Move (i + 1) To i
    Loop

    Move 0 To i
    Get ComSizeOfArray Of hoJResp "RuleGroup.RulesSource.StatelessRulesAndCustomActions.CustomActions" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "RuleGroup.RulesSource.StatelessRulesAndCustomActions.CustomActions[i].ActionName" To sActionName
        Move 0 To j
        Get ComSizeOfArray Of hoJResp "RuleGroup.RulesSource.StatelessRulesAndCustomActions.CustomActions[i].ActionDefinition.PublishMetricAction.Dimensions" To iCount_j
        While (j < iCount_j)
            Set ComJ Of hoJResp To j
            Get ComStringOf Of hoJResp "RuleGroup.RulesSource.StatelessRulesAndCustomActions.CustomActions[i].ActionDefinition.PublishMetricAction.Dimensions[j].Value" To sValue
            Move (j + 1) To j
        Loop

        Move (i + 1) To i
    Loop

    Move 0 To i
    Get ComSizeOfArray Of hoJResp "RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComIntOf Of hoJResp "RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].Priority" To iPriority
        Move 0 To j
        Get ComSizeOfArray Of hoJResp "RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.Actions" To iCount_j
        While (j < iCount_j)
            Set ComJ Of hoJResp To j
            Get ComStringOf Of hoJResp "RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.Actions[j]" To sStrVal
            Move (j + 1) To j
        Loop

        Move 0 To j
        Get ComSizeOfArray Of hoJResp "RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.DestinationPorts" To iCount_j
        While (j < iCount_j)
            Set ComJ Of hoJResp To j
            Get ComIntOf Of hoJResp "RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.DestinationPorts[j].FromPort" To iFromPort
            Get ComIntOf Of hoJResp "RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.DestinationPorts[j].ToPort" To iToPort
            Move (j + 1) To j
        Loop

        Move 0 To j
        Get ComSizeOfArray Of hoJResp "RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.Destinations" To iCount_j
        While (j < iCount_j)
            Set ComJ Of hoJResp To j
            Get ComStringOf Of hoJResp "RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.Destinations[j].AddressDefinition" To sAddressDefinition
            Move (j + 1) To j
        Loop

        Move 0 To j
        Get ComSizeOfArray Of hoJResp "RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.Protocols" To iCount_j
        While (j < iCount_j)
            Set ComJ Of hoJResp To j
            Get ComIntOf Of hoJResp "RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.Protocols[j]" To iIntVal
            Move (j + 1) To j
        Loop

        Move 0 To j
        Get ComSizeOfArray Of hoJResp "RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.SourcePorts" To iCount_j
        While (j < iCount_j)
            Set ComJ Of hoJResp To j
            Get ComIntOf Of hoJResp "RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.SourcePorts[j].FromPort" To iFromPort
            Get ComIntOf Of hoJResp "RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.SourcePorts[j].ToPort" To iToPort
            Move (j + 1) To j
        Loop

        Move 0 To j
        Get ComSizeOfArray Of hoJResp "RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.Sources" To iCount_j
        While (j < iCount_j)
            Set ComJ Of hoJResp To j
            Get ComStringOf Of hoJResp "RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.Sources[j].AddressDefinition" To sAddressDefinition
            Move (j + 1) To j
        Loop

        Move 0 To j
        Get ComSizeOfArray Of hoJResp "RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.TCPFlags" To iCount_j
        While (j < iCount_j)
            Set ComJ Of hoJResp To j
            Move 0 To k
            Get ComSizeOfArray Of hoJResp "RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.TCPFlags[j].Flags" To iCount_k
            While (k < iCount_k)
                Set ComK Of hoJResp To k
                Get ComStringOf Of hoJResp "RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.TCPFlags[j].Flags[k]" To sStrVal
                Move (k + 1) To k
            Loop

            Move 0 To k
            Get ComSizeOfArray Of hoJResp "RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.TCPFlags[j].Masks" To iCount_k
            While (k < iCount_k)
                Set ComK Of hoJResp To k
                Get ComStringOf Of hoJResp "RuleGroup.RulesSource.StatelessRulesAndCustomActions.StatelessRules[i].RuleDefinition.MatchAttributes.TCPFlags[j].Masks[k]" To sStrVal
                Move (k + 1) To k
            Loop

            Move (j + 1) To j
        Loop

        Move (i + 1) To i
    Loop

    Move 0 To i
    Get ComSizeOfArray Of hoJResp "RuleGroup.RuleVariables.IPSets.string.Definition" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "RuleGroup.RuleVariables.IPSets.string.Definition[i]" To sStrVal
        Move (i + 1) To i
    Loop

    Move 0 To i
    Get ComSizeOfArray Of hoJResp "RuleGroup.RuleVariables.PortSets.string.Definition" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "RuleGroup.RuleVariables.PortSets.string.Definition[i]" To sStrVal
        Move (i + 1) To i
    Loop

    Move 0 To i
    Get ComSizeOfArray Of hoJResp "RuleGroupResponse.Tags" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "RuleGroupResponse.Tags[i].Key" To sKey
        Get ComStringOf Of hoJResp "RuleGroupResponse.Tags[i].Value" To sValue
        Move (i + 1) To i
    Loop

    // 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"
    // }


End_Procedure