]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - shared/server-commands/server/object-storage-command.ts
Use private ACL for private videos in s3
[github/Chocobozzz/PeerTube.git] / shared / server-commands / server / object-storage-command.ts
1
2 import { HttpStatusCode } from '@shared/models'
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
10 static readonly DEFAULT_SCALEWAY_BUCKET = 'peertube-ci-test'
11
12 // ---------------------------------------------------------------------------
13
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
23 streaming_playlists: {
24 bucket_name: this.DEFAULT_PLAYLIST_MOCK_BUCKET
25 },
26
27 videos: {
28 bucket_name: this.DEFAULT_WEBTORRENT_MOCK_BUCKET
29 }
30 }
31 }
32 }
33
34 static getMockCredentialsConfig () {
35 return {
36 access_key_id: 'AKIAIOSFODNN7EXAMPLE',
37 secret_access_key: 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY'
38 }
39 }
40
41 static getMockEndpointHost () {
42 return 'localhost:9444'
43 }
44
45 static getMockRegion () {
46 return 'us-east-1'
47 }
48
49 static getMockWebTorrentBaseUrl () {
50 return `http://${this.DEFAULT_WEBTORRENT_MOCK_BUCKET}.${this.getMockEndpointHost()}/`
51 }
52
53 static getMockPlaylistBaseUrl () {
54 return `http://${this.DEFAULT_PLAYLIST_MOCK_BUCKET}.${this.getMockEndpointHost()}/`
55 }
56
57 static async prepareDefaultMockBuckets () {
58 await this.createMockBucket(this.DEFAULT_PLAYLIST_MOCK_BUCKET)
59 await this.createMockBucket(this.DEFAULT_WEBTORRENT_MOCK_BUCKET)
60 }
61
62 static async createMockBucket (name: string) {
63 await makePostBodyRequest({
64 url: this.getMockEndpointHost(),
65 path: '/ui/' + name + '?delete',
66 expectedStatus: HttpStatusCode.TEMPORARY_REDIRECT_307
67 })
68
69 await makePostBodyRequest({
70 url: this.getMockEndpointHost(),
71 path: '/ui/' + name + '?create',
72 expectedStatus: HttpStatusCode.TEMPORARY_REDIRECT_307
73 })
74
75 await makePostBodyRequest({
76 url: this.getMockEndpointHost(),
77 path: '/ui/' + name + '?make-public',
78 expectedStatus: HttpStatusCode.TEMPORARY_REDIRECT_307
79 })
80 }
81
82 // ---------------------------------------------------------------------------
83
84 static getDefaultScalewayConfig (serverNumber: number) {
85 return {
86 object_storage: {
87 enabled: true,
88 endpoint: this.getScalewayEndpointHost(),
89 region: this.getScalewayRegion(),
90
91 credentials: this.getScalewayCredentialsConfig(),
92
93 streaming_playlists: {
94 bucket_name: this.DEFAULT_SCALEWAY_BUCKET,
95 prefix: `test:server-${serverNumber}-streaming-playlists:`
96 },
97
98 videos: {
99 bucket_name: this.DEFAULT_SCALEWAY_BUCKET,
100 prefix: `test:server-${serverNumber}-videos:`
101 }
102 }
103 }
104 }
105
106 static getScalewayCredentialsConfig () {
107 return {
108 access_key_id: process.env.OBJECT_STORAGE_SCALEWAY_KEY_ID,
109 secret_access_key: process.env.OBJECT_STORAGE_SCALEWAY_ACCESS_KEY
110 }
111 }
112
113 static getScalewayEndpointHost () {
114 return 's3.fr-par.scw.cloud'
115 }
116
117 static getScalewayRegion () {
118 return 'fr-par'
119 }
120
121 static getScalewayBaseUrl () {
122 return `https://${this.DEFAULT_SCALEWAY_BUCKET}.${this.getScalewayEndpointHost()}/`
123 }
124 }