Skip to content

Commit 27a3d57

Browse files
add authorization guide + links to Google docs
fixes googleapis#483 fixes googleapis#479
1 parent 7e49576 commit 27a3d57

File tree

14 files changed

+134
-150
lines changed

14 files changed

+134
-150
lines changed

docs/authorization.md

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
With `gcloud-node` it's incredibly easy to get authorized and start using Google's APIs. You can set your credentials on a global basis as well as on a per-API basis. See each individual API section below to see how you can auth on a per-API-basis. This is useful if you want to use different accounts for different Google Cloud services.
2+
3+
## On Google Compute Engine
4+
5+
If you are running this client on Google Compute Engine, we handle authorization for you with no configuration. You just need to make sure that when you [set up the GCE instance][gce-how-to], you add the correct scopes for the APIs you want to access.
6+
7+
``` js
8+
var config = {
9+
projectId: 'grape-spaceship-123'
10+
};
11+
12+
var gcloud = require('gcloud')(config);
13+
```
14+
15+
## Elsewhere
16+
17+
If you are not running this client on Google Compute Engine, you need a Google Developers service account. To create a service account:
18+
19+
1. Visit the [Google Developers Console][dev-console].
20+
2. Create a new project or click on an existing project.
21+
3. Navigate to **APIs & auth** > **APIs section** and turn on the following APIs (you may need to enable billing in order to use these services):
22+
* Google Cloud Datastore API
23+
* Google Cloud Storage
24+
* Google Cloud Storage JSON API
25+
4. Navigate to **APIs & auth** > **Credentials** and then:
26+
* If you want to use a new service account, click on **Create new Client ID** and select **Service account**. After the account is created, you will be prompted to download the JSON key file that the library uses to authorize your requests.
27+
* If you want to generate a new key for an existing service account, click on **Generate new JSON key** and download the JSON key file.
28+
29+
``` js
30+
var config = {
31+
projectId: 'grape-spaceship-123',
32+
keyFilename: '/path/to/keyfile.json'
33+
};
34+
35+
var gcloud = require('gcloud')(config);
36+
```
37+
38+
### The `config` object
39+
40+
A `config` object requires the following properties:
41+
42+
1. `projectId`
43+
44+
2. One of the following:
45+
1. `config.credentials` object containing `client_email` and `private_key` properties.
46+
2. `config.keyFilename` path to a .json, .pem, or .p12 key file.
47+
3. `GOOGLE_APPLICATION_CREDENTIALS` environment variable with a full path to your key file.
48+
49+
**Note**: When using a .pem or .p12 key file, `config.email` is also required.
50+
51+
[dev-console]: https://console.developers.google.com/project
52+
[gce-how-to]: https://cloud.google.com/compute/docs/authentication#using

docs/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
<script src="site/components/docs/docs-directives.js"></script>
3737
<script src="site/components/docs/docs-services.js"></script>
3838
<script src="site/components/docs/docs-values.js"></script>
39+
<script src="site/components/authorization/authorization.js"></script>
3940
<script src="site/components/faq/faq.js"></script>
4041
<script src="site/components/subpage/subpage-directive.js"></script>
4142
<script src="site/components/header/header-directive.js"></script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<script id="authorization-header.html" type="text/ng-template">
2+
<header header title="Authorization">
3+
<div class="row row--right">
4+
<div class="col margin-vertical">
5+
<a href="https://github.com/GoogleCloudPlatform/gcloud-node/edit/master/docs/authorization.md"
6+
class="v-btn">
7+
<img src="site/img/icon-link-github.svg" />
8+
Edit on GitHub
9+
</a>
10+
</div>
11+
</div>
12+
</header>
13+
</script>
14+
15+
<div subpage
16+
header-templateUrl="authorization-header.html"
17+
title="Authorization">
18+
<btf-markdown ng-include="'authorization.md'"></btf-markdown>
19+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
angular
2+
.module('gcloud.authorization', ['ngRoute', 'gcloud.subpage', 'btford.markdown'])
3+
.config(function($routeProvider) {
4+
'use strict';
5+
6+
$routeProvider.when('/authorization', {
7+
controller: 'AuthorizationCtrl',
8+
templateUrl: 'site/components/authorization/authorization.html'
9+
});
10+
})
11+
12+
.controller('AuthorizationCtrl', function($scope) {
13+
'use strict';
14+
15+
});

docs/site/components/docs/docs.html

+14-34
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ <h3 class="sub-heading">
4444
<div hljs>$ npm install --save gcloud</div>
4545
<div hljs>var gcloud = require('gcloud');</div>
4646
<p>
47-
If you are running your app on Google App Engine or Google Compute Engine, you won't need to worry about supplying connection configuration options to <code>gcloud</code>&mdash; we figure that out for you.
47+
If you are running your app on Google Compute Engine, you won't need to worry about supplying connection configuration options to <code>gcloud</code>&mdash; we figure that out for you.
4848
</p>
4949
<p>
5050
However, if you're running your app elsewhere, you will need to provide project details to authenticate API requests.
5151
</p>
5252
<div hljs>
53-
// App Engine and Compute Engine
53+
// Compute Engine
5454
var gcloud = require('gcloud');
5555

5656
// Elsewhere
@@ -59,7 +59,7 @@ <h3 class="sub-heading">
5959
keyFilename: '/path/to/keyfile.json'
6060
});</div>
6161
<p>
62-
The full set of options which can be passed to gcloud and sub-modules are <a href="#/docs/?method=gcloud">outlined here</a>.
62+
The full set of options which can be passed to gcloud and sub-modules are <a href="#/authorization">outlined here</a>.
6363
</p>
6464
</article>
6565
<hr>
@@ -69,10 +69,8 @@ <h3>BigQuery Overview</h3>
6969
<p>
7070
The object returned from <code>gcloud.bigquery</code> gives you complete access to and control of your BigQuery datasets. You can work with existing ones, by using the <code>dataset</code> method, or create new ones with <code>createDataset</code>.
7171
</p>
72-
<div hljs>
73-
var bigquery = gcloud.bigquery();</div>
7472
<p>
75-
Follow along with the examples below to see how to query your datasets, create tables, import data from your Cloud Storage buckets, and more.
73+
To learn more about BigQuery, see <a href="https://cloud.google.com/bigquery/what-is-bigquery">What is BigQuery?</a>
7674
</p>
7775
</article>
7876

@@ -81,13 +79,8 @@ <h3>Datastore Overview</h3>
8179
<p>
8280
The <code>gcloud.datastore</code> object gives you some convenience methods, as well as exposes a <code>dataset</code> function. This will allow you to create a <code>dataset</code>, which is the object from which you will interact with the Google Cloud Datastore.
8381
</p>
84-
<div hljs>
85-
var dataset = gcloud.datastore.dataset({
86-
projectId: 'project-id',
87-
keyFilename: '/path/to/keyfile.json'
88-
});</div>
89-
<p ng-if="!isActiveUrl('/docs/datastore/dataset')">
90-
See <a href="#/docs/{{version}}/datastore/dataset">the Dataset documentation</a> for examples of how to query the datastore, save entities, run a transaction, and others.
82+
<p>
83+
To learn more about Datastore, read the <a href="https://cloud.google.com/datastore/docs/concepts/overview">Google Cloud Datastore Concepts Overview</a>.
9184
</p>
9285
</article>
9386

@@ -97,41 +90,28 @@ <h3>Pub/Sub Overview</h3>
9790
Google Cloud Pub/Sub is in Alpha status. As a result, it might be changed in backward-incompatible ways and is not recommended for production use. It is not subject to any SLA or deprecation policy.
9891
</p>
9992
<p>
100-
The <code>gcloud.pubsub</code> method will return a <code>pubsub</code> object, allowing you to create topics, publish messages, subscribe to topics, and more. See the <a href="https://developers.google.com/pubsub/overview">Google Cloud Pub/Sub overview</a> for more information.
93+
The <code>gcloud.pubsub</code> method will return a <code>pubsub</code> object, allowing you to create topics, publish messages, subscribe to topics, and more.
10194
</p>
102-
<div hljs>
103-
var pubsub = gcloud.pubsub({
104-
projectId: 'project-id',
105-
keyFilename: '/path/to/keyfile.json'
106-
});</div>
10795
<p>
108-
See the examples below, which demonstrate everything from creating a topic to subscribing to messages on a topic.
96+
To learn more about Pub/Sub, see the <a href="https://developers.google.com/pubsub/overview">Google Cloud Pub/Sub overview</a>.
10997
</p>
11098
</article>
11199

112100
<article ng-if="isActiveDoc('storage')">
113101
<h3>Storage Overview</h3>
114102
<p>
115-
The <code>gcloud.storage</code> object contains a <code>bucket</code> function, which is how you will interact with your Google Cloud Storage bucket. See the guide on <a href="https://developers.google.com/storage">Google Cloud Storage</a> to create a bucket.
103+
The <code>gcloud.storage</code> object contains a <code>bucket</code> function, which is how you will interact with your Google Cloud Storage bucket.
116104
</p>
117-
<div hljs>
118-
var bucket = gcloud.storage().bucket('my-bucket');</div>
119-
<h4>ACLs</h4>
120105
<p>
121-
Google Cloud Storage uses access control lists (ACLs) to manage object and bucket access. ACLs are the mechanism you use to share files with other users and allow other users to access your buckets and files.
106+
To learn more about Cloud Storage, see the <a href="https://cloud.google.com/storage/docs/overview">Google Cloud Storage overview</a>.
122107
</p>
108+
109+
<h4>ACLs</h4>
123110
<p>
124-
Convenience methods are provided to perform common operations, such as the following.
111+
Google Cloud Storage uses access control lists (ACLs) to manage object and bucket access. ACLs are the mechanism you use to share files with other users and allow other users to access your buckets and files.
125112
</p>
126-
<div hljs>
127-
// Allow a user to read files from a bucket.
128-
bucket.acl.readers.addUser('[email protected]', function(err, aclObject) {});
129-
130-
// Revoke file ownership permissions from a group.
131-
var myFile = bucket.file('my-file.txt');
132-
myFile.acl.owners.deleteGroup('group-id', function(err, aclObject) {});</div>
133113
<p>
134-
See examples below for more on how to access your bucket to upload a file, read its files, create signed URLs, and more.
114+
To learn more about ACLs, read this overview on <a href="https://cloud.google.com/storage/docs/access-control">Access Control</a>.
135115
</p>
136116
</article>
137117

docs/site/components/subpage/subpage.html

+5
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ <h1 class="logo">
5656
Documentation
5757
</a>
5858
</li>
59+
<li>
60+
<a href="#/authorization" ng-class="{ current: isActiveUrl('/authorization') }" title="Authorization">
61+
Authorization
62+
</a>
63+
</li>
5964
<li>
6065
<a href="#/faq" ng-class="{ current: isActiveUrl('/faq') }" title="Frequently Asked Questions">
6166
FAQ

docs/site/css/main.css

+7
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,13 @@ ul {
725725
cursor: pointer;
726726
}
727727

728+
.js {
729+
display: block;
730+
padding: .5em;
731+
color: #333;
732+
background: #F8F8F8;
733+
}
734+
728735
/*
729736
Page Title
730737
*/

docs/site/home.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
angular
22
.module('gcloud', [
33
'ngRoute',
4+
'gcloud.authorization',
45
'gcloud.docs',
56
'gcloud.faq',
67
'gcloud.troubleshooting',

lib/bigquery/index.js

+2-17
Original file line numberDiff line numberDiff line change
@@ -66,35 +66,20 @@ var SCOPES = ['https://www.googleapis.com/auth/bigquery'];
6666
* The examples below will demonstrate the different usage patterns your app may
6767
* need to support to retrieve a BigQuery object.
6868
*
69-
* The full set of options that can be passed to BigQuery are
70-
* [outlined here](#/docs/?method=gcloud).
71-
*
7269
* @alias module:bigquery
7370
* @constructor
7471
*
75-
* @param {object=} options - Configuration object.
72+
* @param {object} options - [Configuration object](#/docs/?method=gcloud).
7673
*
7774
* @example
78-
* var gcloud = require('gcloud');
79-
*
80-
* //-
81-
* // Providing configuration details up-front.
82-
* //-
83-
* var myProject = gcloud({
75+
* var gcloud = require('gcloud')({
8476
* keyFilename: '/path/to/keyfile.json',
8577
* projectId: 'my-project'
8678
* });
8779
*
8880
* var bigquery = myProject.bigquery();
8981
*
9082
* //-
91-
* // Overriding default configuration details.
92-
* //-
93-
* var bigquery = myProject.bigquery({
94-
* keyFilename: '/path/to/another/keyfile.json'
95-
* });
96-
*
97-
* //-
9883
* // In the following examples from this page and the other modules (Dataset,
9984
* // Table, etc.), we are going to be using a dataset from
10085
* // data.gov (http://goo.gl/f2SXcb) of higher education institutions.

lib/datastore/dataset.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,11 @@ var SCOPES = [
6666
* Interact with a dataset from the
6767
* [Google Cloud Datastore](https://developers.google.com/datastore/).
6868
*
69-
* The full set of options that can be passed to this method are
70-
* [outlined here](#/docs/?method=gcloud).
71-
*
7269
* @constructor
7370
* @alias module:datastore/dataset
7471
* @mixes module:datastore/request
7572
*
76-
* @param {object=} options - Configuration object.
77-
* @param {string=} options.projectId - Dataset ID. This is your project ID from
78-
* the Google Developers Console.
73+
* @param {object=} options - [Configuration object](#/docs/?method=gcloud).
7974
* @param {string=} options.apiEndpoint - Override the default API endpoint used
8075
* to reach Datastore. This is useful for connecting to your local Datastore
8176
* server (usually "http://localhost:8080").
@@ -94,6 +89,11 @@ var SCOPES = [
9489
* projectId: 'my-project',
9590
* apiEndpoint: 'http://localhost:8080'
9691
* });
92+
*
93+
* //-
94+
* // The `process.env.DATASTORE_HOST` environment variable is also recognized.
95+
* // If set, you may omit the `apiEndpoint` option.
96+
* //-
9797
*/
9898
function Dataset(options) {
9999
if (!(this instanceof Dataset)) {

lib/datastore/index.js

+5-15
Original file line numberDiff line numberDiff line change
@@ -62,28 +62,18 @@ var Dataset = require('./dataset');
6262
* @alias module:datastore
6363
* @constructor
6464
*
65-
* @example
66-
* var gcloud = require('gcloud');
65+
* @param {object} options - [Configuration object](#/docs/?method=gcloud).
6766
*
68-
* //-
69-
* // Providing configuration details up-front.
70-
* //-
71-
* var myProject = gcloud({
67+
* @example
68+
* var gcloud = require('gcloud')({
7269
* keyFilename: '/path/to/keyfile.json',
7370
* projectId: 'my-project'
7471
* });
7572
*
7673
* var dataset = gcloud.dataset();
77-
*
78-
* //-
79-
* // Overriding default configuration details.
80-
* //-
81-
* var dataset = myProject.datastore.dataset({
82-
* keyFilename: '/path/to/another/keyfile.json'
83-
* });
8474
*/
85-
function Datastore(config) {
86-
this.config = config || {};
75+
function Datastore(options) {
76+
this.config = options || {};
8777
}
8878

8979
/*! Developer Documentation

lib/index.js

+2-39
Original file line numberDiff line numberDiff line change
@@ -58,45 +58,8 @@ var util = require('./common/util.js');
5858
* 2. Provide them at the time of instantiation of sub-modules, e.g. a Datastore
5959
* dataset, a Cloud Storage bucket, etc.
6060
*
61-
* If you are using Google App Engine or Google Compute Engine, your connection
62-
* details are handled for you. You won't have to worry about specifying these,
63-
* however you may find it advantageous to provide a `projectId` at
64-
* instantiation.
65-
*
66-
* To specify the configuration details up-front, invoke the gcloud module,
67-
* passing in an object. The properties defined on this object will be persisted
68-
* to the instantiation of every sub-module. It's important to note that you can
69-
* override any of these defaults when you invoke a sub-module later.
70-
*
71-
* You can invoke this module as many times as your project warrants. Each time,
72-
* your provided configuration will remain isolated to the returned gcloud
73-
* module.
74-
*
75-
* To authenticate API requests,
76-
* [google-auth-library](https://github.com/google/google-auth-library-nodejs)
77-
* is used to detect the environment your project is running in. Use the
78-
* following guide to determine the appropriate configuration.
79-
*
80-
* <h4>Google Compute Engine</h4>
81-
*
82-
* - No configuration necessary!
83-
*
84-
* <h4>Google App Engine Production</h4>
85-
*
86-
* - No configuration necessary!
87-
*
88-
* <h4>Other</h4>
89-
90-
* - Provide `config.projectId`
91-
* - Use one of the following:
92-
* - `config.credentials` object containing `client_email` and `private_key`
93-
* properties.
94-
* - `config.keyFilename` path to a .json, .pem, or .p12 key file.
95-
* - `GOOGLE_APPLICATION_CREDENTIALS` environment variable with a full path
96-
* to your key file.
97-
*
98-
* **Note**: When using a .pem or .p12 key file, `config.email` is also
99-
* required.
61+
* See our [Authorization Guide](#/authorization) for how to obtain the
62+
* necessary credentials for connecting to your project.
10063
*
10164
* @alias module:gcloud
10265
* @constructor

0 commit comments

Comments
 (0)