Exemplo n.º 1
0
def get(path: str) -> Optional[dict]:
    try:
        device_type = ScriptKeyValueAggregator(path).collect(unique_keys=True)
        if len(device_type.keys()) > 1:
            log.error(
                "Multiple key=value pairs found in the device_type file. Only one is allowed"
            )
            return None
        return device_type
    except FileNotFoundError:
        log.error(f"No device_type file found in {path}")
        return None
Exemplo n.º 2
0
def get(path: str) -> Optional[dict]:
    try:
        artifact_info = ScriptKeyValueAggregator(path).collect(
            unique_keys=True)
        return artifact_info
    except FileNotFoundError:
        log.error("No artifact_info file found in {path}")
        return None
Exemplo n.º 3
0
def inventory_scripts(inventory_dir: str) -> List[ScriptKeyValueAggregator]:
    """Returns all the inventory scripts in a directory.

    An inventory scripts needs to:

    * Be executable
    * Be located in '/usr/share/mender/inventory'
    """
    scripts = []
    for f in os.listdir(inventory_dir):
        filepath = path.join(inventory_dir, f)
        if path.isfile(filepath) and os.access(filepath, os.X_OK):
            scripts.append(ScriptKeyValueAggregator(filepath))
    return scripts
Exemplo n.º 4
0
def aggregate(path: str) -> dict:
    """Runs the identity script in 'path', and parses the 'key=value' pairs
    into a data-structure ready for passing it on to the Mender server"""
    log.info("Aggregating the device identity attributes...")
    log.debug(f"Aggregating from: {path}")
    identity_data = {}
    if os.path.isfile(path):
        if os.access(path, os.X_OK):
            identity_data = ScriptKeyValueAggregator(path).run()
        else:
            log.error(f"The identity-script at {path} is not executable")
    else:
        log.error(f"{path} not found. No identity can be collected")
    log.debug(f"Aggregated identity data: {identity_data}")
    return identity_data