ContextContains

This script searches for a value in a context path.

python · Common Scripts

Source

import demistomock as demisto  # noqa: F401
from CommonServerPython import *  # noqa: F401


def search(context, path, value):
    """
    searches a value in a context path.
    @param context - context tree to search in
    @param path - a path to search in the context
    @value - value to search
    """

    if isinstance(context, dict):
        if len(path) > 0 and path[0] in context:
            return search(context[path[0]], path[1:], value)
        else:
            return False
    elif isinstance(context, list):
        # in case current context has multiple objects, search them all.
        return any(search(c, path, value) for c in context)
    else:
        # if we got to a leaf in the context
        return len(path) == 0 and context == value


path = demisto.args().get("path", "")
value = demisto.args().get("value")

results = {
    True: "yes",
    False: "no",
}

demisto.results(results[search(demisto.context(), path.split("."), value)])

README

Searches for a value in a context path.

Script Data


Name Description
Script Type python
Tags  

Inputs


Argument Name Description
path The path in the context.
value The value to search for.

Outputs


There are no outputs for this script.