diff --git a/docs/how-to-use.md b/docs/how-to-use.md index 25fc4c4..41dc8c4 100644 --- a/docs/how-to-use.md +++ b/docs/how-to-use.md @@ -8,13 +8,18 @@ Select a id for your project, for example: `opensumi-core`. and visit to configure your project. +if you want set a token for `opensumi-core`, +you can visit to set a token. + ## Configure Github Webhook +You need configure a secret in first: + Open `https://github.com/opensumi/core/settings/hooks/new`: 1. `Payload URL`: Input `https://worker.bot/webhook/opensumi-core` 2. `Content type`: Select `application/json` -3. `Secret`: Input the secret you want to set, [HERE IS A SECRET]。 +3. `Secret`: Input the secret you want to set. 4. `events`: Select `Send me everything.` ### Configure Dingtalk Webhook @@ -30,25 +35,23 @@ Check the radio: **是否开启 Outgoing 机制**, input the worker's address to `POST 地址`: ```txt -https://worker.bot/ding/xxx +https://worker.bot/ding/opensumi-core ``` -The outgoing `Token` should be set in [KVManager](./kv.md), [HERE IS A SECRET]. +The outgoing `Token` should be set in . ### Configure Github App -First you need to create a GitHub App, in the settings: +First you need to create a GitHub App, in the GitHub website: set `webhooks` to: ```txt -https://worker.bot/gh_app +https://worker.bot/github/app/opensumi-core ``` -set `secret` to the value you set([Secrets](./secrets.md), [HERE IS A SECRET])。 +set `secret` to the value you seted in When create bot done, you can get the last two secrets you need: -set **App ID** to [Secrets](./secrets.md), [HERE IS A SECRET] - -and generate a private key. and set it's value to [Secrets](./secrets.md), [HERE IS A SECRET]. +**App ID** and **private key**, and set it's value to . diff --git a/src/controllers/admin.ts b/src/controllers/admin.ts index 8894abb..ceb266a 100644 --- a/src/controllers/admin.ts +++ b/src/controllers/admin.ts @@ -17,4 +17,34 @@ export function route(hono: THono) { await AdminService.instance().setAdminToken(newToken); return c.send.message('Token updated successfully'); }); + + hono.get('/admin/configure-scope', async (c) => { + const scope = c.req.query('scope'); + const token = c.req.query('token'); + const adminToken = c.req.query('adminToken'); + if (!adminToken) { + return c.send.error(400, 'bad request'); + } + + const existsAdminToken = await AdminService.instance().getAdminToken(); + if (!existsAdminToken) { + return c.send.error(400, 'server is not initialized'); + } + + if (existsAdminToken !== adminToken) { + return c.send.error(400, 'token is not correct'); + } + + if (!scope) { + return c.send.error(400, 'scope is required'); + } + + if (!token) { + return c.send.error(400, 'token is required'); + } + + await AdminService.instance().setScopeToken(scope, token); + + return c.send.message('Token updated successfully'); + }); }