ONES API Subscribe
Suitable Enviroment | Private Deployment |
This ability is obsolete as of October 13, 2023. If relevant requirements require similar capabilities, please submit a new request form to the open platform.
Requireâ
ONES |
---|
Overviewâ
Sometimes we need to change the performance of certain behaviors in the ONES system and add some operations after a certain behavior. The plug-in can post-subscribe to all open interfaces in the ONES standard system.
useâ
Terms and Conditionsâ
- The difference between the organization-level interface and the team-level interface is that the
url
of the team-level interface contains/team/:teamUUID
. - The same interface can be post-subscribed by multiple plug-ins at the same time in its level context.
- For the same interface in the context of its level, the post-subscription capability and the interface hijacking capability cannot be used at the same time.
- For the same interface in the context of its level, pre-interception and post-subscription can be used at the same time.
- The results returned by the plug-in do not affect the original interface.
- In local debugging, if the plug-in configuration file
config/plugin.yaml
is modified, you need to runnpx op invoke clear
and re-run thenpx op invoke run
command to make the configuration take effect.
Request processâ
Configuration fileâ
Add the following configuration to the apis
field in the plugin configuration file:
apis:
- type: subscribe #Interface type: subscribe: post-subscription
methods: #Interface request method
- GET
url: /users/me #Hijack interface url
scope: project #project or wiki interface, without this attribute, the default is project
function: jackFunc #The name should be consistent with the function name in the code
Specific codeâ
This example pre-intercepts the project's personal information acquisition interface. The headers and body in the code are the request header and request body of the original request respectively.
import { Logger } from '@ones-op/node-logger'
export async function jackFunc(
request: PluginRequest<Record<string, any>>,
): Promise<PluginResponse> {
const reqBody = request.reqBody as any
const respBody = request.respBody as any
const reqHeaders = request.reqHeaders as any
const respHeaders = request.respHeaders as any
Logger.info('[Plugin] hello ======= Request successful')
Logger.info('[Plugin] respBody ======= Request successful', respBody)
Logger.info('[Plugin] respHeaders ======= Request successful', respHeaders)
Logger.info('[Plugin] reqBody ======= Request successful', reqBody)
Logger.info('[Plugin] reqHeaders ======= Request successful', reqHeaders)
return {
body: {
res: 'hello world',
requestBody: {},
},
}
}
-
Precautions
The following points need to be noted when using interface request parameters:
- What is being intercepted is the ONES API, so the
url
filled in must be consistent with theurl
used to access the ONES API; - Confirm whether the intercepted interface itself is a
POST
request or aGET
request;
- What is being intercepted is the ONES API, so the
Debugging methodâ
-
Use the
curl
tool to access, taking the/users/me
interface as an example:curl --location --request GET 'https://yourhost/users/me' \
--header 'Ones-User-Id: {user_uuid}' \
--header 'Ones-Auth-Token: {user_token}' \
--header 'Content-Type: application/json' \
--data '' -
Example of code request parameters
url: https://yourhost/users/me
headers:
Ones-User-Id:{user_uuid}
Ones-Auth-Token:{user_token}
...
method: GET