]>
Commit | Line | Data |
---|---|---|
0305db28 JB |
1 | |
2 | import { HttpStatusCode } from '@shared/models' | |
3 | import { makePostBodyRequest } from '../requests' | |
4 | import { AbstractCommand } from '../shared' | |
5 | ||
6 | export class ObjectStorageCommand extends AbstractCommand { | |
9ab330b9 C |
7 | static readonly DEFAULT_PLAYLIST_MOCK_BUCKET = 'streaming-playlists' |
8 | static readonly DEFAULT_WEBTORRENT_MOCK_BUCKET = 'videos' | |
0305db28 | 9 | |
9ab330b9 C |
10 | static readonly DEFAULT_SCALEWAY_BUCKET = 'peertube-ci-test' |
11 | ||
12 | // --------------------------------------------------------------------------- | |
13 | ||
14 | static getDefaultMockConfig () { | |
0305db28 JB |
15 | return { |
16 | object_storage: { | |
17 | enabled: true, | |
9ab330b9 C |
18 | endpoint: 'http://' + this.getMockEndpointHost(), |
19 | region: this.getMockRegion(), | |
0305db28 | 20 | |
9ab330b9 | 21 | credentials: this.getMockCredentialsConfig(), |
0305db28 JB |
22 | |
23 | streaming_playlists: { | |
9ab330b9 | 24 | bucket_name: this.DEFAULT_PLAYLIST_MOCK_BUCKET |
0305db28 JB |
25 | }, |
26 | ||
27 | videos: { | |
9ab330b9 | 28 | bucket_name: this.DEFAULT_WEBTORRENT_MOCK_BUCKET |
0305db28 JB |
29 | } |
30 | } | |
31 | } | |
32 | } | |
33 | ||
9ab330b9 | 34 | static getMockCredentialsConfig () { |
0305db28 JB |
35 | return { |
36 | access_key_id: 'AKIAIOSFODNN7EXAMPLE', | |
37 | secret_access_key: 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY' | |
38 | } | |
39 | } | |
40 | ||
9ab330b9 | 41 | static getMockEndpointHost () { |
0305db28 JB |
42 | return 'localhost:9444' |
43 | } | |
44 | ||
9ab330b9 | 45 | static getMockRegion () { |
0305db28 JB |
46 | return 'us-east-1' |
47 | } | |
48 | ||
9ab330b9 C |
49 | static getMockWebTorrentBaseUrl () { |
50 | return `http://${this.DEFAULT_WEBTORRENT_MOCK_BUCKET}.${this.getMockEndpointHost()}/` | |
0305db28 JB |
51 | } |
52 | ||
9ab330b9 C |
53 | static getMockPlaylistBaseUrl () { |
54 | return `http://${this.DEFAULT_PLAYLIST_MOCK_BUCKET}.${this.getMockEndpointHost()}/` | |
0305db28 JB |
55 | } |
56 | ||
9ab330b9 C |
57 | static async prepareDefaultMockBuckets () { |
58 | await this.createMockBucket(this.DEFAULT_PLAYLIST_MOCK_BUCKET) | |
59 | await this.createMockBucket(this.DEFAULT_WEBTORRENT_MOCK_BUCKET) | |
0305db28 JB |
60 | } |
61 | ||
9ab330b9 | 62 | static async createMockBucket (name: string) { |
0305db28 | 63 | await makePostBodyRequest({ |
9ab330b9 | 64 | url: this.getMockEndpointHost(), |
0305db28 JB |
65 | path: '/ui/' + name + '?delete', |
66 | expectedStatus: HttpStatusCode.TEMPORARY_REDIRECT_307 | |
67 | }) | |
68 | ||
69 | await makePostBodyRequest({ | |
9ab330b9 | 70 | url: this.getMockEndpointHost(), |
0305db28 JB |
71 | path: '/ui/' + name + '?create', |
72 | expectedStatus: HttpStatusCode.TEMPORARY_REDIRECT_307 | |
73 | }) | |
74 | ||
75 | await makePostBodyRequest({ | |
9ab330b9 | 76 | url: this.getMockEndpointHost(), |
0305db28 JB |
77 | path: '/ui/' + name + '?make-public', |
78 | expectedStatus: HttpStatusCode.TEMPORARY_REDIRECT_307 | |
79 | }) | |
80 | } | |
9ab330b9 C |
81 | |
82 | // --------------------------------------------------------------------------- | |
83 | ||
5a122ddd C |
84 | static getDefaultScalewayConfig (options: { |
85 | serverNumber: number | |
86 | enablePrivateProxy?: boolean // default true | |
87 | privateACL?: 'private' | 'public-read' // default 'private' | |
88 | }) { | |
89 | const { serverNumber, enablePrivateProxy = true, privateACL = 'private' } = options | |
90 | ||
9ab330b9 C |
91 | return { |
92 | object_storage: { | |
93 | enabled: true, | |
94 | endpoint: this.getScalewayEndpointHost(), | |
95 | region: this.getScalewayRegion(), | |
96 | ||
97 | credentials: this.getScalewayCredentialsConfig(), | |
98 | ||
5a122ddd C |
99 | upload_acl: { |
100 | private: privateACL | |
101 | }, | |
102 | ||
103 | proxy: { | |
104 | proxify_private_files: enablePrivateProxy | |
105 | }, | |
106 | ||
9ab330b9 C |
107 | streaming_playlists: { |
108 | bucket_name: this.DEFAULT_SCALEWAY_BUCKET, | |
109 | prefix: `test:server-${serverNumber}-streaming-playlists:` | |
110 | }, | |
111 | ||
112 | videos: { | |
113 | bucket_name: this.DEFAULT_SCALEWAY_BUCKET, | |
114 | prefix: `test:server-${serverNumber}-videos:` | |
115 | } | |
116 | } | |
117 | } | |
118 | } | |
119 | ||
120 | static getScalewayCredentialsConfig () { | |
121 | return { | |
122 | access_key_id: process.env.OBJECT_STORAGE_SCALEWAY_KEY_ID, | |
123 | secret_access_key: process.env.OBJECT_STORAGE_SCALEWAY_ACCESS_KEY | |
124 | } | |
125 | } | |
126 | ||
127 | static getScalewayEndpointHost () { | |
128 | return 's3.fr-par.scw.cloud' | |
129 | } | |
130 | ||
131 | static getScalewayRegion () { | |
132 | return 'fr-par' | |
133 | } | |
134 | ||
135 | static getScalewayBaseUrl () { | |
136 | return `https://${this.DEFAULT_SCALEWAY_BUCKET}.${this.getScalewayEndpointHost()}/` | |
137 | } | |
0305db28 | 138 | } |