Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/google/cloud/logging_v2/resource.py: 78%
9 statements
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-08 06:45 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-08 06:45 +0000
1# Copyright 2017 Google LLC
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
15"""Monitored Resource for the Google Logging API V2."""
17import collections
20class Resource(collections.namedtuple("Resource", "type labels")):
21 """A monitored resource identified by specifying values for all labels.
23 Attributes:
24 type (str): The resource type name.
25 labels (dict): A mapping from label names to values for all labels
26 enumerated in the associated :class:`ResourceDescriptor`.
27 """
29 __slots__ = ()
31 @classmethod
32 def _from_dict(cls, info):
33 """Construct a resource object from the parsed JSON representation.
35 Args:
36 info (dict): A ``dict`` parsed from the JSON wire-format representation.
38 Returns:
39 Resource: A resource object.
40 """
41 return cls(type=info["type"], labels=info.get("labels", {}))
43 def _to_dict(self):
44 """Build a dictionary ready to be serialized to the JSON format.
46 Returns:
47 dict:
48 A dict representation of the object that can be written to
49 the API.
50 """
51 return {"type": self.type, "labels": self.labels}