From 8d2be0ed7bb87283a1ec98609df6b82d83db706a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 11 Jul 2019 17:23:24 +0200 Subject: WIP plugins: move plugin CLI in peertube script Install/uninstall/list plugins remotely --- shared/extra-utils/server/plugins.ts | 125 +++++++++++++++++++++++++++++++++++ shared/extra-utils/server/servers.ts | 14 ++-- 2 files changed, 133 insertions(+), 6 deletions(-) create mode 100644 shared/extra-utils/server/plugins.ts (limited to 'shared/extra-utils/server') diff --git a/shared/extra-utils/server/plugins.ts b/shared/extra-utils/server/plugins.ts new file mode 100644 index 000000000..6cd7cd17a --- /dev/null +++ b/shared/extra-utils/server/plugins.ts @@ -0,0 +1,125 @@ +import { makeGetRequest, makePostBodyRequest } from '../requests/requests' +import { PluginType } from '../../models/plugins/plugin.type' + +function listPlugins (parameters: { + url: string, + accessToken: string, + start?: number, + count?: number, + sort?: string, + type?: PluginType, + expectedStatus?: number +}) { + const { url, accessToken, start, count, sort, type, expectedStatus = 200 } = parameters + const path = '/api/v1/plugins' + + return makeGetRequest({ + url, + path, + token: accessToken, + query: { + start, + count, + sort, + type + }, + statusCodeExpected: expectedStatus + }) +} + +function getPlugin (parameters: { + url: string, + accessToken: string, + npmName: string, + expectedStatus?: number +}) { + const { url, accessToken, npmName, expectedStatus = 200 } = parameters + const path = '/api/v1/plugins/' + npmName + + return makeGetRequest({ + url, + path, + token: accessToken, + statusCodeExpected: expectedStatus + }) +} + +function getPluginSettings (parameters: { + url: string, + accessToken: string, + npmName: string, + expectedStatus?: number +}) { + const { url, accessToken, npmName, expectedStatus = 200 } = parameters + const path = '/api/v1/plugins/' + npmName + '/settings' + + return makeGetRequest({ + url, + path, + token: accessToken, + statusCodeExpected: expectedStatus + }) +} + +function getPluginRegisteredSettings (parameters: { + url: string, + accessToken: string, + npmName: string, + expectedStatus?: number +}) { + const { url, accessToken, npmName, expectedStatus = 200 } = parameters + const path = '/api/v1/plugins/' + npmName + '/registered-settings' + + return makeGetRequest({ + url, + path, + token: accessToken, + statusCodeExpected: expectedStatus + }) +} + +function installPlugin (parameters: { + url: string, + accessToken: string, + path?: string, + npmName?: string + expectedStatus?: number +}) { + const { url, accessToken, npmName, path, expectedStatus = 204 } = parameters + const apiPath = '/api/v1/plugins/install' + + return makePostBodyRequest({ + url, + path: apiPath, + token: accessToken, + fields: { npmName, path }, + statusCodeExpected: expectedStatus + }) +} + +function uninstallPlugin (parameters: { + url: string, + accessToken: string, + npmName: string + expectedStatus?: number +}) { + const { url, accessToken, npmName, expectedStatus = 204 } = parameters + const apiPath = '/api/v1/plugins/uninstall' + + return makePostBodyRequest({ + url, + path: apiPath, + token: accessToken, + fields: { npmName }, + statusCodeExpected: expectedStatus + }) +} + +export { + listPlugins, + installPlugin, + getPlugin, + uninstallPlugin, + getPluginSettings, + getPluginRegisteredSettings +} diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index 4c7d6862a..9167ebe5b 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts @@ -3,7 +3,7 @@ import { ChildProcess, exec, fork } from 'child_process' import { join } from 'path' import { root, wait } from '../miscs/miscs' -import { copy, readdir, readFile, remove } from 'fs-extra' +import { copy, pathExists, readdir, readFile, remove } from 'fs-extra' import { existsSync } from 'fs' import { expect } from 'chai' import { VideoChannel } from '../../models/videos' @@ -241,20 +241,22 @@ async function reRunServer (server: ServerInfo, configOverride?: any) { return server } -async function checkTmpIsEmpty (server: ServerInfo) { - return checkDirectoryIsEmpty(server, 'tmp') +function checkTmpIsEmpty (server: ServerInfo) { + return checkDirectoryIsEmpty(server, 'tmp', [ 'plugins-global.css' ]) } -async function checkDirectoryIsEmpty (server: ServerInfo, directory: string) { +async function checkDirectoryIsEmpty (server: ServerInfo, directory: string, exceptions: string[] = []) { const testDirectory = 'test' + server.internalServerNumber const directoryPath = join(root(), testDirectory, directory) - const directoryExists = existsSync(directoryPath) + const directoryExists = await pathExists(directoryPath) expect(directoryExists).to.be.true const files = await readdir(directoryPath) - expect(files).to.have.lengthOf(0) + const filtered = files.filter(f => exceptions.includes(f) === false) + + expect(filtered).to.have.lengthOf(0) } function killallServers (servers: ServerInfo[]) { -- cgit v1.2.3