The Cloud service exposes metadata that can provide additional information about the various properties that might be returned. This example shows how to access this data and display the values available.
A list of the properties will be displayed, along with some additional information about each property. Note that this is the list of properties used by the supplied resource key, rather than all properties that can be returned by the Cloud service.
In addition, the evidence keys that are accepted by the service are listed. These are the keys that, when added to the evidence collection in flow data, could have some impact on the result that is returned.
Bear in mind that this is a list of ALL evidence keys accepted by all products offered by the cloud. If you are only using a single product (for example, IP intelligence) then not all of these keys will be relevant.
To run this example, you will eventually need to create a Resource Key. A Resource Key is used as shorthand to store the particular set of properties you are interested in as well as any associated License Keys that entitle you to increased request limits and/or paid-for properties, but it is not yet available for IP Intelligence. For now you can run a custom hosted Cloud service, such as the one provided by the GettingStartedAPI example in ip-intelligence-dotnet-examples, and point this example to its endpoint.
package fiftyone.ipintelligence.examples.console;
import fiftyone.ipintelligence.IPIntelligenceCloudPipelineBuilder;
import fiftyone.ipintelligence.IPIntelligencePipelineBuilder;
import fiftyone.ipintelligence.cloud.flowelements.IPIntelligenceCloudEngine;
import fiftyone.ipintelligence.examples.shared.KeyHelper;
import fiftyone.ipintelligence.shared.testhelpers.KeyUtils;
import fiftyone.pipeline.cloudrequestengine.flowelements.CloudRequestEngine;
import fiftyone.pipeline.core.data.EvidenceKeyFilterWhitelist;
import fiftyone.pipeline.core.flowelements.Pipeline;
import fiftyone.pipeline.engines.data.AspectPropertyMetaData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Map;
import static fiftyone.common.testhelpers.LogbackHelper.configureLogback;
import static fiftyone.pipeline.util.FileFinder.getFilePath;
public class MetadataCloud {
private static final Logger logger = LoggerFactory.getLogger(MetadataCloud.class);
public static void main(String[] args) throws Exception {
configureLogback(getFilePath("logback.xml"));
String resourceKey = args.length > 0 ? args[0] :
KeyHelper.getOrSetTestResourceKey();
String endPoint = args.length > 1 ? args[1] :
KeyUtils.getNamedKey(GettingStartedCloud.CLOUD_END_POINT_NAME);
run(resourceKey, endPoint, System.out);
}
public static void run(String resourceKey,
String endPoint,
OutputStream outputStream) throws Exception {
logger.info("Running MetadataCloud example");
IPIntelligenceCloudPipelineBuilder builder = new IPIntelligencePipelineBuilder()
.useCloud(resourceKey);
if (endPoint != null && endPoint.isEmpty() == false) {
builder.setEndPoint(endPoint);
}
try (Pipeline pipeline = builder.build()) {
PrintWriter writer = new PrintWriter(outputStream);
logger.info("Listing Properties");
outputProperties(
pipeline.getElement(IPIntelligenceCloudEngine.class),
writer);
writer.println();
writer.flush();
logger.info("Listing Evidence Key Details");
outputEvidenceKeyDetails(
pipeline.getElement(CloudRequestEngine.class),
writer);
writer.println();
writer.flush();
logger.info("All done");
}
}
private static void outputEvidenceKeyDetails(CloudRequestEngine engine,
PrintWriter output) {
output.println();
if (engine.getEvidenceKeyFilter() instanceof EvidenceKeyFilterWhitelist) {
EvidenceKeyFilterWhitelist filter =
(EvidenceKeyFilterWhitelist) engine.getEvidenceKeyFilter();
output.println("Accepted evidence keys:");
for (Map.Entry<String, Integer> entry : filter.getWhitelist().entrySet()) {
output.println("\t" + entry.getKey());
}
} else {
output.format("The evidence key filter has type " +
"%s. As this does not extend " +
"EvidenceKeyFilterWhitelist, a list of accepted values cannot be " +
"displayed. As an alternative, you can pass evidence keys to " +
"filter.include(string) to see if a particular key will be included " +
"or not.\n", engine.getEvidenceKeyFilter().getClass().getName());
output.println("For example, query.client-ip " +
(engine.getEvidenceKeyFilter().include("query.client-ip") ?
"is " : "is not ") + "accepted.");
}
}
private static void outputProperties(IPIntelligenceCloudEngine engine,
PrintWriter output) {
for (AspectPropertyMetaData property : engine.getProperties()) {
output.format("Property - %s [Category: %s] (%s)\n",
property.getName(),
property.getCategory(),
property.getType().getSimpleName());
}
}
}