(projectId, cdnKeyId, privateKey, isMediaCdn = true)
| 16 | 'use strict'; |
| 17 | |
| 18 | function main(projectId, cdnKeyId, privateKey, isMediaCdn = true) { |
| 19 | // [START videostitcher_create_cdn_key] |
| 20 | const location = 'us-central1'; |
| 21 | const hostname = 'cdn.example.com'; |
| 22 | const keyName = 'cdn-key'; |
| 23 | /** |
| 24 | * TODO(developer): Uncomment these variables before running the sample. |
| 25 | */ |
| 26 | // projectId = 'my-project-id'; |
| 27 | // cdnKeyId = 'my-cdn-key'; |
| 28 | // privateKey = 'my-private-key'; |
| 29 | |
| 30 | // Imports the Video Stitcher library |
| 31 | const {VideoStitcherServiceClient} = |
| 32 | require('@google-cloud/video-stitcher').v1; |
| 33 | // Instantiates a client |
| 34 | const stitcherClient = new VideoStitcherServiceClient(); |
| 35 | |
| 36 | async function createCdnKey() { |
| 37 | // Construct request |
| 38 | const request = { |
| 39 | parent: stitcherClient.locationPath(projectId, location), |
| 40 | cdnKey: { |
| 41 | hostname: hostname, |
| 42 | }, |
| 43 | cdnKeyId: cdnKeyId, |
| 44 | }; |
| 45 | |
| 46 | if (isMediaCdn === 'true') { |
| 47 | request.cdnKey.mediaCdnKey = { |
| 48 | keyName: keyName, |
| 49 | privateKey: privateKey, |
| 50 | }; |
| 51 | } else { |
| 52 | request.cdnKey.googleCdnKey = { |
| 53 | keyName: keyName, |
| 54 | privateKey: privateKey, |
| 55 | }; |
| 56 | } |
| 57 | |
| 58 | const [operation] = await stitcherClient.createCdnKey(request); |
| 59 | const [response] = await operation.promise(); |
| 60 | console.log(`CDN key: ${response.name}`); |
| 61 | } |
| 62 | |
| 63 | createCdnKey().catch(err => { |
| 64 | console.error(err.message); |
| 65 | process.exitCode = 1; |
| 66 | }); |
| 67 | // [END videostitcher_create_cdn_key] |
| 68 | } |
| 69 | |
| 70 | // node createCdnKey.js <projectId> <cdnKeyId> <privateKey> <isMediaCdn> <location> <hostname> <keyName> |
| 71 | main(...process.argv.slice(2)); |
no test coverage detected