-
Notifications
You must be signed in to change notification settings - Fork 84
Add Zhizhangyi MBS service adapter #449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
tongzhouli
wants to merge
1
commit into
chaitin:main
from
tongzhouli:add-zhizhangyi-mbs-service-clean-v13
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,193 @@ | ||
| # Zhizhangyi MBS | ||
|
|
||
| This service package exposes Zhizhangyi MBS (Mobile Security Management Platform) user management APIs through OctoBus. | ||
|
|
||
| The package is scoped to MBS user operations: listing users, reading user details, checking login names, creating and updating users, deleting users, enabling or disabling users, updating passwords, forcing users offline, and importing users. | ||
|
|
||
| ## Configuration | ||
|
|
||
| Configure the target MBS endpoint in the service config: | ||
|
|
||
| ```json | ||
| { | ||
| "endpoint": "https://mbs.example.com:9074", | ||
| "skipTlsVerify": false, | ||
| "timeoutMs": 30000 | ||
| } | ||
| ``` | ||
|
|
||
| `endpoint` is the MBS REST API base URL. Use a hostname or sanitized placeholder in shared examples. Do not commit real internal IP addresses. | ||
|
|
||
| Configure credentials in the service secret: | ||
|
|
||
| ```json | ||
| { | ||
| "appkey": "<mbs-appkey>", | ||
| "secretkey": "<mbs-secretkey>", | ||
| "orgCode": "<org-code>" | ||
| } | ||
| ``` | ||
|
|
||
| Do not commit real `appkey`, `secretkey`, `orgCode`, password ciphertext, or generated `sign` values. | ||
|
|
||
| ## Authentication | ||
|
|
||
| MBS signs requests as: | ||
|
|
||
| ```text | ||
| MD5(appkey + param1 + param2 + ... + secretkey) | ||
| ``` | ||
|
|
||
| The adapter computes signatures when `sign` is not provided. Password fields are forwarded as caller-provided MBS 3DES-encrypted strings; this package does not derive or perform password encryption. | ||
|
|
||
| ## Methods | ||
|
|
||
| All methods are exposed under the `zhizhangyi.mbs.UserManagement` service. | ||
|
|
||
| | Method | Purpose | Key request fields | | ||
| | --- | --- | --- | | ||
| | `GetUsers` | List users with pagination, sorting, and filters. | `index`, `size`, `orderCode`, `orderType`, `condition.deptId` required, optional `condition.keyWord`, `condition.state`, `condition.isMdm`. | | ||
| | `AddUser` | Create a user. | `userName`, `loginName`, `deptId`, `password` required; optional contact fields, `userSource`, `isMdm`, `state`, `weight`, `attrs`. | | ||
| | `UpdUser` | Update a user. | `userId`, `userName`, `deptId` required; optional `loginName`, contact fields, `isMdm`, `weight`, `attrs`. | | ||
| | `DetailUser` | Get user detail by ID. | `userId` required. | | ||
| | `DelUsers` | Delete users by ID list or by condition. | `type=0` with `userIds`, or `type=1` with `condition`. | | ||
| | `StateUsers` | Enable or disable users by ID list or condition. | `state` required; `type=0` with `userIds`, or `type=1` with `condition`. | | ||
| | `CheckLoginName` | Check login name availability. | `loginName` required. | | ||
| | `GetUserByPhone` | Find users by phone number. | `phone` required. | | ||
| | `UpdUserPwd` | Update a password using v1 admin mode or v2 self-service mode. | `version` must be `v1` or `v2`; v1 requires `userId` and `password`; v2 requires `loginName` and `newPwd`, optional `oldPwd`. | | ||
| | `ForceOffline` | Force a user offline. | `userId` required. | | ||
| | `ImportUser` | Import users from an uploaded file. | `fileId` required, optional `lang`. | | ||
|
|
||
| ## Connect RPC Examples | ||
|
|
||
| Replace `mbs-capset` and `mbs-instance` with your OctoBus capset and instance IDs. The examples use sanitized hostnames and placeholder secrets only. | ||
|
|
||
| ### GetUsers | ||
|
|
||
| ```http | ||
| POST http://127.0.0.1:9000/capsets/mbs-capset/connect/mbs-instance/zhizhangyi.mbs.UserManagement/GetUsers | ||
| Content-Type: application/json | ||
|
|
||
| { | ||
| "index": 0, | ||
| "size": 20, | ||
| "orderCode": 0, | ||
| "orderType": 1, | ||
| "condition": { | ||
| "deptId": "1", | ||
| "keyWord": "", | ||
| "state": 0, | ||
| "isMdm": 0 | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| `condition.deptId` is required. Valid falsy filter values such as `state: 0` and `isMdm: 0` are preserved. | ||
|
|
||
| ### AddUser | ||
|
|
||
| ```http | ||
| POST http://127.0.0.1:9000/capsets/mbs-capset/connect/mbs-instance/zhizhangyi.mbs.UserManagement/AddUser | ||
| Content-Type: application/json | ||
|
|
||
| { | ||
| "userName": "Example User", | ||
| "loginName": "example.user", | ||
| "deptId": "1", | ||
| "password": "<3des-encrypted-password>", | ||
| "phoneNumber": "13800000000", | ||
| "email": "user@example.com", | ||
| "userSource": 0, | ||
| "state": 1, | ||
| "isMdm": 0 | ||
| } | ||
| ``` | ||
|
|
||
| `password` must already be encrypted in the format required by MBS. Empty numeric fields such as `state`, `isMdm`, and `weight` are treated as omitted instead of being converted to `0`. | ||
|
|
||
| ### UpdUser | ||
|
|
||
| ```http | ||
| POST http://127.0.0.1:9000/capsets/mbs-capset/connect/mbs-instance/zhizhangyi.mbs.UserManagement/UpdUser | ||
| Content-Type: application/json | ||
|
|
||
| { | ||
| "userId": "<user-id>", | ||
| "userName": "Example User", | ||
| "deptId": "1", | ||
| "email": "user@example.com" | ||
| } | ||
| ``` | ||
|
|
||
| `userId`, `userName`, and `deptId` are required. | ||
|
|
||
| ### DelUsers | ||
|
|
||
| ```http | ||
| POST http://127.0.0.1:9000/capsets/mbs-capset/connect/mbs-instance/zhizhangyi.mbs.UserManagement/DelUsers | ||
| Content-Type: application/json | ||
|
|
||
| { | ||
| "type": 0, | ||
| "userIds": ["<user-id-1>", "<user-id-2>"] | ||
| } | ||
| ``` | ||
|
|
||
| For condition mode, set `type` to `1` and provide `condition`: | ||
|
|
||
| ```json | ||
| { | ||
| "type": 1, | ||
| "condition": { | ||
| "deptId": "1", | ||
| "status": 0, | ||
| "isMdm": 0 | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### StateUsers | ||
|
|
||
| ```http | ||
| POST http://127.0.0.1:9000/capsets/mbs-capset/connect/mbs-instance/zhizhangyi.mbs.UserManagement/StateUsers | ||
| Content-Type: application/json | ||
|
|
||
| { | ||
| "type": 0, | ||
| "state": "1", | ||
| "userIds": ["<user-id>"] | ||
| } | ||
| ``` | ||
|
|
||
| `state` is required and is not defaulted. Use `"1"` to enable and `"0"` to disable according to the MBS API semantics. | ||
|
|
||
| ### UpdUserPwd | ||
|
|
||
| ```http | ||
| POST http://127.0.0.1:9000/capsets/mbs-capset/connect/mbs-instance/zhizhangyi.mbs.UserManagement/UpdUserPwd | ||
| Content-Type: application/json | ||
|
|
||
| { | ||
| "version": "v2", | ||
| "loginName": "example.user", | ||
| "oldPwd": "<3des-encrypted-old-password>", | ||
| "newPwd": "<3des-encrypted-new-password>" | ||
| } | ||
| ``` | ||
|
|
||
| `version` is restricted to `v1` or `v2`. Invalid values are rejected before constructing the upstream path. | ||
|
|
||
| ## Error Handling | ||
|
|
||
| HTTP errors from MBS are mapped to gRPC errors. Upstream HTTP response bodies are truncated before being included in error messages, so callers do not receive full upstream debug output or sensitive error details. | ||
|
|
||
| ## Local Testing | ||
|
|
||
| Run service tests with: | ||
|
|
||
| ```bash | ||
| node --test services/zhizhangyi__mbs/test/zhizhangyi-mbs.test.js | ||
| npm --prefix services test -- --service-dir zhizhangyi__mbs | ||
| ``` | ||
|
|
||
| The test files use mocked HTTP responses and sanitized example values. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| import { runServiceMain } from "@chaitin-ai/octobus-sdk"; | ||
|
|
||
| import { service } from "../src/service.js"; | ||
|
|
||
| runServiceMain(service); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| { | ||
| "$schema": "https://json-schema.org/draft/2020-12/schema", | ||
| "type": "object", | ||
| "additionalProperties": true, | ||
| "properties": { | ||
| "endpoint": { | ||
| "type": "string", | ||
| "description": "MBS REST API base URL. Example: https://mbs.example.com:9074" | ||
| }, | ||
| "baseUrl": { | ||
| "type": "string", | ||
| "description": "Legacy alias for endpoint." | ||
| }, | ||
| "skipTlsVerify": { | ||
| "type": "boolean", | ||
| "default": false, | ||
| "description": "Skip TLS certificate verification. Enable only when the target MBS endpoint uses a trusted self-signed certificate." | ||
| }, | ||
| "timeoutMs": { | ||
| "type": "integer", | ||
| "minimum": 1, | ||
| "default": 30000, | ||
| "description": "HTTP timeout in milliseconds." | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| { | ||
| "name": "zhizhangyi-mbs", | ||
| "version": "0.0.0", | ||
| "private": true, | ||
| "type": "module", | ||
| "files": [ | ||
| "bin/zhizhangyi-mbs.js", | ||
| "config.schema.json", | ||
| "secret.schema.json", | ||
| "service.json", | ||
| "proto", | ||
| "src" | ||
| ], | ||
| "bin": { | ||
| "zhizhangyi-mbs": "bin/zhizhangyi-mbs.js" | ||
| }, | ||
| "dependencies": { | ||
| "@chaitin-ai/octobus-sdk": "^0.5.0" | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
package.json 中 OctoBus SDK 版本与仓库基线不一致
package.json 声明的依赖为 "@chaitin-ai/octobus-sdk": "^0.5.0",但仓库基线分支(f0c1fb7)已合并 PR #433 将 SDK 升级至 0.6.0。该服务作为新增代码仍使用旧版本 SDK,可能导致以下风险:1) 无法获得 0.6.0 的 bug 修复与行为变更;2) 与仓库中已升级的其他服务出现运行时行为差异;3) 若 0.6.0 对 GrpcError、grpcStatus、defineService、runServiceMain 等导出项有调整,该服务可能在集成时发生运行时错误。
Problem code:
Recommendation:
将 package.json 中的 @chaitin-ai/octobus-sdk 版本号改为与仓库基线一致的 ^0.6.0,并在本地运行测试确认兼容性。
Suggested diff: