"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ObjectStorageCommand = void 0;
const tslib_1 = require("tslib");
const requests_1 = require("../requests");
const shared_1 = require("../shared");
class ObjectStorageCommand extends shared_1.AbstractCommand {
    static getDefaultMockConfig() {
        return {
            object_storage: {
                enabled: true,
                endpoint: 'http://' + this.getMockEndpointHost(),
                region: this.getMockRegion(),
                credentials: this.getMockCredentialsConfig(),
                streaming_playlists: {
                    bucket_name: this.DEFAULT_PLAYLIST_MOCK_BUCKET
                },
                videos: {
                    bucket_name: this.DEFAULT_WEBTORRENT_MOCK_BUCKET
                }
            }
        };
    }
    static getMockCredentialsConfig() {
        return {
            access_key_id: 'AKIAIOSFODNN7EXAMPLE',
            secret_access_key: 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY'
        };
    }
    static getMockEndpointHost() {
        return 'localhost:9444';
    }
    static getMockRegion() {
        return 'us-east-1';
    }
    static getMockWebTorrentBaseUrl() {
        return `http://${this.DEFAULT_WEBTORRENT_MOCK_BUCKET}.${this.getMockEndpointHost()}/`;
    }
    static getMockPlaylistBaseUrl() {
        return `http://${this.DEFAULT_PLAYLIST_MOCK_BUCKET}.${this.getMockEndpointHost()}/`;
    }
    static prepareDefaultMockBuckets() {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            yield this.createMockBucket(this.DEFAULT_PLAYLIST_MOCK_BUCKET);
            yield this.createMockBucket(this.DEFAULT_WEBTORRENT_MOCK_BUCKET);
        });
    }
    static createMockBucket(name) {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            yield (0, requests_1.makePostBodyRequest)({
                url: this.getMockEndpointHost(),
                path: '/ui/' + name + '?delete',
                expectedStatus: 307
            });
            yield (0, requests_1.makePostBodyRequest)({
                url: this.getMockEndpointHost(),
                path: '/ui/' + name + '?create',
                expectedStatus: 307
            });
            yield (0, requests_1.makePostBodyRequest)({
                url: this.getMockEndpointHost(),
                path: '/ui/' + name + '?make-public',
                expectedStatus: 307
            });
        });
    }
    static getDefaultScalewayConfig(options) {
        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:`
                },
                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()}/`;
    }
}
exports.ObjectStorageCommand = ObjectStorageCommand;
ObjectStorageCommand.DEFAULT_PLAYLIST_MOCK_BUCKET = 'streaming-playlists';
ObjectStorageCommand.DEFAULT_WEBTORRENT_MOCK_BUCKET = 'videos';
ObjectStorageCommand.DEFAULT_SCALEWAY_BUCKET = 'peertube-ci-test';
//# sourceMappingURL=object-storage-command.js.map