diff options
Diffstat (limited to 'server/tools/cli.ts')
-rw-r--r-- | server/tools/cli.ts | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/server/tools/cli.ts b/server/tools/cli.ts index 58e2445ac..ba80872fb 100644 --- a/server/tools/cli.ts +++ b/server/tools/cli.ts | |||
@@ -6,6 +6,8 @@ import { getVideoChannel } from '../../shared/extra-utils/videos/video-channels' | |||
6 | import { Command } from 'commander' | 6 | import { Command } from 'commander' |
7 | import { VideoChannel, VideoPrivacy } from '../../shared/models/videos' | 7 | import { VideoChannel, VideoPrivacy } from '../../shared/models/videos' |
8 | import { createLogger, format, transports } from 'winston' | 8 | import { createLogger, format, transports } from 'winston' |
9 | import { getAccessToken, getMyUserInformation } from '@shared/extra-utils' | ||
10 | import { User, UserRole } from '@shared/models' | ||
9 | 11 | ||
10 | let configName = 'PeerTube/CLI' | 12 | let configName = 'PeerTube/CLI' |
11 | if (isTestInstance()) configName += `-${getAppNumber()}` | 13 | if (isTestInstance()) configName += `-${getAppNumber()}` |
@@ -14,6 +16,19 @@ const config = require('application-config')(configName) | |||
14 | 16 | ||
15 | const version = require('../../../package.json').version | 17 | const version = require('../../../package.json').version |
16 | 18 | ||
19 | async function getAdminTokenOrDie (url: string, username: string, password: string) { | ||
20 | const accessToken = await getAccessToken(url, username, password) | ||
21 | const resMe = await getMyUserInformation(url, accessToken) | ||
22 | const me: User = resMe.body | ||
23 | |||
24 | if (me.role !== UserRole.ADMINISTRATOR) { | ||
25 | console.error('You must be an administrator.') | ||
26 | process.exit(-1) | ||
27 | } | ||
28 | |||
29 | return accessToken | ||
30 | } | ||
31 | |||
17 | interface Settings { | 32 | interface Settings { |
18 | remotes: any[], | 33 | remotes: any[], |
19 | default: number | 34 | default: number |
@@ -222,5 +237,7 @@ export { | |||
222 | getServerCredentials, | 237 | getServerCredentials, |
223 | 238 | ||
224 | buildCommonVideoOptions, | 239 | buildCommonVideoOptions, |
225 | buildVideoAttributesFromCommander | 240 | buildVideoAttributesFromCommander, |
241 | |||
242 | getAdminTokenOrDie | ||
226 | } | 243 | } |