|
| 1 | +# Copyright 2015 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 Pubsub 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 Pub/Sub consumer.""" |
| 49 | + |
| 50 | + def __init__(self, credentials=None, http=None, api_base_url=None): |
| 51 | + super(Connection, self).__init__(credentials=credentials, http=http) |
| 52 | + if api_base_url is None: |
| 53 | + api_base_url = self.__class__.API_BASE_URL |
| 54 | + self.api_base_url = api_base_url |
| 55 | + |
| 56 | + def build_api_url(self, path, query_params=None, |
| 57 | + api_base_url=None, api_version=None): |
| 58 | + """Construct an API url given a few components, some optional. |
| 59 | +
|
| 60 | + Typically, you shouldn't need to use this method. |
| 61 | +
|
| 62 | + :type path: string |
| 63 | + :param path: The path to the resource. |
| 64 | +
|
| 65 | + :type query_params: dict |
| 66 | + :param query_params: A dictionary of keys and values to insert into |
| 67 | + the query string of the URL. |
| 68 | +
|
| 69 | + :type api_base_url: string |
| 70 | + :param api_base_url: The base URL for the API endpoint. |
| 71 | + Typically you won't have to provide this. |
| 72 | +
|
| 73 | + :type api_version: string |
| 74 | + :param api_version: The version of the API to call. |
| 75 | + Typically you shouldn't provide this and instead |
| 76 | + use the default for the library. |
| 77 | +
|
| 78 | + :rtype: string |
| 79 | + :returns: The URL assembled from the pieces provided. |
| 80 | + """ |
| 81 | + if api_base_url is None: |
| 82 | + api_base_url = self.api_base_url |
| 83 | + return super(Connection, self.__class__).build_api_url( |
| 84 | + path, query_params=query_params, |
| 85 | + api_base_url=api_base_url, api_version=api_version) |
0 commit comments