Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.8k
Fixed #5 - Adding support for Google Cloud Storage#20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| *.py[cod] | ||
| *.sw[op] | ||
| # C extensions | ||
| *.so | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| Cloud Common | ||
| ============ | ||
| Connections | ||
| ----------- | ||
| .. automodule:: gcloud.connection | ||
| :members: | ||
| :undoc-members: | ||
| :show-inheritance: | ||
| Credentials | ||
| ----------- | ||
| .. automodule:: gcloud.credentials | ||
| :members: | ||
| :undoc-members: | ||
| :show-inheritance: |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| Cloud Storage | ||
| ============= | ||
| :mod:`gcloud.storage` | ||
| ----------------------- | ||
| .. automodule:: gcloud.storage.__init__ | ||
| :members: | ||
| :undoc-members: | ||
| :show-inheritance: | ||
| Connections | ||
| ----------- | ||
| .. automodule:: gcloud.storage.connection | ||
| :members: | ||
| :undoc-members: | ||
| :show-inheritance: | ||
| Buckets | ||
| ------- | ||
| .. automodule:: gcloud.storage.bucket | ||
| :members: | ||
| :undoc-members: | ||
| :show-inheritance: | ||
| Keys | ||
| ---- | ||
| .. automodule:: gcloud.storage.key | ||
| :members: | ||
| :undoc-members: | ||
| :show-inheritance: | ||
| Access Control | ||
| -------------- | ||
| .. automodule:: gcloud.storage.acl | ||
| :members: | ||
| :undoc-members: | ||
| :show-inheritance: | ||
| Iterators | ||
| --------- | ||
| .. automodule:: gcloud.storage.iterator | ||
| :members: | ||
| :undoc-members: | ||
| :show-inheritance: | ||
| Exceptions | ||
| ---------- | ||
| .. automodule:: gcloud.storage.exceptions | ||
| :members: | ||
| :undoc-members: | ||
| :show-inheritance: |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| Cloud Storage in 10 seconds | ||
| =========================== | ||
| Install the library | ||
| ------------------- | ||
| The source code for the library | ||
| (and demo code) | ||
| lives on GitHub, | ||
| You can install the library quickly with ``pip``:: | ||
| $ pip install gcloud | ||
| Run the | ||
| `example script <https://github.com/jgeewax/gcloud/blob/master/gcloud/storage/demo.py>`_ | ||
| included in the package:: | ||
| $ python -m gcloud.storage.demo | ||
| And that's it! | ||
| You should be walking through | ||
| a demonstration of using ``gcloud.storage`` | ||
| to read and write data to Google Cloud Storage. | ||
| Try it yourself | ||
| --------------- | ||
| You can interact with a demo dataset | ||
| in a Python interactive shell. | ||
| Start by importing the demo module | ||
| and instantiating the demo connection:: | ||
| >>> from gcloud.storage import demo | ||
| >>> connection = demo.get_connection() | ||
| Once you have the connection, | ||
| you can create buckets and keys:: | ||
| >>> connection.get_all_buckets() | ||
| [<Bucket: ...>, ...] | ||
| >>> bucket = connection.create_bucket('my-new-bucket') | ||
| >>> print bucket | ||
| <Bucket: my-new-bucket> | ||
| >>> key = bucket.new_key('my-test-file.txt') | ||
| >>> print key | ||
| <Key: my-new-bucket, my-test-file.txt> | ||
| >>> key = key.set_contents_from_string('this is test content!') | ||
| >>> print key.get_contents_as_string() | ||
| 'this is test content!' | ||
| >>> print bucket.get_all_keys() | ||
| [<Key: my-new-bucket, my-test-file.txt>] | ||
| >>> bucket.delete() | ||
| .. note:: | ||
| The ``get_connection`` method is just a shortcut for:: | ||
| >>> from gcloud import storage | ||
| >>> from gcloud.storage import demo | ||
| >>> connection = storage.get_connection( | ||
| >>> demo.PROJECT_NAME, demo.CLIENT_EMAIL, demo.PRIVATE_KEY_PATH) | ||
| OK, that's it! | ||
| -------------- | ||
| And you can always check out | ||
| the :doc:`storage-api`. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import httplib2 | ||
| class Connection(object): | ||
| """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. | ||
| """ | ||
| 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.""" | ||
| 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 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() | ||
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page.
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page.
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page.
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page.
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page.
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page.
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page.
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page.
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page.
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page. | ||
| if self._credentials: | ||
| self._http = self._credentials.authorize(self._http) | ||
| return self._http | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -15,12 +15,8 @@ class Credentials(object): | ||
| which use this class under the hood. | ||
| """ | ||
| SCOPE = ('https://www.googleapis.com/auth/datastore ' | ||
| 'https://www.googleapis.com/auth/userinfo.email') | ||
| """The scope required for authenticating as a Cloud Datastore consumer.""" | ||
| @classmethod | ||
| def get_for_service_account(cls, client_email, private_key_path): | ||
| def get_for_service_account(cls, client_email, private_key_path, scope=None): | ||
| """Gets the credentials for a service account. | ||
| :type client_email: string | ||
| @@ -30,8 +26,15 @@ def get_for_service_account(cls, client_email, private_key_path): | ||
| :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( | ||
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page.
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page.
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page.
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page.
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page. | ||
| service_account_name=client_email, | ||
| private_key=open(private_key_path).read(), | ||
| scope=cls.SCOPE) | ||
| scope=scope) | ||
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.