2021-08-17 02:26:20 -04:00
|
|
|
|
|
|
|
import { HttpStatusCode } from '@shared/models'
|
|
|
|
import { makePostBodyRequest } from '../requests'
|
|
|
|
import { AbstractCommand } from '../shared'
|
|
|
|
|
|
|
|
export class ObjectStorageCommand extends AbstractCommand {
|
2022-10-19 04:43:53 -04:00
|
|
|
static readonly DEFAULT_PLAYLIST_MOCK_BUCKET = 'streaming-playlists'
|
|
|
|
static readonly DEFAULT_WEBTORRENT_MOCK_BUCKET = 'videos'
|
2021-08-17 02:26:20 -04:00
|
|
|
|
2022-10-19 04:43:53 -04:00
|
|
|
static readonly DEFAULT_SCALEWAY_BUCKET = 'peertube-ci-test'
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
static getDefaultMockConfig () {
|
2021-08-17 02:26:20 -04:00
|
|
|
return {
|
|
|
|
object_storage: {
|
|
|
|
enabled: true,
|
2022-10-19 04:43:53 -04:00
|
|
|
endpoint: 'http://' + this.getMockEndpointHost(),
|
|
|
|
region: this.getMockRegion(),
|
2021-08-17 02:26:20 -04:00
|
|
|
|
2022-10-19 04:43:53 -04:00
|
|
|
credentials: this.getMockCredentialsConfig(),
|
2021-08-17 02:26:20 -04:00
|
|
|
|
|
|
|
streaming_playlists: {
|
2022-10-19 04:43:53 -04:00
|
|
|
bucket_name: this.DEFAULT_PLAYLIST_MOCK_BUCKET
|
2021-08-17 02:26:20 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
videos: {
|
2022-10-19 04:43:53 -04:00
|
|
|
bucket_name: this.DEFAULT_WEBTORRENT_MOCK_BUCKET
|
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'
|
|
|
|
}
|
|
|
|
|
2022-10-19 04:43:53 -04:00
|
|
|
static getMockWebTorrentBaseUrl () {
|
|
|
|
return `http://${this.DEFAULT_WEBTORRENT_MOCK_BUCKET}.${this.getMockEndpointHost()}/`
|
2021-08-17 02:26:20 -04:00
|
|
|
}
|
|
|
|
|
2022-10-19 04:43:53 -04:00
|
|
|
static getMockPlaylistBaseUrl () {
|
|
|
|
return `http://${this.DEFAULT_PLAYLIST_MOCK_BUCKET}.${this.getMockEndpointHost()}/`
|
2021-08-17 02:26:20 -04:00
|
|
|
}
|
|
|
|
|
2022-10-19 04:43:53 -04:00
|
|
|
static async prepareDefaultMockBuckets () {
|
|
|
|
await this.createMockBucket(this.DEFAULT_PLAYLIST_MOCK_BUCKET)
|
|
|
|
await this.createMockBucket(this.DEFAULT_WEBTORRENT_MOCK_BUCKET)
|
2021-08-17 02:26:20 -04:00
|
|
|
}
|
|
|
|
|
2022-10-19 04:43:53 -04:00
|
|
|
static async createMockBucket (name: string) {
|
2021-08-17 02:26:20 -04:00
|
|
|
await makePostBodyRequest({
|
2022-10-19 04:43:53 -04:00
|
|
|
url: this.getMockEndpointHost(),
|
2021-08-17 02:26:20 -04:00
|
|
|
path: '/ui/' + name + '?delete',
|
|
|
|
expectedStatus: HttpStatusCode.TEMPORARY_REDIRECT_307
|
|
|
|
})
|
|
|
|
|
|
|
|
await makePostBodyRequest({
|
2022-10-19 04:43:53 -04:00
|
|
|
url: this.getMockEndpointHost(),
|
2021-08-17 02:26:20 -04:00
|
|
|
path: '/ui/' + name + '?create',
|
|
|
|
expectedStatus: HttpStatusCode.TEMPORARY_REDIRECT_307
|
|
|
|
})
|
|
|
|
|
|
|
|
await makePostBodyRequest({
|
2022-10-19 04:43:53 -04:00
|
|
|
url: this.getMockEndpointHost(),
|
2021-08-17 02:26:20 -04:00
|
|
|
path: '/ui/' + name + '?make-public',
|
|
|
|
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
|
|
|
}
|