#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (C) 2019 tribe29 GmbH - License: GNU General Public License v2
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
# conditions defined in the file COPYING, which is part of this source code package.
import cmk.base.plugins.agent_based.utils.docker as docker


def parse_docker_container_labels(info):
    version = docker.get_version(info)
    index = 0 if version is None else 1
    data = docker.json_get_obj(info[index]) if info[index:] else None
    return data


def inv_docker_container_labels(info, inventory_tree):
    data = parse_docker_container_labels(info)
    if data is None:
        return
    container = inventory_tree.get_dict("software.applications.docker.container.")
    container["labels"] = docker.format_labels({"Labels": data})


inv_info['docker_container_labels'] = {
    'inv_function': inv_docker_container_labels,
}
