Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to Get API Resource information from API Hub using Java Client Library #11172

Open
dsam0162 opened this issue Sep 23, 2024 · 3 comments
Open
Labels
priority: p3 Desirable enhancement or fix. May not be included in next release. type: question Request for information or clarification. Not an issue.

Comments

@dsam0162
Copy link

I'm using the following libraries to configure the Apihub Java Client to the Gradle project.

  • implementation platform('com.google.cloud:libraries-bom:26.45.0')
  • implementation 'com.google.cloud:google-cloud-apihub'
  • implementation group: 'com.google.auth', name: 'google-auth-library-oauth2-http', version: '1.24.0'

However, I'm getting a permission error that is blocking me from invoking any of the ApiHubClient methods.
I'm using an access token retrieved from Google Cloud SDK using the command (gcloud auth print-access-token) which has all the necessary permissions to access the APIHub resources. Also, the API Hub Rest APIs are working without issues using the same access token.

Environment details

Java version: 17

Steps to reproduce

(Replace "access-token-here" and put valid values for API name details(project,location,api-id) in the code snippet.)

  1. Create a GoogleCredentials object using an Access token obtained from Google Cloud SDK which has all necessary permissions,
  2. Pass the credentials object as a credential provider for ApiHubSettings
  3. Initialize the ApiHubClient using created ApiHubSettings
  4. Run Java code snippet

Code example

GoogleCredentials credentials = GoogleCredentials.create(AccessToken.newBuilder().setTokenValue("access-token-here").build());

ApiHubSettings apiHubSettings = ApiHubSettings.newBuilder()
    .setCredentialsProvider(()->credentials)
    .build();

//Get Api Resource Details
try (ApiHubClient apiHubClient = ApiHubClient.create(apiHubSettings)) {
   GetApiRequest request =
       GetApiRequest.newBuilder()
           .setName(ApiName.of("xyz-apigee-sbx", "us-central2", "200ab164-97cb-479e-9451-98e42bae1563")
               .toString())
           .build();
   Api response = apiHubClient.getApi(request);
   logger.info("Response: {}",response);
} catch (Exception e) {
   logger.error("An error occurred while processing: {}", e.getMessage(), e);
}

Stack trace

com.google.api.gax.rpc.PermissionDeniedException: io.grpc.StatusRuntimeException: PERMISSION_DENIED: Read access to project 'xyz-apigee-sbx' was denied

External references such as API reference guides

Thanks!

@blakeli0 blakeli0 added type: question Request for information or clarification. Not an issue. priority: p2 Moderately-important priority. Fix may not be included in next release. priority: p3 Desirable enhancement or fix. May not be included in next release. and removed priority: p2 Moderately-important priority. Fix may not be included in next release. labels Sep 24, 2024
@ssvaidyanathan
Copy link

ssvaidyanathan commented Oct 7, 2024

@dsam0162 - I used

ApiHubSettings hubSettings = ApiHubSettings.newBuilder()
	            .setCredentialsProvider(FixedCredentialsProvider.create(credentials))
	            .build();

and it worked for me

I use it in https://github.com/apigee/apigee-apihub-maven-plugin

@dsam0162
Copy link
Author

dsam0162 commented Oct 8, 2024

Thanks @ssvaidyanathan This fix worked for the following Gradle dependency as well. 🎉🎉🎉

  • implementation 'com.google.cloud:google-cloud-apihub'

@ssvaidyanathan
Copy link

@dsam0162 - Glad it worked

Can this issue be closed then?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p3 Desirable enhancement or fix. May not be included in next release. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

3 participants