DescribeFindings PureBasic Example
IncludeFile "CkJsonObject.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkRest.pb"
IncludeFile "CkAuthAws.pb"
Procedure ChilkatExample()
; This example requires the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
rest.i = CkRest::ckCreate()
If rest.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success.i
authAws.i = CkAuthAws::ckCreate()
If authAws.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkAuthAws::setCkAccessKey(authAws, "AWS_ACCESS_KEY")
CkAuthAws::setCkSecretKey(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::setCkRegion(authAws, "us-west-2")
CkAuthAws::setCkServiceName(authAws, "inspector")
; SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
CkRest::ckSetAuthAws(rest,authAws)
; URL: https://inspector.us-west-2.amazonaws.com/
; Use the same region as specified above.
success = CkRest::ckConnect(rest,"inspector.us-west-2.amazonaws.com",443,1,1)
If success <> 1
Debug "ConnectFailReason: " + Str(CkRest::ckConnectFailReason(rest))
Debug CkRest::ckLastErrorText(rest)
CkRest::ckDispose(rest)
CkAuthAws::ckDispose(authAws)
ProcedureReturn
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
json.i = CkJsonObject::ckCreate()
If json.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkJsonObject::ckUpdateString(json,"findingArns[0]","string")
CkJsonObject::ckUpdateString(json,"locale","string")
; The JSON request body created by the above code:
; {
; "findingArns": [
; "string"
; ],
; "locale": "string"
; }
CkRest::ckAddHeader(rest,"Content-Type","application/x-amz-json-1.1")
CkRest::ckAddHeader(rest,"X-Amz-Target","InspectorService.DescribeFindings")
sbRequestBody.i = CkStringBuilder::ckCreate()
If sbRequestBody.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkJsonObject::ckEmitSb(json,sbRequestBody)
sbResponseBody.i = CkStringBuilder::ckCreate()
If sbResponseBody.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success = CkRest::ckFullRequestSb(rest,"POST","/",sbRequestBody,sbResponseBody)
If success <> 1
Debug CkRest::ckLastErrorText(rest)
CkRest::ckDispose(rest)
CkAuthAws::ckDispose(authAws)
CkJsonObject::ckDispose(json)
CkStringBuilder::ckDispose(sbRequestBody)
CkStringBuilder::ckDispose(sbResponseBody)
ProcedureReturn
EndIf
respStatusCode.i = CkRest::ckResponseStatusCode(rest)
Debug "response status code = " + Str(respStatusCode)
If respStatusCode <> 200
Debug "Response Header:"
Debug CkRest::ckResponseHeader(rest)
Debug "Response Body:"
Debug CkStringBuilder::ckGetAsString(sbResponseBody)
CkRest::ckDispose(rest)
CkAuthAws::ckDispose(authAws)
CkJsonObject::ckDispose(json)
CkStringBuilder::ckDispose(sbRequestBody)
CkStringBuilder::ckDispose(sbResponseBody)
ProcedureReturn
EndIf
jResp.i = CkJsonObject::ckCreate()
If jResp.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkJsonObject::ckLoadSb(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
arn.s
AgentId.s
AmiId.s
AutoScalingGroup.s
Hostname.s
SchemaVersion.i
assetType.s
confidence.i
createdAt.i
description.s
id.s
indicatorOfCompromise.i
numericSeverity.i
recommendation.s
schemaVersion.i
service.s
AssessmentRunArn.s
RulesPackageArn.s
serviceAttributesSchemaVersion.i
severity.s
title.s
updatedAt.i
j.i
count_j.i
strVal.s
networkInterfaceId.s
privateDnsName.s
privateIpAddress.s
publicDnsName.s
publicIp.s
subnetId.s
vpcId.s
k.i
count_k.i
groupId.s
groupName.s
key.s
value.s
FailureCode.s = CkJsonObject::ckStringOf(jResp,"failedItems.string.failureCode")
Retryable.i = CkJsonObject::ckIntOf(jResp,"failedItems.string.retryable")
i.i = 0
count_i.i = CkJsonObject::ckSizeOfArray(jResp,"findings")
While i < count_i
CkJsonObject::setCkI(jResp, i)
arn = CkJsonObject::ckStringOf(jResp,"findings[i].arn")
AgentId = CkJsonObject::ckStringOf(jResp,"findings[i].assetAttributes.agentId")
AmiId = CkJsonObject::ckStringOf(jResp,"findings[i].assetAttributes.amiId")
AutoScalingGroup = CkJsonObject::ckStringOf(jResp,"findings[i].assetAttributes.autoScalingGroup")
Hostname = CkJsonObject::ckStringOf(jResp,"findings[i].assetAttributes.hostname")
SchemaVersion = CkJsonObject::ckIntOf(jResp,"findings[i].assetAttributes.schemaVersion")
assetType = CkJsonObject::ckStringOf(jResp,"findings[i].assetType")
confidence = CkJsonObject::ckIntOf(jResp,"findings[i].confidence")
createdAt = CkJsonObject::ckIntOf(jResp,"findings[i].createdAt")
description = CkJsonObject::ckStringOf(jResp,"findings[i].description")
id = CkJsonObject::ckStringOf(jResp,"findings[i].id")
indicatorOfCompromise = CkJsonObject::ckIntOf(jResp,"findings[i].indicatorOfCompromise")
numericSeverity = CkJsonObject::ckIntOf(jResp,"findings[i].numericSeverity")
recommendation = CkJsonObject::ckStringOf(jResp,"findings[i].recommendation")
schemaVersion = CkJsonObject::ckIntOf(jResp,"findings[i].schemaVersion")
service = CkJsonObject::ckStringOf(jResp,"findings[i].service")
AssessmentRunArn = CkJsonObject::ckStringOf(jResp,"findings[i].serviceAttributes.assessmentRunArn")
RulesPackageArn = CkJsonObject::ckStringOf(jResp,"findings[i].serviceAttributes.rulesPackageArn")
serviceAttributesSchemaVersion = CkJsonObject::ckIntOf(jResp,"findings[i].serviceAttributes.schemaVersion")
severity = CkJsonObject::ckStringOf(jResp,"findings[i].severity")
title = CkJsonObject::ckStringOf(jResp,"findings[i].title")
updatedAt = CkJsonObject::ckIntOf(jResp,"findings[i].updatedAt")
j = 0
count_j = CkJsonObject::ckSizeOfArray(jResp,"findings[i].assetAttributes.ipv4Addresses")
While j < count_j
CkJsonObject::setCkJ(jResp, j)
strVal = CkJsonObject::ckStringOf(jResp,"findings[i].assetAttributes.ipv4Addresses[j]")
j = j + 1
Wend
j = 0
count_j = CkJsonObject::ckSizeOfArray(jResp,"findings[i].assetAttributes.networkInterfaces")
While j < count_j
CkJsonObject::setCkJ(jResp, j)
networkInterfaceId = CkJsonObject::ckStringOf(jResp,"findings[i].assetAttributes.networkInterfaces[j].networkInterfaceId")
privateDnsName = CkJsonObject::ckStringOf(jResp,"findings[i].assetAttributes.networkInterfaces[j].privateDnsName")
privateIpAddress = CkJsonObject::ckStringOf(jResp,"findings[i].assetAttributes.networkInterfaces[j].privateIpAddress")
publicDnsName = CkJsonObject::ckStringOf(jResp,"findings[i].assetAttributes.networkInterfaces[j].publicDnsName")
publicIp = CkJsonObject::ckStringOf(jResp,"findings[i].assetAttributes.networkInterfaces[j].publicIp")
subnetId = CkJsonObject::ckStringOf(jResp,"findings[i].assetAttributes.networkInterfaces[j].subnetId")
vpcId = CkJsonObject::ckStringOf(jResp,"findings[i].assetAttributes.networkInterfaces[j].vpcId")
k = 0
count_k = CkJsonObject::ckSizeOfArray(jResp,"findings[i].assetAttributes.networkInterfaces[j].ipv6Addresses")
While k < count_k
CkJsonObject::setCkK(jResp, k)
strVal = CkJsonObject::ckStringOf(jResp,"findings[i].assetAttributes.networkInterfaces[j].ipv6Addresses[k]")
k = k + 1
Wend
k = 0
count_k = CkJsonObject::ckSizeOfArray(jResp,"findings[i].assetAttributes.networkInterfaces[j].privateIpAddresses")
While k < count_k
CkJsonObject::setCkK(jResp, k)
privateDnsName = CkJsonObject::ckStringOf(jResp,"findings[i].assetAttributes.networkInterfaces[j].privateIpAddresses[k].privateDnsName")
privateIpAddress = CkJsonObject::ckStringOf(jResp,"findings[i].assetAttributes.networkInterfaces[j].privateIpAddresses[k].privateIpAddress")
k = k + 1
Wend
k = 0
count_k = CkJsonObject::ckSizeOfArray(jResp,"findings[i].assetAttributes.networkInterfaces[j].securityGroups")
While k < count_k
CkJsonObject::setCkK(jResp, k)
groupId = CkJsonObject::ckStringOf(jResp,"findings[i].assetAttributes.networkInterfaces[j].securityGroups[k].groupId")
groupName = CkJsonObject::ckStringOf(jResp,"findings[i].assetAttributes.networkInterfaces[j].securityGroups[k].groupName")
k = k + 1
Wend
j = j + 1
Wend
j = 0
count_j = CkJsonObject::ckSizeOfArray(jResp,"findings[i].assetAttributes.tags")
While j < count_j
CkJsonObject::setCkJ(jResp, j)
key = CkJsonObject::ckStringOf(jResp,"findings[i].assetAttributes.tags[j].key")
value = CkJsonObject::ckStringOf(jResp,"findings[i].assetAttributes.tags[j].value")
j = j + 1
Wend
j = 0
count_j = CkJsonObject::ckSizeOfArray(jResp,"findings[i].attributes")
While j < count_j
CkJsonObject::setCkJ(jResp, j)
key = CkJsonObject::ckStringOf(jResp,"findings[i].attributes[j].key")
value = CkJsonObject::ckStringOf(jResp,"findings[i].attributes[j].value")
j = j + 1
Wend
j = 0
count_j = CkJsonObject::ckSizeOfArray(jResp,"findings[i].userAttributes")
While j < count_j
CkJsonObject::setCkJ(jResp, j)
key = CkJsonObject::ckStringOf(jResp,"findings[i].userAttributes[j].key")
value = CkJsonObject::ckStringOf(jResp,"findings[i].userAttributes[j].value")
j = j + 1
Wend
i = i + 1
Wend
; A sample JSON response body parsed by the above code:
; {
; "failedItems": {
; "string": {
; "failureCode": "string",
; "retryable": boolean
; }
; },
; "findings": [
; {
; "arn": "string",
; "assetAttributes": {
; "agentId": "string",
; "amiId": "string",
; "autoScalingGroup": "string",
; "hostname": "string",
; "ipv4Addresses": [
; "string"
; ],
; "networkInterfaces": [
; {
; "ipv6Addresses": [
; "string"
; ],
; "networkInterfaceId": "string",
; "privateDnsName": "string",
; "privateIpAddress": "string",
; "privateIpAddresses": [
; {
; "privateDnsName": "string",
; "privateIpAddress": "string"
; }
; ],
; "publicDnsName": "string",
; "publicIp": "string",
; "securityGroups": [
; {
; "groupId": "string",
; "groupName": "string"
; }
; ],
; "subnetId": "string",
; "vpcId": "string"
; }
; ],
; "schemaVersion": number,
; "tags": [
; {
; "key": "string",
; "value": "string"
; }
; ]
; },
; "assetType": "string",
; "attributes": [
; {
; "key": "string",
; "value": "string"
; }
; ],
; "confidence": number,
; "createdAt": number,
; "description": "string",
; "id": "string",
; "indicatorOfCompromise": boolean,
; "numericSeverity": number,
; "recommendation": "string",
; "schemaVersion": number,
; "service": "string",
; "serviceAttributes": {
; "assessmentRunArn": "string",
; "rulesPackageArn": "string",
; "schemaVersion": number
; },
; "severity": "string",
; "title": "string",
; "updatedAt": number,
; "userAttributes": [
; {
; "key": "string",
; "value": "string"
; }
; ]
; }
; ]
; }
CkRest::ckDispose(rest)
CkAuthAws::ckDispose(authAws)
CkJsonObject::ckDispose(json)
CkStringBuilder::ckDispose(sbRequestBody)
CkStringBuilder::ckDispose(sbResponseBody)
CkJsonObject::ckDispose(jResp)
ProcedureReturn
EndProcedure