From f702283f97f20c5592026c85e9b427f3151512a0 Mon Sep 17 00:00:00 2001 From: 0721Betty <1942433767@qq.com> Date: Wed, 17 Jan 2024 14:09:45 +0800 Subject: [PATCH] feat(i18n): add auth help codes & more connectors i18n --- packages/i18n/CHANGELOG.md | 6 ++ .../i18n/lib/__test__/authHelpCodeMap.test.ts | 18 ++++ packages/i18n/lib/authHelpCodeMap.ts | 86 +++++++++++++++++++ packages/i18n/lib/enConnectorsLabel.ts | 34 ++++++-- packages/i18n/lib/zhConnectorsLabel.ts | 34 ++++++-- packages/i18n/package.json | 2 +- 6 files changed, 167 insertions(+), 13 deletions(-) create mode 100644 packages/i18n/lib/__test__/authHelpCodeMap.test.ts create mode 100644 packages/i18n/lib/authHelpCodeMap.ts diff --git a/packages/i18n/CHANGELOG.md b/packages/i18n/CHANGELOG.md index 1e0b7e3..af69165 100644 --- a/packages/i18n/CHANGELOG.md +++ b/packages/i18n/CHANGELOG.md @@ -1,5 +1,11 @@ # @emqx/shared-ui-i18n +## 0.0.7 + +### Patch Changes + +- add auth code help files & adapt more connectors i18n + ## 0.0.6 ### Patch Changes diff --git a/packages/i18n/lib/__test__/authHelpCodeMap.test.ts b/packages/i18n/lib/__test__/authHelpCodeMap.test.ts new file mode 100644 index 0000000..5ca2832 --- /dev/null +++ b/packages/i18n/lib/__test__/authHelpCodeMap.test.ts @@ -0,0 +1,18 @@ +import { authHelpCodeMap } from '../authHelpCodeMap' +import { describe, it, expect } from 'vitest' + +describe('sqlTemplate', () => { + it('contains expected auth code map keys', () => { + const expectedKeys = ['authn', 'authz'] + expectedKeys.forEach((key) => { + expect(authHelpCodeMap).toHaveProperty(key) + }) + + const expectedSubKeys = ['mysql', 'postgresql', 'mongodb', 'redis'] + Object.values(authHelpCodeMap).forEach((value) => { + expectedSubKeys.forEach((subKey) => { + expect(value).toHaveProperty(subKey) + }) + }) + }) +}) diff --git a/packages/i18n/lib/authHelpCodeMap.ts b/packages/i18n/lib/authHelpCodeMap.ts new file mode 100644 index 0000000..bbaa496 --- /dev/null +++ b/packages/i18n/lib/authHelpCodeMap.ts @@ -0,0 +1,86 @@ +export const authHelpCodeMap = { + authn: { + mysql: `CREATE TABLE IF NOT EXISTS \`mqtt_user\` ( + \`id\` int(11) unsigned NOT NULL AUTO_INCREMENT, + \`username\` varchar(100) DEFAULT NULL, + \`password_hash\` varchar(100) DEFAULT NULL, + \`salt\` varchar(35) DEFAULT NULL, + \`is_superuser\` tinyint(1) DEFAULT 0, + \`created\` datetime DEFAULT NULL, + PRIMARY KEY (\`id\`), + UNIQUE KEY \`mqtt_username\` (\`username\`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;`, + postgresql: `CREATE TABLE mqtt_user ( + id SERIAL primary key, + is_superuser boolean, + username character varying(100), + password_hash character varying(100), + salt character varying(40) +)`, + mongodb: `{ + username: "emqx_user", + password_hash: "******", + salt: "foo+bar", + is_superuser: false, + created: "2021-01-01 12:00:01" +} + +db.mqtt_user.findOne({"username": "emqx_user"})`, + redis: `# sample data +HMSET mqtt_user:emqx_u password_hash *** salt foo+bar is_superuser 1 + +# sample cmd +# HMGET mqtt_user:\${username} + +## only password +HMGET mqtt_user:emqx_u password_hash + +## password + salt +HMGET mqtt_user:emqx_u password_hash salt + +## password + salt, enable superuser +HMGET mqtt_user:emqx_u password_hash salt is_superuser + +## only password, enable superuser +HMGET mqtt_user:emqx_u password_hash is_superuser`, + }, + authz: { + mysql: `CREATE TABLE \`mqtt_acl\` ( +\`id\` int(11) unsigned NOT NULL AUTO_INCREMENT, +\`ipaddress\` VARCHAR(60) NOT NULL DEFAULT '', +\`username\` VARCHAR(255) NOT NULL DEFAULT '', +\`clientid\` VARCHAR(255) NOT NULL DEFAULT '', +\`action\` ENUM('publish', 'subscribe', 'all') NOT NULL, +\`permission\` ENUM('allow', 'deny') NOT NULL, +\`topic\` VARCHAR(255) NOT NULL DEFAULT '', +PRIMARY KEY (\`id\`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;`, + postgresql: `CREATE TYPE ACTION AS ENUM('publish','subscribe','all'); +CREATE TYPE PERMISSION AS ENUM('allow','deny'); + +CREATE TABLE mqtt_acl ( + id SERIAL PRIMARY KEY, + ipaddress CHARACTER VARYING(60) NOT NULL DEFAULT '', + username CHARACTER VARYING(255) NOT NULL DEFAULT '', + clientid CHARACTER VARYING(255) NOT NULL DEFAULT '', + action ACTION, + permission PERMISSION, + topic CHARACTER VARYING(255) NOT NULL +);`, + mongodb: `{ + username: "emqx_u", + clientid: "emqx_c", + ipaddress: "127.0.0.1", + permission: "allow", + action: "all", + topics: ["#"] +} + +db.mqtt_acl.findOne({"username": "emqx_user"})`, + redis: `# sample data +HSET mqtt_acl:emqx_u 't/#' subscribe + +# sample cmd +HGETALL mqtt_acl:\${username}`, + }, +} diff --git a/packages/i18n/lib/enConnectorsLabel.ts b/packages/i18n/lib/enConnectorsLabel.ts index 9849b53..8a355d8 100644 --- a/packages/i18n/lib/enConnectorsLabel.ts +++ b/packages/i18n/lib/enConnectorsLabel.ts @@ -1,8 +1,6 @@ export const enConnectorsLabel: Record> = { common: { connect_timeout: 'Connect Timeout', - }, - kafka_producer: { bootstrap_hosts: 'Bootstrap Hosts', min_metadata_refresh_interval: 'Min Metadata Refresh Interval', metadata_request_timeout: 'Metadata Request Timeout', @@ -10,17 +8,41 @@ export const enConnectorsLabel: Record> = { sndbuf: 'Socket Send Buffer Size', recbuf: 'Socket Receive Buffer Size', nodelay: 'No Delay', + username: 'Username', + password: 'Password', + pool_size: 'Connection Pool Size', + pool_type: 'Pool Type', + server: 'Server Host', + database: 'Database Name', + health_check_interval: 'Health Check Interval', + start_timeout: 'Start Timeout', + max_retries: 'Max Retries', + worker_pool_size: 'Buffer Pool Size', + request_ttl: 'Request TTL', + max_buffer_bytes: 'Max Buffer Queue Size', + inflight_window: 'Inflight Window', + }, + kafka_producer: { kerberos_principal: 'Kerberos Principal', kerberos_keytab_file: 'Kerberos keytab file', mechanism: 'Mechanism', - username: 'Username', - password: 'Password', }, http: { url: 'URL', headers: 'Headers', enable_pipelining: 'HTTP Pipelining', - pool_size: 'Connection Pool Size', - pool_type: 'Pool Type', + }, + gcp_pubsub_producer: { + pipelining: 'HTTP Pipelining', + service_account_json: 'GCP Service Account Credentials', + query_mode: 'Query Mode', + batch_size: 'Batch Size', + }, + azure_event_hub_producer: { + bootstrap_hosts: 'Bootstrap Hosts', + }, + syskeeper_forwarder: { + ack_mode: 'ACK Mode', + ack_timeout: 'ACK Timeout', }, } diff --git a/packages/i18n/lib/zhConnectorsLabel.ts b/packages/i18n/lib/zhConnectorsLabel.ts index b97e1d0..3c9d0f8 100644 --- a/packages/i18n/lib/zhConnectorsLabel.ts +++ b/packages/i18n/lib/zhConnectorsLabel.ts @@ -1,8 +1,6 @@ export const zhConnectorsLabel: Record> = { common: { connect_timeout: '连接超时', - }, - kafka_producer: { bootstrap_hosts: '主机列表', min_metadata_refresh_interval: '元数据刷新最小间隔', metadata_request_timeout: '元数据请求超时', @@ -10,17 +8,41 @@ export const zhConnectorsLabel: Record> = { sndbuf: 'Socket 发送缓存大小', recbuf: 'Socket 收包缓存大小', nodelay: '是否关闭延迟发送', + username: '用户名', + password: '密码', + pool_size: '连接池大小', + pool_type: '连接池类型', + server: '服务器地址', + database: '数据库名字', + health_check_interval: '健康检查间隔', + start_timeout: '启动超时时间', + max_retries: '最大重试次数', + worker_pool_size: '缓存池大小', + request_ttl: '请求超期', + max_buffer_bytes: '缓存队列最大长度', + inflight_window: '请求飞行队列窗口', + }, + kafka_producer: { kerberos_principal: 'Kerberos Principal', kerberos_keytab_file: 'Kerberos keytab 文件', mechanism: '认证方法', - username: '用户名', - password: '密码', }, http: { url: 'URL', headers: '请求头', enable_pipelining: 'HTTP 管道', - pool_size: '连接池大小', - pool_type: '连接池类型', + }, + gcp_pubsub_producer: { + pipelining: 'HTTP 流水线', + service_account_json: 'GCP 服务账户凭证', + query_mode: '请求模式', + batch_size: '最大批量请求大小', + }, + azure_event_hub_producer: { + bootstrap_hosts: '引导主机', + }, + syskeeper_forwarder: { + ack_mode: 'ACK 模式', + ack_timeout: 'ACK 超时', }, } diff --git a/packages/i18n/package.json b/packages/i18n/package.json index a5ac72b..a57a3aa 100644 --- a/packages/i18n/package.json +++ b/packages/i18n/package.json @@ -1,6 +1,6 @@ { "name": "@emqx/shared-ui-i18n", - "version": "0.0.6", + "version": "0.0.7", "homepage": "https://emqx.io", "license": "Apache-2.0", "repository": {