aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tools/cli.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tools/cli.ts')
-rw-r--r--server/tools/cli.ts19
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'
6import { Command } from 'commander' 6import { Command } from 'commander'
7import { VideoChannel, VideoPrivacy } from '../../shared/models/videos' 7import { VideoChannel, VideoPrivacy } from '../../shared/models/videos'
8import { createLogger, format, transports } from 'winston' 8import { createLogger, format, transports } from 'winston'
9import { getAccessToken, getMyUserInformation } from '@shared/extra-utils'
10import { User, UserRole } from '@shared/models'
9 11
10let configName = 'PeerTube/CLI' 12let configName = 'PeerTube/CLI'
11if (isTestInstance()) configName += `-${getAppNumber()}` 13if (isTestInstance()) configName += `-${getAppNumber()}`
@@ -14,6 +16,19 @@ const config = require('application-config')(configName)
14 16
15const version = require('../../../package.json').version 17const version = require('../../../package.json').version
16 18
19async 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
17interface Settings { 32interface 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}