Get Google channel config (v1)

Retrieve a Google channel config for a specified project and location.

Code sample

Go

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


import (
	"context"
	"fmt"
	"io"

	eventarc "cloud.google.com/go/eventarc/apiv1"
	eventarcpb "cloud.google.com/go/eventarc/apiv1/eventarcpb"
)

// getGoogleChannelConfig retrieves the Google channel configuration for a project and location.
func getGoogleChannelConfig(ctx context.Context, w io.Writer, projectID string, locationID string) error {
	name := fmt.Sprintf("projects/%s/locations/%s/googleChannelConfig", projectID, locationID)

	client, err := eventarc.NewClient(ctx)
	if err != nil {
		return fmt.Errorf("NewClient failed: %w", err)
	}
	defer client.Close()

	req := &eventarcpb.GetGoogleChannelConfigRequest{
		Name: name,
	}

	config, err := client.GetGoogleChannelConfig(ctx, req)
	if err != nil {
		return fmt.Errorf("GetGoogleChannelConfig failed: %w", err)
	}

	fmt.Fprintf(w, "Retrieved Google channel config: %s\n", config.GetName())
	return nil
}

Java

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

import com.google.cloud.eventarc.v1.EventarcClient;
import com.google.cloud.eventarc.v1.GoogleChannelConfig;
import com.google.cloud.eventarc.v1.GoogleChannelConfigName;

public class GetGoogleChannelConfig {

  public static void main(String[] args) throws Exception {
    String projectId = "example-project_id";
    String locationId = "example-location_id";
    getGoogleChannelConfig(projectId, locationId);
  }

  public static void getGoogleChannelConfig(String projectId, String locationId) throws Exception {
    try (EventarcClient client = EventarcClient.create()) {
      String name = GoogleChannelConfigName.of(projectId, locationId).toString();
      GoogleChannelConfig response = client.getGoogleChannelConfig(name);
      System.out.println("Retrieved GoogleChannelConfig: " + response.getName());
    }
  }
}

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 the Google channel configuration for a specified project and location.
 *
 * @param {string} projectId - The Google Cloud project ID.
 * @param {string} locationId - The Google Cloud region for the GoogleChannelConfig (for example, "us-central1").
 */
async function getGoogleChannelConfig(projectId, locationId) {
  try {
    const name = `projects/${projectId}/locations/${locationId}/googleChannelConfig`;

    const [response] = await client.getGoogleChannelConfig({
      name,
    });

    console.log(`GoogleChannelConfig name: ${response.name}`);
    if (response.cryptoKeyName) {
      console.log(`CryptoKey name: ${response.cryptoKeyName}`);
    }
  } catch (err) {
    if (err.code === status.NOT_FOUND) {
      console.error(`Google channel configuration not found: ${err.message}`);
    } else if (err.code === status.PERMISSION_DENIED) {
      console.error(`Permission denied accessing configuration: ${err.message}`);
    } else {
      console.error(`API error retrieving configuration: ${err.message}`);
    }
  }
}

module.exports = { getGoogleChannelConfig };

Python

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

import google.api_core.exceptions
from google.cloud import eventarc_v1

client = eventarc_v1.EventarcClient()


def get_google_channel_config(project_id: str, location_id: str) -> None:
    """Retrieves the Eventarc Google channel configuration for a project and location.

    Args:
        project_id: The Google Cloud project ID.
        location_id: The Google Cloud region or location (for example, 'us-central1').
    """
    name = f"projects/{project_id}/locations/{location_id}/googleChannelConfig"

    try:
        response = client.get_google_channel_config(name=name)
        print(f"Retrieved Google channel config: {response.name}")
        print(f"Crypto key name: {response.crypto_key_name}")
        print(f"Update time: {response.update_time}")
    except google.api_core.exceptions.GoogleAPICallError as error:
        print(f"API call failed: {error}")

What's next

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