From 26fcf2efebc681104d8e181da42b9ec112a8d28e Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 28 Jan 2020 11:07:23 +0100 Subject: Add redundancy CLI --- server/tools/cli.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'server/tools/cli.ts') 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' import { Command } from 'commander' import { VideoChannel, VideoPrivacy } from '../../shared/models/videos' import { createLogger, format, transports } from 'winston' +import { getAccessToken, getMyUserInformation } from '@shared/extra-utils' +import { User, UserRole } from '@shared/models' let configName = 'PeerTube/CLI' if (isTestInstance()) configName += `-${getAppNumber()}` @@ -14,6 +16,19 @@ const config = require('application-config')(configName) const version = require('../../../package.json').version +async function getAdminTokenOrDie (url: string, username: string, password: string) { + const accessToken = await getAccessToken(url, username, password) + const resMe = await getMyUserInformation(url, accessToken) + const me: User = resMe.body + + if (me.role !== UserRole.ADMINISTRATOR) { + console.error('You must be an administrator.') + process.exit(-1) + } + + return accessToken +} + interface Settings { remotes: any[], default: number @@ -222,5 +237,7 @@ export { getServerCredentials, buildCommonVideoOptions, - buildVideoAttributesFromCommander + buildVideoAttributesFromCommander, + + getAdminTokenOrDie } -- cgit v1.2.3