0

I'm trying grant publish rights to a topic using SetIamPolicy as has been described here: [Google Cloud Pub/Sub API - Push E-mail but no success yet - not sure what the exact call should look like.

For now I've made a json file containing this:

POST "https://pubsub.googleapis.com/v1beta2/{resource=projects/myproject/topics/mytopic}:setIamPolicy"
Content-type: application/json

{
  "policy": {
    "bindings": [{
      "role": "roles/pubsub.publisher",
      "members": ["serviceAccount:gmail-api-push@system.gserviceaccount.com"],
    }],
  }
}

as described here: http://developers.google.com/gmail/api/guides/push and call it like this: topics.SetIamPolicy('pubsub_policy.json'); - but setiampolicy is an undefined function. Any ideas? Googling has yielded absolutely nothing in terms of examples in node.js

Community
  • 1
  • 1
Dan
  • 589
  • 6
  • 20
  • Have you replaced `{resource=projects/myproject/topics/mytopic}` with a real value? E.g. `projects/gmail_client/topics/gmail_push_notif`? – Tholle Jul 29 '15 at 17:13
  • Yes, I have replaced it with `{resource=projects/gmail_client/topics?gmail_push_notif}` and have also tried with the `{resource=` part - then i pasted the exact code above into a json file and call it with 'topics.setIamPolicy('pubsub_policy.json');`.... really not sure how this is supposed to work though, any help, even at a basic level, would be appreciated! – Dan Jul 29 '15 at 18:00
  • * without the resource part – Dan Jul 29 '15 at 18:17

1 Answers1

2

I used the Google Developers Console

After a lot searching I found it was easier to just set the publish rights in the Google Developers Console.

  1. click on your project
  2. click on Big Data > Pub/Sub
  3. If you haven't already done so, create a topic
  4. Check the box next to that topic
  5. Click the permissions button at the top
  6. Add your permissions in the box that should look like this



I did find this documentation about setIamPolicy() for nodejs.

var 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) {});


But I couldn't get it to work. topic.iam.setPolicy() didn't exist. All I saw was this:

//console.log(topic)
{
    ...
    iam: { 
         resource: 'projects/[projectId]/topics/[topicName]',
         makeReq_: [Function] } 
}