in source/aws_imds_client.c [1062:1106]
static int s_parse_iam_profile(cJSON *document_root, struct aws_imds_iam_profile *dest) {
bool success = false;
cJSON *last_updated = cJSON_GetObjectItemCaseSensitive(document_root, "LastUpdated");
if (!cJSON_IsString(last_updated) || (last_updated->valuestring == NULL)) {
AWS_LOGF_ERROR(AWS_LS_IMDS_CLIENT, "Failed to parse LastUpdated from Json document for iam profile.");
goto done;
}
cJSON *profile_arn = cJSON_GetObjectItemCaseSensitive(document_root, "InstanceProfileArn");
if (!cJSON_IsString(profile_arn) || (profile_arn->valuestring == NULL)) {
AWS_LOGF_ERROR(AWS_LS_IMDS_CLIENT, "Failed to parse InstanceProfileArn from Json document for iam profile.");
goto done;
}
cJSON *profile_id = cJSON_GetObjectItemCaseSensitive(document_root, "InstanceProfileId");
if (!cJSON_IsString(profile_id) || (profile_id->valuestring == NULL)) {
AWS_LOGF_ERROR(AWS_LS_IMDS_CLIENT, "Failed to parse InstanceProfileId from Json document for iam profile.");
goto done;
}
struct aws_byte_cursor last_updated_cursor = aws_byte_cursor_from_c_str(last_updated->valuestring);
struct aws_byte_cursor profile_arn_cursor = aws_byte_cursor_from_c_str(profile_arn->valuestring);
struct aws_byte_cursor profile_id_cursor = aws_byte_cursor_from_c_str(profile_id->valuestring);
if (last_updated_cursor.len == 0 || profile_arn_cursor.len == 0 || profile_id_cursor.len == 0) {
AWS_LOGF_ERROR(AWS_LS_IMDS_CLIENT, "Parsed an unexpected Json document fro iam profile.");
goto done;
}
if (aws_date_time_init_from_str_cursor(&dest->last_updated, &last_updated_cursor, AWS_DATE_FORMAT_ISO_8601)) {
AWS_LOGF_ERROR(
AWS_LS_IMDS_CLIENT, "LastUpdate in iam profile Json document is not a valid ISO_8601 date string.");
goto done;
}
dest->instance_profile_arn = profile_arn_cursor;
dest->instance_profile_id = profile_id_cursor;
success = true;
done:
return success ? AWS_OP_ERR : AWS_OP_SUCCESS;
}