|
14 | 14 |
|
15 | 15 | """Client for interacting with the Google Cloud Logging API.""" |
16 | 16 |
|
17 | | - |
18 | 17 | from gcloud.client import JSONClient |
19 | 18 | from gcloud.logging.connection import Connection |
| 19 | +from gcloud.logging.connection import _LoggingAPI |
| 20 | +from gcloud.logging.connection import _MetricsAPI |
| 21 | +from gcloud.logging.connection import _SinksAPI |
20 | 22 | from gcloud.logging.entries import ProtobufEntry |
21 | 23 | from gcloud.logging.entries import StructEntry |
22 | 24 | from gcloud.logging.entries import TextEntry |
@@ -47,6 +49,41 @@ class Client(JSONClient): |
47 | 49 | """ |
48 | 50 |
|
49 | 51 | _connection_class = Connection |
| 52 | + _logging_api = _sinks_api = _metrics_api = None |
| 53 | + |
| 54 | + @property |
| 55 | + def logging_api(self): |
| 56 | + """Helper for logging-related API calls. |
| 57 | +
|
| 58 | + See: |
| 59 | + https://cloud.google.com/logging/docs/api/ref_v2beta1/rest/v2beta1/entries |
| 60 | + https://cloud.google.com/logging/docs/api/ref_v2beta1/rest/v2beta1/projects.logs |
| 61 | + """ |
| 62 | + if self._logging_api is None: |
| 63 | + self._logging_api = _LoggingAPI(self.connection) |
| 64 | + return self._logging_api |
| 65 | + |
| 66 | + @property |
| 67 | + def sinks_api(self): |
| 68 | + """Helper for log sink-related API calls. |
| 69 | +
|
| 70 | + See: |
| 71 | + https://cloud.google.com/logging/docs/api/ref_v2beta1/rest/v2beta1/projects.sinks |
| 72 | + """ |
| 73 | + if self._sinks_api is None: |
| 74 | + self._sinks_api = _SinksAPI(self.connection) |
| 75 | + return self._sinks_api |
| 76 | + |
| 77 | + @property |
| 78 | + def metrics_api(self): |
| 79 | + """Helper for log metric-related API calls. |
| 80 | +
|
| 81 | + See: |
| 82 | + https://cloud.google.com/logging/docs/api/ref_v2beta1/rest/v2beta1/projects.metrics |
| 83 | + """ |
| 84 | + if self._metrics_api is None: |
| 85 | + self._metrics_api = _MetricsAPI(self.connection) |
| 86 | + return self._metrics_api |
50 | 87 |
|
51 | 88 | def logger(self, name): |
52 | 89 | """Creates a logger bound to the current client. |
@@ -120,22 +157,9 @@ def list_entries(self, projects=None, filter_=None, order_by=None, |
120 | 157 | if projects is None: |
121 | 158 | projects = [self.project] |
122 | 159 |
|
123 | | - params = {'projectIds': projects} |
124 | | - |
125 | | - if filter_ is not None: |
126 | | - params['filter'] = filter_ |
127 | | - |
128 | | - if order_by is not None: |
129 | | - params['orderBy'] = order_by |
130 | | - |
131 | | - if page_size is not None: |
132 | | - params['pageSize'] = page_size |
133 | | - |
134 | | - if page_token is not None: |
135 | | - params['pageToken'] = page_token |
136 | | - |
137 | | - resp = self.connection.api_request(method='POST', path='/entries:list', |
138 | | - data=params) |
| 160 | + resp = self.logging_api.list_entries( |
| 161 | + projects=projects, filter_=filter_, order_by=order_by, |
| 162 | + page_size=page_size, page_token=page_token) |
139 | 163 | loggers = {} |
140 | 164 | entries = [self._entry_from_resource(resource, loggers) |
141 | 165 | for resource in resp.get('entries', ())] |
@@ -181,17 +205,7 @@ def list_sinks(self, page_size=None, page_token=None): |
181 | 205 | more sinks can be retrieved with another call (pass that |
182 | 206 | value as ``page_token``). |
183 | 207 | """ |
184 | | - params = {} |
185 | | - |
186 | | - if page_size is not None: |
187 | | - params['pageSize'] = page_size |
188 | | - |
189 | | - if page_token is not None: |
190 | | - params['pageToken'] = page_token |
191 | | - |
192 | | - path = '/projects/%s/sinks' % (self.project,) |
193 | | - resp = self.connection.api_request(method='GET', path=path, |
194 | | - query_params=params) |
| 208 | + resp = self.sinks_api.list_sinks(self.project, page_size, page_token) |
195 | 209 | sinks = [Sink.from_api_repr(resource, self) |
196 | 210 | for resource in resp.get('sinks', ())] |
197 | 211 | return sinks, resp.get('nextPageToken') |
@@ -235,17 +249,8 @@ def list_metrics(self, page_size=None, page_token=None): |
235 | 249 | more metrics can be retrieved with another call (pass that |
236 | 250 | value as ``page_token``). |
237 | 251 | """ |
238 | | - params = {} |
239 | | - |
240 | | - if page_size is not None: |
241 | | - params['pageSize'] = page_size |
242 | | - |
243 | | - if page_token is not None: |
244 | | - params['pageToken'] = page_token |
245 | | - |
246 | | - path = '/projects/%s/metrics' % (self.project,) |
247 | | - resp = self.connection.api_request(method='GET', path=path, |
248 | | - query_params=params) |
| 252 | + resp = self.metrics_api.list_metrics( |
| 253 | + self.project, page_size, page_token) |
249 | 254 | metrics = [Metric.from_api_repr(resource, self) |
250 | 255 | for resource in resp.get('metrics', ())] |
251 | 256 | return metrics, resp.get('nextPageToken') |
0 commit comments