Skip to content

Commit

Permalink
Merge pull request #207 from dhermes/indent-four-spaces
Browse files Browse the repository at this point in the history
Indenting four spaces in all files.
  • Loading branch information
dhermes committed Oct 2, 2014
2 parents 97278d8 + aa73c17 commit 4b2f3a9
Show file tree
Hide file tree
Showing 26 changed files with 3,241 additions and 3,223 deletions.
62 changes: 31 additions & 31 deletions gcloud/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,42 @@


class Connection(object):
"""A generic connection to Google Cloud Platform.
"""A generic connection to Google Cloud Platform.
Subclasses should understand
only the basic types
in method arguments,
however they should be capable
of returning advanced types.
"""
Subclasses should understand
only the basic types
in method arguments,
however they should be capable
of returning advanced types.
"""

API_BASE_URL = 'https://www.googleapis.com'
"""The base of the API call URL."""
API_BASE_URL = 'https://www.googleapis.com'
"""The base of the API call URL."""

_EMPTY = object()
"""A pointer to represent an empty value for default arguments."""
_EMPTY = object()
"""A pointer to represent an empty value for default arguments."""

def __init__(self, credentials=None):
"""
:type credentials: :class:`gcloud.credentials.Credentials`
:param credentials: The OAuth2 Credentials to use for this connection.
"""
def __init__(self, credentials=None):
""":type credentials: :class:`gcloud.credentials.Credentials`
:param credentials: The OAuth2 Credentials to use for this connection.
self._credentials = credentials
"""

@property
def credentials(self):
return self._credentials
self._credentials = credentials

@property
def http(self):
"""A getter for the HTTP transport used in talking to the API.
@property
def credentials(self):
return self._credentials

:rtype: :class:`httplib2.Http`
:returns: A Http object used to transport data.
"""
if not hasattr(self, '_http'):
self._http = httplib2.Http()
if self._credentials:
self._http = self._credentials.authorize(self._http)
return self._http
@property
def http(self):
"""A getter for the HTTP transport used in talking to the API.
:rtype: :class:`httplib2.Http`
:returns: A Http object used to transport data.
"""
if not hasattr(self, '_http'):
self._http = httplib2.Http()
if self._credentials:
self._http = self._credentials.authorize(self._http)
return self._http
67 changes: 34 additions & 33 deletions gcloud/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,38 @@


class Credentials(object):
"""An object used to simplify the OAuth2 credentials library.
.. note::
You should not need to use this class directly.
Instead, use the helper methods provided in
:func:`gcloud.datastore.__init__.get_connection`
and
:func:`gcloud.datastore.__init__.get_dataset`
which use this class under the hood.
"""

@classmethod
def get_for_service_account(cls, client_email, private_key_path, scope=None):
"""Gets the credentials for a service account.
:type client_email: string
:param client_email: The e-mail attached to the service account.
:type private_key_path: string
:param private_key_path: The path to a private key file (this file was
given to you when you created the service
account).
:type scope: string or tuple of strings
:param scope: The scope against which to authenticate.
(Different services require different scopes,
check the documentation for which scope is required
for the different levels of access
to any particular API.)
"""An object used to simplify the OAuth2 credentials library.
.. note::
You should not need to use this class directly.
Instead, use the helper methods provided in
:func:`gcloud.datastore.__init__.get_connection`
and
:func:`gcloud.datastore.__init__.get_dataset`
which use this class under the hood.
"""
return client.SignedJwtAssertionCredentials(
service_account_name=client_email,
private_key=open(private_key_path).read(),
scope=scope)

@classmethod
def get_for_service_account(cls, client_email, private_key_path,
scope=None):
"""Gets the credentials for a service account.
:type client_email: string
:param client_email: The e-mail attached to the service account.
:type private_key_path: string
:param private_key_path: The path to a private key file (this file was
given to you when you created the service
account).
:type scope: string or tuple of strings
:param scope: The scope against which to authenticate.
(Different services require different scopes,
check the documentation for which scope is required
for the different levels of access
to any particular API.)
"""
return client.SignedJwtAssertionCredentials(
service_account_name=client_email,
private_key=open(private_key_path).read(),
scope=scope)
107 changes: 53 additions & 54 deletions gcloud/datastore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
which represents a lookup or search over the rows in the datastore.
"""


__version__ = '0.1.2'

SCOPE = ('https://www.googleapis.com/auth/datastore ',
Expand All @@ -41,65 +40,65 @@


def get_connection(client_email, private_key_path):
"""Shortcut method to establish a connection to the Cloud Datastore.
"""Shortcut method to establish a connection to the Cloud Datastore.
Use this if you are going to access several datasets
with the same set of credentials (unlikely):
Use this if you are going to access several datasets
with the same set of credentials (unlikely):
>>> from gcloud import datastore
>>> connection = datastore.get_connection(email, key_path)
>>> dataset1 = connection.dataset('dataset1')
>>> dataset2 = connection.dataset('dataset2')
>>> from gcloud import datastore
>>> connection = datastore.get_connection(email, key_path)
>>> dataset1 = connection.dataset('dataset1')
>>> dataset2 = connection.dataset('dataset2')
:type client_email: string
:param client_email: The e-mail attached to the service account.
:type client_email: string
:param client_email: The e-mail attached to the service account.
:type private_key_path: string
:param private_key_path: The path to a private key file (this file was
given to you when you created the service
account).
:type private_key_path: string
:param private_key_path: The path to a private key file (this file was
given to you when you created the service
account).
:rtype: :class:`gcloud.datastore.connection.Connection`
:returns: A connection defined with the proper credentials.
"""
from gcloud.credentials import Credentials
from gcloud.datastore.connection import Connection
:rtype: :class:`gcloud.datastore.connection.Connection`
:returns: A connection defined with the proper credentials.
"""
from gcloud.credentials import Credentials
from gcloud.datastore.connection import Connection

credentials = Credentials.get_for_service_account(
client_email, private_key_path, scope=SCOPE)
return Connection(credentials=credentials)
credentials = Credentials.get_for_service_account(
client_email, private_key_path, scope=SCOPE)
return Connection(credentials=credentials)


def get_dataset(dataset_id, client_email, private_key_path):
"""Establish a connection to a particular dataset in the Cloud Datastore.
This is a shortcut method for creating a connection and using it
to connect to a dataset.
You'll generally use this as the first call to working with the API:
>>> from gcloud import datastore
>>> dataset = datastore.get_dataset('dataset-id', email, key_path)
>>> # Now you can do things with the dataset.
>>> dataset.query().kind('TestKind').fetch()
[...]
:type dataset_id: string
:param dataset_id: The id of the dataset you want to use.
This is akin to a database name
and is usually the same as your Cloud Datastore project
name.
:type client_email: string
:param client_email: The e-mail attached to the service account.
:type private_key_path: string
:param private_key_path: The path to a private key file (this file was
given to you when you created the service
account).
:rtype: :class:`gcloud.datastore.dataset.Dataset`
:returns: A dataset with a connection using the provided credentials.
"""
connection = get_connection(client_email, private_key_path)
return connection.dataset(dataset_id)
"""Establish a connection to a particular dataset in the Cloud Datastore.
This is a shortcut method for creating a connection and using it
to connect to a dataset.
You'll generally use this as the first call to working with the API:
>>> from gcloud import datastore
>>> dataset = datastore.get_dataset('dataset-id', email, key_path)
>>> # Now you can do things with the dataset.
>>> dataset.query().kind('TestKind').fetch()
[...]
:type dataset_id: string
:param dataset_id: The id of the dataset you want to use.
This is akin to a database name
and is usually the same as your Cloud Datastore project
name.
:type client_email: string
:param client_email: The e-mail attached to the service account.
:type private_key_path: string
:param private_key_path: The path to a private key file (this file was
given to you when you created the service
account).
:rtype: :class:`gcloud.datastore.dataset.Dataset`
:returns: A dataset with a connection using the provided credentials.
"""
connection = get_connection(client_email, private_key_path)
return connection.dataset(dataset_id)
Loading

0 comments on commit 4b2f3a9

Please sign in to comment.