Constructor
new Project(resource, id)
Parameters:
| Name | Type | Description |
|---|---|---|
resource |
Resource |
Resource object this project belongs to. |
id |
string |
The project's ID. |
Members
id
Methods
create(configopt)
Create a project.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
config |
object |
<optional> |
See Resource#createProject. |
Example
const {Resource} = require('@google-cloud/resource');
const resource = new Resource();
const project = resource.project('grape-spaceship-123');
project.create((err, project, operation, apiResponse) => {
if (err) {
// Error handling omitted.
}
// `operation` will emit `error` or `complete` when the status
updates.
operation
.on('error', err => {})
.on('complete', () => {
// Project was created successfully!
});
});
//-
// If the callback is omitted, we'll return a Promise.
//-
project.create()
.then(data => {
const project = data[0];
const operation = data[1];
const apiResponse = data[2];
return operation.promise();
})
.then(data => {
const operationMetadata = data[0];
// Project created successfully!
});
delete(callbackopt)
Delete the project.
This method only works if you are authenticated as yourself, e.g. using the gcloud SDK.
Parameters:
| Name | Type | Attributes | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
callback |
function |
<optional> |
The callback function. Properties
|
Example
const {Resource} = require('@google-cloud/resource');
const resource = new Resource();
const project = resource.project('grape-spaceship-123');
project.delete((err, apiResponse) => {
if (!err) {
// The project was deleted!
}
});
//-
// If the callback is omitted, we'll return a Promise.
//-
project.delete().then((data) => {
const apiResponse = data[0];
});
exists(callback)
Check if the project exists.
Parameters:
| Name | Type | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
callback |
function |
The callback function. Properties
|
Example
const {Resource} = require('@google-cloud/resource');
const resource = new Resource();
const project = resource.project('grape-spaceship-123');
project.exists((err, exists) => {});
//-
// If the callback is omitted, we'll return a Promise.
//-
project.exists().then((data) => {
const exists = data[0];
});
get(optionsopt)
Get a project if it exists.
You may optionally use this to "get or create" an object by providing
an object with autoCreate set to true. Any extra configuration that
is normally required for the create method must be contained within
this object as well.
Parameters:
| Name | Type | Attributes | Description | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
options |
<optional> |
Configuration object. Properties
|
Example
const {Resource} = require('@google-cloud/resource');
const resource = new Resource();
const project = resource.project('grape-spaceship-123');
project.get((err, project, apiResponse) => {
// `project.metadata` has been populated.
});
//-
// If the callback is omitted, we'll return a Promise.
//-
project.get().then((data) => {
const project = data[0];
const apiResponse = data[1];
});
getIamPolicy(optionsopt, callbackopt) → {Promise.<GetIamPolicyResponse>}
Get the IAM policy for this project.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
options |
GetIamPolicyOptions |
<optional> |
Options object to get IAM policy. |
callback |
GetIamPolicyCallback |
<optional> |
Callback function. |
Returns:
| Type | Description |
|---|---|
| Promise.<GetIamPolicyResponse> |
Example
const {Resource} = require('@google-cloud/resource');
const resource = new Resource();
const project = resource.project('grape-spaceship-123');
project.getIamPolicy((err, policy) => {
if (!err) {
console.log(policy).
}
});
//-
// If the callback is omitted, we'll return a Promise.
//-
project.getIamPolicy().then((data) => {
const policy = data[0];
});
getMetadata(callbackopt)
Get the metadata for the project.
Parameters:
| Name | Type | Attributes | Description | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
callback |
function |
<optional> |
The callback function. Properties
|
Example
const {Resource} = require('@google-cloud/resource');
const resource = new Resource();
const project = resource.project('grape-spaceship-123');
project.getMetadata((err, metadata, apiResponse) => {});
//-
// If the callback is omitted, we'll return a Promise.
//-
project.getMetadata().then((data) => {
const metadata = data[0];
const apiResponse = data[1];
});
restore(callbackopt)
Restore a project.
This method only works if you are authenticated as yourself, e.g. using the gcloud SDK.
Parameters:
| Name | Type | Attributes | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
callback |
function |
<optional> |
The callback function. Properties
|
Example
const {Resource} = require('@google-cloud/resource');
const resource = new Resource();
const project = resource.project('grape-spaceship-123');
project.restore((err, apiResponse) => {
if (!err) {
// Project restored.
}
});
//-
// If the callback is omitted, we'll return a Promise.
//-
project.restore().then((data) => {
const apiResponse = data[0];
});
setMetadata(metadata, callbackopt)
Set the project's metadata.
This method only works if you are authenticated as yourself, e.g. using the gcloud SDK.
Parameters:
| Name | Type | Attributes | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
metadata |
object |
See a Project resource. |
|||||||||||||
callback |
function |
<optional> |
The callback function. Properties
|
Example
const {Resource} = require('@google-cloud/resource');
const resource = new Resource();
const project = resource.project('grape-spaceship-123');
const metadata = {
name: 'New name'
};
project.setMetadata(metadata, (err, apiResponse) => {
if (!err) {
// The project has been successfully updated.
}
});
//-
// If the callback is omitted, we'll return a Promise.
//-
project.setMetadata(metadata).then((data) => {
const apiResponse = data[0];
});