#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
# +------------------------------------------------------------------+
# |             ____ _               _        __  __ _  __           |
# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
# |                                                                  |
# | Copyright Mathias Kettner 2018             mk@mathias-kettner.de |
# +------------------------------------------------------------------+
#
# This file is part of Check_MK.
# The official homepage is at http://mathias-kettner.de/check_mk.
#
# check_mk is free software;  you can redistribute it and/or modify it
# under the  terms of the  GNU General Public License  as published by
# the Free Software Foundation in version 2.  check_mk is  distributed
# in the hope that it will be useful, but WITHOUT ANY WARRANTY;  with-
# out even the implied warranty of  MERCHANTABILITY  or  FITNESS FOR A
# PARTICULAR PURPOSE. See the  GNU General Public License for more de-
# tails. You should have  received  a copy of the  GNU  General Public
# License along with GNU Make; see the file  COPYING.  If  not,  write
# to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
# Boston, MA 02110-1301 USA.


def agent_azure_arguments(params, _no_hostname, _no_ipaddress):
    args = []

    keys = ("subscription", "tenant", "client", "secret", "piggyback_vms", "sequential")
    present_keys = (k for k in keys if k in params.keys())

    for key in present_keys:
        option = "--%s" % key
        value = params[key]
        if isinstance(value, bool):
            if value:
                args.append(option)
        else:
            args += [option, quote_shell_string(value)]

    config = params['config']
    if "fetchall" in config:
        return ' '.join(args)

    explicit = config.get('explicit', [])
    if explicit:
        args.append("--explicit-config")
    for group_dict in explicit:
        group_name = group_dict['group_name']
        args.append(quote_shell_string("group=%s" % group_name))

        group_resources = group_dict.get('resources')
        if group_resources:
            args.append(quote_shell_string("resources=%s" % ",".join(group_resources)))

    return ' '.join(args)


special_agent_info['azure'] = agent_azure_arguments
