Home > database >  sharing GCP image using api
sharing GCP image using api

Time:05-20

I have been trying to share my GCP image with other accounts using API... on the UI I can do it in permissions and by adding members...

I used the following URL with the post request:

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/images/IMAGE_NAME:getIamPolicy

with headers 'Content-Type': 'application/json; charset=utf-8'

and with data:

                            {"version": "0",
                             "bindings":
                                 [
                                        {
                                            "members": ["user:[email protected]"],
                                            "role":"roles/compute.imageUser"
                                        }
                                 ]
                             }
                        }

bypassing the authorization bearer key,

after hitting it in postman or with curl or in python request, getting a response: 404 Not Found

I also enabled the API permissions using CLI using gcloud services enable pubsub.googleapis.com

what do I need to pass extra to make this work? hoping I will get help from someone ... Thanks in advance

CodePudding user response:

@Ganesh

To set IAM Policy, you need to use different url.

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/images/IMAGE_NAME/setIamPolicy

json({
  "version": "0",
  "bindings": [
    {
      "members": ["user:[email protected]"],
      "role": "roles/compute.imageUser"
    }
  ]
})

Note:

  • replace projectId
  • replace imagename

reference: google-docs, collection, Dothttp

  • Related