From 3cc9dd0ccc3ab9927401c5375eef3560ec4f89a5 Mon Sep 17 00:00:00 2001 From: Nicholas Cook Date: Fri, 10 Jun 2022 15:20:10 -0700 Subject: [PATCH] docs(samples): add Video Stitcher slate and CDN key code samples and tests (#6) Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [X] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/nodejs-video-stitcher/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [X] Ensure the tests and linter pass - [ ] Code coverage does not decrease (if any source code was changed) - [ ] Appropriate docs were updated (if necessary) Fixes b:202972969 --- media/video-stitcher/createCdnKey.js | 79 ++++++++ media/video-stitcher/createSlate.js | 56 ++++++ media/video-stitcher/deleteCdnKey.js | 51 ++++++ media/video-stitcher/deleteSlate.js | 51 ++++++ media/video-stitcher/getCdnKey.js | 51 ++++++ media/video-stitcher/getSlate.js | 51 ++++++ media/video-stitcher/listCdnKeys.js | 51 ++++++ media/video-stitcher/listSlates.js | 51 ++++++ media/video-stitcher/package.json | 3 +- media/video-stitcher/test/stitcher.test.js | 202 +++++++++++++++++++++ media/video-stitcher/updateCdnKey.js | 84 +++++++++ media/video-stitcher/updateSlate.js | 59 ++++++ 12 files changed, 788 insertions(+), 1 deletion(-) create mode 100644 media/video-stitcher/createCdnKey.js create mode 100644 media/video-stitcher/createSlate.js create mode 100644 media/video-stitcher/deleteCdnKey.js create mode 100644 media/video-stitcher/deleteSlate.js create mode 100644 media/video-stitcher/getCdnKey.js create mode 100644 media/video-stitcher/getSlate.js create mode 100644 media/video-stitcher/listCdnKeys.js create mode 100644 media/video-stitcher/listSlates.js create mode 100644 media/video-stitcher/test/stitcher.test.js create mode 100644 media/video-stitcher/updateCdnKey.js create mode 100644 media/video-stitcher/updateSlate.js diff --git a/media/video-stitcher/createCdnKey.js b/media/video-stitcher/createCdnKey.js new file mode 100644 index 0000000000..bb456575be --- /dev/null +++ b/media/video-stitcher/createCdnKey.js @@ -0,0 +1,79 @@ +/** + * Copyright 2022, Google, Inc. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +'use strict'; + +function main( + projectId, + location, + cdnKeyId, + hostname, + gCdnKeyname, + gCdnPrivateKey, + akamaiTokenKey = '' +) { + // [START video_stitcher_create_cdn_key] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + // projectId = 'my-project-id'; + // location = 'us-central1'; + // cdnKeyId = 'my-cdn-key'; + // hostname = 'cdn.example.com'; + // gCdnKeyname = 'gcdn-key'; + // gCdnPrivateKey = 'VGhpcyBpcyBhIHRlc3Qgc3RyaW5nLg=='; + // akamaiTokenKey = 'VGhpcyBpcyBhIHRlc3Qgc3RyaW5nLg=='; + + // Imports the Video Stitcher library + const {VideoStitcherServiceClient} = + require('@google-cloud/video-stitcher').v1; + // Instantiates a client + const stitcherClient = new VideoStitcherServiceClient(); + + async function createCdnKey() { + // Construct request + const request = { + parent: stitcherClient.locationPath(projectId, location), + cdnKey: { + hostname: hostname, + }, + cdnKeyId: cdnKeyId, + }; + + if (akamaiTokenKey !== '') { + request.cdnKey.akamaiCdnKey = { + tokenKey: akamaiTokenKey, + }; + } else { + request.cdnKey.googleCdnKey = { + keyName: gCdnKeyname, + privateKey: gCdnPrivateKey, + }; + } + + const [cdnKey] = await stitcherClient.createCdnKey(request); + console.log(`CDN key: ${cdnKey.name}`); + } + + createCdnKey(); + // [END video_stitcher_create_cdn_key] +} + +// node createCdnKey.js +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/media/video-stitcher/createSlate.js b/media/video-stitcher/createSlate.js new file mode 100644 index 0000000000..763aaed14c --- /dev/null +++ b/media/video-stitcher/createSlate.js @@ -0,0 +1,56 @@ +/** + * Copyright 2022, Google, Inc. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +'use strict'; + +function main(projectId, location, slateId, slateUri) { + // [START video_stitcher_create_slate] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + // projectId = 'my-project-id'; + // location = 'us-central1'; + // slateId = 'my-slate'; + // slateUri = 'https://my-slate-uri/test.mp4'; + + // Imports the Video Stitcher library + const {VideoStitcherServiceClient} = + require('@google-cloud/video-stitcher').v1; + // Instantiates a client + const stitcherClient = new VideoStitcherServiceClient(); + + async function createSlate() { + // Construct request + const request = { + parent: stitcherClient.locationPath(projectId, location), + slate: { + uri: slateUri, + }, + slateId: slateId, + }; + const [slate] = await stitcherClient.createSlate(request); + console.log(`Slate: ${slate.name}`); + } + + createSlate(); + // [END video_stitcher_create_slate] +} + +// node createSlate.js +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/media/video-stitcher/deleteCdnKey.js b/media/video-stitcher/deleteCdnKey.js new file mode 100644 index 0000000000..2e71cac996 --- /dev/null +++ b/media/video-stitcher/deleteCdnKey.js @@ -0,0 +1,51 @@ +/** + * Copyright 2022, Google, Inc. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +'use strict'; + +function main(projectId, location, cdnKeyId) { + // [START video_stitcher_delete_cdn_key] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + // projectId = 'my-project-id'; + // location = 'us-central1'; + // cdnKeyId = 'my-cdn-key'; + + // Imports the Video Stitcher library + const {VideoStitcherServiceClient} = + require('@google-cloud/video-stitcher').v1; + // Instantiates a client + const stitcherClient = new VideoStitcherServiceClient(); + + async function deleteCdnKey() { + // Construct request + const request = { + name: stitcherClient.cdnKeyPath(projectId, location, cdnKeyId), + }; + await stitcherClient.deleteCdnKey(request); + console.log('Deleted CDN key'); + } + + deleteCdnKey(); + // [END video_stitcher_delete_cdn_key] +} + +// node deleteCdnKey.js +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/media/video-stitcher/deleteSlate.js b/media/video-stitcher/deleteSlate.js new file mode 100644 index 0000000000..0dd0536b0a --- /dev/null +++ b/media/video-stitcher/deleteSlate.js @@ -0,0 +1,51 @@ +/** + * Copyright 2022, Google, Inc. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +'use strict'; + +function main(projectId, location, slateId) { + // [START video_stitcher_delete_slate] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + // projectId = 'my-project-id'; + // location = 'us-central1'; + // slateId = 'my-slate'; + + // Imports the Video Stitcher library + const {VideoStitcherServiceClient} = + require('@google-cloud/video-stitcher').v1; + // Instantiates a client + const stitcherClient = new VideoStitcherServiceClient(); + + async function deleteSlate() { + // Construct request + const request = { + name: stitcherClient.slatePath(projectId, location, slateId), + }; + await stitcherClient.deleteSlate(request); + console.log('Deleted slate'); + } + + deleteSlate(); + // [END video_stitcher_delete_slate] +} + +// node deleteSlate.js +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/media/video-stitcher/getCdnKey.js b/media/video-stitcher/getCdnKey.js new file mode 100644 index 0000000000..57a27c6de2 --- /dev/null +++ b/media/video-stitcher/getCdnKey.js @@ -0,0 +1,51 @@ +/** + * Copyright 2022, Google, Inc. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +'use strict'; + +function main(projectId, location, cdnKeyId) { + // [START video_stitcher_get_cdn_key] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + // projectId = 'my-project-id'; + // location = 'us-central1'; + // cdnKeyId = 'my-cdn-key'; + + // Imports the Video Stitcher library + const {VideoStitcherServiceClient} = + require('@google-cloud/video-stitcher').v1; + // Instantiates a client + const stitcherClient = new VideoStitcherServiceClient(); + + async function getCdnKey() { + // Construct request + const request = { + name: stitcherClient.cdnKeyPath(projectId, location, cdnKeyId), + }; + const [cdnKey] = await stitcherClient.getCdnKey(request); + console.log(`CDN key: ${cdnKey.name}`); + } + + getCdnKey(); + // [END video_stitcher_get_cdn_key] +} + +// node getCdnKey.js +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/media/video-stitcher/getSlate.js b/media/video-stitcher/getSlate.js new file mode 100644 index 0000000000..36908d8f41 --- /dev/null +++ b/media/video-stitcher/getSlate.js @@ -0,0 +1,51 @@ +/** + * Copyright 2022, Google, Inc. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +'use strict'; + +function main(projectId, location, slateId) { + // [START video_stitcher_get_slate] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + // projectId = 'my-project-id'; + // location = 'us-central1'; + // slateId = 'my-slate'; + + // Imports the Video Stitcher library + const {VideoStitcherServiceClient} = + require('@google-cloud/video-stitcher').v1; + // Instantiates a client + const stitcherClient = new VideoStitcherServiceClient(); + + async function getSlate() { + // Construct request + const request = { + name: stitcherClient.slatePath(projectId, location, slateId), + }; + const [slate] = await stitcherClient.getSlate(request); + console.log(`Slate: ${slate.name}`); + } + + getSlate(); + // [END video_stitcher_get_slate] +} + +// node getSlate.js +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/media/video-stitcher/listCdnKeys.js b/media/video-stitcher/listCdnKeys.js new file mode 100644 index 0000000000..70372888e0 --- /dev/null +++ b/media/video-stitcher/listCdnKeys.js @@ -0,0 +1,51 @@ +/** + * Copyright 2022, Google, Inc. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +'use strict'; + +function main(projectId, location) { + // [START video_stitcher_list_cdn_keys] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + // projectId = 'my-project-id'; + // location = 'us-central1'; + + // Imports the Video Stitcher library + const {VideoStitcherServiceClient} = + require('@google-cloud/video-stitcher').v1; + // Instantiates a client + const stitcherClient = new VideoStitcherServiceClient(); + + async function listCdnKeys() { + const iterable = await stitcherClient.listCdnKeysAsync({ + parent: stitcherClient.locationPath(projectId, location), + }); + console.info('CDN keys:'); + for await (const response of iterable) { + console.log(response.name); + } + } + + listCdnKeys(); + // [END video_stitcher_list_cdn_keys] +} + +// node listCdnKeys.js +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/media/video-stitcher/listSlates.js b/media/video-stitcher/listSlates.js new file mode 100644 index 0000000000..bffbd917d0 --- /dev/null +++ b/media/video-stitcher/listSlates.js @@ -0,0 +1,51 @@ +/** + * Copyright 2022, Google, Inc. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +'use strict'; + +function main(projectId, location) { + // [START video_stitcher_list_slates] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + // projectId = 'my-project-id'; + // location = 'us-central1'; + + // Imports the Video Stitcher library + const {VideoStitcherServiceClient} = + require('@google-cloud/video-stitcher').v1; + // Instantiates a client + const stitcherClient = new VideoStitcherServiceClient(); + + async function listSlates() { + const iterable = await stitcherClient.listSlatesAsync({ + parent: stitcherClient.locationPath(projectId, location), + }); + console.info('Slates:'); + for await (const response of iterable) { + console.log(response.name); + } + } + + listSlates(); + // [END video_stitcher_list_slates] +} + +// node listSlates.js +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/media/video-stitcher/package.json b/media/video-stitcher/package.json index 48366a7ab6..e970e12593 100644 --- a/media/video-stitcher/package.json +++ b/media/video-stitcher/package.json @@ -18,6 +18,7 @@ "devDependencies": { "c8": "^7.1.0", "chai": "^4.2.0", - "mocha": "^8.0.0" + "mocha": "^8.0.0", + "uuid": "^8.0.0" } } diff --git a/media/video-stitcher/test/stitcher.test.js b/media/video-stitcher/test/stitcher.test.js new file mode 100644 index 0000000000..66a0b99adb --- /dev/null +++ b/media/video-stitcher/test/stitcher.test.js @@ -0,0 +1,202 @@ +/** + * Copyright 2022, Google, Inc. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +'use strict'; + +const path = require('path'); +const assert = require('assert'); +const {v4: uuidv4} = require('uuid'); +const {execSync} = require('child_process'); +const {describe, it, before, after} = require('mocha'); + +const uniqueId = uuidv4().split('-')[0]; +const bucketName = 'cloud-samples-data/media'; + +const projectId = process.env.GCLOUD_PROJECT; +const location = 'us-central1'; +const slateId = `nodejs-test-stitcher-slate-${uniqueId}`; +const slateUri = `https://storage.googleapis.com/${bucketName}/ForBiggerEscapes.mp4`; +const slateName = `/locations/${location}/slates/${slateId}`; + +const akamaiCdnKeyId = `nodejs-test-stitcher-akamai-key-${uniqueId}`; +const akamaiCdnKeyName = `/locations/${location}/cdnKeys/${akamaiCdnKeyId}`; +const googleCdnKeyId = `nodejs-test-stitcher-google-key-${uniqueId}`; +const googleCdnKeyName = `/locations/${location}/cdnKeys/${googleCdnKeyId}`; + +const hostname = 'cdn.example.com'; +const gCdnKeyname = 'gcdn-test-key'; +const gCdnPrivateKey = 'VGhpcyBpcyBhIHRlc3Qgc3RyaW5nLg=='; +const akamaiTokenKey = 'VGhpcyBpcyBhIHRlc3Qgc3RyaW5nLg=='; +const cwd = path.join(__dirname, '..'); + +before(async () => { + // Delete the slate if it already exists + try { + execSync(`node deleteSlate.js ${projectId} ${location} ${slateId}`, { + cwd, + }); + } catch (err) { + // Ignore not found error + } + // Delete the Akamai CDN key if it already exists + try { + execSync( + `node deleteCdnKey.js ${projectId} ${location} ${akamaiCdnKeyId}`, + { + cwd, + } + ); + } catch (err) { + // Ignore not found error + } + // Delete the Google CDN key if it already exists + try { + execSync( + `node deleteCdnKey.js ${projectId} ${location} ${googleCdnKeyId}`, + { + cwd, + } + ); + } catch (err) { + // Ignore not found error + } +}); + +after(async () => {}); + +describe('Slate functions', () => { + it('should create a slate', () => { + const output = execSync( + `node createSlate.js ${projectId} ${location} ${slateId} ${slateUri}`, + {cwd} + ); + assert.ok(output.includes(slateName)); + }); + + it('should show a list of slates', () => { + const output = execSync(`node listSlates.js ${projectId} ${location}`, { + cwd, + }); + assert.ok(output.includes(slateName)); + }); + + it('should update a slate', () => { + const output = execSync( + `node updateSlate.js ${projectId} ${location} ${slateId} ${slateUri}`, + {cwd} + ); + assert.ok(output.includes(slateName)); + }); + + it('should get a slate', () => { + const output = execSync( + `node getSlate.js ${projectId} ${location} ${slateId}`, + {cwd} + ); + assert.ok(output.includes(slateName)); + }); + + it('should delete a slate', () => { + const output = execSync( + `node deleteSlate.js ${projectId} ${location} ${slateId}`, + {cwd} + ); + assert.ok(output.includes('Deleted slate')); + }); +}); + +describe('CDN key functions', () => { + // Google CDN + + it('should create a Google CDN key', () => { + const output = execSync( + `node createCdnKey.js ${projectId} ${location} ${googleCdnKeyId} ${hostname} ${gCdnKeyname} ${gCdnPrivateKey} ''`, + {cwd} + ); + assert.ok(output.includes(googleCdnKeyName)); + }); + + it('should show a list of CDN keys', () => { + const output = execSync(`node listCdnKeys.js ${projectId} ${location}`, { + cwd, + }); + assert.ok(output.includes(googleCdnKeyName)); + }); + + it('should update a Google CDN key', () => { + const output = execSync( + `node updateCdnKey.js ${projectId} ${location} ${googleCdnKeyId} ${hostname} ${gCdnKeyname} ${gCdnPrivateKey} ''`, + {cwd} + ); + assert.ok(output.includes(googleCdnKeyName)); + }); + + it('should get a Google CDN key', () => { + const output = execSync( + `node getCdnKey.js ${projectId} ${location} ${googleCdnKeyId}`, + {cwd} + ); + assert.ok(output.includes(googleCdnKeyName)); + }); + + it('should delete a Google CDN key', () => { + const output = execSync( + `node deleteCdnKey.js ${projectId} ${location} ${googleCdnKeyId}`, + {cwd} + ); + assert.ok(output.includes('Deleted CDN key')); + }); + + // Akamai CDN + + it('should create an Akamai CDN key', () => { + const output = execSync( + `node createCdnKey.js ${projectId} ${location} ${akamaiCdnKeyId} ${hostname} '' '' ${akamaiTokenKey}`, + {cwd} + ); + assert.ok(output.includes(akamaiCdnKeyName)); + }); + + it('should show a list of CDN keys', () => { + const output = execSync(`node listCdnKeys.js ${projectId} ${location}`, { + cwd, + }); + assert.ok(output.includes(akamaiCdnKeyName)); + }); + + it('should update an Akamai CDN key', () => { + const output = execSync( + `node updateCdnKey.js ${projectId} ${location} ${akamaiCdnKeyId} ${hostname} '' '' ${akamaiTokenKey}`, + {cwd} + ); + assert.ok(output.includes(akamaiCdnKeyName)); + }); + + it('should get an Akamai CDN key', () => { + const output = execSync( + `node getCdnKey.js ${projectId} ${location} ${akamaiCdnKeyId}`, + {cwd} + ); + assert.ok(output.includes(akamaiCdnKeyName)); + }); + + it('should delete an Akamai CDN key', () => { + const output = execSync( + `node deleteCdnKey.js ${projectId} ${location} ${akamaiCdnKeyId}`, + {cwd} + ); + assert.ok(output.includes('Deleted CDN key')); + }); +}); diff --git a/media/video-stitcher/updateCdnKey.js b/media/video-stitcher/updateCdnKey.js new file mode 100644 index 0000000000..5d1cfe9256 --- /dev/null +++ b/media/video-stitcher/updateCdnKey.js @@ -0,0 +1,84 @@ +/** + * Copyright 2022, Google, Inc. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +'use strict'; + +function main( + projectId, + location, + cdnKeyId, + hostname, + gCdnKeyname, + gCdnPrivateKey, + akamaiTokenKey = '' +) { + // [START video_stitcher_update_cdn_key] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + // projectId = 'my-project-id'; + // location = 'us-central1'; + // cdnKeyId = 'my-cdn-key'; + // hostname = 'cdn.example.com'; + // gCdnKeyname = 'gcdn-key'; + // gCdnPrivateKey = 'VGhpcyBpcyBhIHRlc3Qgc3RyaW5nLg=='; + // akamaiTokenKey = 'VGhpcyBpcyBhIHRlc3Qgc3RyaW5nLg=='; + + // Imports the Video Stitcher library + const {VideoStitcherServiceClient} = + require('@google-cloud/video-stitcher').v1; + // Instantiates a client + const stitcherClient = new VideoStitcherServiceClient(); + + async function updateCdnKey() { + // Construct request + const request = { + cdnKey: { + name: stitcherClient.cdnKeyPath(projectId, location, cdnKeyId), + hostname: hostname, + }, + }; + + if (akamaiTokenKey !== '') { + request.cdnKey.akamaiCdnKey = { + tokenKey: akamaiTokenKey, + }; + request.updateMask = { + paths: ['hostname', 'akamai_cdn_key'], + }; + } else { + request.cdnKey.googleCdnKey = { + keyName: gCdnKeyname, + privateKey: gCdnPrivateKey, + }; + request.updateMask = { + paths: ['hostname', 'google_cdn_key'], + }; + } + + const [cdnKey] = await stitcherClient.updateCdnKey(request); + console.log(`Updated CDN key: ${cdnKey.name}`); + } + + updateCdnKey(); + // [END video_stitcher_update_cdn_key] +} + +// node updateCdnKey.js +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/media/video-stitcher/updateSlate.js b/media/video-stitcher/updateSlate.js new file mode 100644 index 0000000000..bd15424ebf --- /dev/null +++ b/media/video-stitcher/updateSlate.js @@ -0,0 +1,59 @@ +/** + * Copyright 2022, Google, Inc. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +'use strict'; + +function main(projectId, location, slateId, slateUri) { + // [START video_stitcher_update_slate] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + // projectId = 'my-project-id'; + // location = 'us-central1'; + // slateId = 'my-slate'; + // slateUri = 'https://my-slate-uri/test.mp4'; + + // Imports the Video Stitcher library + const {VideoStitcherServiceClient} = + require('@google-cloud/video-stitcher').v1; + // Instantiates a client + const stitcherClient = new VideoStitcherServiceClient(); + + async function updateSlate() { + // Construct request + const request = { + slate: { + name: stitcherClient.slatePath(projectId, location, slateId), + uri: slateUri, + }, + updateMask: { + paths: ['uri'], + }, + }; + + const [slate] = await stitcherClient.updateSlate(request); + console.log(`Updated slate: ${slate.name}`); + } + + updateSlate(); + // [END video_stitcher_update_slate] +} + +// node updateSlate.js +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2));