The schema mode defines whether a schema registry or a specific subject allows changes, such as writing or editing schemas.
-
The supported values for schema mode are Readonlyand Readwrite.
-
Schema mode is managed as a JSON object containing key-value pairs. For example, the following is a sample:
{ "mode" : "READWRITE" }
-
If not explicitly set at the schema registry level, the schema mode defaults to Readwrite.
-
If a schema mode is not explicitly specified at the subject level, it inherits the value from the schema registry.
-
Configurations set at the subject level override those set at the schema registry level.
For more information about schema mode including its values, see Schema mode .
Required roles and permissions to update schema mode
To get the permissions that
you need to update schema mode for a schema registry or subject,
ask your administrator to grant you the Managed Kafka Schema Registry Editor
( roles/managedkafka.schemaRegistryEditor
)
IAM role on your project.
For more information about granting roles, see Manage access to projects, folders, and organizations
.
This predefined role contains the permissions required to update schema mode for a schema registry or subject. To see the exact permissions that are required, expand the Required permissionssection:
Required permissions
The following permissions are required to update schema mode for a schema registry or subject:
- Grant the following permission on the resource for which you want to update the mode:
managedkafka.mode.update
You might also be able to get these permissions with custom roles or other predefined roles .
For more information about the predefined roles available for Managed Service for Apache Kafka, see the Access control documentation .
Update schema mode for a schema registry
Console
To update the schema mode for the entire schema registry, follow these steps:
- In the Google Cloud console, go to the Schema registries
page.
A list of schema registries in your project is displayed.
- Click the name of the schema registry for which you want to update the schema mode.
The Schema registry details page opens.
- In the main details section for the registry, find the Schema mode
setting and click the Edit
icon next to it.
The Edit schema mode page opens.
- From the Schema mode
dropdown menu, select the value.
For more information about these values, see About schema mode .
- Click Save .
gcloud
To update the schema mode for a schema registry, use the gcloud alpha managed-kafka schema-registries update
command:
gcloud alpha managed-kafka schema-registries update SCHEMA_REGISTRY_ID \ --location= LOCATION \ --mode= MODE_TYPE
-
SCHEMA_REGISTRY_ID
: the ID of the schema registry to update. -
LOCATION
: the region of the schema registry to update. -
MODE_TYPE
: the new schema mode. The valid values are:-
READWRITE
-
READONLY
-
Example:
To update the schema mode of the test-registry
schema registry in the us-central1
region to READONLY
, run the following command:
gcloud alpha managed-kafka schema-registries update test-registry \ --location=us-central1 \ --mode=READONLY
REST
The request must be authenticated with an access token in the Authorization
header. To obtain an access token for the current
Application Default Credentials: gcloud auth application-default print-access-token
.
To update the schema mode, make a PUT
request to the
REST API endpoint for the schema registry using the projects.locations.schemaRegistries.contexts.mode.update
method.
Updating schema mode for the schema registry with a default context:
PUT https://managedkafka.googleapis.com/v1main/projects/ PROJECT_ID /locations/ LOCATION /schemaRegistries/ SCHEMA_REGISTRY_ID /mode
Replace the following path parameters:
-
PROJECT_ID
: your Google Cloud project ID. -
LOCATION
: the region where the schema registry exists. -
SCHEMA_REGISTRY_ID
: the unique ID of the schema registry.
Request body:
Include a JSON object in the request body specifying the mode details.
{ "mode" : " MODE_TYPE " }
Replace MODE_TYPE
with one of the valid string options for the mode:
-
READWRITE
-
READONLY
If successful, the API returns a 200 OK
status code and a
response body containing the JSON representation of the updated mode
configuration.
For more information, see the REST API documentation .
Update schema mode for a subject
Console
To update the schema mode for a specific subject, follow these steps:
- In the Google Cloud console, go to the Schema registries page.
- Click the name of the schema registry that contains the subject.
The Schema registry details page opens.
- In the Subjects in this schema registry table, click the name of the subject for which you want to update the schema mode.
- Find the Schema mode
setting for the subject and
click the Edit
icon next to it.
The Edit schema mode page opens.
- From the Schema mode
dropdown menu, select the value.
Choosing a value here overrides the registry-level setting for this
specific subject.
For more information about these values, see About schema mode .
- Click Save .
gcloud
To update the schema mode for a subject, use the gcloud alpha managed-kafka schema-registries subject update
command:
gcloud alpha managed-kafka schema-registries subject update SUBJECT_NAME \ --schema-registry= SCHEMA_REGISTRY_ID \ --location= LOCATION \ --mode= MODE_TYPE
-
SUBJECT_NAME
: the name of the subject to update. -
SCHEMA_REGISTRY_ID
: the ID of the schema registry that contains the subject. -
LOCATION
: the region of the schema registry that contains the subject. -
MODE_TYPE
: the new schema mode. The valid values are:-
READWRITE
-
READONLY
-
Example:
To update the schema mode of the test-subject
subject in the test-registry
schema registry in the us-central1
region to READONLY
, run the following command:
gcloud alpha managed-kafka schema-registries subject update test-subject \ --schema-registry=test-registry \ --location=us-central1 \ --mode=READONLY
REST
The request must be authenticated with an access token in the Authorization
header. To obtain an access token for the current
Application Default Credentials: gcloud auth application-default print-access-token
.
To update the schema mode for a subject, make a PUT
request to the REST API endpoint for a
specific subject using the projects.locations.schemaRegistries.contexts.mode.update
method.
Updating schema mode for a subject in the default context:
PUT https://managedkafka.googleapis.com/v1main/projects/ PROJECT_ID /locations/ LOCATION /schemaRegistries/ SCHEMA_REGISTRY_ID /mode/ SUBJECT_NAME
Replace the following path parameters:
-
PROJECT_ID
: your Google Cloud project ID. -
LOCATION
: the region where the schema registry exists. -
SCHEMA_REGISTRY_ID
: the unique ID of the schema registry. -
SUBJECT_NAME
: the name of the subject.
Request body:
Include a JSON object in the request body specifying the mode details.
{ "mode" : " MODE_TYPE " }
Replace MODE_TYPE
with one of the valid string options for the mode:
-
READWRITE
-
READONLY
Example—Set subject user_events
schema mode to Readonly
in the default context:
Request to PUT https://managedkafka.googleapis.com/v1main/projects/test-gcp-project/locations/us-east1/schemaRegistries/main_registry/mode/user_events
With body:
{ "mode" : "READONLY" }
If successful, the API returns a 200 OK
status code and a
response body containing the JSON representation of the updated subject or context resource reflecting this change.
Updating schema mode for a subject in a specific context:
PUT https://managedkafka.googleapis.com/v1main/projects/ PROJECT_ID /locations/ LOCATION /schemaRegistries/ SCHEMA_REGISTRY_ID /contexts/ CONTEXT_NAME /mode/ SUBJECT_NAME
Replace the following path parameters:
-
PROJECT_ID
: your Google Cloud project ID. -
LOCATION
: the region where the schema registry exists. -
SCHEMA_REGISTRY_ID
: the unique ID of the schema registry. -
CONTEXT_NAME
: the name of the context. -
SUBJECT_NAME
: the name of the subject.
Request body:
Include a JSON object in the request body specifying the mode details.
{ "mode" : " MODE_TYPE " }
Replace MODE_TYPE
with one of the valid string options for the mode:
-
READWRITE
-
READONLY
Example—Set subject user_events
schema mode to Readonly
in the context test_context
:
Request to PUT https://managedkafka.googleapis.com/v1main/projects/test-gcp-project/locations/us-east1/schemaRegistries/main_registry/contexts/test_context/mode/user_events
With body:
{ "mode" : "READONLY" }
If successful, the API returns a 200 OK
status code and a
response body containing the JSON representation of the updated subject or context resource reflecting this change.
For more information, see the REST API documentation .