Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/google/cloud/logging_v2/resource.py: 70%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

10 statements  

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. 

14 

15"""Monitored Resource for the Google Logging API V2.""" 

16 

17import collections 

18 

19 

20class Resource(collections.namedtuple("Resource", "type labels")): 

21 """A monitored resource identified by specifying values for all labels. 

22 

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 """ 

28 

29 __slots__ = () 

30 

31 @classmethod 

32 def _from_dict(cls, info): 

33 """Construct a resource object from the parsed JSON representation. 

34 

35 Args: 

36 info (dict): A ``dict`` parsed from the JSON wire-format representation. 

37 

38 Returns: 

39 Resource: A resource object. 

40 """ 

41 return cls(type=info["type"], labels=info.get("labels", {})) 

42 

43 def _to_dict(self): 

44 """Build a dictionary ready to be serialized to the JSON format. 

45 

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}