diff options
author | Chocobozzz <me@florianbigard.com> | 2020-01-28 11:07:23 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-01-28 11:35:26 +0100 |
commit | 26fcf2efebc681104d8e181da42b9ec112a8d28e (patch) | |
tree | 1d2a4a5c8c5547659274a765238b6b58839493eb /server/tools/cli.ts | |
parent | b764380ac23f4e9d4677d08acdc3474c2931a16d (diff) | |
download | PeerTube-26fcf2efebc681104d8e181da42b9ec112a8d28e.tar.gz PeerTube-26fcf2efebc681104d8e181da42b9ec112a8d28e.tar.zst PeerTube-26fcf2efebc681104d8e181da42b9ec112a8d28e.zip |
Add redundancy CLI
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 | } |