Skip to content

Commit 7407556

Browse files
authored
Merge pull request #1878 from tseaver/logging-collapse__helpers
Collapse 'gcloud.logging._helpers' into '.entries'.
2 parents 22bf022 + 54eabe4 commit 7407556

4 files changed

Lines changed: 46 additions & 79 deletions

File tree

gcloud/logging/_helpers.py

Lines changed: 0 additions & 42 deletions
This file was deleted.

gcloud/logging/entries.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,35 @@
1515
"""Log entries within the Google Cloud Logging API."""
1616

1717
import json
18+
import re
1819

1920
from google.protobuf.json_format import Parse
2021

22+
from gcloud._helpers import _name_from_project_path
2123
from 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

2549
class _BaseEntry(object):

gcloud/logging/test__helpers.py

Lines changed: 0 additions & 36 deletions
This file was deleted.

gcloud/logging/test_entries.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,27 @@
1515
import 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+
1839
class Test_BaseEntry(unittest2.TestCase):
1940

2041
PROJECT = 'PROJECT'

0 commit comments

Comments
 (0)