Update the customer-managed encryption key settings for a Google channel configuration.

## Code sample

### Java


To authenticate to Eventarc, set up Application Default Credentials.
For more information, see

[Set up authentication for a local development environment](https://docs.cloud.google.com/docs/authentication/set-up-adc-local-dev-environment.md.txt).

```java
import com.google.cloud.eventarc.v1.EventarcClient;
import com.google.cloud.eventarc.v1.GoogleChannelConfig;
import com.google.protobuf.FieldMask;

public class UpdateGoogleChannelConfig {

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

  public static void updateGoogleChannelConfig(String projectId, String locationId)
      throws Exception {
    try (EventarcClient client = EventarcClient.create()) {
      // Configure customer-managed encryption key (CMEK) settings for the Google channel
      GoogleChannelConfig googleChannelConfig =
          GoogleChannelConfig.newBuilder()
              .setName(
                  String.format(
                      "projects/%s/locations/%s/googleChannelConfig", projectId, locationId))
              .setCryptoKeyName(
                  String.format(
                      "projects/%s/locations/%s/keyRings/example-keyring/cryptoKeys/example-key",
                      projectId, locationId))
              .build();

      // Specify the fields to update (GoogleChannelConfig manages crypto_key_name; labels are unsupported)
      FieldMask updateMask = FieldMask.newBuilder().addPaths("crypto_key_name").build();

      GoogleChannelConfig response =
          client.updateGoogleChannelConfig(googleChannelConfig, updateMask);
      System.out.println("Updated Google channel config: " + 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](https://docs.cloud.google.com/docs/authentication/set-up-adc-local-dev-environment.md.txt).

```javascript
'use strict';

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

const client = new EventarcClient();

/**
 * Updates the Eventarc Google channel config.
 */
async function updateGoogleChannelConfig() {
  try {
    const projectId = await client.getProjectId();
    const location = 'us-central1';

    const googleChannelConfig = {
      name: client.googleChannelConfigPath(projectId, location),
    };

    const request = {
      googleChannelConfig,
    };

    const [response] = await client.updateGoogleChannelConfig(request);
    console.log(`Updated Google channel config: ${response.name}`);
    if (response.cryptoKeyName) {
      console.log(`Configured encryption key: ${response.cryptoKeyName}`);
    }
  } catch (err) {
    if (err.code === status.NOT_FOUND) {
      console.error(`Google channel config not found: ${err.message}`);
    } else if (err.code === status.PERMISSION_DENIED) {
      console.error(`Permission denied: ${err.message}`);
    } else if (err.code === status.INVALID_ARGUMENT) {
      console.error(`Invalid argument: ${err.message}`);
    } else {
      console.error(`Failed to update Google channel config: ${err.message}`);
    }
    throw err;
  }
}

module.exports = { updateGoogleChannelConfig };
```

### Python


To authenticate to Eventarc, set up Application Default Credentials.
For more information, see

[Set up authentication for a local development environment](https://docs.cloud.google.com/docs/authentication/set-up-adc-local-dev-environment.md.txt).

```python
import google.api_core.exceptions
from google.cloud import eventarc_v1
from google.protobuf import field_mask_pb2

client = eventarc_v1.EventarcClient()


def update_google_channel_config(project_id: str, location_id: str) -> None:
    """Use the update_google_channel_config method

    Args:
        project_id: The Google Cloud project ID.
        location_id: The Google Cloud region for the channel configuration (e.g., 'us-central1').
    """
    google_channel_config = eventarc_v1.GoogleChannelConfig(
        name=f"projects/{project_id}/locations/{location_id}/googleChannelConfig",
        labels={"env": "test"},
    )
    update_mask = field_mask_pb2.FieldMask(paths=["labels"])

    try:
        response = client.update_google_channel_config(
            google_channel_config=google_channel_config,
            update_mask=update_mask,
        )
        print(f"Updated Google channel configuration: {response.name}")
    except google.api_core.exceptions.GoogleAPICallError as e:
        print(f"Failed to update Google channel configuration: {e}")
```

## What's next


To search and filter code samples for other Google Cloud products, see the
[Google Cloud sample browser](https://docs.cloud.google.com/docs/samples.md.txt?product=eventarc).