Get enrollment (v1)

Retrieve an existing Eventarc enrollment.

Code sample

Node.js

To authenticate to Eventarc, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

'use strict';

const {EventarcClient} = require('@google-cloud/eventarc');
const {status} = require('@grpc/grpc-js');

const client = new EventarcClient();

/**
 * Retrieves an Eventarc enrollment.
 *
 * @param {string} projectId - The Google Cloud project ID.
 * @param {string} locationId - The Google Cloud region or location of the enrollment.
 * @param {string} enrollmentId - The caller-chosen identifier of the existing Eventarc enrollment to retrieve.
 */
async function getEnrollment(projectId, locationId, enrollmentId) {
  const name = `projects/${projectId}/locations/${locationId}/enrollments/${enrollmentId}`;

  try {
    const [enrollment] = await client.getEnrollment({name});

    console.log(`Retrieved enrollment: ${enrollment.name}`);
    console.log(`Message bus: ${enrollment.messageBus}`);
    console.log(`Destination: ${enrollment.destination}`);
    return enrollment;
  } catch (err) {
    if (err.code === status.NOT_FOUND) {
      console.error(`Enrollment not found at ${name}`);
    } else if (err.code === status.PERMISSION_DENIED) {
      console.error(`Permission denied accessing enrollment at ${name}`);
    } else {
      console.error(`Error retrieving enrollment: ${err.message}`);
    }
    throw err;
  }
}

module.exports = { getEnrollment };

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.