1# Unless explicitly stated otherwise all files in this repository are licensed under the BSD-3-Clause License.
2# This product includes software developed at Datadog (https://www.datadoghq.com/).
3# Copyright 2015-Present Datadog, Inc
4from datadog.api.resources import (
5    CreateableAPIResource,
6    UpdatableAPIResource,
7    DeletableAPIResource,
8    GetableAPIResource,
9    ListableAPIResource,
10)
11
12
13class Tag(CreateableAPIResource, UpdatableAPIResource, GetableAPIResource, ListableAPIResource, DeletableAPIResource):
14    """
15    A wrapper around Tag HTTP API.
16    """
17
18    _resource_name = "tags/hosts"
19
20    @classmethod
21    def create(cls, host, **body):
22        """
23        Add tags to a host
24
25        :param tags: list of tags to apply to the host
26        :type tags: string list
27
28        :param source: source of the tags
29        :type source: string
30
31        :returns: Dictionary representing the API's JSON response
32        """
33        params = {}
34        if "source" in body:
35            params["source"] = body["source"]
36        return super(Tag, cls).create(id=host, params=params, **body)
37
38    @classmethod
39    def update(cls, host, **body):
40        """
41        Update all tags for a given host
42
43        :param tags: list of tags to apply to the host
44        :type tags: string list
45
46        :param source: source of the tags
47        :type source: string
48
49        :returns: Dictionary representing the API's JSON response
50        """
51        params = {}
52        if "source" in body:
53            params["source"] = body["source"]
54        return super(Tag, cls).update(id=host, params=params, **body)
55