DescribeFindings delphiDll Example
var
rest: HCkRest;
success: Boolean;
authAws: HCkAuthAws;
json: HCkJsonObject;
sbRequestBody: HCkStringBuilder;
sbResponseBody: HCkStringBuilder;
respStatusCode: Integer;
jResp: HCkJsonObject;
arn: PWideChar;
AgentId: PWideChar;
AmiId: PWideChar;
AutoScalingGroup: PWideChar;
Hostname: PWideChar;
SchemaVersion: Integer;
assetType: PWideChar;
confidence: Integer;
createdAt: Integer;
description: PWideChar;
id: PWideChar;
indicatorOfCompromise: Integer;
numericSeverity: Integer;
recommendation: PWideChar;
schemaVersion: Integer;
service: PWideChar;
AssessmentRunArn: PWideChar;
RulesPackageArn: PWideChar;
serviceAttributesSchemaVersion: Integer;
severity: PWideChar;
title: PWideChar;
updatedAt: Integer;
j: Integer;
count_j: Integer;
strVal: PWideChar;
networkInterfaceId: PWideChar;
privateDnsName: PWideChar;
privateIpAddress: PWideChar;
publicDnsName: PWideChar;
publicIp: PWideChar;
subnetId: PWideChar;
vpcId: PWideChar;
k: Integer;
count_k: Integer;
groupId: PWideChar;
groupName: PWideChar;
key: PWideChar;
value: PWideChar;
FailureCode: PWideChar;
Retryable: Integer;
i: Integer;
count_i: Integer;
begin
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
rest := CkRest_Create();
authAws := CkAuthAws_Create();
CkAuthAws_putAccessKey(authAws,'AWS_ACCESS_KEY');
CkAuthAws_putSecretKey(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_putRegion(authAws,'us-west-2');
CkAuthAws_putServiceName(authAws,'inspector');
// SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
CkRest_SetAuthAws(rest,authAws);
// URL: https://inspector.us-west-2.amazonaws.com/
// Use the same region as specified above.
success := CkRest_Connect(rest,'inspector.us-west-2.amazonaws.com',443,True,True);
if (success <> True) then
begin
Memo1.Lines.Add('ConnectFailReason: ' + IntToStr(CkRest_getConnectFailReason(rest)));
Memo1.Lines.Add(CkRest__lastErrorText(rest));
Exit;
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
json := CkJsonObject_Create();
CkJsonObject_UpdateString(json,'findingArns[0]','string');
CkJsonObject_UpdateString(json,'locale','string');
// The JSON request body created by the above code:
// {
// "findingArns": [
// "string"
// ],
// "locale": "string"
// }
CkRest_AddHeader(rest,'Content-Type','application/x-amz-json-1.1');
CkRest_AddHeader(rest,'X-Amz-Target','InspectorService.DescribeFindings');
sbRequestBody := CkStringBuilder_Create();
CkJsonObject_EmitSb(json,sbRequestBody);
sbResponseBody := CkStringBuilder_Create();
success := CkRest_FullRequestSb(rest,'POST','/',sbRequestBody,sbResponseBody);
if (success <> True) then
begin
Memo1.Lines.Add(CkRest__lastErrorText(rest));
Exit;
end;
respStatusCode := CkRest_getResponseStatusCode(rest);
Memo1.Lines.Add('response status code = ' + IntToStr(respStatusCode));
if (respStatusCode <> 200) then
begin
Memo1.Lines.Add('Response Header:');
Memo1.Lines.Add(CkRest__responseHeader(rest));
Memo1.Lines.Add('Response Body:');
Memo1.Lines.Add(CkStringBuilder__getAsString(sbResponseBody));
Exit;
end;
jResp := CkJsonObject_Create();
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
FailureCode := CkJsonObject__stringOf(jResp,'failedItems.string.failureCode');
Retryable := CkJsonObject_IntOf(jResp,'failedItems.string.retryable');
i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'findings');
while i < count_i do
begin
CkJsonObject_putI(jResp,i);
arn := CkJsonObject__stringOf(jResp,'findings[i].arn');
AgentId := CkJsonObject__stringOf(jResp,'findings[i].assetAttributes.agentId');
AmiId := CkJsonObject__stringOf(jResp,'findings[i].assetAttributes.amiId');
AutoScalingGroup := CkJsonObject__stringOf(jResp,'findings[i].assetAttributes.autoScalingGroup');
Hostname := CkJsonObject__stringOf(jResp,'findings[i].assetAttributes.hostname');
SchemaVersion := CkJsonObject_IntOf(jResp,'findings[i].assetAttributes.schemaVersion');
assetType := CkJsonObject__stringOf(jResp,'findings[i].assetType');
confidence := CkJsonObject_IntOf(jResp,'findings[i].confidence');
createdAt := CkJsonObject_IntOf(jResp,'findings[i].createdAt');
description := CkJsonObject__stringOf(jResp,'findings[i].description');
id := CkJsonObject__stringOf(jResp,'findings[i].id');
indicatorOfCompromise := CkJsonObject_IntOf(jResp,'findings[i].indicatorOfCompromise');
numericSeverity := CkJsonObject_IntOf(jResp,'findings[i].numericSeverity');
recommendation := CkJsonObject__stringOf(jResp,'findings[i].recommendation');
schemaVersion := CkJsonObject_IntOf(jResp,'findings[i].schemaVersion');
service := CkJsonObject__stringOf(jResp,'findings[i].service');
AssessmentRunArn := CkJsonObject__stringOf(jResp,'findings[i].serviceAttributes.assessmentRunArn');
RulesPackageArn := CkJsonObject__stringOf(jResp,'findings[i].serviceAttributes.rulesPackageArn');
serviceAttributesSchemaVersion := CkJsonObject_IntOf(jResp,'findings[i].serviceAttributes.schemaVersion');
severity := CkJsonObject__stringOf(jResp,'findings[i].severity');
title := CkJsonObject__stringOf(jResp,'findings[i].title');
updatedAt := CkJsonObject_IntOf(jResp,'findings[i].updatedAt');
j := 0;
count_j := CkJsonObject_SizeOfArray(jResp,'findings[i].assetAttributes.ipv4Addresses');
while j < count_j do
begin
CkJsonObject_putJ(jResp,j);
strVal := CkJsonObject__stringOf(jResp,'findings[i].assetAttributes.ipv4Addresses[j]');
j := j + 1;
end;
j := 0;
count_j := CkJsonObject_SizeOfArray(jResp,'findings[i].assetAttributes.networkInterfaces');
while j < count_j do
begin
CkJsonObject_putJ(jResp,j);
networkInterfaceId := CkJsonObject__stringOf(jResp,'findings[i].assetAttributes.networkInterfaces[j].networkInterfaceId');
privateDnsName := CkJsonObject__stringOf(jResp,'findings[i].assetAttributes.networkInterfaces[j].privateDnsName');
privateIpAddress := CkJsonObject__stringOf(jResp,'findings[i].assetAttributes.networkInterfaces[j].privateIpAddress');
publicDnsName := CkJsonObject__stringOf(jResp,'findings[i].assetAttributes.networkInterfaces[j].publicDnsName');
publicIp := CkJsonObject__stringOf(jResp,'findings[i].assetAttributes.networkInterfaces[j].publicIp');
subnetId := CkJsonObject__stringOf(jResp,'findings[i].assetAttributes.networkInterfaces[j].subnetId');
vpcId := CkJsonObject__stringOf(jResp,'findings[i].assetAttributes.networkInterfaces[j].vpcId');
k := 0;
count_k := CkJsonObject_SizeOfArray(jResp,'findings[i].assetAttributes.networkInterfaces[j].ipv6Addresses');
while k < count_k do
begin
CkJsonObject_putK(jResp,k);
strVal := CkJsonObject__stringOf(jResp,'findings[i].assetAttributes.networkInterfaces[j].ipv6Addresses[k]');
k := k + 1;
end;
k := 0;
count_k := CkJsonObject_SizeOfArray(jResp,'findings[i].assetAttributes.networkInterfaces[j].privateIpAddresses');
while k < count_k do
begin
CkJsonObject_putK(jResp,k);
privateDnsName := CkJsonObject__stringOf(jResp,'findings[i].assetAttributes.networkInterfaces[j].privateIpAddresses[k].privateDnsName');
privateIpAddress := CkJsonObject__stringOf(jResp,'findings[i].assetAttributes.networkInterfaces[j].privateIpAddresses[k].privateIpAddress');
k := k + 1;
end;
k := 0;
count_k := CkJsonObject_SizeOfArray(jResp,'findings[i].assetAttributes.networkInterfaces[j].securityGroups');
while k < count_k do
begin
CkJsonObject_putK(jResp,k);
groupId := CkJsonObject__stringOf(jResp,'findings[i].assetAttributes.networkInterfaces[j].securityGroups[k].groupId');
groupName := CkJsonObject__stringOf(jResp,'findings[i].assetAttributes.networkInterfaces[j].securityGroups[k].groupName');
k := k + 1;
end;
j := j + 1;
end;
j := 0;
count_j := CkJsonObject_SizeOfArray(jResp,'findings[i].assetAttributes.tags');
while j < count_j do
begin
CkJsonObject_putJ(jResp,j);
key := CkJsonObject__stringOf(jResp,'findings[i].assetAttributes.tags[j].key');
value := CkJsonObject__stringOf(jResp,'findings[i].assetAttributes.tags[j].value');
j := j + 1;
end;
j := 0;
count_j := CkJsonObject_SizeOfArray(jResp,'findings[i].attributes');
while j < count_j do
begin
CkJsonObject_putJ(jResp,j);
key := CkJsonObject__stringOf(jResp,'findings[i].attributes[j].key');
value := CkJsonObject__stringOf(jResp,'findings[i].attributes[j].value');
j := j + 1;
end;
j := 0;
count_j := CkJsonObject_SizeOfArray(jResp,'findings[i].userAttributes');
while j < count_j do
begin
CkJsonObject_putJ(jResp,j);
key := CkJsonObject__stringOf(jResp,'findings[i].userAttributes[j].key');
value := CkJsonObject__stringOf(jResp,'findings[i].userAttributes[j].value');
j := j + 1;
end;
i := i + 1;
end;
// 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_Dispose(rest);
CkAuthAws_Dispose(authAws);
CkJsonObject_Dispose(json);
CkStringBuilder_Dispose(sbRequestBody);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);