1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
import { randomInt } from 'crypto'
import { HttpStatusCode } from '@peertube/peertube-models'
import { makePostBodyRequest } from '../requests/index.js'
export class ObjectStorageCommand {
static readonly DEFAULT_SCALEWAY_BUCKET = 'peertube-ci-test'
private readonly bucketsCreated: string[] = []
private readonly seed: number
// ---------------------------------------------------------------------------
constructor () {
this.seed = randomInt(0, 10000)
}
static getMockCredentialsConfig () {
return {
access_key_id: 'AKIAIOSFODNN7EXAMPLE',
secret_access_key: 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY'
}
}
static getMockEndpointHost () {
return 'localhost:9444'
}
static getMockRegion () {
return 'us-east-1'
}
getDefaultMockConfig () {
return {
object_storage: {
enabled: true,
endpoint: 'http://' + ObjectStorageCommand.getMockEndpointHost(),
region: ObjectStorageCommand.getMockRegion(),
credentials: ObjectStorageCommand.getMockCredentialsConfig(),
streaming_playlists: {
bucket_name: this.getMockStreamingPlaylistsBucketName()
},
web_videos: {
bucket_name: this.getMockWebVideosBucketName()
}
}
}
}
getMockWebVideosBaseUrl () {
return `http://${this.getMockWebVideosBucketName()}.${ObjectStorageCommand.getMockEndpointHost()}/`
}
getMockPlaylistBaseUrl () {
return `http://${this.getMockStreamingPlaylistsBucketName()}.${ObjectStorageCommand.getMockEndpointHost()}/`
}
async prepareDefaultMockBuckets () {
await this.createMockBucket(this.getMockStreamingPlaylistsBucketName())
await this.createMockBucket(this.getMockWebVideosBucketName())
}
async createMockBucket (name: string) {
this.bucketsCreated.push(name)
await this.deleteMockBucket(name)
await makePostBodyRequest({
url: ObjectStorageCommand.getMockEndpointHost(),
path: '/ui/' + name + '?create',
expectedStatus: HttpStatusCode.TEMPORARY_REDIRECT_307
})
await makePostBodyRequest({
url: ObjectStorageCommand.getMockEndpointHost(),
path: '/ui/' + name + '?make-public',
expectedStatus: HttpStatusCode.TEMPORARY_REDIRECT_307
})
}
async cleanupMock () {
for (const name of this.bucketsCreated) {
await this.deleteMockBucket(name)
}
}
getMockStreamingPlaylistsBucketName (name = 'streaming-playlists') {
return this.getMockBucketName(name)
}
getMockWebVideosBucketName (name = 'web-videos') {
return this.getMockBucketName(name)
}
getMockBucketName (name: string) {
return `${this.seed}-${name}`
}
private async deleteMockBucket (name: string) {
await makePostBodyRequest({
url: ObjectStorageCommand.getMockEndpointHost(),
path: '/ui/' + name + '?delete',
expectedStatus: HttpStatusCode.TEMPORARY_REDIRECT_307
})
}
// ---------------------------------------------------------------------------
static getDefaultScalewayConfig (options: {
serverNumber: number
enablePrivateProxy?: boolean // default true
privateACL?: 'private' | 'public-read' // default 'private'
}) {
const { serverNumber, enablePrivateProxy = true, privateACL = 'private' } = options
return {
object_storage: {
enabled: true,
endpoint: this.getScalewayEndpointHost(),
region: this.getScalewayRegion(),
credentials: this.getScalewayCredentialsConfig(),
upload_acl: {
private: privateACL
},
proxy: {
proxify_private_files: enablePrivateProxy
},
streaming_playlists: {
bucket_name: this.DEFAULT_SCALEWAY_BUCKET,
prefix: `test:server-${serverNumber}-streaming-playlists:`
},
web_videos: {
bucket_name: this.DEFAULT_SCALEWAY_BUCKET,
prefix: `test:server-${serverNumber}-web-videos:`
}
}
}
}
static getScalewayCredentialsConfig () {
return {
access_key_id: process.env.OBJECT_STORAGE_SCALEWAY_KEY_ID,
secret_access_key: process.env.OBJECT_STORAGE_SCALEWAY_ACCESS_KEY
}
}
static getScalewayEndpointHost () {
return 's3.fr-par.scw.cloud'
}
static getScalewayRegion () {
return 'fr-par'
}
static getScalewayBaseUrl () {
return `https://${this.DEFAULT_SCALEWAY_BUCKET}.${this.getScalewayEndpointHost()}/`
}
}
|