Skip to content

Commit b081eb0

Browse files
committed
fix json
1 parent ebea47d commit b081eb0

5 files changed

Lines changed: 192 additions & 187 deletions

File tree

internal/cli/serverless/changefeed/create.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,14 @@ func CreateCmd(h *internal.Helper) *cobra.Command {
201201
return errors.New("kafka info is required")
202202
}
203203
if err := json.Unmarshal([]byte(kafkaStr), &kafkaInfo); err != nil {
204-
return errors.New("invalid kafka info, please use JSON format")
204+
return errors.Errorf("invalid kafka: %v", err)
205205
}
206206
case cdc.CHANGEFEEDTYPEENUM_MYSQL:
207207
if mysqlStr == "" {
208208
return errors.New("mysql info is required")
209209
}
210210
if err := json.Unmarshal([]byte(mysqlStr), &mysqlInfo); err != nil {
211-
return errors.New("invalid mysql info, please use JSON format")
211+
return errors.Errorf("invalid mysql: %v", err)
212212
}
213213
default:
214214
return errors.New("currently only KAFKA and MYSQL type is supported")
@@ -218,7 +218,7 @@ func CreateCmd(h *internal.Helper) *cobra.Command {
218218
return errors.New("filter is required")
219219
}
220220
if err := json.Unmarshal([]byte(filterStr), &filter); err != nil {
221-
return errors.New("invalid filter, please use JSON format")
221+
return errors.Errorf("invalid filter: %v", err)
222222
}
223223

224224
// create the changefeed

internal/cli/serverless/changefeed/template.go

Lines changed: 165 additions & 166 deletions
Original file line numberDiff line numberDiff line change
@@ -27,188 +27,187 @@ import (
2727

2828
const (
2929
KafkaInfoTemplateWithExplain = `{
30-
"network": {
31-
"network_type": "PUBLIC"
32-
"public_endpoints": "broker:9092",
33-
},
34-
"broker": {
35-
// "kafka_version": "VERSION_2XX", "VERSION_3XX"
36-
"kafka_version": "VERSION_2XX",
37-
// "compression": "NONE", "GZIP", "LZ4", "ZSTD", "SNAPPY"
38-
"compression": "NONE"
39-
},
40-
"authentication": {
41-
// "auth_type": "DISABLE", "SASL_PLAIN", "SASL_SCRAM_SHA_256", "SASL_SCRAM_SHA_512"
42-
"auth_type": "DISABLE",
43-
// required when auth_type is SASL_PLAIN, SASL_SCRAM_SHA_256, or SASL_SCRAM_SHA_512
44-
"user_name": "",
45-
// required when auth_type is SASL_PLAIN, SASL_SCRAM_SHA_256, or SASL_SCRAM_SHA_512
30+
"network": {
31+
"networkType": "PUBLIC",
32+
"publicEndpoints": "broker:9092"
33+
},
34+
"broker": {
35+
// "kafkaVersion": "VERSION_2XX", "VERSION_3XX"
36+
"kafkaVersion": "VERSION_2XX",
37+
// "compression": "NONE", "GZIP", "LZ4", "ZSTD", "SNAPPY"
38+
"compression": "NONE"
39+
},
40+
"authentication": {
41+
// "authType": "DISABLE", "SASL_PLAIN", "SASL_SCRAM_SHA_256", "SASL_SCRAM_SHA_512"
42+
"authType": "DISABLE",
43+
// required when authType is SASL_PLAIN, SASL_SCRAM_SHA_256, or SASL_SCRAM_SHA_512
44+
"userName": "",
45+
// required when authType is SASL_PLAIN, SASL_SCRAM_SHA_256, or SASL_SCRAM_SHA_512
46+
"password": "",
47+
"enableTls": false
48+
},
49+
"dataFormat": {
50+
// "protocol": "CANAL_JSON", "AVRO", "OPEN_PROTOCOL"
51+
"protocol": "CANAL_JSON",
52+
// available when protocol is CANAL_JSON
53+
"enableTidbExtension": false,
54+
// available when protocol is AVRO
55+
"avroConfig": {
56+
"decimalHandlingMode": "PRECISE",
57+
"bigintUnsignedHandlingMode": "LONG",
58+
// one of "confluentSchemaRegistry", "awsGlueSchemaRegistry"
59+
"confluentSchemaRegistry": {
60+
"endpoint": "",
61+
"enableHttpAuth": false,
62+
"userName": "",
4663
"password": ""
47-
"enable_tls": false,
48-
},
49-
"data_format": {
50-
// "protocol": "CANAL_JSON", "AVRO", "OPEN_PROTOCOL"
51-
"protocol": "CANAL_JSON",
52-
// available when protocol is CANAL_JSON
53-
"enable_tidb_extension": false,
54-
// available when protocol is AVRO
55-
"avro_config": {
56-
"decimal_handling_mode": "PRECISE",
57-
"bigint_unsigned_handling_mode": "LONG",
58-
// one of "confluent_schema_registry", "aws_glue_schema_registry"
59-
"confluent_schema_registry": {
60-
"endpoint": "",
61-
"enable_http_auth": false,
62-
"user_name": "",
63-
"password": ""
64-
},
65-
"aws_glue_schema_registry": {
66-
"region": "",
67-
"name": "",
68-
"access_key_id": "",
69-
"secret_access_key": ""
70-
}
71-
}
72-
},
73-
"topic_partition_config": {
74-
// "dispatch_type": "ONE_TOPIC", "BY_TABLE", "BY_DATABASE"
75-
"dispatch_type": "ONE_TOPIC",
76-
"default_topic": "test-topic",
77-
// required when dispatch_type is BY_TABLE or BY_DATABASE
78-
"topic_prefix": "_prefix",
79-
// required when dispatch_type is BY_TABLE or BY_DATABASE
80-
"separator": "_",
81-
// required when dispatch_type is BY_TABLE or BY_DATABASE
82-
"topic_suffix": "_suffix",
83-
"replication_factor": 1,
84-
"partition_num": 1,
85-
"partition_dispatchers": [
86-
{
87-
// "partition_type": "TABLE", "INDEX_VALUE", "TS", "COLUMN"
88-
"partition_type": "TABLE",
89-
// available when partition_type is TABLE
90-
"matcher": ["*.*"],
91-
// available when partition_type is INDEX_VALUE
92-
"index_name": "index1",
93-
// available when partition_type is COLUMN
94-
"columns": ["col1", "col2"]
95-
}
96-
]
97-
},
98-
"column_selectors": [
99-
{
100-
"matcher": ["*.*"],
101-
"columns": ["col1", "col2"]
102-
}
64+
},
65+
"awsGlueSchemaRegistry": {
66+
"region": "",
67+
"name": "",
68+
"accessKeyId": "",
69+
"secretAccessKey": ""
70+
}
71+
}
72+
},
73+
"topicPartitionConfig": {
74+
// "dispatchType": "ONE_TOPIC", "BY_TABLE", "BY_DATABASE"
75+
"dispatchType": "ONE_TOPIC",
76+
"defaultTopic": "test-topic",
77+
// required when dispatchType is BY_TABLE or BY_DATABASE
78+
"topicPrefix": "_prefix",
79+
// required when dispatchType is BY_TABLE or BY_DATABASE
80+
"separator": "_",
81+
// required when dispatchType is BY_TABLE or BY_DATABASE
82+
"topicSuffix": "_suffix",
83+
"replicationFactor": 1,
84+
"partitionNum": 1,
85+
"partitionDispatchers": [
86+
{
87+
// "partitionType": "TABLE", "INDEX_VALUE", "TS", "COLUMN"
88+
"partitionType": "TABLE",
89+
// available when partitionType is TABLE
90+
"matcher": ["*.*"],
91+
// available when partitionType is INDEX_VALUE
92+
"indexName": "index1",
93+
// available when partitionType is COLUMN
94+
"columns": ["col1", "col2"]
95+
}
10396
]
97+
},
98+
"columnSelectors": [
99+
{
100+
"matcher": ["*.*"],
101+
"columns": ["col1", "col2"]
102+
}
103+
]
104104
}`
105105

106106
KafkaInfoTemplate = `{
107-
"network": {
108-
"network_type": "PUBLIC"
109-
"public_endpoints": "broker1:9092,broker2:9092"
110-
},
111-
"broker": {
112-
"kafka_version": "VERSION_2XX",
113-
"compression": "NONE"
114-
},
115-
"authentication": {
116-
"auth_type": "DISABLE",
117-
"user_name": "",
118-
"password": ""
119-
"enable_tls": false,
120-
},
121-
"data_format": {
122-
"protocol": "CANAL_JSON",
123-
"enable_tidb_extension": false,
124-
"avro_config": {
125-
"decimal_handling_mode": "PRECISE",
126-
"bigint_unsigned_handling_mode": "LONG",
127-
"confluent_schema_registry": {
128-
"schema_registry_endpoints": "",
129-
"enable_http_auth": false,
130-
"user_name": "",
131-
"password": ""
132-
},
133-
"aws_glue_schema_registry": {
134-
"region": "",
135-
"name": "",
136-
"access_key_id": "",
137-
"secret_access_key": ""
138-
}
139-
}
140-
},
141-
"topic_partition_config": {
142-
"dispatch_type": "ONE_TOPIC",
143-
"default_topic": "test-topic",
144-
"topic_prefix": "_prefix",
145-
"separator": "_",
146-
"topic_suffix": "_suffix",
147-
"replication_factor": 1,
148-
"partition_num": 1,
149-
"partition_dispatchers": [{
150-
"partition_type": "TABLE",
151-
"matcher": ["*.*"],
152-
"index_name": "index1",
153-
"columns": ["col1", "col2"]
154-
}]
155-
},
156-
"column_selectors": [{
157-
"matcher": ["*.*"],
158-
"columns": ["col1", "col2"]
159-
}]
160-
}
161-
`
107+
"network": {
108+
"networkType": "PUBLIC",
109+
"publicEndpoints": "broker1:9092,broker2:9092"
110+
},
111+
"broker": {
112+
"kafkaVersion": "VERSION_2XX",
113+
"compression": "NONE"
114+
},
115+
"authentication": {
116+
"authType": "DISABLE",
117+
"userName": "",
118+
"password": "",
119+
"enableTls": false
120+
},
121+
"dataFormat": {
122+
"protocol": "CANAL_JSON",
123+
"enableTidbExtension": false,
124+
"avroConfig": {
125+
"decimalHandlingMode": "PRECISE",
126+
"bigintUnsignedHandlingMode": "LONG",
127+
"confluentSchemaRegistry": {
128+
"schemaRegistryEndpoints": "",
129+
"enableHttpAuth": false,
130+
"userName": "",
131+
"password": ""
132+
},
133+
"awsGlueSchemaRegistry": {
134+
"region": "",
135+
"name": "",
136+
"accessKeyId": "",
137+
"secretAccessKey": ""
138+
}
139+
}
140+
},
141+
"topicPartitionConfig": {
142+
"dispatchType": "ONE_TOPIC",
143+
"defaultTopic": "test-topic",
144+
"topicPrefix": "_prefix",
145+
"separator": "_",
146+
"topicSuffix": "_suffix",
147+
"replicationFactor": 1,
148+
"partitionNum": 1,
149+
"partitionDispatchers": [{
150+
"partitionType": "TABLE",
151+
"matcher": ["*.*"],
152+
"indexName": "index1",
153+
"columns": ["col1", "col2"]
154+
}]
155+
},
156+
"columnSelectors": [{
157+
"matcher": ["*.*"],
158+
"columns": ["col1", "col2"]
159+
}]
160+
}`
162161

163162
CDCFilterTemplateWithExplain = `{
164-
"filterRule": ["test.t1", "test.t2"],
165-
// "mode": "IGNORE_NOT_SUPPORT_TABLE", "FORCE_SYNC"
166-
"mode": "IGNORE_NOT_SUPPORT_TABLE",
167-
"eventFilterRule": [
168-
{
169-
"matcher": ["test.t1", "test.t2"],
170-
"ignore_event": ["all dml", "all ddl"]
171-
}
172-
]
163+
"filterRule": ["test.t1", "test.t2"],
164+
// "mode": "IGNORE_NOT_SUPPORT_TABLE", "FORCE_SYNC"
165+
"mode": "IGNORE_NOT_SUPPORT_TABLE",
166+
"eventFilterRule": [
167+
{
168+
"matcher": ["test.t1", "test.t2"],
169+
"ignoreEvent": ["all dml", "all ddl"]
170+
}
171+
]
173172
}`
174173

175174
CDCFilterTemplate = `{
176-
"filterRule": ["test.t1", "test.t2"],
177-
"mode": "IGNORE_NOT_SUPPORT_TABLE",
178-
"eventFilterRule": [
179-
{
180-
"matcher": ["test.t1", "test.t2"],
181-
"ignore_event": ["all dml", "all ddl"]
182-
}
183-
]
175+
"filterRule": ["test.t1", "test.t2"],
176+
"mode": "IGNORE_NOT_SUPPORT_TABLE",
177+
"eventFilterRule": [
178+
{
179+
"matcher": ["test.t1", "test.t2"],
180+
"ignoreEvent": ["all dml", "all ddl"]
181+
}
182+
]
184183
}`
185184

186185
MySQLTemplateWithExplain = `{
187-
"network": {
188-
// required "PUBLIC", "PRIVATE"
189-
"network_type": "PUBLIC",
190-
"public_endpoint": "127.0.0.1:3306"
191-
},
192-
"authentication": {
193-
// required the user name for MySQL
194-
"user_name": "",
195-
// required the password for MySQL
196-
"password": "",
197-
// optional, enable TLS for MySQL connection
198-
"enable_tls": false
199-
}
186+
"network": {
187+
// required "PUBLIC", "PRIVATE"
188+
"networkType": "PUBLIC",
189+
"publicEndpoint": "127.0.0.1:3306"
190+
},
191+
"authentication": {
192+
// required the user name for MySQL
193+
"userName": "",
194+
// required the password for MySQL
195+
"password": "",
196+
// optional, enable TLS for MySQL connection
197+
"enableTls": false
198+
}
200199
}`
201200

202201
MySQLTemplate = `{
203-
"network": {
204-
"network_type": "PUBLIC",
205-
"public_endpoint": "127.0.0.1:3306"
206-
},
207-
"authentication": {
208-
"user_name": "",
209-
"password": "",
210-
"enable_tls": false
211-
}
202+
"network": {
203+
"networkType": "PUBLIC",
204+
"publicEndpoint": "127.0.0.1:3306"
205+
},
206+
"authentication": {
207+
"userName": "",
208+
"password": "",
209+
"enableTls": false
210+
}
212211
}`
213212
)
214213

pkg/tidbcloud/v1beta1/serverless/cdc.swagger.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,8 +1313,7 @@
13131313
}
13141314
},
13151315
"required": [
1316-
"networkType",
1317-
"publicEndpoint"
1316+
"networkType"
13181317
]
13191318
},
13201319
"MySQLNetworkType.Enum": {
@@ -1513,4 +1512,4 @@
15131512
"description": " - ONE_TOPIC: One topic for all data.\n - BY_TABLE: Dispatch by table.\n - BY_DATABASE: Dispatch by database."
15141513
}
15151514
}
1516-
}
1515+
}

0 commit comments

Comments
 (0)