@remotion/cloudrun 4.1.0-alpha10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +13 -0
- package/LICENSE.md +41 -0
- package/dist/admin/bundle-installer.d.ts +1 -0
- package/dist/admin/bundle-installer.js +32 -0
- package/dist/admin/bundle-renderLogic.d.ts +1 -0
- package/dist/admin/bundle-renderLogic.js +39 -0
- package/dist/api/check-if-service-exists.d.ts +18 -0
- package/dist/api/check-if-service-exists.js +49 -0
- package/dist/api/create-bucket.d.ts +13 -0
- package/dist/api/create-bucket.js +18 -0
- package/dist/api/delete-service.d.ts +12 -0
- package/dist/api/delete-service.js +19 -0
- package/dist/api/delete-site.d.ts +13 -0
- package/dist/api/delete-site.js +30 -0
- package/dist/api/deploy-service.d.ts +28 -0
- package/dist/api/deploy-service.js +90 -0
- package/dist/api/deploy-site.d.ts +35 -0
- package/dist/api/deploy-site.js +78 -0
- package/dist/api/download-file.d.ts +13 -0
- package/dist/api/download-file.js +30 -0
- package/dist/api/get-buckets.d.ts +10 -0
- package/dist/api/get-buckets.js +23 -0
- package/dist/api/get-or-create-bucket.d.ts +17 -0
- package/dist/api/get-or-create-bucket.js +42 -0
- package/dist/api/get-regions.d.ts +7 -0
- package/dist/api/get-regions.js +13 -0
- package/dist/api/get-service-info.d.ts +23 -0
- package/dist/api/get-service-info.js +34 -0
- package/dist/api/get-services.d.ts +14 -0
- package/dist/api/get-services.js +49 -0
- package/dist/api/get-sites.d.ts +23 -0
- package/dist/api/get-sites.js +49 -0
- package/dist/api/helpers/IService.d.ts +2 -0
- package/dist/api/helpers/IService.js +2 -0
- package/dist/api/helpers/construct-service-deploy-request.d.ts +32 -0
- package/dist/api/helpers/construct-service-deploy-request.js +36 -0
- package/dist/api/helpers/extract-mem-from-url.d.ts +1 -0
- package/dist/api/helpers/extract-mem-from-url.js +9 -0
- package/dist/api/helpers/extract-time-from-url.d.ts +1 -0
- package/dist/api/helpers/extract-time-from-url.js +13 -0
- package/dist/api/helpers/get-auth-client-for-url.d.ts +1 -0
- package/dist/api/helpers/get-auth-client-for-url.js +15 -0
- package/dist/api/helpers/get-cloud-logging-client.d.ts +1 -0
- package/dist/api/helpers/get-cloud-logging-client.js +15 -0
- package/dist/api/helpers/get-cloud-run-client.d.ts +2 -0
- package/dist/api/helpers/get-cloud-run-client.js +15 -0
- package/dist/api/helpers/get-cloud-storage-client.d.ts +2 -0
- package/dist/api/helpers/get-cloud-storage-client.js +14 -0
- package/dist/api/helpers/get-cloudrun-endpoint.d.ts +14 -0
- package/dist/api/helpers/get-cloudrun-endpoint.js +36 -0
- package/dist/api/helpers/get-resource-manager-client.d.ts +2 -0
- package/dist/api/helpers/get-resource-manager-client.js +15 -0
- package/dist/api/helpers/parse-service-name.d.ts +8 -0
- package/dist/api/helpers/parse-service-name.js +24 -0
- package/dist/api/iam-validation/testPermissions.d.ts +20 -0
- package/dist/api/iam-validation/testPermissions.js +48 -0
- package/dist/api/render-media-on-cloudrun.d.ts +78 -0
- package/dist/api/render-media-on-cloudrun.js +144 -0
- package/dist/api/render-still-on-cloudrun.d.ts +49 -0
- package/dist/api/render-still-on-cloudrun.js +76 -0
- package/dist/api/speculate-service-name.d.ts +13 -0
- package/dist/api/speculate-service-name.js +20 -0
- package/dist/api/test/service-names.test.d.ts +1 -0
- package/dist/api/test/service-names.test.js +28 -0
- package/dist/api/upload-dir.d.ts +18 -0
- package/dist/api/upload-dir.js +81 -0
- package/dist/cli/args.d.ts +19 -0
- package/dist/cli/args.js +11 -0
- package/dist/cli/commands/permissions.d.ts +2 -0
- package/dist/cli/commands/permissions.js +23 -0
- package/dist/cli/commands/regions.d.ts +2 -0
- package/dist/cli/commands/regions.js +10 -0
- package/dist/cli/commands/render/helpers/renderArgsCheck.d.ts +9 -0
- package/dist/cli/commands/render/helpers/renderArgsCheck.js +75 -0
- package/dist/cli/commands/render/index.d.ts +2 -0
- package/dist/cli/commands/render/index.js +228 -0
- package/dist/cli/commands/services/deploy.d.ts +2 -0
- package/dist/cli/commands/services/deploy.js +129 -0
- package/dist/cli/commands/services/index.d.ts +5 -0
- package/dist/cli/commands/services/index.js +64 -0
- package/dist/cli/commands/services/ls.d.ts +2 -0
- package/dist/cli/commands/services/ls.js +40 -0
- package/dist/cli/commands/services/rm.d.ts +2 -0
- package/dist/cli/commands/services/rm.js +63 -0
- package/dist/cli/commands/services/rmall.d.ts +2 -0
- package/dist/cli/commands/services/rmall.js +52 -0
- package/dist/cli/commands/sites/create.d.ts +2 -0
- package/dist/cli/commands/sites/create.js +138 -0
- package/dist/cli/commands/sites/index.d.ts +4 -0
- package/dist/cli/commands/sites/index.js +60 -0
- package/dist/cli/commands/sites/ls.d.ts +2 -0
- package/dist/cli/commands/sites/ls.js +40 -0
- package/dist/cli/commands/sites/rm.d.ts +2 -0
- package/dist/cli/commands/sites/rm.js +59 -0
- package/dist/cli/commands/sites/rmall.d.ts +2 -0
- package/dist/cli/commands/sites/rmall.js +38 -0
- package/dist/cli/commands/still.d.ts +2 -0
- package/dist/cli/commands/still.js +129 -0
- package/dist/cli/get-gcp-region.d.ts +2 -0
- package/dist/cli/get-gcp-region.js +19 -0
- package/dist/cli/help.d.ts +1 -0
- package/dist/cli/help.js +38 -0
- package/dist/cli/helpers/confirm.d.ts +4 -0
- package/dist/cli/helpers/confirm.js +12 -0
- package/dist/cli/helpers/date-string.d.ts +1 -0
- package/dist/cli/helpers/date-string.js +9 -0
- package/dist/cli/helpers/progress-bar.d.ts +23 -0
- package/dist/cli/helpers/progress-bar.js +81 -0
- package/dist/cli/helpers/quit.d.ts +1 -0
- package/dist/cli/helpers/quit.js +7 -0
- package/dist/cli/helpers/yes-or-no.d.ts +4 -0
- package/dist/cli/helpers/yes-or-no.js +44 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +56 -0
- package/dist/cli/log.d.ts +26 -0
- package/dist/cli/log.js +5 -0
- package/dist/defaults.d.ts +1 -0
- package/dist/defaults.js +17 -0
- package/dist/functions/helpers/get-composition-from-body.d.ts +2 -0
- package/dist/functions/helpers/get-composition-from-body.js +27 -0
- package/dist/functions/helpers/io.d.ts +11 -0
- package/dist/functions/helpers/io.js +17 -0
- package/dist/functions/helpers/payloads.d.ts +300 -0
- package/dist/functions/helpers/payloads.js +104 -0
- package/dist/functions/index.d.ts +3 -0
- package/dist/functions/index.js +39 -0
- package/dist/functions/render-media-single-thread.d.ts +3 -0
- package/dist/functions/render-media-single-thread.js +103 -0
- package/dist/functions/render-still-single-thread.d.ts +3 -0
- package/dist/functions/render-still-single-thread.js +82 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +31 -0
- package/dist/internals.d.ts +3 -0
- package/dist/internals.js +7 -0
- package/dist/pricing/gcp-regions.d.ts +5 -0
- package/dist/pricing/gcp-regions.js +77 -0
- package/dist/regions.d.ts +2 -0
- package/dist/regions.js +5 -0
- package/dist/shared/bundle-site.d.ts +2 -0
- package/dist/shared/bundle-site.js +5 -0
- package/dist/shared/constants.d.ts +13 -0
- package/dist/shared/constants.js +18 -0
- package/dist/shared/convert-to-serve-url.d.ts +4 -0
- package/dist/shared/convert-to-serve-url.js +14 -0
- package/dist/shared/docs-url.d.ts +1 -0
- package/dist/shared/docs-url.js +4 -0
- package/dist/shared/generate-service-name.d.ts +5 -0
- package/dist/shared/generate-service-name.js +20 -0
- package/dist/shared/get-etag.d.ts +1 -0
- package/dist/shared/get-etag.js +24 -0
- package/dist/shared/get-storage-operations.d.ts +10 -0
- package/dist/shared/get-storage-operations.js +36 -0
- package/dist/shared/make-storage-key.d.ts +1 -0
- package/dist/shared/make-storage-key.js +11 -0
- package/dist/shared/make-storage-url.d.ts +4 -0
- package/dist/shared/make-storage-url.js +7 -0
- package/dist/shared/random-hash.d.ts +3 -0
- package/dist/shared/random-hash.js +14 -0
- package/dist/shared/read-dir.d.ts +9 -0
- package/dist/shared/read-dir.js +57 -0
- package/dist/shared/sa-permissions.json +64 -0
- package/dist/shared/service-version-string.d.ts +1 -0
- package/dist/shared/service-version-string.js +8 -0
- package/dist/shared/validate-bucketname.d.ts +8 -0
- package/dist/shared/validate-bucketname.js +35 -0
- package/dist/shared/validate-cloudrun-url.d.ts +1 -0
- package/dist/shared/validate-cloudrun-url.js +10 -0
- package/dist/shared/validate-gcp-codec.d.ts +4 -0
- package/dist/shared/validate-gcp-codec.js +29 -0
- package/dist/shared/validate-gcp-region.d.ts +2 -0
- package/dist/shared/validate-gcp-region.js +10 -0
- package/dist/shared/validate-image-remotion-version.d.ts +1 -0
- package/dist/shared/validate-image-remotion-version.js +26 -0
- package/dist/shared/validate-privacy.d.ts +2 -0
- package/dist/shared/validate-privacy.js +12 -0
- package/dist/shared/validate-project-id.d.ts +1 -0
- package/dist/shared/validate-project-id.js +17 -0
- package/dist/shared/validate-region.d.ts +1 -0
- package/dist/shared/validate-region.js +15 -0
- package/dist/shared/validate-retries.d.ts +1 -0
- package/dist/shared/validate-retries.js +21 -0
- package/dist/shared/validate-serveurl.d.ts +1 -0
- package/dist/shared/validate-serveurl.js +30 -0
- package/dist/shared/validate-service-name.d.ts +1 -0
- package/dist/shared/validate-service-name.js +9 -0
- package/dist/shared/validate-site-name.d.ts +1 -0
- package/dist/shared/validate-site-name.js +17 -0
- package/package.json +57 -0
- package/readme.md +3 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getOrCreateBucket = void 0;
|
|
4
|
+
const constants_1 = require("../shared/constants");
|
|
5
|
+
const validate_bucketname_1 = require("../shared/validate-bucketname");
|
|
6
|
+
const create_bucket_1 = require("./create-bucket");
|
|
7
|
+
const get_buckets_1 = require("./get-buckets");
|
|
8
|
+
/**
|
|
9
|
+
* @description Creates a bucket for Remotion Cloud Run in your GCP Project, in a particular region. If one already exists, it will get returned instead.
|
|
10
|
+
* @link https://remotion.dev/docs/cloudrun/getorcreatebucket
|
|
11
|
+
* @param params.region The region in which you want your Storage bucket to reside in.
|
|
12
|
+
* @param params.updateBucketState A function that gets called whenever the state of the bucket changes. This is useful for CLI updates.
|
|
13
|
+
* @returns {Promise<GetOrCreateBucketOutput>} An object containing the `bucketName`.
|
|
14
|
+
*/
|
|
15
|
+
const getOrCreateBucket = async (params) => {
|
|
16
|
+
var _a, _b, _c;
|
|
17
|
+
const { remotionBuckets } = await (0, get_buckets_1.getRemotionStorageBuckets)(params.region);
|
|
18
|
+
if (remotionBuckets.length > 1) {
|
|
19
|
+
throw new Error(`You have multiple buckets (${remotionBuckets
|
|
20
|
+
.map((b) => b.name)
|
|
21
|
+
.join(', ')}) in your Cloud Storage region (${params.region}) starting with "${constants_1.REMOTION_BUCKET_PREFIX}". This is an error, please delete buckets so that you have one maximum.`);
|
|
22
|
+
}
|
|
23
|
+
if (remotionBuckets.length === 1) {
|
|
24
|
+
(_a = params === null || params === void 0 ? void 0 : params.updateBucketState) === null || _a === void 0 ? void 0 : _a.call(params, 'Using existing bucket');
|
|
25
|
+
return {
|
|
26
|
+
bucketName: remotionBuckets[0].name,
|
|
27
|
+
alreadyExisted: true,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
if (params === null || params === void 0 ? void 0 : params.region) {
|
|
31
|
+
(_b = params.updateBucketState) === null || _b === void 0 ? void 0 : _b.call(params, 'Creating new bucket');
|
|
32
|
+
const bucketName = (0, validate_bucketname_1.makeBucketName)();
|
|
33
|
+
await (0, create_bucket_1.createBucket)({
|
|
34
|
+
bucketName,
|
|
35
|
+
region: params.region,
|
|
36
|
+
});
|
|
37
|
+
(_c = params.updateBucketState) === null || _c === void 0 ? void 0 : _c.call(params, 'Created bucket');
|
|
38
|
+
return { bucketName, alreadyExisted: false };
|
|
39
|
+
}
|
|
40
|
+
throw new Error('Bucket creation is required, but no region has been passed.');
|
|
41
|
+
};
|
|
42
|
+
exports.getOrCreateBucket = getOrCreateBucket;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { GcpRegion } from '../pricing/gcp-regions';
|
|
2
|
+
/**
|
|
3
|
+
* @description Gets an array of all supported GCP regions of this release of Remotion Cloudrun.
|
|
4
|
+
* @see [Documentation](https://remotion.dev/docs/cloudrun/getregions)
|
|
5
|
+
* @returns {GcpRegion[]} A list of GCP regions.
|
|
6
|
+
*/
|
|
7
|
+
export declare const getRegions: () => readonly GcpRegion[];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getRegions = void 0;
|
|
4
|
+
const regions_1 = require("../regions");
|
|
5
|
+
/**
|
|
6
|
+
* @description Gets an array of all supported GCP regions of this release of Remotion Cloudrun.
|
|
7
|
+
* @see [Documentation](https://remotion.dev/docs/cloudrun/getregions)
|
|
8
|
+
* @returns {GcpRegion[]} A list of GCP regions.
|
|
9
|
+
*/
|
|
10
|
+
const getRegions = () => {
|
|
11
|
+
return regions_1.GCP_REGIONS;
|
|
12
|
+
};
|
|
13
|
+
exports.getRegions = getRegions;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { GcpRegion } from '../pricing/gcp-regions';
|
|
2
|
+
export declare type ServiceInfo = {
|
|
3
|
+
serviceName: string;
|
|
4
|
+
timeoutInSeconds: number;
|
|
5
|
+
memoryLimit: string;
|
|
6
|
+
cpuLimit: string;
|
|
7
|
+
remotionVersion: string | null;
|
|
8
|
+
uri: string;
|
|
9
|
+
region: GcpRegion;
|
|
10
|
+
consoleUrl: string;
|
|
11
|
+
};
|
|
12
|
+
export declare type GetServiceInfoInput = {
|
|
13
|
+
region: GcpRegion;
|
|
14
|
+
serviceName: string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* @description Given a region and service name, returns information about the service such as version, memory limit and timeout.
|
|
18
|
+
* @see [Documentation](https://remotion.dev/docs/cloudrun/getserviceinfo)
|
|
19
|
+
* @param params.region The region in which the service resides in.
|
|
20
|
+
* @param params.serviceName The name of the service.
|
|
21
|
+
* @returns {Promise<ServiceInfo[]>} An array with the objects containing information about the deployed services.
|
|
22
|
+
*/
|
|
23
|
+
export declare const getServiceInfo: ({ region, serviceName, }: GetServiceInfoInput) => Promise<ServiceInfo>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getServiceInfo = void 0;
|
|
4
|
+
const get_cloud_run_client_1 = require("./helpers/get-cloud-run-client");
|
|
5
|
+
const parse_service_name_1 = require("./helpers/parse-service-name");
|
|
6
|
+
/**
|
|
7
|
+
* @description Given a region and service name, returns information about the service such as version, memory limit and timeout.
|
|
8
|
+
* @see [Documentation](https://remotion.dev/docs/cloudrun/getserviceinfo)
|
|
9
|
+
* @param params.region The region in which the service resides in.
|
|
10
|
+
* @param params.serviceName The name of the service.
|
|
11
|
+
* @returns {Promise<ServiceInfo[]>} An array with the objects containing information about the deployed services.
|
|
12
|
+
*/
|
|
13
|
+
const getServiceInfo = async ({ region, serviceName, }) => {
|
|
14
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
15
|
+
const cloudRunClient = (0, get_cloud_run_client_1.getCloudRunClient)();
|
|
16
|
+
const [service] = await cloudRunClient.getService({
|
|
17
|
+
name: `projects/${process.env.REMOTION_GCP_PROJECT_ID}/locations/${region}/services/${serviceName}`,
|
|
18
|
+
});
|
|
19
|
+
if (!service) {
|
|
20
|
+
throw new Error(`Service ${serviceName} not found`);
|
|
21
|
+
}
|
|
22
|
+
const { region: deployedRegion, remotionVersion, serviceName: deployedServiceName, } = (0, parse_service_name_1.parseServiceName)(service.name, region);
|
|
23
|
+
return {
|
|
24
|
+
serviceName: deployedServiceName,
|
|
25
|
+
timeoutInSeconds: (_b = (_a = service.template) === null || _a === void 0 ? void 0 : _a.timeout) === null || _b === void 0 ? void 0 : _b.seconds,
|
|
26
|
+
memoryLimit: (_f = (_e = (_d = (_c = service.template) === null || _c === void 0 ? void 0 : _c.containers) === null || _d === void 0 ? void 0 : _d[0].resources) === null || _e === void 0 ? void 0 : _e.limits) === null || _f === void 0 ? void 0 : _f.memory,
|
|
27
|
+
cpuLimit: (_k = (_j = (_h = (_g = service.template) === null || _g === void 0 ? void 0 : _g.containers) === null || _h === void 0 ? void 0 : _h[0].resources) === null || _j === void 0 ? void 0 : _j.limits) === null || _k === void 0 ? void 0 : _k.cpu,
|
|
28
|
+
remotionVersion,
|
|
29
|
+
uri: service.uri,
|
|
30
|
+
region: deployedRegion,
|
|
31
|
+
consoleUrl: `https://console.cloud.google.com/run/detail/${deployedRegion}/${deployedServiceName}/logs`,
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
exports.getServiceInfo = getServiceInfo;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { GcpRegion } from '../pricing/gcp-regions';
|
|
2
|
+
import type { ServiceInfo } from './get-service-info';
|
|
3
|
+
export declare type GetServicesInput = {
|
|
4
|
+
region: GcpRegion;
|
|
5
|
+
compatibleOnly: boolean;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* @description Lists Remotion Cloud Run render services deployed to GCP Cloud Run.
|
|
9
|
+
* @see [Documentation](https://remotion.dev/docs/cloudrun/getservices)
|
|
10
|
+
* @param params.region The region of which the services should be listed.
|
|
11
|
+
* @param params.compatibleOnly Whether only services compatible with the installed version of Remotion Cloud Run should be returned.
|
|
12
|
+
* @returns {Promise<ServiceInfo[]>} An array with the objects containing information about the deployed services.
|
|
13
|
+
*/
|
|
14
|
+
export declare const getServices: (params: GetServicesInput) => Promise<ServiceInfo[]>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getServices = void 0;
|
|
4
|
+
const constants_1 = require("../shared/constants");
|
|
5
|
+
const service_version_string_1 = require("../shared/service-version-string");
|
|
6
|
+
const get_cloud_run_client_1 = require("./helpers/get-cloud-run-client");
|
|
7
|
+
const parse_service_name_1 = require("./helpers/parse-service-name");
|
|
8
|
+
/**
|
|
9
|
+
* @description Lists Remotion Cloud Run render services deployed to GCP Cloud Run.
|
|
10
|
+
* @see [Documentation](https://remotion.dev/docs/cloudrun/getservices)
|
|
11
|
+
* @param params.region The region of which the services should be listed.
|
|
12
|
+
* @param params.compatibleOnly Whether only services compatible with the installed version of Remotion Cloud Run should be returned.
|
|
13
|
+
* @returns {Promise<ServiceInfo[]>} An array with the objects containing information about the deployed services.
|
|
14
|
+
*/
|
|
15
|
+
const getServices = async (params) => {
|
|
16
|
+
const cloudRunClient = (0, get_cloud_run_client_1.getCloudRunClient)();
|
|
17
|
+
const parent = (0, parse_service_name_1.getGcpParent)(params.region);
|
|
18
|
+
const [services] = await cloudRunClient.listServices({
|
|
19
|
+
parent,
|
|
20
|
+
});
|
|
21
|
+
let remotionServices = [];
|
|
22
|
+
if (params.compatibleOnly) {
|
|
23
|
+
remotionServices = services.filter((s) => {
|
|
24
|
+
var _a;
|
|
25
|
+
return (_a = s.name) === null || _a === void 0 ? void 0 : _a.startsWith(`${parent}/services/${constants_1.RENDER_SERVICE_PREFIX}-${(0, service_version_string_1.serviceVersionString)()}-`);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
remotionServices = services.filter((s) => {
|
|
30
|
+
var _a;
|
|
31
|
+
return (_a = s.name) === null || _a === void 0 ? void 0 : _a.startsWith(`${parent}/services/${constants_1.RENDER_SERVICE_PREFIX}-`);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return remotionServices.map((service) => {
|
|
35
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
36
|
+
const { consoleUrl, region, remotionVersion, serviceName } = (0, parse_service_name_1.parseServiceName)(service.name, params.region);
|
|
37
|
+
return {
|
|
38
|
+
consoleUrl,
|
|
39
|
+
region,
|
|
40
|
+
remotionVersion,
|
|
41
|
+
serviceName,
|
|
42
|
+
timeoutInSeconds: (_b = (_a = service.template) === null || _a === void 0 ? void 0 : _a.timeout) === null || _b === void 0 ? void 0 : _b.seconds,
|
|
43
|
+
memoryLimit: (_f = (_e = (_d = (_c = service.template) === null || _c === void 0 ? void 0 : _c.containers) === null || _d === void 0 ? void 0 : _d[0].resources) === null || _e === void 0 ? void 0 : _e.limits) === null || _f === void 0 ? void 0 : _f.memory,
|
|
44
|
+
cpuLimit: (_k = (_j = (_h = (_g = service.template) === null || _g === void 0 ? void 0 : _g.containers) === null || _h === void 0 ? void 0 : _h[0].resources) === null || _j === void 0 ? void 0 : _j.limits) === null || _k === void 0 ? void 0 : _k.cpu,
|
|
45
|
+
uri: service.uri,
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
exports.getServices = getServices;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { GcpRegion } from '../pricing/gcp-regions';
|
|
2
|
+
export declare type Site = {
|
|
3
|
+
bucketName: string;
|
|
4
|
+
id: string;
|
|
5
|
+
serveUrl: string;
|
|
6
|
+
bucketRegion: GcpRegion;
|
|
7
|
+
};
|
|
8
|
+
export declare type BucketWithLocation = {
|
|
9
|
+
name: string;
|
|
10
|
+
creationDate: number;
|
|
11
|
+
region: GcpRegion;
|
|
12
|
+
};
|
|
13
|
+
export declare type GetSitesOutput = {
|
|
14
|
+
sites: Site[];
|
|
15
|
+
buckets: BucketWithLocation[];
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* @description Gets all the deployed sites for a certain GCP project, within the specified region.
|
|
19
|
+
* @see [Documentation](https://remotion.dev/docs/cloudrun/getsites)
|
|
20
|
+
* @param {GcpRegion} params.region The GCP region that you want to query for.
|
|
21
|
+
* @returns {Promise<GetSitesOutput>} A Promise containing an object with `sites` and `bucket` keys. Consult documentation for details.
|
|
22
|
+
*/
|
|
23
|
+
export declare const getSites: (region: GcpRegion | 'all regions') => Promise<GetSitesOutput>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSites = void 0;
|
|
4
|
+
const constants_1 = require("../shared/constants");
|
|
5
|
+
const get_cloud_storage_client_1 = require("./helpers/get-cloud-storage-client");
|
|
6
|
+
/**
|
|
7
|
+
* @description Gets all the deployed sites for a certain GCP project, within the specified region.
|
|
8
|
+
* @see [Documentation](https://remotion.dev/docs/cloudrun/getsites)
|
|
9
|
+
* @param {GcpRegion} params.region The GCP region that you want to query for.
|
|
10
|
+
* @returns {Promise<GetSitesOutput>} A Promise containing an object with `sites` and `bucket` keys. Consult documentation for details.
|
|
11
|
+
*/
|
|
12
|
+
const getSites = async (region) => {
|
|
13
|
+
var _a, _b;
|
|
14
|
+
const cloudStorageClient = (0, get_cloud_storage_client_1.getCloudStorageClient)();
|
|
15
|
+
const buckets = [];
|
|
16
|
+
const sites = [];
|
|
17
|
+
const [fetchedBuckets] = await cloudStorageClient.getBuckets();
|
|
18
|
+
for (const bucket of fetchedBuckets) {
|
|
19
|
+
if (((_a = bucket.name) === null || _a === void 0 ? void 0 : _a.startsWith(constants_1.REMOTION_BUCKET_PREFIX)) &&
|
|
20
|
+
(region === 'all regions' ||
|
|
21
|
+
bucket.metadata.location === region.toUpperCase())) {
|
|
22
|
+
const bucketObject = {
|
|
23
|
+
name: bucket.name,
|
|
24
|
+
creationDate: new Date((_b = bucket.metadata) === null || _b === void 0 ? void 0 : _b.timeCreated).getTime(),
|
|
25
|
+
region: bucket.metadata.location.toLowerCase(),
|
|
26
|
+
};
|
|
27
|
+
buckets.push(bucketObject);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
for (const bucket of buckets) {
|
|
31
|
+
const [, , apiResponse] = await cloudStorageClient
|
|
32
|
+
.bucket(bucket.name)
|
|
33
|
+
.getFiles({ autoPaginate: false, delimiter: '/', prefix: 'sites/' });
|
|
34
|
+
if (!apiResponse.prefixes) {
|
|
35
|
+
continue; // no sites folder within bucket
|
|
36
|
+
}
|
|
37
|
+
for (const prefix of apiResponse.prefixes) {
|
|
38
|
+
const sitePath = prefix.split('/');
|
|
39
|
+
sites.push({
|
|
40
|
+
bucketName: bucket.name,
|
|
41
|
+
id: sitePath[1],
|
|
42
|
+
serveUrl: `https://storage.googleapis.com/${bucket.name}/${prefix}index.html`,
|
|
43
|
+
bucketRegion: bucket.region,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return { sites, buckets };
|
|
48
|
+
};
|
|
49
|
+
exports.getSites = getSites;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
declare enum ExecutionEnvironment {
|
|
2
|
+
EXECUTION_ENVIRONMENT_UNSPECIFIED = 0,
|
|
3
|
+
EXECUTION_ENVIRONMENT_GEN1 = 1,
|
|
4
|
+
EXECUTION_ENVIRONMENT_GEN2 = 2
|
|
5
|
+
}
|
|
6
|
+
export declare const constructServiceTemplate: ({ memoryLimit, cpuLimit, timeoutSeconds, minInstances, maxInstances, }: {
|
|
7
|
+
memoryLimit: string;
|
|
8
|
+
cpuLimit: string;
|
|
9
|
+
timeoutSeconds: number;
|
|
10
|
+
minInstances: number;
|
|
11
|
+
maxInstances: number;
|
|
12
|
+
}) => {
|
|
13
|
+
scaling: {
|
|
14
|
+
minInstanceCount: number;
|
|
15
|
+
maxInstanceCount: number;
|
|
16
|
+
};
|
|
17
|
+
timeout: {
|
|
18
|
+
seconds: number;
|
|
19
|
+
};
|
|
20
|
+
containers: {
|
|
21
|
+
image: string;
|
|
22
|
+
resources: {
|
|
23
|
+
limits: {
|
|
24
|
+
memory: string;
|
|
25
|
+
cpu: string;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
}[];
|
|
29
|
+
maxInstanceRequestConcurrency: number;
|
|
30
|
+
executionEnvironment: ExecutionEnvironment;
|
|
31
|
+
};
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.constructServiceTemplate = void 0;
|
|
4
|
+
const version_1 = require("remotion/version");
|
|
5
|
+
// taken from within the @google-cloud/run package, can't import it directly
|
|
6
|
+
var ExecutionEnvironment;
|
|
7
|
+
(function (ExecutionEnvironment) {
|
|
8
|
+
ExecutionEnvironment[ExecutionEnvironment["EXECUTION_ENVIRONMENT_UNSPECIFIED"] = 0] = "EXECUTION_ENVIRONMENT_UNSPECIFIED";
|
|
9
|
+
ExecutionEnvironment[ExecutionEnvironment["EXECUTION_ENVIRONMENT_GEN1"] = 1] = "EXECUTION_ENVIRONMENT_GEN1";
|
|
10
|
+
ExecutionEnvironment[ExecutionEnvironment["EXECUTION_ENVIRONMENT_GEN2"] = 2] = "EXECUTION_ENVIRONMENT_GEN2";
|
|
11
|
+
})(ExecutionEnvironment || (ExecutionEnvironment = {}));
|
|
12
|
+
const constructServiceTemplate = ({ memoryLimit, cpuLimit, timeoutSeconds, minInstances, maxInstances, }) => {
|
|
13
|
+
return {
|
|
14
|
+
scaling: {
|
|
15
|
+
minInstanceCount: minInstances,
|
|
16
|
+
maxInstanceCount: maxInstances,
|
|
17
|
+
},
|
|
18
|
+
timeout: {
|
|
19
|
+
seconds: timeoutSeconds,
|
|
20
|
+
},
|
|
21
|
+
containers: [
|
|
22
|
+
{
|
|
23
|
+
image: `us-docker.pkg.dev/remotion-dev/production/render:${version_1.VERSION}`,
|
|
24
|
+
resources: {
|
|
25
|
+
limits: {
|
|
26
|
+
memory: memoryLimit,
|
|
27
|
+
cpu: cpuLimit,
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
maxInstanceRequestConcurrency: 1,
|
|
33
|
+
executionEnvironment: ExecutionEnvironment.EXECUTION_ENVIRONMENT_GEN1,
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
exports.constructServiceTemplate = constructServiceTemplate;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function extractMemoryFromURL(url: string): string | undefined;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractMemoryFromURL = void 0;
|
|
4
|
+
function extractMemoryFromURL(url) {
|
|
5
|
+
const regex = /mem(.*?)-/;
|
|
6
|
+
const match = url.match(regex);
|
|
7
|
+
return match ? match[1] : undefined;
|
|
8
|
+
}
|
|
9
|
+
exports.extractMemoryFromURL = extractMemoryFromURL;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function extractTimeoutFromURL(url: string): number | undefined;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractTimeoutFromURL = void 0;
|
|
4
|
+
function extractTimeoutFromURL(url) {
|
|
5
|
+
const firstTIndex = url.indexOf('-t');
|
|
6
|
+
if (firstTIndex !== -1) {
|
|
7
|
+
const substrAfterT = url.substring(firstTIndex + 2);
|
|
8
|
+
const numberStr = substrAfterT.split('-')[0];
|
|
9
|
+
return parseInt(numberStr, 10);
|
|
10
|
+
}
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
exports.extractTimeoutFromURL = extractTimeoutFromURL;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getAuthClientForUrl: (url: string) => Promise<import("google-auth-library").IdTokenClient>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAuthClientForUrl = void 0;
|
|
4
|
+
const google_auth_library_1 = require("google-auth-library");
|
|
5
|
+
const getAuthClientForUrl = async (url) => {
|
|
6
|
+
const auth = new google_auth_library_1.GoogleAuth({
|
|
7
|
+
credentials: {
|
|
8
|
+
client_email: process.env.REMOTION_GCP_CLIENT_EMAIL,
|
|
9
|
+
private_key: process.env.REMOTION_GCP_PRIVATE_KEY,
|
|
10
|
+
},
|
|
11
|
+
});
|
|
12
|
+
const client = await auth.getIdTokenClient(url);
|
|
13
|
+
return client;
|
|
14
|
+
};
|
|
15
|
+
exports.getAuthClientForUrl = getAuthClientForUrl;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getCloudLoggingClient: () => any;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCloudLoggingClient = void 0;
|
|
4
|
+
const logging_1 = require("@google-cloud/logging");
|
|
5
|
+
const { LoggingServiceV2Client } = logging_1.v2;
|
|
6
|
+
const getCloudLoggingClient = () => {
|
|
7
|
+
return new LoggingServiceV2Client({
|
|
8
|
+
projectId: process.env.REMOTION_GCP_PROJECT_ID,
|
|
9
|
+
credentials: {
|
|
10
|
+
client_email: process.env.REMOTION_GCP_CLIENT_EMAIL,
|
|
11
|
+
private_key: process.env.REMOTION_GCP_PRIVATE_KEY,
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
exports.getCloudLoggingClient = getCloudLoggingClient;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCloudRunClient = void 0;
|
|
4
|
+
const run_1 = require("@google-cloud/run");
|
|
5
|
+
const { ServicesClient } = run_1.v2;
|
|
6
|
+
const getCloudRunClient = () => {
|
|
7
|
+
return new ServicesClient({
|
|
8
|
+
projectId: process.env.REMOTION_GCP_PROJECT_ID,
|
|
9
|
+
credentials: {
|
|
10
|
+
client_email: process.env.REMOTION_GCP_CLIENT_EMAIL,
|
|
11
|
+
private_key: process.env.REMOTION_GCP_PRIVATE_KEY,
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
exports.getCloudRunClient = getCloudRunClient;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCloudStorageClient = void 0;
|
|
4
|
+
const storage_1 = require("@google-cloud/storage");
|
|
5
|
+
const getCloudStorageClient = () => {
|
|
6
|
+
return new storage_1.Storage({
|
|
7
|
+
projectId: process.env.REMOTION_GCP_PROJECT_ID,
|
|
8
|
+
credentials: {
|
|
9
|
+
client_email: process.env.REMOTION_GCP_CLIENT_EMAIL,
|
|
10
|
+
private_key: process.env.REMOTION_GCP_PRIVATE_KEY,
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
exports.getCloudStorageClient = getCloudStorageClient;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare type getCloudrunEndpointInput = {
|
|
2
|
+
cloudRunUrl?: string;
|
|
3
|
+
serviceName?: string;
|
|
4
|
+
region?: string;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* @description If the Cloud Run URL is passed, it will be validated and returned. If the service name is passed, the service will be looked up and the endpoint will be returned.
|
|
8
|
+
* @see [Documentation](https://remotion.dev/docs/lambda/renderMediaOnGcp)
|
|
9
|
+
* @param params.cloudRunUrl The url of the Cloud Run service
|
|
10
|
+
* @param params.serviceName The name of the Cloud Run service
|
|
11
|
+
* @param params.region The region of the service - required if the serviceName is passed.
|
|
12
|
+
* @returns {Promise<string>} Returns the endpoint of the Cloud Run service
|
|
13
|
+
*/
|
|
14
|
+
export declare const getCloudrunEndpoint: ({ cloudRunUrl, serviceName, region, }: getCloudrunEndpointInput) => Promise<string>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCloudrunEndpoint = void 0;
|
|
4
|
+
const validate_cloudrun_url_1 = require("../../shared/validate-cloudrun-url");
|
|
5
|
+
const validate_region_1 = require("../../shared/validate-region");
|
|
6
|
+
const validate_service_name_1 = require("../../shared/validate-service-name");
|
|
7
|
+
const get_service_info_1 = require("../get-service-info");
|
|
8
|
+
/**
|
|
9
|
+
* @description If the Cloud Run URL is passed, it will be validated and returned. If the service name is passed, the service will be looked up and the endpoint will be returned.
|
|
10
|
+
* @see [Documentation](https://remotion.dev/docs/lambda/renderMediaOnGcp)
|
|
11
|
+
* @param params.cloudRunUrl The url of the Cloud Run service
|
|
12
|
+
* @param params.serviceName The name of the Cloud Run service
|
|
13
|
+
* @param params.region The region of the service - required if the serviceName is passed.
|
|
14
|
+
* @returns {Promise<string>} Returns the endpoint of the Cloud Run service
|
|
15
|
+
*/
|
|
16
|
+
const getCloudrunEndpoint = async ({ cloudRunUrl, serviceName, region, }) => {
|
|
17
|
+
if (!cloudRunUrl && !serviceName)
|
|
18
|
+
throw new Error('Either cloudRunUrl or serviceName must be provided');
|
|
19
|
+
if (cloudRunUrl && serviceName)
|
|
20
|
+
throw new Error('Either cloudRunUrl or serviceName must be provided, not both');
|
|
21
|
+
let cloudRunEndpoint = '';
|
|
22
|
+
if (cloudRunUrl) {
|
|
23
|
+
(0, validate_cloudrun_url_1.validateCloudRunUrl)(cloudRunUrl);
|
|
24
|
+
cloudRunEndpoint = cloudRunUrl;
|
|
25
|
+
}
|
|
26
|
+
if (serviceName) {
|
|
27
|
+
if (!region)
|
|
28
|
+
throw new Error('If determining Cloudrun Url from serviceName, region must be provided');
|
|
29
|
+
(0, validate_service_name_1.validateServiceName)(serviceName);
|
|
30
|
+
const validatedRegion = (0, validate_region_1.validateRegion)(region);
|
|
31
|
+
const { uri } = await (0, get_service_info_1.getServiceInfo)({ serviceName, region: validatedRegion });
|
|
32
|
+
cloudRunEndpoint = uri;
|
|
33
|
+
}
|
|
34
|
+
return cloudRunEndpoint;
|
|
35
|
+
};
|
|
36
|
+
exports.getCloudrunEndpoint = getCloudrunEndpoint;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getResourceManagerClient = void 0;
|
|
4
|
+
const resource_manager_1 = require("@google-cloud/resource-manager");
|
|
5
|
+
const { ProjectsClient } = resource_manager_1.v3;
|
|
6
|
+
const getResourceManagerClient = () => {
|
|
7
|
+
return new ProjectsClient({
|
|
8
|
+
projectId: process.env.REMOTION_GCP_PROJECT_ID,
|
|
9
|
+
credentials: {
|
|
10
|
+
client_email: process.env.REMOTION_GCP_CLIENT_EMAIL,
|
|
11
|
+
private_key: process.env.REMOTION_GCP_PRIVATE_KEY,
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
exports.getResourceManagerClient = getResourceManagerClient;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { GcpRegion } from '../../pricing/gcp-regions';
|
|
2
|
+
export declare const getGcpParent: (region: GcpRegion) => string;
|
|
3
|
+
export declare const parseServiceName: (fullServiceName: string, region: GcpRegion) => {
|
|
4
|
+
serviceName: string;
|
|
5
|
+
remotionVersion: string;
|
|
6
|
+
region: "asia-east1" | "asia-east2" | "asia-northeast1" | "asia-northeast2" | "asia-northeast3" | "asia-south1" | "asia-south2" | "asia-southeast1" | "asia-southeast2" | "australia-southeast1" | "australia-southeast2" | "europe-central2" | "europe-north1" | "europe-southwest1" | "europe-west1" | "europe-west2" | "europe-west3" | "europe-west4" | "europe-west6" | "europe-west8" | "europe-west9" | "me-west1" | "northamerica-northeast1" | "northamerica-northeast2" | "southamerica-east1" | "southamerica-west1" | "us-central1" | "us-east1" | "us-east4" | "us-east5" | "us-south1" | "us-west1" | "us-west2" | "us-west3" | "us-west4";
|
|
7
|
+
consoleUrl: string;
|
|
8
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseServiceName = exports.getGcpParent = void 0;
|
|
4
|
+
const getGcpParent = (region) => {
|
|
5
|
+
const parent = `projects/${process.env.REMOTION_GCP_PROJECT_ID}/locations/${region}`;
|
|
6
|
+
return parent;
|
|
7
|
+
};
|
|
8
|
+
exports.getGcpParent = getGcpParent;
|
|
9
|
+
const parseServiceName = (fullServiceName, region) => {
|
|
10
|
+
const parent = (0, exports.getGcpParent)(region);
|
|
11
|
+
const shortServiceName = fullServiceName.replace(parent + '/services/', '');
|
|
12
|
+
const deployedRegion = fullServiceName.split('/')[3];
|
|
13
|
+
const matched = shortServiceName.match(/remotion-(.*)-mem([0-9])/);
|
|
14
|
+
if (!matched) {
|
|
15
|
+
throw new Error(`Could not parse service name ${shortServiceName}`);
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
serviceName: shortServiceName,
|
|
19
|
+
remotionVersion: matched[1],
|
|
20
|
+
region: deployedRegion,
|
|
21
|
+
consoleUrl: `https://console.cloud.google.com/run/detail/${deployedRegion}/${shortServiceName}/logs`,
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
exports.parseServiceName = parseServiceName;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare const logPermissionOutput: (output: TestResult) => string;
|
|
2
|
+
declare type TestResult = {
|
|
3
|
+
decision: true | false;
|
|
4
|
+
permissionName: string;
|
|
5
|
+
};
|
|
6
|
+
declare type TestPermissionsInput = {
|
|
7
|
+
onTest: (result: TestResult) => void;
|
|
8
|
+
};
|
|
9
|
+
declare type TestPermissionsOutput = {
|
|
10
|
+
results: TestResult[];
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* @description Test the permissions on the service account match the permissions required.
|
|
14
|
+
* @see [Remotion-Documentation](http://remotion.dev/docs/cloudrun/testpermissions)
|
|
15
|
+
* @see [Cloudrun-Documentation](https://cloud.google.com/resource-manager/reference/rest/v3/projects/testIamPermissions)
|
|
16
|
+
* @param {(result: TestResult) => void} params.onTest Function to run on each test result
|
|
17
|
+
* @returns {Promise<TestPermissionsOutput>} Returns array of TestResult objects
|
|
18
|
+
*/
|
|
19
|
+
export declare const testPermissions: (params?: TestPermissionsInput) => Promise<TestPermissionsOutput>;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.testPermissions = exports.logPermissionOutput = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const get_resource_manager_client_1 = require("../helpers/get-resource-manager-client");
|
|
10
|
+
const logPermissionOutput = (output) => {
|
|
11
|
+
return [output.decision ? '✅' : '❌', output.permissionName].join(' ');
|
|
12
|
+
};
|
|
13
|
+
exports.logPermissionOutput = logPermissionOutput;
|
|
14
|
+
/**
|
|
15
|
+
* @description Test the permissions on the service account match the permissions required.
|
|
16
|
+
* @see [Remotion-Documentation](http://remotion.dev/docs/cloudrun/testpermissions)
|
|
17
|
+
* @see [Cloudrun-Documentation](https://cloud.google.com/resource-manager/reference/rest/v3/projects/testIamPermissions)
|
|
18
|
+
* @param {(result: TestResult) => void} params.onTest Function to run on each test result
|
|
19
|
+
* @returns {Promise<TestPermissionsOutput>} Returns array of TestResult objects
|
|
20
|
+
*/
|
|
21
|
+
const testPermissions = async (params) => {
|
|
22
|
+
const resourceManagerClient = (0, get_resource_manager_client_1.getResourceManagerClient)();
|
|
23
|
+
const saPermissions = JSON.parse(fs_1.default.readFileSync(path_1.default.join(__dirname, '../../shared/sa-permissions.json'), 'utf-8'));
|
|
24
|
+
const permissionList = saPermissions.list.map((permission) => permission.name);
|
|
25
|
+
const response = await resourceManagerClient.testIamPermissions({
|
|
26
|
+
resource: `projects/${process.env.REMOTION_GCP_PROJECT_ID}`,
|
|
27
|
+
permissions: permissionList,
|
|
28
|
+
});
|
|
29
|
+
const returnedPermissions = response[0].permissions;
|
|
30
|
+
if (!returnedPermissions) {
|
|
31
|
+
throw new Error('No permissions returned from the testIamPermissions call.');
|
|
32
|
+
}
|
|
33
|
+
const results = [];
|
|
34
|
+
saPermissions.list.forEach((permission) => {
|
|
35
|
+
if (returnedPermissions.includes(permission.name)) {
|
|
36
|
+
const thisResult = { decision: true, permissionName: permission.name };
|
|
37
|
+
results.push(thisResult);
|
|
38
|
+
params === null || params === void 0 ? void 0 : params.onTest(thisResult);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
const thisResult = { decision: false, permissionName: permission.name };
|
|
42
|
+
results.push(thisResult);
|
|
43
|
+
params === null || params === void 0 ? void 0 : params.onTest(thisResult);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
return { results };
|
|
47
|
+
};
|
|
48
|
+
exports.testPermissions = testPermissions;
|