File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1515"""Log entries within the Google Cloud Logging API."""
1616
1717import json
18+ import re
1819
1920from google .protobuf .json_format import Parse
2021
22+ from gcloud ._helpers import _name_from_project_path
2123from gcloud ._helpers import _rfc3339_nanos_to_datetime
22- from gcloud .logging ._helpers import logger_name_from_path
24+
25+
26+ _LOGGER_TEMPLATE = re .compile (r"""
27+ projects/ # static prefix
28+ (?P<project>[^/]+) # initial letter, wordchars + hyphen
29+ /logs/ # static midfix
30+ (?P<name>[^/]+) # initial letter, wordchars + allowed punc
31+ """ , re .VERBOSE )
32+
33+
34+ def logger_name_from_path (path ):
35+ """Validate a logger URI path and get the logger name.
36+
37+ :type path: str
38+ :param path: URI path for a logger API request.
39+
40+ :rtype: str
41+ :returns: Logger name parsed from ``path``.
42+ :raises: :class:`ValueError` if the ``path`` is ill-formed or if
43+ the project from the ``path`` does not agree with the
44+ ``project`` passed in.
45+ """
46+ return _name_from_project_path (path , None , _LOGGER_TEMPLATE )
2347
2448
2549class _BaseEntry (object ):
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1515import unittest2
1616
1717
18+ class Test_logger_name_from_path (unittest2 .TestCase ):
19+
20+ def _callFUT (self , path ):
21+ from gcloud .logging .entries import logger_name_from_path
22+ return logger_name_from_path (path )
23+
24+ def test_w_simple_name (self ):
25+ LOGGER_NAME = 'LOGGER_NAME'
26+ PROJECT = 'my-project-1234'
27+ PATH = 'projects/%s/logs/%s' % (PROJECT , LOGGER_NAME )
28+ logger_name = self ._callFUT (PATH )
29+ self .assertEqual (logger_name , LOGGER_NAME )
30+
31+ def test_w_name_w_all_extras (self ):
32+ LOGGER_NAME = 'LOGGER_NAME-part.one~part.two%part-three'
33+ PROJECT = 'my-project-1234'
34+ PATH = 'projects/%s/logs/%s' % (PROJECT , LOGGER_NAME )
35+ logger_name = self ._callFUT (PATH )
36+ self .assertEqual (logger_name , LOGGER_NAME )
37+
38+
1839class Test_BaseEntry (unittest2 .TestCase ):
1940
2041 PROJECT = 'PROJECT'
You can’t perform that action at this time.
0 commit comments