Skip to content
This repository has been archived by the owner on Oct 29, 2023. It is now read-only.

Commit

Permalink
Adds tests, CLI, and fixes some tiny bugs. [(#973)](GoogleCloudPlatfo…
Browse files Browse the repository at this point in the history
…rm/python-docs-samples#973)

* Adds tests, CLI, and fixes some tiny bugs.

* Fixes lint and adds fake certs for tests.

* Print is a function.

* I had to change something to retrigger tests

* Address review comments

* Import order style
  • Loading branch information
gguuss authored and dpebot committed Jun 2, 2017
1 parent 37d3f63 commit 3c2b6c8
Show file tree
Hide file tree
Showing 10 changed files with 876 additions and 380 deletions.
43 changes: 0 additions & 43 deletions samples/api-client/manager/README.md

This file was deleted.

150 changes: 150 additions & 0 deletions samples/api-client/manager/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
.. This file is automatically generated. Do not edit this file directly.
Google Cloud IoT Core API Python Samples
===============================================================================

This directory contains samples for Google Cloud IoT Core API. `Google Cloud IoT Core`_ allows developers to easily integrate Publish and Subscribe functionality with devices and programmatically manage device authorization.




.. _Google Cloud IoT Core API: https://cloud.google.com/vision/docs

Setup
-------------------------------------------------------------------------------


Authentication
++++++++++++++

Authentication is typically done through `Application Default Credentials`_,
which means you do not have to change the code to authenticate as long as
your environment has credentials. You have a few options for setting up
authentication:

#. When running locally, use the `Google Cloud SDK`_

.. code-block:: bash
gcloud auth application-default login
#. When running on App Engine or Compute Engine, credentials are already
set-up. However, you may need to configure your Compute Engine instance
with `additional scopes`_.

#. You can create a `Service Account key file`_. This file can be used to
authenticate to Google Cloud Platform services from any environment. To use
the file, set the ``GOOGLE_APPLICATION_CREDENTIALS`` environment variable to
the path to the key file, for example:

.. code-block:: bash
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service_account.json
.. _Application Default Credentials: https://cloud.google.com/docs/authentication#getting_credentials_for_server-centric_flow
.. _additional scopes: https://cloud.google.com/compute/docs/authentication#using
.. _Service Account key file: https://developers.google.com/identity/protocols/OAuth2ServiceAccount#creatinganaccount

Install Dependencies
++++++++++++++++++++

#. Install `pip`_ and `virtualenv`_ if you do not already have them.

#. Create a virtualenv. Samples are compatible with Python 2.7 and 3.4+.

.. code-block:: bash
$ virtualenv env
$ source env/bin/activate
#. Install the dependencies needed to run the samples.

.. code-block:: bash
$ pip install -r requirements.txt
.. _pip: https://pip.pypa.io/
.. _virtualenv: https://virtualenv.pypa.io/

Samples
-------------------------------------------------------------------------------

Manager
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++



To run this sample:

.. code-block:: bash
$ python manager.py
usage: manager.py [-h] --project_id PROJECT_ID --pubsub_topic PUBSUB_TOPIC
--api_key API_KEY [--ec_public_key_file EC_PUBLIC_KEY_FILE]
[--rsa_certificate_file RSA_CERTIFICATE_FILE]
[--cloud_region CLOUD_REGION]
[--service_account_json SERVICE_ACCOUNT_JSON]
[--registry_id REGISTRY_ID] [--device_id DEVICE_ID]
{create-es256,create-registry,create-rsa256,create-topic,create-unauth,delete-device,delete-registry,get,list,patch-es256,patch-rs256}
...
Example of using the Google Cloud IoT Core device manager to administer
devices.
Usage example:
python manager.py \
--project_id=my-project-id \
--pubsub_topic=projects/my-project-id/topics/my-topic-id \
--api_key=YOUR_API_KEY \
--ec_public_key_file=../ec_public.pem \
--rsa_certificate_file=../rsa_cert.pem \
--service_account_json=$HOME/service_account.json
list
positional arguments:
{create-es256,create-registry,create-rsa256,create-topic,create-unauth,delete-device,delete-registry,get,list,patch-es256,patch-rs256}
create-es256 Create a new device with the given id, using ES256 for
authentication.
create-registry Gets or creates a device registry.
create-rsa256 Create a new device with the given id, using RS256 for
authentication.
create-topic Creates a PubSub Topic and grants access to Cloud IoT
Core.
create-unauth Create a new device without authentication.
delete-device Delete the device with the given id.
delete-registry Deletes the specified registry.
get Retrieve the device with the given id.
list List all devices in the registry.
patch-es256 Patch the device to add an ES256 public key to the
device.
patch-rs256 Patch the device to add an RSA256 public key to the
device.
optional arguments:
-h, --help show this help message and exit
--project_id PROJECT_ID
GCP cloud project name.
--pubsub_topic PUBSUB_TOPIC
Google Cloud Pub/Sub topic. Format is
projects/project_id/topics/topic-id
--api_key API_KEY Your API key.
--ec_public_key_file EC_PUBLIC_KEY_FILE
Path to public ES256 key file.
--rsa_certificate_file RSA_CERTIFICATE_FILE
Path to RS256 certificate file.
--cloud_region CLOUD_REGION
GCP cloud region
--service_account_json SERVICE_ACCOUNT_JSON
Path to service account json file.
--registry_id REGISTRY_ID
Registry id. If not set, a name will be generated.
--device_id DEVICE_ID
Device id.
.. _Google Cloud SDK: https://cloud.google.com/sdk/
21 changes: 21 additions & 0 deletions samples/api-client/manager/README.rst.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This file is used to generate README.rst

product:
name: Google Cloud IoT Core API
short_name: Cloud IoT Core
url: https://cloud.google.com/vision/docs
description: >
`Google Cloud IoT Core`_ allows developers to easily integrate Publish and
Subscribe functionality with devices and programmatically manage device
authorization.

setup:
- auth
- install_deps

samples:
- name: Manager
file: manager.py
show_help: True

cloud_client_library: false
Loading

0 comments on commit 3c2b6c8

Please sign in to comment.