diff options
Diffstat (limited to 'server/tools/cli.ts')
-rw-r--r-- | server/tools/cli.ts | 31 |
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' | |||
3 | import { join } from 'path' | 3 | import { join } from 'path' |
4 | import { createLogger, format, transports } from 'winston' | 4 | import { createLogger, format, transports } from 'winston' |
5 | import { assignCommands, ServerInfo } from '@shared/extra-utils' | 5 | import { assignCommands, ServerInfo } from '@shared/extra-utils' |
6 | import { getAccessToken } from '@shared/extra-utils/users/login' | ||
7 | import { getMyUserInformation } from '@shared/extra-utils/users/users' | 6 | import { getMyUserInformation } from '@shared/extra-utils/users/users' |
8 | import { User, UserRole } from '@shared/models' | 7 | import { User, UserRole } from '@shared/models' |
9 | import { root } from '../../shared/extra-utils/miscs/miscs' | ||
10 | import { VideoPrivacy } from '../../shared/models/videos' | 8 | import { VideoPrivacy } from '../../shared/models/videos' |
11 | import { getAppNumber, isTestInstance } from '../helpers/core-utils' | 9 | import { getAppNumber, isTestInstance, root } from '../helpers/core-utils' |
12 | 10 | ||
13 | let configName = 'PeerTube/CLI' | 11 | let configName = 'PeerTube/CLI' |
14 | if (isTestInstance()) configName += `-${getAppNumber()}` | 12 | if (isTestInstance()) configName += `-${getAppNumber()}` |
@@ -17,9 +15,9 @@ const config = require('application-config')(configName) | |||
17 | 15 | ||
18 | const version = require('../../../package.json').version | 16 | const version = require('../../../package.json').version |
19 | 17 | ||
20 | async function getAdminTokenOrDie (url: string, username: string, password: string) { | 18 | async 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 | ||
33 | async function getAccessTokenOrDie (url: string, username: string, password: string) { | ||
34 | return getAccessToken(url, username, password) | ||
35 | } | ||
36 | |||
37 | interface Settings { | 31 | interface 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 | ||
190 | function buildServer (url: string, accessToken?: string): ServerInfo { | 184 | function 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 | ||
191 | async 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 | |||
197 | function getLogger (logLevel = 'info') { | 200 | function 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 | } |