| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,11 +15,35 @@ | |||
| 15 | 15 | """Log entries within the Google Cloud Logging API.""" | |
| 16 | 16 | ||
| 17 | 17 | import json | |
| 18 | + import re | ||
| 18 | 19 | ||
| 19 | 20 | from google.protobuf.json_format import Parse | |
| 20 | 21 | ||
| 22 | + from gcloud._helpers import _name_from_project_path | ||
| 21 | 23 | 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) | ||
| 23 | 47 | ||
| 24 | 48 | ||
| 25 | 49 | class _BaseEntry(object): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,6 +15,27 @@ | |||
| 15 | 15 | import unittest2 | |
| 16 | 16 | ||
| 17 | 17 | ||
| 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 | + | ||
| 18 | 39 | class Test_BaseEntry(unittest2.TestCase): | |
| 19 | 40 | ||
| 20 | 41 | PROJECT = 'PROJECT' | |
| Back | FazBrowse Home | New Git URL |
0 commit comments