Skip to content

Commit

Permalink
feat: support configure scope token
Browse files Browse the repository at this point in the history
  • Loading branch information
bytemain committed Oct 15, 2024
1 parent cbc0734 commit 7d58190
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
21 changes: 12 additions & 9 deletions docs/how-to-use.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@ Select a id for your project, for example: `opensumi-core`.

and visit <https://worker.bot/configuration/opensumi-core> to configure your project.

if you want set a token for `opensumi-core`,
you can visit <https://worker.bot/admin/configure-scope?adminToken=password&scope=opensumi-core&token=p1> to set a token.

## Configure Github Webhook

You need configure a secret in <https://worker.bot/configuration/opensumi-core/setting> 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
Expand All @@ -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 <https://worker.bot/configuration/opensumi-core/ding-setting>.

### 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 <https://worker.bot/configuration/opensumi-core/app-settings>

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 <https://worker.bot/configuration/opensumi-core/app-settings>.
30 changes: 30 additions & 0 deletions src/controllers/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
}

0 comments on commit 7d58190

Please sign in to comment.