Skip to content

Commit

Permalink
Merge pull request #101 from GoogleCloudPlatform/moar-nits
Browse files Browse the repository at this point in the history
More consistency and standardization improvements.
  • Loading branch information
Jonathan Wayne Parrott committed Sep 18, 2015
2 parents a1d2121 + d33ea01 commit 03251f8
Show file tree
Hide file tree
Showing 16 changed files with 193 additions and 184 deletions.
12 changes: 9 additions & 3 deletions bigquery/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ This section contains samples for [Google BigQuery](https://cloud.google.com/big

## Running the samples

In order to run it, your environment must be setup with [authentication
information](https://developers.google.com/identity/protocols/application-default-credentials#howtheywork). If you're running it in your local development environment and you have the [Google Cloud SDK](https://cloud.google.com/sdk/) installed, you can do this easily by running:
1. Your environment must be setup with [authentication
information](https://developers.google.com/identity/protocols/application-default-credentials#howtheywork). If you're running in your local development environment and you have the [Google Cloud SDK](https://cloud.google.com/sdk/) installed, you can do this easily by running:

$ gcloud auth login
$ gcloud auth login

2. Install dependencies from the top-level [`requirements.txt`](../requirements.txt):

$ pip install -r requirements.txt

3. Depending on the sample, you may also need to create resources on the [Google Developers Console](https://console.developers.google.com). Refer to the sample description and associated documentation page.

## Additional resources

Expand Down
6 changes: 4 additions & 2 deletions blog/introduction_to_data_models_in_cloud_datastore/README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
# Introduction to data models in Cloud Datastore

This sample code is used in [this blog post](). It demonstrates two data models
This sample code is used in [this blog post](http://googlecloudplatform.blogspot.com/2015/08/Introduction-to-data-models-in-Cloud-Datastore.html). It demonstrates two data models
using [Google Cloud Datastore](https://cloud.google.com/datastore).

## Prerequisites

1. Create project with billing enabled on the [Google Developers Console](https://console.developers.google.com)

2. [Enable the Datastore API](https://console.developers.google.com/project/_/apiui/apiview/datastore/overview).

3. Install the [Google Cloud SDK](https://cloud.google.com/sdk) and be sure to run ``gcloud auth``.


## Running the samples

Install any dependencies:
Install dependencies from the top-level [`requirements.txt`](../../requirements.txt):

pip install -r requirements.txt

Expand Down

This file was deleted.

14 changes: 9 additions & 5 deletions cloud_logging/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ This section contains samples for [Google Cloud Logging](https://cloud.google.co

## Running the samples

In order to run it, your environment must be setup with [authentication
information](https://developers.google.com/identity/protocols/application-default-credentials#howtheywork). If you're running it in your local development environment and you have the [Google Cloud SDK](https://cloud.google.com/sdk/) installed, you can do this easily by running:
1. Your environment must be setup with [authentication
information](https://developers.google.com/identity/protocols/application-default-credentials#howtheywork). If you're running in your local development environment and you have the [Google Cloud SDK](https://cloud.google.com/sdk/) installed, you can do this easily by running:

$ gcloud auth login
$ gcloud auth login

2. Install dependencies from the top-level [`requirements.txt`](../requirements.txt):

$ pip install -r requirements.txt

3. Depending on the sample, you may also need to create resources on the [Google Developers Console](https://console.developers.google.com). Refer to the sample description and associated documentation page.

## Additional resources

Expand All @@ -23,5 +29,3 @@ can visit:
For information on the Python Client Library visit:

> https://developers.google.com/api-client-library/python
## Other Samples
33 changes: 33 additions & 0 deletions monitoring/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Google Cloud Monitoring Samples

This section contains samples for [Google Cloud Monitoring](https://cloud.google.com/monitoring).

## Running the samples

1. Your environment must be setup with [authentication
information](https://developers.google.com/identity/protocols/application-default-credentials#howtheywork). *Note* that Cloud Monitoring does not currently work
with `gcloud auth`. You will need to use a *service account* when running
locally and set the `GOOGLE_APPLICATION_CREDENTIALS` environment variable.

$ export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service_account.json

2. Install dependencies from the top-level [`requirements.txt`](../requirements.txt):

$ pip install -r requirements.txt

3. Depending on the sample, you may also need to create resources on the [Google Developers Console](https://console.developers.google.com). Refer to the sample description and associated documentation page.

## Additional resources

For more information on Cloud Monitoring you can visit:

> https://cloud.google.com/monitoring
For more information on the Cloud Monitoring API Python library surface you
can visit:

> https://developers.google.com/resources/api-libraries/documentation/storage/v2beta2/python/latest/
For information on the Python Client Library visit:

> https://developers.google.com/api-client-library/python
75 changes: 27 additions & 48 deletions monitoring/api/auth.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env pyhton

# Copyright 2015 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -14,81 +16,58 @@

"""Sample command-line program for retrieving Google Cloud Monitoring API data.
Simple command-line program to demonstrate connecting to the Google Cloud
Monitoring API to retrieve API data, using application default credentials to
authenticate.
This sample obtains authentication information from its environment via
application default credentials [1].
If you're not running the sample on Google App Engine or Compute Engine (where
the environment comes pre-authenticated as a service account), you'll have to
initialize your environment with credentials the sample can use.
One way to do this is through the cloud console's credentials page [2]. Create
a new client ID of type 'Service account', and download its JSON key. This will
be the account the sample authenticates as.
Once you've downloaded the service account's JSON key, you provide it to the
sample by setting the GOOGLE_APPLICATION_CREDENTIALS environment variable to
point to the key file:
This sample is used on this page:
$ export GOOGLE_APPLICATION_CREDENTIALS=/path/to/json-key.json
https://cloud.google.com/monitoring/api/authentication
[1] https://developers.google.com/identity/protocols/\
application-default-credentials
[2] https://console.developers.google.com/project/_/apiui/credential
""" # NOQA
For more information, see the README.md under /monitoring.
"""

# [START all]
import argparse
import json
import sys

from googleapiclient.discovery import build

from oauth2client.client import GoogleCredentials


METRIC = 'compute.googleapis.com/instance/disk/read_ops_count'
YOUNGEST = '2015-01-01T00:00:00Z'


def ListTimeseries(project_name, service):
def list_timeseries(monitoring, project_name):
"""Query the Timeseries.list API method.
Args:
monitoring: the CloudMonitoring service object.
project_name: the name of the project you'd like to monitor.
service: the CloudMonitoring service object.
"""
timeseries = monitoring.timeseries()

timeseries = service.timeseries()
response = timeseries.list(
project=project_name, metric=METRIC, youngest=YOUNGEST).execute()

print('Timeseries.list raw response:')
try:
response = timeseries.list(
project=project_name, metric=METRIC, youngest=YOUNGEST).execute()

print(json.dumps(response,
sort_keys=True,
indent=4,
separators=(',', ': ')))
except:
print('Error:')
for error in sys.exc_info():
print(error)
print(json.dumps(response,
sort_keys=True,
indent=4,
separators=(',', ': ')))


def main(project_name):
# Create and return the CloudMonitoring service object.
service = build('cloudmonitoring', 'v2beta2',
credentials=GoogleCredentials.get_application_default())
credentials = GoogleCredentials.get_application_default()
monitoring = build('cloudmonitoring', 'v2beta2', credentials=credentials)

ListTimeseries(project_name, service)
list_timeseries(monitoring, project_name)


if __name__ == '__main__':
if len(sys.argv) != 2:
print("Usage: {} <project-name>".format(sys.argv[0]))
sys.exit(1)
main(sys.argv[1])
parser = argparse.ArgumentParser(
description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('project_id', help='Your Google Cloud project ID.')

args = parser.parse_args()

main(args.project_id)
# [END all]
2 changes: 2 additions & 0 deletions monitoring/api/auth_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ class TestTimeseriesList(tests.CloudBaseTest):
def test_main(self):
with tests.capture_stdout() as stdout:
auth.main(self.project_id)

output = stdout.getvalue().strip()

self.assertRegexpMatches(
output, re.compile(r'Timeseries.list raw response:\s*'
r'{\s*"kind": "[^"]+",'
Expand Down
17 changes: 17 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
beautifulsoup4==4.4.0
coverage==3.7.1
Flask==0.10.1
funcsigs==0.4
itsdangerous==0.24
Jinja2==2.8
MarkupSafe==0.23
mock==1.3.0
nose==1.3.7
nose-exclude==0.4.1
nosegae==0.5.7
pbr==1.8.0
PyYAML==3.11
waitress==0.8.10
WebOb==1.4.1
WebTest==2.0.18
Werkzeug==0.10.4
24 changes: 12 additions & 12 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
argparse>=1.2.1
google-api-python-client>=1.4.2
httplib2>=0.9.1
oauth2client>=1.5.1
py==1.4.26
pyasn1==0.1.7
pyasn1-modules==0.0.5
rsa==3.1.4
simplejson==3.6.5
gcloud==0.7.1
google-api-python-client==1.4.2
google-apitools==0.4.11
httplib2==0.9.1
oauth2client==1.5.1
protobuf==3.0.0a1
protorpc==0.11.1
pyasn1==0.1.8
pyasn1-modules==0.0.7
pycrypto==2.6.1
rsa==3.2
simplejson==3.8.0
six==1.9.0
tox==1.9.0
uritemplate==0.6
virtualenv==12.0.7
wsgiref==0.1.2
40 changes: 22 additions & 18 deletions storage/README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
## Python Samples for Google Cloud Storage
# Google Cloud Storage Samples

Two samples:
This section contains samples for [Google Cloud Storage](https://cloud.google.com/storage).

1. ``list_objects.py`` lists objects in a bucket.
2. ``compose_objects.py`` composes objects together to create another.
## Running the samples

See the docstring for each sample for usage, or run the sample for the help text.
1. Your environment must be setup with [authentication
information](https://developers.google.com/identity/protocols/application-default-credentials#howtheywork). If you're running in your local development environment and you have the [Google Cloud SDK](https://cloud.google.com/sdk/) installed, you can do this easily by running:

### Setup
$ gcloud auth login

Before running the samples, you'll need the Google Cloud SDK in order to setup authentication.
2. Install dependencies from the top-level [`requirements.txt`](../requirements.txt):

1. Install the [Google Cloud SDK](https://cloud.google.com/sdk/), including the [gcloud tool](https://cloud.google.com/sdk/gcloud/), and [gcloud app component](https://cloud.google.com/sdk/gcloud-app).
2. Setup the gcloud tool.
$ pip install -r requirements.txt

```
gcloud components update app
gcloud auth login
gcloud config set project <your-app-id>
```
3. Depending on the sample, you may also need to create resources on the [Google Developers Console](https://console.developers.google.com). Refer to the sample description and associated documentation page.

You will also need to install the dependencies using [pip](https://pypi.python.org/pypi/pip):
## Additional resources

```
pip install -r requirements.txt
```
For more information on Cloud Storage you can visit:

> https://cloud.google.com/storage
For more information on the Cloud Storage API Python library surface you
can visit:

> https://developers.google.com/resources/api-libraries/documentation/storage/v1/python/latest/
For information on the Python Client Library visit:

> https://developers.google.com/api-client-library/python
Loading

0 comments on commit 03251f8

Please sign in to comment.