Constructor
new IAM(pubsub, id)
Parameters:
Name | Type | Description |
---|---|---|
pubsub |
PubSub |
PubSub Object. |
id |
string |
The name of the topic or subscription. |
- Source:
- See:
Methods
getPolicy(gaxOptionsopt, callbackopt) → {Promise.<GetPolicyResponse>}
Get the IAM policy
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
gaxOptions |
object |
<optional> |
Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/CallSettings.html. |
callback |
GetPolicyCallback |
<optional> |
Callback function. |
- Source:
- See:
Example
const {PubSub} = require('@google-cloud/pubsub');
const pubsub = new PubSub();
const topic = pubsub.topic('my-topic');
const subscription = topic.subscription('my-subscription');
topic.iam.getPolicy(function(err, policy, apiResponse) {});
subscription.iam.getPolicy(function(err, policy, apiResponse) {});
//-
// If the callback is omitted, we'll return a Promise.
//-
topic.iam.getPolicy().then(function(data) {
const policy = data[0];
const apiResponse = data[1];
});
setPolicy(policy, gaxOptionsopt, callback) → {Promise.<SetPolicyResponse>}
Set the IAM policy
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
policy |
object |
The policy. Properties
|
|||||||||||||||||
gaxOptions |
object |
<optional> |
Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/CallSettings.html. |
||||||||||||||||
callback |
SetPolicyCallback |
Callback function. |
- Source:
- See:
Throws:
-
If no policy is provided.
- Type
- Error
Example
const {PubSub} = require('@google-cloud/pubsub');
const pubsub = new PubSub();
const topic = pubsub.topic('my-topic');
const subscription = topic.subscription('my-subscription');
const myPolicy = {
bindings: [
{
role: 'roles/pubsub.subscriber',
members:
['serviceAccount:myotherproject@appspot.gserviceaccount.com']
}
]
};
topic.iam.setPolicy(myPolicy, function(err, policy, apiResponse) {});
subscription.iam.setPolicy(myPolicy, function(err, policy, apiResponse)
{});
//-
// If the callback is omitted, we'll return a Promise.
//-
topic.iam.setPolicy(myPolicy).then(function(data) {
const policy = data[0];
const apiResponse = data[1];
});
testPermissions(permissions, gaxOptionsopt, callbackopt) → {Promise.<TestIamPermissionsResponse>}
Test a set of permissions for a resource.
Permissions with wildcards such as *
or storage.*
are not allowed.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
permissions |
string | Array.<string> |
The permission(s) to test for. |
|
gaxOptions |
object |
<optional> |
Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/CallSettings.html. |
callback |
TestIamPermissionsCallback |
<optional> |
Callback function. |
- Source:
- See:
Throws:
-
If permissions are not provided.
- Type
- Error
Example
const {PubSub} = require('@google-cloud/pubsub');
const pubsub = new PubSub();
const topic = pubsub.topic('my-topic');
const subscription = topic.subscription('my-subscription');
//-
// Test a single permission.
//-
const test = 'pubsub.topics.update';
topic.iam.testPermissions(test, function(err, permissions, apiResponse) {
console.log(permissions);
// {
// "pubsub.topics.update": true
// }
});
//-
// Test several permissions at once.
//-
const tests = [
'pubsub.subscriptions.consume',
'pubsub.subscriptions.update'
];
subscription.iam.testPermissions(tests, function(err, permissions) {
console.log(permissions);
// {
// "pubsub.subscriptions.consume": true,
// "pubsub.subscriptions.update": false
// }
});
//-
// If the callback is omitted, we'll return a Promise.
//-
topic.iam.testPermissions(test).then(function(data) {
const permissions = data[0];
const apiResponse = data[1];
});