Tim Burks 838c790915 Update Datastore example to avoid build/run problems on Linux. 8 gadi atpakaļ
..
Sources 838c790915 Update Datastore example to avoid build/run problems on Linux. 8 gadi atpakaļ
Makefile e5568059fa Update remaining examples to remove explicit -lz linker commands. 8 gadi atpakaļ
Package.swift 838c790915 Update Datastore example to avoid build/run problems on Linux. 8 gadi atpakaļ
README.md 459480eed6 Simple (very!) datastore example. 8 gadi atpakaļ
RUNME f3926c5c6a Change access level for generated classes and methods from "public" to "internal". 8 gadi atpakaļ
roots.pem 459480eed6 Simple (very!) datastore example. 8 gadi atpakaļ

README.md

Calling the Google Cloud Datastore API

This directory contains a very simple sample that calls the Google Cloud Datastore API. Calls are made directly to the Datastore RPC interface. In practice, these would be wrapped in idiomatic code.

Use RUNME to generate the necessary Protocol Buffer and gRPC support code.

Calls require a Google project ID and an OAuth token. Both should be specified in Sources/main.swift.

To create a project ID, visit the Google Cloud Console.

One easy way to get an OAuth token is to use the Instance Metadata Service that is available in Google cloud instances, such as Google Compute Engine or Google Cloud Shell. This allows you to get a short-lived service token with curl:

curl \
  http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token \
  -H Metadata-Flavor:Google

That will return something like the following:

{"access_token":"OAUTH ACCESS TOKEN","expires_in":1799,"token_type":"Bearer"}

Put the string matching OAUTH ACCESS TOKEN in the authToken variable in Sources/main.swift. Please note that you must run the curl command from within a Google cloud instance. Once you have the OAuth token, you can use it from anywhere until it expires.

CAUTION: Please take care to not share your OAuth token. It provides access to all of your Google services.