aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tools/cli.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-13 11:44:16 +0200
committerChocobozzz <me@florianbigard.com>2021-07-20 15:27:18 +0200
commitd0a0fa429d4651710ed951a3c11af0219e408964 (patch)
treec0638f2604e3442d1f15715b9b0f01ecab17ab20 /server/tools/cli.ts
parent41d1d075011174e73dccb74006181a92a618d7b4 (diff)
downloadPeerTube-d0a0fa429d4651710ed951a3c11af0219e408964.tar.gz
PeerTube-d0a0fa429d4651710ed951a3c11af0219e408964.tar.zst
PeerTube-d0a0fa429d4651710ed951a3c11af0219e408964.zip
Adapt CLI to new commands
Diffstat (limited to 'server/tools/cli.ts')
-rw-r--r--server/tools/cli.ts31
1 files changed, 17 insertions, 14 deletions
diff --git a/server/tools/cli.ts b/server/tools/cli.ts
index 0528859a4..3e0e03b97 100644
--- a/server/tools/cli.ts
+++ b/server/tools/cli.ts
@@ -3,12 +3,10 @@ import { Netrc } from 'netrc-parser'
3import { join } from 'path' 3import { join } from 'path'
4import { createLogger, format, transports } from 'winston' 4import { createLogger, format, transports } from 'winston'
5import { assignCommands, ServerInfo } from '@shared/extra-utils' 5import { assignCommands, ServerInfo } from '@shared/extra-utils'
6import { getAccessToken } from '@shared/extra-utils/users/login'
7import { getMyUserInformation } from '@shared/extra-utils/users/users' 6import { getMyUserInformation } from '@shared/extra-utils/users/users'
8import { User, UserRole } from '@shared/models' 7import { User, UserRole } from '@shared/models'
9import { root } from '../../shared/extra-utils/miscs/miscs'
10import { VideoPrivacy } from '../../shared/models/videos' 8import { VideoPrivacy } from '../../shared/models/videos'
11import { getAppNumber, isTestInstance } from '../helpers/core-utils' 9import { getAppNumber, isTestInstance, root } from '../helpers/core-utils'
12 10
13let configName = 'PeerTube/CLI' 11let configName = 'PeerTube/CLI'
14if (isTestInstance()) configName += `-${getAppNumber()}` 12if (isTestInstance()) configName += `-${getAppNumber()}`
@@ -17,9 +15,9 @@ const config = require('application-config')(configName)
17 15
18const version = require('../../../package.json').version 16const version = require('../../../package.json').version
19 17
20async function getAdminTokenOrDie (url: string, username: string, password: string) { 18async function getAdminTokenOrDie (server: ServerInfo, username: string, password: string) {
21 const accessToken = await getAccessToken(url, username, password) 19 const accessToken = await server.loginCommand.getAccessToken(username, password)
22 const resMe = await getMyUserInformation(url, accessToken) 20 const resMe = await getMyUserInformation(server.url, accessToken)
23 const me: User = resMe.body 21 const me: User = resMe.body
24 22
25 if (me.role !== UserRole.ADMINISTRATOR) { 23 if (me.role !== UserRole.ADMINISTRATOR) {
@@ -30,10 +28,6 @@ async function getAdminTokenOrDie (url: string, username: string, password: stri
30 return accessToken 28 return accessToken
31} 29}
32 30
33async function getAccessTokenOrDie (url: string, username: string, password: string) {
34 return getAccessToken(url, username, password)
35}
36
37interface Settings { 31interface Settings {
38 remotes: any[] 32 remotes: any[]
39 default: number 33 default: number
@@ -187,13 +181,22 @@ function getServerCredentials (program: Command) {
187 }) 181 })
188} 182}
189 183
190function buildServer (url: string, accessToken?: string): ServerInfo { 184function buildServer (url: string): ServerInfo {
191 const server = { url, accessToken, internalServerNumber: undefined } 185 const server = { url, internalServerNumber: undefined }
192 assignCommands(server) 186 assignCommands(server)
193 187
194 return server 188 return server
195} 189}
196 190
191async function assignToken (server: ServerInfo, username: string, password: string) {
192 const bodyClient = await server.loginCommand.getClient()
193 const client = { id: bodyClient.client_id, secret: bodyClient.client_secret }
194
195 const body = await server.loginCommand.login({ client, user: { username, password } })
196
197 server.accessToken = body.access_token
198}
199
197function getLogger (logLevel = 'info') { 200function getLogger (logLevel = 'info') {
198 const logLevels = { 201 const logLevels = {
199 0: 0, 202 0: 0,
@@ -241,6 +244,6 @@ export {
241 buildVideoAttributesFromCommander, 244 buildVideoAttributesFromCommander,
242 245
243 getAdminTokenOrDie, 246 getAdminTokenOrDie,
244 getAccessTokenOrDie, 247 buildServer,
245 buildServer 248 assignToken
246} 249}