googleapis / googleapis/google-cloud-node

getIamPolicy for KMS KeyManagementServiceClient is erroring with Syntax Error: Unexpected token < in JSON at position 0 , when using fallback REST

Open
#7,742 1 comment 0 reactions 0 assignees View on GitHub
library: google-cloud-node-core priority: p2 type: bug
Dominant language
TypeScript
Stars
3.2k
Forks
712
Avg merge
2d 3h
Merged PRs (30d)
99

Description

1) Is this a client library issue or a product issue?
Yes it is a client library issue, the definition for `getIamPolicy` method in iam_services.json mentions `POST` call whether the actual call is `GET`

2) Did someone already solve this?
Could not find any solution or issues created for the same.

3) Do you have a support contract?
No

#### Environment details

- OS: WSL 2Ubuntu 20.04.4 LTS
- Node.js version: 18.14.2
- npm version: 9.5.0
- `google-gax` version: 3.6.0

#### Steps to reproduce

1. Call the following method for KMS
```typescript
import * as kms from "@google-cloud/kms";
import { google } from "@google-cloud/iap/build/protos/protos";
import GetIamPolicyRequest = google.iam.v1.GetIamPolicyRequest;

const keyManagementServiceClient = new kms.KeyManagementServiceClient({
credentials: {
client_email: "user@project-id.iam.gserviceaccount.com",
private_key:"very-long-private-key",
},
projectId: "project-id",
fallback: "rest",
});

const req = new GetIamPolicyRequest({
resource: "projects/project-id/locations/global/keyRings/qflow",
});
keyManagementServiceClient
.getIamPolicy(req)
.then(console.log)
.catch(console.error);

```
2. It is using the POST method to hit the API
Output (Before)
![image](https://github.com/googleapis/google-cloud-node/assets/32898073/629ea27f-dbbc-4a09-a455-ed01c053ad80)

3. After making a change to the following [file ](https://github.com/googleapis/gax-
nodejs/blob/main/protos/iam_service.json#L43,L49)and replacing `post` with `get` issue seems to be resolved.

Changes

![image](https://github.com/googleapis/google-cloud-node/assets/32898073/1512f9c5-1702-4bc0-88af-b6fe94189d70)

Output (After)
![image](https://github.com/googleapis/google-cloud-node/assets/32898073/c16fe8d0-875e-47dc-8214-6131527f0730)

Making sure to follow these steps will guarantee the quickest resolution possible.

Thanks!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.