diff options
author | Chocobozzz <me@florianbigard.com> | 2019-07-11 17:23:24 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2019-07-24 10:58:16 +0200 |
commit | 8d2be0ed7bb87283a1ec98609df6b82d83db706a (patch) | |
tree | 31a36b252df32be83ceb77658a53b57f9d15e8ac /shared/extra-utils/server | |
parent | dba85a1e9e9f603ba52e1ea42deaf3fdd799b1d8 (diff) | |
download | PeerTube-8d2be0ed7bb87283a1ec98609df6b82d83db706a.tar.gz PeerTube-8d2be0ed7bb87283a1ec98609df6b82d83db706a.tar.zst PeerTube-8d2be0ed7bb87283a1ec98609df6b82d83db706a.zip |
WIP plugins: move plugin CLI in peertube script
Install/uninstall/list plugins remotely
Diffstat (limited to 'shared/extra-utils/server')
-rw-r--r-- | shared/extra-utils/server/plugins.ts | 125 | ||||
-rw-r--r-- | shared/extra-utils/server/servers.ts | 14 |
2 files changed, 133 insertions, 6 deletions
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 @@ | |||
1 | import { makeGetRequest, makePostBodyRequest } from '../requests/requests' | ||
2 | import { PluginType } from '../../models/plugins/plugin.type' | ||
3 | |||
4 | function listPlugins (parameters: { | ||
5 | url: string, | ||
6 | accessToken: string, | ||
7 | start?: number, | ||
8 | count?: number, | ||
9 | sort?: string, | ||
10 | type?: PluginType, | ||
11 | expectedStatus?: number | ||
12 | }) { | ||
13 | const { url, accessToken, start, count, sort, type, expectedStatus = 200 } = parameters | ||
14 | const path = '/api/v1/plugins' | ||
15 | |||
16 | return makeGetRequest({ | ||
17 | url, | ||
18 | path, | ||
19 | token: accessToken, | ||
20 | query: { | ||
21 | start, | ||
22 | count, | ||
23 | sort, | ||
24 | type | ||
25 | }, | ||
26 | statusCodeExpected: expectedStatus | ||
27 | }) | ||
28 | } | ||
29 | |||
30 | function getPlugin (parameters: { | ||
31 | url: string, | ||
32 | accessToken: string, | ||
33 | npmName: string, | ||
34 | expectedStatus?: number | ||
35 | }) { | ||
36 | const { url, accessToken, npmName, expectedStatus = 200 } = parameters | ||
37 | const path = '/api/v1/plugins/' + npmName | ||
38 | |||
39 | return makeGetRequest({ | ||
40 | url, | ||
41 | path, | ||
42 | token: accessToken, | ||
43 | statusCodeExpected: expectedStatus | ||
44 | }) | ||
45 | } | ||
46 | |||
47 | function getPluginSettings (parameters: { | ||
48 | url: string, | ||
49 | accessToken: string, | ||
50 | npmName: string, | ||
51 | expectedStatus?: number | ||
52 | }) { | ||
53 | const { url, accessToken, npmName, expectedStatus = 200 } = parameters | ||
54 | const path = '/api/v1/plugins/' + npmName + '/settings' | ||
55 | |||
56 | return makeGetRequest({ | ||
57 | url, | ||
58 | path, | ||
59 | token: accessToken, | ||
60 | statusCodeExpected: expectedStatus | ||
61 | }) | ||
62 | } | ||
63 | |||
64 | function getPluginRegisteredSettings (parameters: { | ||
65 | url: string, | ||
66 | accessToken: string, | ||
67 | npmName: string, | ||
68 | expectedStatus?: number | ||
69 | }) { | ||
70 | const { url, accessToken, npmName, expectedStatus = 200 } = parameters | ||
71 | const path = '/api/v1/plugins/' + npmName + '/registered-settings' | ||
72 | |||
73 | return makeGetRequest({ | ||
74 | url, | ||
75 | path, | ||
76 | token: accessToken, | ||
77 | statusCodeExpected: expectedStatus | ||
78 | }) | ||
79 | } | ||
80 | |||
81 | function installPlugin (parameters: { | ||
82 | url: string, | ||
83 | accessToken: string, | ||
84 | path?: string, | ||
85 | npmName?: string | ||
86 | expectedStatus?: number | ||
87 | }) { | ||
88 | const { url, accessToken, npmName, path, expectedStatus = 204 } = parameters | ||
89 | const apiPath = '/api/v1/plugins/install' | ||
90 | |||
91 | return makePostBodyRequest({ | ||
92 | url, | ||
93 | path: apiPath, | ||
94 | token: accessToken, | ||
95 | fields: { npmName, path }, | ||
96 | statusCodeExpected: expectedStatus | ||
97 | }) | ||
98 | } | ||
99 | |||
100 | function uninstallPlugin (parameters: { | ||
101 | url: string, | ||
102 | accessToken: string, | ||
103 | npmName: string | ||
104 | expectedStatus?: number | ||
105 | }) { | ||
106 | const { url, accessToken, npmName, expectedStatus = 204 } = parameters | ||
107 | const apiPath = '/api/v1/plugins/uninstall' | ||
108 | |||
109 | return makePostBodyRequest({ | ||
110 | url, | ||
111 | path: apiPath, | ||
112 | token: accessToken, | ||
113 | fields: { npmName }, | ||
114 | statusCodeExpected: expectedStatus | ||
115 | }) | ||
116 | } | ||
117 | |||
118 | export { | ||
119 | listPlugins, | ||
120 | installPlugin, | ||
121 | getPlugin, | ||
122 | uninstallPlugin, | ||
123 | getPluginSettings, | ||
124 | getPluginRegisteredSettings | ||
125 | } | ||
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 @@ | |||
3 | import { ChildProcess, exec, fork } from 'child_process' | 3 | import { ChildProcess, exec, fork } from 'child_process' |
4 | import { join } from 'path' | 4 | import { join } from 'path' |
5 | import { root, wait } from '../miscs/miscs' | 5 | import { root, wait } from '../miscs/miscs' |
6 | import { copy, readdir, readFile, remove } from 'fs-extra' | 6 | import { copy, pathExists, readdir, readFile, remove } from 'fs-extra' |
7 | import { existsSync } from 'fs' | 7 | import { existsSync } from 'fs' |
8 | import { expect } from 'chai' | 8 | import { expect } from 'chai' |
9 | import { VideoChannel } from '../../models/videos' | 9 | import { VideoChannel } from '../../models/videos' |
@@ -241,20 +241,22 @@ async function reRunServer (server: ServerInfo, configOverride?: any) { | |||
241 | return server | 241 | return server |
242 | } | 242 | } |
243 | 243 | ||
244 | async function checkTmpIsEmpty (server: ServerInfo) { | 244 | function checkTmpIsEmpty (server: ServerInfo) { |
245 | return checkDirectoryIsEmpty(server, 'tmp') | 245 | return checkDirectoryIsEmpty(server, 'tmp', [ 'plugins-global.css' ]) |
246 | } | 246 | } |
247 | 247 | ||
248 | async function checkDirectoryIsEmpty (server: ServerInfo, directory: string) { | 248 | async function checkDirectoryIsEmpty (server: ServerInfo, directory: string, exceptions: string[] = []) { |
249 | const testDirectory = 'test' + server.internalServerNumber | 249 | const testDirectory = 'test' + server.internalServerNumber |
250 | 250 | ||
251 | const directoryPath = join(root(), testDirectory, directory) | 251 | const directoryPath = join(root(), testDirectory, directory) |
252 | 252 | ||
253 | const directoryExists = existsSync(directoryPath) | 253 | const directoryExists = await pathExists(directoryPath) |
254 | expect(directoryExists).to.be.true | 254 | expect(directoryExists).to.be.true |
255 | 255 | ||
256 | const files = await readdir(directoryPath) | 256 | const files = await readdir(directoryPath) |
257 | expect(files).to.have.lengthOf(0) | 257 | const filtered = files.filter(f => exceptions.includes(f) === false) |
258 | |||
259 | expect(filtered).to.have.lengthOf(0) | ||
258 | } | 260 | } |
259 | 261 | ||
260 | function killallServers (servers: ServerInfo[]) { | 262 | function killallServers (servers: ServerInfo[]) { |