Home > Net >  Is it possible to programmatically retrieve from serviceaccount credentials which api's are ena
Is it possible to programmatically retrieve from serviceaccount credentials which api's are ena

Time:03-20

I have a service account credentials json file with client_email and private_key. Is it then possible to programmatically retrieve from serviceaccount credentials which api's are enabled? I don't mean a solution like go to console.cloud.google.com but from within nodejs. Thanks!

CodePudding user response:

Google has an API Gateway Client Library for NodeJS with the desired capability

const projectId = 'my-project';
const {ApiGatewayServiceClient} = require('@google-cloud/api-gateway');
const client = new ApiGatewayServiceClient();
async function listApis() {
  const [apis] = await client.listApis({
    parent: `projects/${projectId}/locations/global`,
  });
  for (const api of apis) {
    console.info(`name: ${api.name}`);
  }
}
listApis();

CodePudding user response:

You will need to know the Project ID as well. The answer from @wardenunleashed is for API Gateway. That does not cover which Google APIs are enabled.

APIs are enabled per project, so you must specify the project to query.

A service account JSON key file contains the Project ID for the project that owns the service account.

The private_key_id is also important. That ID is used to lookup the public key for validating private key signatures.

  • Related