diff options
Diffstat (limited to 'shared/server-commands/server/object-storage-command.ts')
-rw-r--r-- | shared/server-commands/server/object-storage-command.ts | 103 |
1 files changed, 65 insertions, 38 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 | } |