Skip to content

Commit d59b974

Browse files
authored
feat: [VideoStitcher] add CDN samples (GoogleCloudPlatform#1727)
1 parent 882dbb0 commit d59b974

File tree

8 files changed

+768
-16
lines changed

8 files changed

+768
-16
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2022 Google LLC.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/**
20+
* For instructions on how to run the samples:
21+
*
22+
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/media/videostitcher/README.md
23+
*/
24+
25+
namespace Google\Cloud\Samples\Media\Stitcher;
26+
27+
// [START videostitcher_create_cdn_key]
28+
use Google\Cloud\Video\Stitcher\V1\VideoStitcherServiceClient;
29+
use Google\Cloud\Video\Stitcher\V1\CdnKey;
30+
use Google\Cloud\Video\Stitcher\V1\GoogleCdnKey;
31+
use Google\Cloud\Video\Stitcher\V1\MediaCdnKey;
32+
33+
/**
34+
* Creates a CDN key. Cloud CDN keys and Media CDN keys are supported.
35+
*
36+
* @param string $callingProjectId The project ID to run the API call under
37+
* @param string $location The location of the CDN key
38+
* @param string $cdnKeyId The ID of the CDN key to be created
39+
* @param string $hostname The hostname of the CDN key
40+
* @param string $keyName For a Media CDN key, this is the keyset name.
41+
* For a Cloud CDN key, this is the public name of the
42+
* CDN key.
43+
* @param string $privateKey For a Media CDN key, this is a 64-byte Ed25519 private
44+
* key encoded as a base64-encoded string. See
45+
* https://cloud.google.com/video-stitcher/docs/how-to/managing-cdn-keys#create-private-key-media-cdn
46+
* for more information. For a Cloud CDN key,
47+
* this is a base64-encoded string secret.
48+
* @param boolean $isMediaCdn If true, create a Media CDN key. If false,
49+
* create a Cloud CDN key.
50+
*/
51+
function create_cdn_key(
52+
string $callingProjectId,
53+
string $location,
54+
string $cdnKeyId,
55+
string $hostname,
56+
string $keyName,
57+
string $privateKey,
58+
string $isMediaCdn
59+
): void {
60+
// Instantiate a client.
61+
$stitcherClient = new VideoStitcherServiceClient();
62+
63+
$parent = $stitcherClient->locationName($callingProjectId, $location);
64+
$cdnKey = new CdnKey();
65+
$cdnKey->setHostname($hostname);
66+
67+
if ($isMediaCdn == true) {
68+
$cloudCdn = new MediaCdnKey();
69+
$cdnKey->setMediaCdnKey($cloudCdn);
70+
} else {
71+
$cloudCdn = new GoogleCdnKey();
72+
$cdnKey->setGoogleCdnKey($cloudCdn);
73+
}
74+
$cloudCdn->setKeyName($keyName);
75+
$cloudCdn->setPrivateKey($privateKey);
76+
77+
// Run CDN key creation request
78+
$response = $stitcherClient->createCdnKey($parent, $cdnKey, $cdnKeyId);
79+
80+
// Print results
81+
printf('CDN key: %s' . PHP_EOL, $response->getName());
82+
}
83+
// [END videostitcher_create_cdn_key]
84+
85+
// The following 2 lines are only needed to run the samples
86+
require_once __DIR__ . '/../../../testing/sample_helpers.php';
87+
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2022 Google LLC.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/**
20+
* For instructions on how to run the samples:
21+
*
22+
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/media/videostitcher/README.md
23+
*/
24+
25+
namespace Google\Cloud\Samples\Media\Stitcher;
26+
27+
// [START videostitcher_create_cdn_key_akamai]
28+
use Google\Cloud\Video\Stitcher\V1\VideoStitcherServiceClient;
29+
use Google\Cloud\Video\Stitcher\V1\CdnKey;
30+
use Google\Cloud\Video\Stitcher\V1\AkamaiCdnKey;
31+
32+
/**
33+
* Creates an Akamai CDN key.
34+
*
35+
* @param string $callingProjectId The project ID to run the API call under
36+
* @param string $location The location of the CDN key
37+
* @param string $cdnKeyId The ID of the CDN key to be created
38+
* @param string $hostname The hostname of the CDN key
39+
* @param string $tokenKey The base64-encoded string token key for
40+
* the Akamai CDN edge configuration
41+
*/
42+
function create_cdn_key_akamai(
43+
string $callingProjectId,
44+
string $location,
45+
string $cdnKeyId,
46+
string $hostname,
47+
string $tokenKey
48+
): void {
49+
// Instantiate a client.
50+
$stitcherClient = new VideoStitcherServiceClient();
51+
52+
$parent = $stitcherClient->locationName($callingProjectId, $location);
53+
$cdnKey = new CdnKey();
54+
$cdnKey->setHostname($hostname);
55+
$cloudCdn = new AkamaiCdnKey();
56+
$cloudCdn->setTokenKey($tokenKey);
57+
$cdnKey->setAkamaiCdnKey($cloudCdn);
58+
59+
// Run CDN key creation request
60+
$response = $stitcherClient->createCdnKey($parent, $cdnKey, $cdnKeyId);
61+
62+
// Print results
63+
printf('CDN key: %s' . PHP_EOL, $response->getName());
64+
}
65+
// [END videostitcher_create_cdn_key_akamai]
66+
67+
// The following 2 lines are only needed to run the samples
68+
require_once __DIR__ . '/../../../testing/sample_helpers.php';
69+
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2022 Google LLC.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/**
20+
* For instructions on how to run the samples:
21+
*
22+
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/media/videostitcher/README.md
23+
*/
24+
25+
namespace Google\Cloud\Samples\Media\Stitcher;
26+
27+
// [START videostitcher_delete_cdn_key]
28+
use Google\Cloud\Video\Stitcher\V1\VideoStitcherServiceClient;
29+
30+
/**
31+
* Deletes a CDN key.
32+
*
33+
* @param string $callingProjectId The project ID to run the API call under
34+
* @param string $location The location of the CDN key
35+
* @param string $cdnKeyId The ID of the CDN key
36+
*/
37+
function delete_cdn_key(
38+
string $callingProjectId,
39+
string $location,
40+
string $cdnKeyId
41+
): void {
42+
// Instantiate a client.
43+
$stitcherClient = new VideoStitcherServiceClient();
44+
45+
$formattedName = $stitcherClient->cdnKeyName($callingProjectId, $location, $cdnKeyId);
46+
$stitcherClient->deleteCdnKey($formattedName);
47+
48+
// Print status
49+
printf('Deleted CDN key %s' . PHP_EOL, $cdnKeyId);
50+
}
51+
// [END videostitcher_delete_cdn_key]
52+
53+
// The following 2 lines are only needed to run the samples
54+
require_once __DIR__ . '/../../../testing/sample_helpers.php';
55+
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2022 Google LLC.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/**
20+
* For instructions on how to run the samples:
21+
*
22+
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/media/videostitcher/README.md
23+
*/
24+
25+
namespace Google\Cloud\Samples\Media\Stitcher;
26+
27+
// [START videostitcher_get_cdn_key]
28+
use Google\Cloud\Video\Stitcher\V1\VideoStitcherServiceClient;
29+
30+
/**
31+
* Gets a CDN key.
32+
*
33+
* @param string $callingProjectId The project ID to run the API call under
34+
* @param string $location The location of the CDN key
35+
* @param string $cdnKeyId The ID of the CDN key
36+
*/
37+
function get_cdn_key(
38+
string $callingProjectId,
39+
string $location,
40+
string $cdnKeyId
41+
): void {
42+
// Instantiate a client.
43+
$stitcherClient = new VideoStitcherServiceClient();
44+
45+
$formattedName = $stitcherClient->cdnKeyName($callingProjectId, $location, $cdnKeyId);
46+
$key = $stitcherClient->getCdnKey($formattedName);
47+
48+
// Print results
49+
printf('CDN key: %s' . PHP_EOL, $key->getName());
50+
}
51+
// [END videostitcher_get_cdn_key]
52+
53+
// The following 2 lines are only needed to run the samples
54+
require_once __DIR__ . '/../../../testing/sample_helpers.php';
55+
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2022 Google LLC.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/**
20+
* For instructions on how to run the samples:
21+
*
22+
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/media/videostitcher/README.md
23+
*/
24+
25+
namespace Google\Cloud\Samples\Media\Stitcher;
26+
27+
// [START videostitcher_list_cdn_keys]
28+
use Google\Cloud\Video\Stitcher\V1\VideoStitcherServiceClient;
29+
30+
/**
31+
* Lists all CDN keys for a location.
32+
*
33+
* @param string $callingProjectId The project ID to run the API call under
34+
* @param string $location The location of the CDN keys
35+
*/
36+
function list_cdn_keys(
37+
string $callingProjectId,
38+
string $location
39+
): void {
40+
// Instantiate a client.
41+
$stitcherClient = new VideoStitcherServiceClient();
42+
43+
$parent = $stitcherClient->locationName($callingProjectId, $location);
44+
$response = $stitcherClient->listCdnKeys($parent);
45+
46+
// Print the CDN key list.
47+
$cdn_keys = $response->iterateAllElements();
48+
print('CDN keys:' . PHP_EOL);
49+
foreach ($cdn_keys as $key) {
50+
printf('%s' . PHP_EOL, $key->getName());
51+
}
52+
}
53+
// [END videostitcher_list_cdn_keys]
54+
55+
// The following 2 lines are only needed to run the samples
56+
require_once __DIR__ . '/../../../testing/sample_helpers.php';
57+
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);

0 commit comments

Comments
 (0)