2023-05-23 04:49:45 -04:00
|
|
|
import { randomInt } from 'crypto'
|
2021-08-17 02:26:20 -04:00
|
|
|
import { HttpStatusCode } from '@shared/models'
|
|
|
|
import { makePostBodyRequest } from '../requests'
|
|
|
|
|
2023-05-23 04:49:45 -04:00
|
|
|
export class ObjectStorageCommand {
|
2022-10-19 04:43:53 -04:00
|
|
|
static readonly DEFAULT_SCALEWAY_BUCKET = 'peertube-ci-test'
|
|
|
|
|
2023-05-23 04:49:45 -04:00
|
|
|
private readonly bucketsCreated: string[] = []
|
|
|
|
private readonly seed: number
|
2021-08-17 02:26:20 -04:00
|
|
|
|
2023-05-23 04:49:45 -04:00
|
|
|
// ---------------------------------------------------------------------------
|
2021-08-17 02:26:20 -04:00
|
|
|
|
2023-05-23 04:49:45 -04:00
|
|
|
constructor () {
|
|
|
|
this.seed = randomInt(0, 10000)
|
2021-08-17 02:26:20 -04:00
|
|
|
}
|
|
|
|
|
2022-10-19 04:43:53 -04:00
|
|
|
static getMockCredentialsConfig () {
|
2021-08-17 02:26:20 -04:00
|
|
|
return {
|
|
|
|
access_key_id: 'AKIAIOSFODNN7EXAMPLE',
|
|
|
|
secret_access_key: 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-19 04:43:53 -04:00
|
|
|
static getMockEndpointHost () {
|
2021-08-17 02:26:20 -04:00
|
|
|
return 'localhost:9444'
|
|
|
|
}
|
|
|
|
|
2022-10-19 04:43:53 -04:00
|
|
|
static getMockRegion () {
|
2021-08-17 02:26:20 -04:00
|
|
|
return 'us-east-1'
|
|
|
|
}
|
|
|
|
|
2023-05-23 04:49:45 -04:00
|
|
|
getDefaultMockConfig () {
|
|
|
|
return {
|
|
|
|
object_storage: {
|
|
|
|
enabled: true,
|
|
|
|
endpoint: 'http://' + ObjectStorageCommand.getMockEndpointHost(),
|
|
|
|
region: ObjectStorageCommand.getMockRegion(),
|
|
|
|
|
|
|
|
credentials: ObjectStorageCommand.getMockCredentialsConfig(),
|
|
|
|
|
|
|
|
streaming_playlists: {
|
|
|
|
bucket_name: this.getMockStreamingPlaylistsBucketName()
|
|
|
|
},
|
|
|
|
|
|
|
|
videos: {
|
|
|
|
bucket_name: this.getMockWebVideosBucketName()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-08-17 02:26:20 -04:00
|
|
|
}
|
|
|
|
|
2023-05-23 04:49:45 -04:00
|
|
|
getMockWebVideosBaseUrl () {
|
|
|
|
return `http://${this.getMockWebVideosBucketName()}.${ObjectStorageCommand.getMockEndpointHost()}/`
|
2021-08-17 02:26:20 -04:00
|
|
|
}
|
|
|
|
|
2023-05-23 04:49:45 -04:00
|
|
|
getMockPlaylistBaseUrl () {
|
|
|
|
return `http://${this.getMockStreamingPlaylistsBucketName()}.${ObjectStorageCommand.getMockEndpointHost()}/`
|
2021-08-17 02:26:20 -04:00
|
|
|
}
|
|
|
|
|
2023-05-23 04:49:45 -04:00
|
|
|
async prepareDefaultMockBuckets () {
|
|
|
|
await this.createMockBucket(this.getMockStreamingPlaylistsBucketName())
|
|
|
|
await this.createMockBucket(this.getMockWebVideosBucketName())
|
|
|
|
}
|
|
|
|
|
|
|
|
async createMockBucket (name: string) {
|
|
|
|
this.bucketsCreated.push(name)
|
|
|
|
|
|
|
|
await this.deleteMockBucket(name)
|
|
|
|
|
2021-08-17 02:26:20 -04:00
|
|
|
await makePostBodyRequest({
|
2023-05-23 04:49:45 -04:00
|
|
|
url: ObjectStorageCommand.getMockEndpointHost(),
|
|
|
|
path: '/ui/' + name + '?create',
|
2021-08-17 02:26:20 -04:00
|
|
|
expectedStatus: HttpStatusCode.TEMPORARY_REDIRECT_307
|
|
|
|
})
|
|
|
|
|
|
|
|
await makePostBodyRequest({
|
2023-05-23 04:49:45 -04:00
|
|
|
url: ObjectStorageCommand.getMockEndpointHost(),
|
|
|
|
path: '/ui/' + name + '?make-public',
|
2021-08-17 02:26:20 -04:00
|
|
|
expectedStatus: HttpStatusCode.TEMPORARY_REDIRECT_307
|
|
|
|
})
|
2023-05-23 04:49:45 -04:00
|
|
|
}
|
2021-08-17 02:26:20 -04:00
|
|
|
|
2023-05-23 04:49:45 -04:00
|
|
|
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) {
|
2021-08-17 02:26:20 -04:00
|
|
|
await makePostBodyRequest({
|
2023-05-23 04:49:45 -04:00
|
|
|
url: ObjectStorageCommand.getMockEndpointHost(),
|
|
|
|
path: '/ui/' + name + '?delete',
|
2021-08-17 02:26:20 -04:00
|
|
|
expectedStatus: HttpStatusCode.TEMPORARY_REDIRECT_307
|
|
|
|
})
|
|
|
|
}
|
2022-10-19 04:43:53 -04:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2022-10-26 10:23:39 -04:00
|
|
|
static getDefaultScalewayConfig (options: {
|
|
|
|
serverNumber: number
|
|
|
|
enablePrivateProxy?: boolean // default true
|
|
|
|
privateACL?: 'private' | 'public-read' // default 'private'
|
|
|
|
}) {
|
|
|
|
const { serverNumber, enablePrivateProxy = true, privateACL = 'private' } = options
|
|
|
|
|
2022-10-19 04:43:53 -04:00
|
|
|
return {
|
|
|
|
object_storage: {
|
|
|
|
enabled: true,
|
|
|
|
endpoint: this.getScalewayEndpointHost(),
|
|
|
|
region: this.getScalewayRegion(),
|
|
|
|
|
|
|
|
credentials: this.getScalewayCredentialsConfig(),
|
|
|
|
|
2022-10-26 10:23:39 -04:00
|
|
|
upload_acl: {
|
|
|
|
private: privateACL
|
|
|
|
},
|
|
|
|
|
|
|
|
proxy: {
|
|
|
|
proxify_private_files: enablePrivateProxy
|
|
|
|
},
|
|
|
|
|
2022-10-19 04:43:53 -04:00
|
|
|
streaming_playlists: {
|
|
|
|
bucket_name: this.DEFAULT_SCALEWAY_BUCKET,
|
|
|
|
prefix: `test:server-${serverNumber}-streaming-playlists:`
|
|
|
|
},
|
|
|
|
|
|
|
|
videos: {
|
|
|
|
bucket_name: this.DEFAULT_SCALEWAY_BUCKET,
|
|
|
|
prefix: `test:server-${serverNumber}-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()}/`
|
|
|
|
}
|
2021-08-17 02:26:20 -04:00
|
|
|
}
|