The cloud service exposes meta data that can provide additional information about the various properties that might be returned.
The cloud service exposes meta data 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 - device detection) then not all of these keys will be relevant.
from pathlib import Path
import sys
bgRed = "\u001b[41m"
fgWhite = "\u001b[37;1m"
colReset = "\u001b[0m"
class MetaDataConsole():
def run(self, resource_key, logger, output):
pipeline = DeviceDetectionCloudPipelineBuilder(
resource_key = resource_key).add_logger(logger).
build()
self.outputProperties(pipeline.get_element("device"), output)
self.outputEvidenceKeyDetails(pipeline.get_element("cloud"), output)
def outputEvidenceKeyDetails(self, engine, output):
if (issubclass(type(engine.get_evidence_key_filter()), BasicListEvidenceKeyFilter)):
filter = engine.get_evidence_key_filter()
output("Accepted evidence keys:")
for key in filter.list:
output(f"\t{key}")
else:
output("The evidence key filter has type " +
f"{type(engine.get_evidence_key_filter())}. As this does not extend " +
"BasicListEvidenceKeyFilter, a list of accepted values cannot be " +
"displayed. As an alternative, you can pass evidence keys to " +
"filter.filter_evidence_key(string) to see if a particular key will be included " +
"or not.")
output("For example, header.user-agent is " +
("" if engine.get_evidence_key_filter().filter_evidence_key("header.user-agent") else "not ") +
"accepted.")
def outputProperties(self, engine, output):
for propertyName, property in engine.get_properties().items():
output(f"{bgRed}{fgWhite}Property - {propertyName}{colReset}" +
f"[Category: {property['category']}] ({property['type']})")
def main(argv):
resource_key = argv[0] if len(argv) > 0 else ExampleUtils.get_resource_key()
logger = Logger(min_level="info")
if (resource_key):
MetaDataConsole().run(resource_key, logger, print)
else:
logger.log("error",
"No resource key specified in environment variable " +
f"'{ExampleUtils.RESOURCE_KEY_ENV_VAR}'. The 51Degrees " +
"cloud service is accessed using a 'ResourceKey'. " +
"For more detail see " +
"/documentation/_services__cloud__resource_keys.html?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-metadata_console.py&utm_term=resource-key-required. " +
"A resource key with the properties required by this " +
"example can be created for free at " +
"https://configure.51degrees.com/1QWJwHxl?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-cloud-metadata_console.py&utm_term=resource-key-required. " +
"Once complete, populate the environment variable " +
"mentioned at the start of this message with the key.")
if __name__ == "__main__":
main(sys.argv[1:])
Definition onpremise/build/__init__.py:1
Definition devicedetection_cloud_pipelinebuilder.py:1
Definition example_utils.py:1