DescribeFindings C Example
#include <C_CkRest.h>
#include <C_CkAuthAws.h>
#include <C_CkJsonObject.h>
#include <C_CkStringBuilder.h>
void ChilkatSample(void)
{
HCkRest rest;
BOOL success;
HCkAuthAws authAws;
HCkJsonObject json;
HCkStringBuilder sbRequestBody;
HCkStringBuilder sbResponseBody;
int respStatusCode;
HCkJsonObject jResp;
const char *arn;
const char *AgentId;
const char *AmiId;
const char *AutoScalingGroup;
const char *Hostname;
int SchemaVersion;
const char *assetType;
int confidence;
int createdAt;
const char *description;
const char *id;
int indicatorOfCompromise;
int numericSeverity;
const char *recommendation;
int schemaVersion;
const char *service;
const char *AssessmentRunArn;
const char *RulesPackageArn;
int serviceAttributesSchemaVersion;
const char *severity;
const char *title;
int updatedAt;
int j;
int count_j;
const char *strVal;
const char *networkInterfaceId;
const char *privateDnsName;
const char *privateIpAddress;
const char *publicDnsName;
const char *publicIp;
const char *subnetId;
const char *vpcId;
int k;
int count_k;
const char *groupId;
const char *groupName;
const char *key;
const char *value;
const char *FailureCode;
int Retryable;
int i;
int count_i;
// 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) {
printf("ConnectFailReason: %d\n",CkRest_getConnectFailReason(rest));
printf("%s\n",CkRest_lastErrorText(rest));
CkRest_Dispose(rest);
CkAuthAws_Dispose(authAws);
return;
}
// 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) {
printf("%s\n",CkRest_lastErrorText(rest));
CkRest_Dispose(rest);
CkAuthAws_Dispose(authAws);
CkJsonObject_Dispose(json);
CkStringBuilder_Dispose(sbRequestBody);
CkStringBuilder_Dispose(sbResponseBody);
return;
}
respStatusCode = CkRest_getResponseStatusCode(rest);
printf("response status code = %d\n",respStatusCode);
if (respStatusCode != 200) {
printf("Response Header:\n");
printf("%s\n",CkRest_responseHeader(rest));
printf("Response Body:\n");
printf("%s\n",CkStringBuilder_getAsString(sbResponseBody));
CkRest_Dispose(rest);
CkAuthAws_Dispose(authAws);
CkJsonObject_Dispose(json);
CkStringBuilder_Dispose(sbRequestBody);
CkStringBuilder_Dispose(sbResponseBody);
return;
}
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
// Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.
// See this example explaining how this memory should be used: const char * functions.
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) {
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) {
CkJsonObject_putJ(jResp,j);
strVal = CkJsonObject_stringOf(jResp,"findings[i].assetAttributes.ipv4Addresses[j]");
j = j + 1;
}
j = 0;
count_j = CkJsonObject_SizeOfArray(jResp,"findings[i].assetAttributes.networkInterfaces");
while (j < count_j) {
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) {
CkJsonObject_putK(jResp,k);
strVal = CkJsonObject_stringOf(jResp,"findings[i].assetAttributes.networkInterfaces[j].ipv6Addresses[k]");
k = k + 1;
}
k = 0;
count_k = CkJsonObject_SizeOfArray(jResp,"findings[i].assetAttributes.networkInterfaces[j].privateIpAddresses");
while (k < count_k) {
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;
}
k = 0;
count_k = CkJsonObject_SizeOfArray(jResp,"findings[i].assetAttributes.networkInterfaces[j].securityGroups");
while (k < count_k) {
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;
}
j = j + 1;
}
j = 0;
count_j = CkJsonObject_SizeOfArray(jResp,"findings[i].assetAttributes.tags");
while (j < count_j) {
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;
}
j = 0;
count_j = CkJsonObject_SizeOfArray(jResp,"findings[i].attributes");
while (j < count_j) {
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;
}
j = 0;
count_j = CkJsonObject_SizeOfArray(jResp,"findings[i].userAttributes");
while (j < count_j) {
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;
}
i = i + 1;
}
// 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);
}