diff options
Diffstat (limited to 'shared/server-commands/server')
-rw-r--r-- | shared/server-commands/server/object-storage-command.ts | 103 | ||||
-rw-r--r-- | shared/server-commands/server/server.ts | 3 |
2 files changed, 65 insertions, 41 deletions
diff --git a/shared/server-commands/server/object-storage-command.ts b/shared/server-commands/server/object-storage-command.ts index a1fe4f0f7..7d8ec93cd 100644 --- a/shared/server-commands/server/object-storage-command.ts +++ b/shared/server-commands/server/object-storage-command.ts | |||
@@ -1,34 +1,17 @@ | |||
1 | 1 | import { randomInt } from 'crypto' | |
2 | import { HttpStatusCode } from '@shared/models' | 2 | import { HttpStatusCode } from '@shared/models' |
3 | import { makePostBodyRequest } from '../requests' | 3 | import { makePostBodyRequest } from '../requests' |
4 | import { AbstractCommand } from '../shared' | ||
5 | |||
6 | export class ObjectStorageCommand extends AbstractCommand { | ||
7 | static readonly DEFAULT_PLAYLIST_MOCK_BUCKET = 'streaming-playlists' | ||
8 | static readonly DEFAULT_WEBTORRENT_MOCK_BUCKET = 'videos' | ||
9 | 4 | ||
5 | export class ObjectStorageCommand { | ||
10 | static readonly DEFAULT_SCALEWAY_BUCKET = 'peertube-ci-test' | 6 | static readonly DEFAULT_SCALEWAY_BUCKET = 'peertube-ci-test' |
11 | 7 | ||
12 | // --------------------------------------------------------------------------- | 8 | private readonly bucketsCreated: string[] = [] |
13 | 9 | private readonly seed: number | |
14 | static getDefaultMockConfig () { | ||
15 | return { | ||
16 | object_storage: { | ||
17 | enabled: true, | ||
18 | endpoint: 'http://' + this.getMockEndpointHost(), | ||
19 | region: this.getMockRegion(), | ||
20 | |||
21 | credentials: this.getMockCredentialsConfig(), | ||
22 | 10 | ||
23 | streaming_playlists: { | 11 | // --------------------------------------------------------------------------- |
24 | bucket_name: this.DEFAULT_PLAYLIST_MOCK_BUCKET | ||
25 | }, | ||
26 | 12 | ||
27 | videos: { | 13 | constructor () { |
28 | bucket_name: this.DEFAULT_WEBTORRENT_MOCK_BUCKET | 14 | this.seed = randomInt(0, 10000) |
29 | } | ||
30 | } | ||
31 | } | ||
32 | } | 15 | } |
33 | 16 | ||
34 | static getMockCredentialsConfig () { | 17 | static getMockCredentialsConfig () { |
@@ -46,35 +29,79 @@ export class ObjectStorageCommand extends AbstractCommand { | |||
46 | return 'us-east-1' | 29 | return 'us-east-1' |
47 | } | 30 | } |
48 | 31 | ||
49 | static getMockWebTorrentBaseUrl () { | 32 | getDefaultMockConfig () { |
50 | return `http://${this.DEFAULT_WEBTORRENT_MOCK_BUCKET}.${this.getMockEndpointHost()}/` | 33 | return { |
34 | object_storage: { | ||
35 | enabled: true, | ||
36 | endpoint: 'http://' + ObjectStorageCommand.getMockEndpointHost(), | ||
37 | region: ObjectStorageCommand.getMockRegion(), | ||
38 | |||
39 | credentials: ObjectStorageCommand.getMockCredentialsConfig(), | ||
40 | |||
41 | streaming_playlists: { | ||
42 | bucket_name: this.getMockStreamingPlaylistsBucketName() | ||
43 | }, | ||
44 | |||
45 | videos: { | ||
46 | bucket_name: this.getMockWebVideosBucketName() | ||
47 | } | ||
48 | } | ||
49 | } | ||
51 | } | 50 | } |
52 | 51 | ||
53 | static getMockPlaylistBaseUrl () { | 52 | getMockWebVideosBaseUrl () { |
54 | return `http://${this.DEFAULT_PLAYLIST_MOCK_BUCKET}.${this.getMockEndpointHost()}/` | 53 | return `http://${this.getMockWebVideosBucketName()}.${ObjectStorageCommand.getMockEndpointHost()}/` |
55 | } | 54 | } |
56 | 55 | ||
57 | static async prepareDefaultMockBuckets () { | 56 | getMockPlaylistBaseUrl () { |
58 | await this.createMockBucket(this.DEFAULT_PLAYLIST_MOCK_BUCKET) | 57 | return `http://${this.getMockStreamingPlaylistsBucketName()}.${ObjectStorageCommand.getMockEndpointHost()}/` |
59 | await this.createMockBucket(this.DEFAULT_WEBTORRENT_MOCK_BUCKET) | ||
60 | } | 58 | } |
61 | 59 | ||
62 | static async createMockBucket (name: string) { | 60 | async prepareDefaultMockBuckets () { |
61 | await this.createMockBucket(this.getMockStreamingPlaylistsBucketName()) | ||
62 | await this.createMockBucket(this.getMockWebVideosBucketName()) | ||
63 | } | ||
64 | |||
65 | async createMockBucket (name: string) { | ||
66 | this.bucketsCreated.push(name) | ||
67 | |||
68 | await this.deleteMockBucket(name) | ||
69 | |||
63 | await makePostBodyRequest({ | 70 | await makePostBodyRequest({ |
64 | url: this.getMockEndpointHost(), | 71 | url: ObjectStorageCommand.getMockEndpointHost(), |
65 | path: '/ui/' + name + '?delete', | 72 | path: '/ui/' + name + '?create', |
66 | expectedStatus: HttpStatusCode.TEMPORARY_REDIRECT_307 | 73 | expectedStatus: HttpStatusCode.TEMPORARY_REDIRECT_307 |
67 | }) | 74 | }) |
68 | 75 | ||
69 | await makePostBodyRequest({ | 76 | await makePostBodyRequest({ |
70 | url: this.getMockEndpointHost(), | 77 | url: ObjectStorageCommand.getMockEndpointHost(), |
71 | path: '/ui/' + name + '?create', | 78 | path: '/ui/' + name + '?make-public', |
72 | expectedStatus: HttpStatusCode.TEMPORARY_REDIRECT_307 | 79 | expectedStatus: HttpStatusCode.TEMPORARY_REDIRECT_307 |
73 | }) | 80 | }) |
81 | } | ||
74 | 82 | ||
83 | async cleanupMock () { | ||
84 | for (const name of this.bucketsCreated) { | ||
85 | await this.deleteMockBucket(name) | ||
86 | } | ||
87 | } | ||
88 | |||
89 | getMockStreamingPlaylistsBucketName (name = 'streaming-playlists') { | ||
90 | return this.getMockBucketName(name) | ||
91 | } | ||
92 | |||
93 | getMockWebVideosBucketName (name = 'web-videos') { | ||
94 | return this.getMockBucketName(name) | ||
95 | } | ||
96 | |||
97 | getMockBucketName (name: string) { | ||
98 | return `${this.seed}-${name}` | ||
99 | } | ||
100 | |||
101 | private async deleteMockBucket (name: string) { | ||
75 | await makePostBodyRequest({ | 102 | await makePostBodyRequest({ |
76 | url: this.getMockEndpointHost(), | 103 | url: ObjectStorageCommand.getMockEndpointHost(), |
77 | path: '/ui/' + name + '?make-public', | 104 | path: '/ui/' + name + '?delete', |
78 | expectedStatus: HttpStatusCode.TEMPORARY_REDIRECT_307 | 105 | expectedStatus: HttpStatusCode.TEMPORARY_REDIRECT_307 |
79 | }) | 106 | }) |
80 | } | 107 | } |
diff --git a/shared/server-commands/server/server.ts b/shared/server-commands/server/server.ts index 66b7ff09d..70f7a3ee2 100644 --- a/shared/server-commands/server/server.ts +++ b/shared/server-commands/server/server.ts | |||
@@ -48,7 +48,6 @@ import { DebugCommand } from './debug-command' | |||
48 | import { FollowsCommand } from './follows-command' | 48 | import { FollowsCommand } from './follows-command' |
49 | import { JobsCommand } from './jobs-command' | 49 | import { JobsCommand } from './jobs-command' |
50 | import { MetricsCommand } from './metrics-command' | 50 | import { MetricsCommand } from './metrics-command' |
51 | import { ObjectStorageCommand } from './object-storage-command' | ||
52 | import { PluginsCommand } from './plugins-command' | 51 | import { PluginsCommand } from './plugins-command' |
53 | import { RedundancyCommand } from './redundancy-command' | 52 | import { RedundancyCommand } from './redundancy-command' |
54 | import { ServersCommand } from './servers-command' | 53 | import { ServersCommand } from './servers-command' |
@@ -140,7 +139,6 @@ export class PeerTubeServer { | |||
140 | servers?: ServersCommand | 139 | servers?: ServersCommand |
141 | login?: LoginCommand | 140 | login?: LoginCommand |
142 | users?: UsersCommand | 141 | users?: UsersCommand |
143 | objectStorage?: ObjectStorageCommand | ||
144 | videoStudio?: VideoStudioCommand | 142 | videoStudio?: VideoStudioCommand |
145 | videos?: VideosCommand | 143 | videos?: VideosCommand |
146 | videoStats?: VideoStatsCommand | 144 | videoStats?: VideoStatsCommand |
@@ -429,7 +427,6 @@ export class PeerTubeServer { | |||
429 | this.login = new LoginCommand(this) | 427 | this.login = new LoginCommand(this) |
430 | this.users = new UsersCommand(this) | 428 | this.users = new UsersCommand(this) |
431 | this.videos = new VideosCommand(this) | 429 | this.videos = new VideosCommand(this) |
432 | this.objectStorage = new ObjectStorageCommand(this) | ||
433 | this.videoStudio = new VideoStudioCommand(this) | 430 | this.videoStudio = new VideoStudioCommand(this) |
434 | this.videoStats = new VideoStatsCommand(this) | 431 | this.videoStats = new VideoStatsCommand(this) |
435 | this.views = new ViewsCommand(this) | 432 | this.views = new ViewsCommand(this) |