From 9ab330b90decf4edf152ff8e1d2948c065766b2c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 19 Oct 2022 10:43:53 +0200 Subject: Use private ACL for private videos in s3 --- .../server/object-storage-command.ts | 91 ++++++++++++++++------ 1 file changed, 69 insertions(+), 22 deletions(-) (limited to 'shared/server-commands/server') diff --git a/shared/server-commands/server/object-storage-command.ts b/shared/server-commands/server/object-storage-command.ts index b4de8f4cb..405e1b043 100644 --- a/shared/server-commands/server/object-storage-command.ts +++ b/shared/server-commands/server/object-storage-command.ts @@ -4,74 +4,121 @@ import { makePostBodyRequest } from '../requests' import { AbstractCommand } from '../shared' export class ObjectStorageCommand extends AbstractCommand { - static readonly DEFAULT_PLAYLIST_BUCKET = 'streaming-playlists' - static readonly DEFAULT_WEBTORRENT_BUCKET = 'videos' + static readonly DEFAULT_PLAYLIST_MOCK_BUCKET = 'streaming-playlists' + static readonly DEFAULT_WEBTORRENT_MOCK_BUCKET = 'videos' - static getDefaultConfig () { + static readonly DEFAULT_SCALEWAY_BUCKET = 'peertube-ci-test' + + // --------------------------------------------------------------------------- + + static getDefaultMockConfig () { return { object_storage: { enabled: true, - endpoint: 'http://' + this.getEndpointHost(), - region: this.getRegion(), + endpoint: 'http://' + this.getMockEndpointHost(), + region: this.getMockRegion(), - credentials: this.getCredentialsConfig(), + credentials: this.getMockCredentialsConfig(), streaming_playlists: { - bucket_name: this.DEFAULT_PLAYLIST_BUCKET + bucket_name: this.DEFAULT_PLAYLIST_MOCK_BUCKET }, videos: { - bucket_name: this.DEFAULT_WEBTORRENT_BUCKET + bucket_name: this.DEFAULT_WEBTORRENT_MOCK_BUCKET } } } } - static getCredentialsConfig () { + static getMockCredentialsConfig () { return { access_key_id: 'AKIAIOSFODNN7EXAMPLE', secret_access_key: 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY' } } - static getEndpointHost () { + static getMockEndpointHost () { return 'localhost:9444' } - static getRegion () { + static getMockRegion () { return 'us-east-1' } - static getWebTorrentBaseUrl () { - return `http://${this.DEFAULT_WEBTORRENT_BUCKET}.${this.getEndpointHost()}/` + static getMockWebTorrentBaseUrl () { + return `http://${this.DEFAULT_WEBTORRENT_MOCK_BUCKET}.${this.getMockEndpointHost()}/` } - static getPlaylistBaseUrl () { - return `http://${this.DEFAULT_PLAYLIST_BUCKET}.${this.getEndpointHost()}/` + static getMockPlaylistBaseUrl () { + return `http://${this.DEFAULT_PLAYLIST_MOCK_BUCKET}.${this.getMockEndpointHost()}/` } - static async prepareDefaultBuckets () { - await this.createBucket(this.DEFAULT_PLAYLIST_BUCKET) - await this.createBucket(this.DEFAULT_WEBTORRENT_BUCKET) + static async prepareDefaultMockBuckets () { + await this.createMockBucket(this.DEFAULT_PLAYLIST_MOCK_BUCKET) + await this.createMockBucket(this.DEFAULT_WEBTORRENT_MOCK_BUCKET) } - static async createBucket (name: string) { + static async createMockBucket (name: string) { await makePostBodyRequest({ - url: this.getEndpointHost(), + url: this.getMockEndpointHost(), path: '/ui/' + name + '?delete', expectedStatus: HttpStatusCode.TEMPORARY_REDIRECT_307 }) await makePostBodyRequest({ - url: this.getEndpointHost(), + url: this.getMockEndpointHost(), path: '/ui/' + name + '?create', expectedStatus: HttpStatusCode.TEMPORARY_REDIRECT_307 }) await makePostBodyRequest({ - url: this.getEndpointHost(), + url: this.getMockEndpointHost(), path: '/ui/' + name + '?make-public', expectedStatus: HttpStatusCode.TEMPORARY_REDIRECT_307 }) } + + // --------------------------------------------------------------------------- + + static getDefaultScalewayConfig (serverNumber: number) { + return { + object_storage: { + enabled: true, + endpoint: this.getScalewayEndpointHost(), + region: this.getScalewayRegion(), + + credentials: this.getScalewayCredentialsConfig(), + + 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()}/` + } } -- cgit v1.2.3