Skip to content

Commit 6074fef

Browse files
committed
Merge pull request #1560 from tseaver/logging-client
Add logging connection and client.
2 parents d0c0bb0 + 64318db commit 6074fef

File tree

8 files changed

+218
-0
lines changed

8 files changed

+218
-0
lines changed

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
:caption: Cloud Logging
112112

113113
logging-usage
114+
Client <logging-client>
114115

115116
.. toctree::
116117
:maxdepth: 0

docs/logging-client.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Logging Client
2+
==============
3+
4+
.. automodule:: gcloud.logging.client
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
8+
9+
Connection
10+
~~~~~~~~~~
11+
12+
.. automodule:: gcloud.logging.connection
13+
:members:
14+
:undoc-members:
15+
:show-inheritance:
16+

gcloud/logging/__init__.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright 2016 Google Inc. All rights reserved.
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+
"""Google Cloud Logging API wrapper."""
16+
17+
from gcloud.logging.client import Client
18+
from gcloud.logging.connection import Connection
19+
20+
21+
SCOPE = Connection.SCOPE

gcloud/logging/client.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Copyright 2016 Google Inc. All rights reserved.
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+
"""Client for interacting with the Google Cloud Logging API."""
16+
17+
18+
from gcloud.client import JSONClient
19+
from gcloud.logging.connection import Connection
20+
21+
22+
class Client(JSONClient):
23+
"""Client to bundle configuration needed for API requests.
24+
25+
:type project: string
26+
:param project: the project which the client acts on behalf of.
27+
If not passed, falls back to the default inferred
28+
from the environment.
29+
30+
:type credentials: :class:`oauth2client.client.OAuth2Credentials` or
31+
:class:`NoneType`
32+
:param credentials: The OAuth2 Credentials to use for the connection
33+
owned by this client. If not passed (and if no ``http``
34+
object is passed), falls back to the default inferred
35+
from the environment.
36+
37+
:type http: :class:`httplib2.Http` or class that defines ``request()``.
38+
:param http: An optional HTTP object to make requests. If not passed, an
39+
``http`` object is created that is bound to the
40+
``credentials`` for the current object.
41+
"""
42+
43+
_connection_class = Connection

gcloud/logging/connection.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Copyright 2016 Google Inc. All rights reserved.
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+
"""Create / interact with gcloud logging connections."""
16+
17+
from gcloud import connection as base_connection
18+
19+
20+
class Connection(base_connection.JSONConnection):
21+
"""A connection to Google Cloud Logging via the JSON REST API.
22+
23+
:type credentials: :class:`oauth2client.client.OAuth2Credentials`
24+
:param credentials: (Optional) The OAuth2 Credentials to use for this
25+
connection.
26+
27+
:type http: :class:`httplib2.Http` or class that defines ``request()``.
28+
:param http: (Optional) HTTP object to make requests.
29+
30+
:type api_base_url: string
31+
:param api_base_url: The base of the API call URL. Defaults to the value
32+
:attr:`Connection.API_BASE_URL`.
33+
"""
34+
35+
API_BASE_URL = 'https://logging.googleapis.com'
36+
"""The base of the API call URL."""
37+
38+
API_VERSION = 'v2beta1'
39+
"""The version of the API, used in building the API call's URL."""
40+
41+
API_URL_TEMPLATE = '{api_base_url}/{api_version}{path}'
42+
"""A template for the URL of a particular API call."""
43+
44+
SCOPE = ('https://www.googleapis.com/auth/logging.read',
45+
'https://www.googleapis.com/auth/logging.write',
46+
'https://www.googleapis.com/auth/logging.admin',
47+
'https://www.googleapis.com/auth/cloud-platform')
48+
"""The scopes required for authenticating as a Cloud Logging consumer."""

gcloud/logging/test_client.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Copyright 2016 Google Inc. All rights reserved.
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+
import unittest2
16+
17+
18+
class TestClient(unittest2.TestCase):
19+
20+
def _getTargetClass(self):
21+
from gcloud.logging.client import Client
22+
return Client
23+
24+
def _makeOne(self, *args, **kw):
25+
return self._getTargetClass()(*args, **kw)
26+
27+
def test_ctor(self):
28+
PROJECT = 'PROJECT'
29+
creds = _Credentials()
30+
client = self._makeOne(project=PROJECT, credentials=creds)
31+
self.assertEqual(client.project, PROJECT)
32+
33+
34+
class _Credentials(object):
35+
36+
_scopes = None
37+
38+
@staticmethod
39+
def create_scoped_required():
40+
return True
41+
42+
def create_scoped(self, scope):
43+
self._scopes = scope
44+
return self

gcloud/logging/test_connection.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Copyright 2016 Google Inc. All rights reserved.
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+
import unittest2
16+
17+
18+
class TestConnection(unittest2.TestCase):
19+
20+
def _getTargetClass(self):
21+
from gcloud.logging.connection import Connection
22+
return Connection
23+
24+
def _makeOne(self, *args, **kw):
25+
return self._getTargetClass()(*args, **kw)
26+
27+
def test_default_url(self):
28+
creds = _Credentials()
29+
conn = self._makeOne(creds)
30+
klass = self._getTargetClass()
31+
self.assertEqual(conn.credentials._scopes, klass.SCOPE)
32+
33+
34+
class _Credentials(object):
35+
36+
_scopes = None
37+
38+
@staticmethod
39+
def create_scoped_required():
40+
return True
41+
42+
def create_scoped(self, scope):
43+
self._scopes = scope
44+
return self

scripts/verify_included_modules.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
'gcloud.datastore.__init__',
3737
'gcloud.dns.__init__',
3838
'gcloud.iterator',
39+
'gcloud.logging.__init__',
3940
'gcloud.pubsub.__init__',
4041
'gcloud.resource_manager.__init__',
4142
'gcloud.search.__init__',

0 commit comments

Comments
 (0)