Skip to content

migrate code from googleapis/python-video-stitcher #10189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 57 commits into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
b52162b
docs(samples): add code samples (#17)
irataxy May 27, 2022
f0990ff
chore(deps): update all dependencies (#33)
renovate-bot May 27, 2022
48a5b50
chore(deps): update all dependencies (#38)
renovate-bot Jul 16, 2022
97351d0
chore(deps): update all dependencies (#49)
renovate-bot Aug 2, 2022
f7c23ed
chore(deps): update all dependencies (#51)
renovate-bot Aug 9, 2022
19a6222
chore(deps): update dependency google-cloud-video-stitcher to v0.2.1 …
renovate-bot Aug 16, 2022
7ed201b
chore(deps): update dependency google-api-python-client to v2.57.0 (#57)
renovate-bot Aug 16, 2022
1e09c38
chore(deps): update dependency google-api-python-client to v2.58.0 (#58)
renovate-bot Aug 23, 2022
1e18ca5
chore(deps): update all dependencies (#64)
renovate-bot Sep 2, 2022
62abf4d
chore(deps): update dependency pytest to v7.1.3 (#68)
renovate-bot Sep 6, 2022
2025b8d
chore(deps): update dependency google-api-python-client to v2.60.0 (#69)
renovate-bot Sep 6, 2022
9617a96
chore(deps): update dependency google-api-python-client to v2.61.0 (#74)
renovate-bot Sep 14, 2022
b374564
chore(deps): update dependency grpcio to v1.49.0 (#76)
renovate-bot Sep 16, 2022
b6f6d81
chore(deps): update dependency google-cloud-video-stitcher to v0.3.0 …
renovate-bot Sep 20, 2022
266c99b
chore(deps): update dependency google-api-python-client to v2.62.0 (#80)
renovate-bot Sep 20, 2022
b7887a7
docs(samples): Fix Video Stitcher region tag prefix (#86)
irataxy Oct 3, 2022
974e427
chore(deps): update dependency grpcio to v1.49.1 (#82)
renovate-bot Oct 4, 2022
df405bb
chore(deps): update all dependencies (#89)
renovate-bot Oct 4, 2022
8d7c83e
chore(deps): update dependency google-api-python-client to v2.64.0 (#90)
renovate-bot Oct 4, 2022
c0365e7
chore(deps): update dependency google-cloud-video-stitcher to v0.3.2 …
renovate-bot Oct 18, 2022
5917d06
chore(deps): update all dependencies (#95)
renovate-bot Oct 19, 2022
f0fb761
chore(deps): update dependency pytest to v7.2.0 (#97)
renovate-bot Oct 26, 2022
c9940d7
chore(deps): update dependency google-cloud-video-stitcher to v0.4.0 …
renovate-bot Oct 28, 2022
529677c
chore(deps): update all dependencies (#105)
renovate-bot Nov 26, 2022
76b27ef
chore(deps): update all dependencies (#108)
renovate-bot Dec 15, 2022
8904a36
chore(deps): update dependency google-cloud-video-stitcher to v0.5.0 …
renovate-bot Dec 16, 2022
ba23150
docs(samples): Add Media CDN samples. Move Akamai sample to its own f…
irataxy Jan 5, 2023
ab24b7e
chore(deps): update dependency google-api-python-client to v2.71.0 (#…
renovate-bot Jan 5, 2023
6108b9e
chore(deps): update dependency google-cloud-video-stitcher to v0.5.1 …
renovate-bot Jan 5, 2023
837d372
chore(deps): update dependency google-api-python-client to v2.72.0 (#…
renovate-bot Jan 10, 2023
3ff4bfe
chore(deps): update dependency requests to v2.28.2 (#119)
renovate-bot Jan 12, 2023
242a4d7
chore(deps): update dependency google-cloud-video-stitcher to v0.6.0 …
renovate-bot Jan 12, 2023
c365631
chore(deps): update dependency pytest to v7.2.1 (#122)
renovate-bot Jan 14, 2023
02f2143
chore(deps): update dependency google-api-python-client to v2.73.0 (#…
renovate-bot Jan 17, 2023
0abc5aa
chore(deps): update dependency google-cloud-video-stitcher to v0.6.1 …
renovate-bot Jan 23, 2023
01250ce
chore(deps): update dependency google-api-python-client to v2.74.0 (#…
renovate-bot Jan 25, 2023
0728d4a
chore(deps): update dependency google-api-python-client to v2.75.0 (#…
renovate-bot Jan 31, 2023
414bf6e
chore(deps): update dependency google-api-python-client to v2.76.0 (#…
renovate-bot Feb 3, 2023
17dd3f4
chore(deps): update dependency google-api-python-client to v2.77.0 (#…
renovate-bot Feb 8, 2023
a9007df
chore(deps): update dependency google-api-python-client to v2.78.0 (#…
renovate-bot Feb 15, 2023
32480b6
chore(deps): update all dependencies (#136)
renovate-bot Mar 1, 2023
aa2387c
chore(deps): update dependency google-api-python-client to v2.80.0 (#…
renovate-bot Mar 1, 2023
25a60f3
chore(deps): update dependency pytest to v7.2.2 (#140)
renovate-bot Mar 4, 2023
84e2be8
docs: skip testing temporarily (#146)
irataxy Apr 13, 2023
ae909e2
chore(deps): update all dependencies (#141)
renovate-bot Apr 19, 2023
726eed8
chore(deps): update all dependencies (#149)
renovate-bot May 15, 2023
de6681f
docs(samples): Update slates and CDN keys to use LROs (#150)
irataxy May 19, 2023
cbf72e3
chore(deps): update dependency requests to v2.31.0 [security] (#153)
renovate-bot May 31, 2023
ae887c7
chore(deps): update dependency google-api-python-client to v2.88.0 (#…
renovate-bot May 31, 2023
ef4e075
chore(deps): update dependency google-cloud-video-stitcher to v0.7.2 …
renovate-bot Jun 1, 2023
956abc3
Merge remote-tracking branch 'migration/main' into python-video-stitc…
parthea Jun 8, 2023
4e5cfb3
ignore python 2.7, 3.6
parthea Jun 8, 2023
114273c
update codeowners;blunderbuss
parthea Jun 8, 2023
db78081
update copyright headers
parthea Jun 8, 2023
2199545
add license header
parthea Jun 8, 2023
5f3834a
Merge branch 'main' into python-video-stitcher-migration
parthea Jun 8, 2023
50b4c24
spacing
parthea Jun 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
/retail/**/* @GoogleCloudPlatform/cloud-retail-team @GoogleCloudPlatform/python-samples-reviewers
/billing/**/* @GoogleCloudPlatform/billing-samples-maintainers @GoogleCloudPlatform/python-samples-reviewers
/iot/**/* @GoogleCloudPlatform/api-iot @GoogleCloudPlatform/python-samples-reviewers
/video/stitcher/* @GoogleCloudPlatform/cloud-media-team @GoogleCloudPlatform/python-samples-reviewers

# Does not have owner
/blog/**/* @GoogleCloudPlatform/python-samples-reviewers
Expand Down
1 change: 1 addition & 0 deletions .github/blunderbuss.yml
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ assign_prs_by:
- GoogleCloudPlatform/cloud-retail-team
- labels:
- "api: cloudmedia"
- "api: videostitcher"
to:
- GoogleCloudPlatform/cloud-media-team

Expand Down
174 changes: 174 additions & 0 deletions video/stitcher/cdn_key_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
# Copyright 2022 Google LLC
#
# 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.

import os
import uuid

from google.protobuf import timestamp_pb2
import pytest

import create_cdn_key
import create_cdn_key_akamai
import delete_cdn_key
import get_cdn_key
import list_cdn_keys
import update_cdn_key
import update_cdn_key_akamai
import utils

location = "us-central1"
project_id = os.environ["GOOGLE_CLOUD_PROJECT"]
now = timestamp_pb2.Timestamp()
now.GetCurrentTime()

media_cdn_key_id = f"python-test-media-key-{uuid.uuid4().hex[:5]}-{now.seconds}"
cloud_cdn_key_id = f"python-test-cloud-key-{uuid.uuid4().hex[:5]}-{now.seconds}"
akamai_cdn_key_id = f"python-test-akamai-key-{uuid.uuid4().hex[:5]}-{now.seconds}"

hostname = "cdn.example.com"
updated_hostname = "updated.example.com"
key_name = "my-key"

media_cdn_private_key = "MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNA"
updated_media_cdn_private_key = (
"ZZZzNDU2Nzg5MDEyMzQ1Njc4OTAxzg5MDEyMzQ1Njc4OTAxMjM0NTY3DkwMTIZZZ"
)
cloud_cdn_private_key = "VGhpcyBpcyBhIHRlc3Qgc3RyaW5nLg=="
updated_cloud_cdn_private_key = "VGhpcyBpcyBhbiB1cGRhdGVkIHRlc3Qgc3RyaW5nLg=="
akamai_key = cloud_cdn_private_key
updated_akamai_key = updated_cloud_cdn_private_key


def test_cdn_key_operations(capsys: pytest.fixture) -> None:

utils.delete_stale_cdn_keys(project_id, location)

# Media CDN key tests

create_cdn_key.create_cdn_key(
project_id,
location,
media_cdn_key_id,
hostname,
key_name,
media_cdn_private_key,
False,
)
out, _ = capsys.readouterr()
assert media_cdn_key_id in out

list_cdn_keys.list_cdn_keys(project_id, location)
out, _ = capsys.readouterr()
assert media_cdn_key_id in out

# Update the hostname and private key; the private key value
# is not returned by the client
response = update_cdn_key.update_cdn_key(
project_id,
location,
media_cdn_key_id,
updated_hostname,
key_name,
updated_media_cdn_private_key,
False,
)
out, _ = capsys.readouterr()
assert media_cdn_key_id in out
assert updated_hostname in response.hostname

get_cdn_key.get_cdn_key(project_id, location, media_cdn_key_id)
out, _ = capsys.readouterr()
assert media_cdn_key_id in out

delete_cdn_key.delete_cdn_key(project_id, location, media_cdn_key_id)
out, _ = capsys.readouterr()
assert "Deleted CDN key" in out

# Cloud CDN key tests

create_cdn_key.create_cdn_key(
project_id,
location,
cloud_cdn_key_id,
hostname,
key_name,
cloud_cdn_private_key,
True,
)
out, _ = capsys.readouterr()
assert cloud_cdn_key_id in out

list_cdn_keys.list_cdn_keys(project_id, location)
out, _ = capsys.readouterr()
assert cloud_cdn_key_id in out

# Update the hostname and private key; the private key value
# is not returned by the client
response = update_cdn_key.update_cdn_key(
project_id,
location,
cloud_cdn_key_id,
updated_hostname,
key_name,
updated_cloud_cdn_private_key,
True,
)
out, _ = capsys.readouterr()
assert cloud_cdn_key_id in out
assert updated_hostname in response.hostname

get_cdn_key.get_cdn_key(project_id, location, cloud_cdn_key_id)
out, _ = capsys.readouterr()
assert cloud_cdn_key_id in out

delete_cdn_key.delete_cdn_key(project_id, location, cloud_cdn_key_id)
out, _ = capsys.readouterr()
assert "Deleted CDN key" in out

# Akamai CDN key tests

create_cdn_key_akamai.create_cdn_key_akamai(
project_id,
location,
akamai_cdn_key_id,
hostname,
akamai_key,
)
out, _ = capsys.readouterr()
assert akamai_cdn_key_id in out

list_cdn_keys.list_cdn_keys(project_id, location)
out, _ = capsys.readouterr()
assert akamai_cdn_key_id in out

# Update the hostname and private key; the private key value
# is not returned by the client
response = update_cdn_key_akamai.update_cdn_key_akamai(
project_id,
location,
akamai_cdn_key_id,
updated_hostname,
updated_akamai_key,
)
out, _ = capsys.readouterr()
assert akamai_cdn_key_id in out
assert updated_hostname in response.hostname

get_cdn_key.get_cdn_key(project_id, location, akamai_cdn_key_id)
out, _ = capsys.readouterr()
assert akamai_cdn_key_id in out

delete_cdn_key.delete_cdn_key(project_id, location, akamai_cdn_key_id)
out, _ = capsys.readouterr()
assert "Deleted CDN key" in out
135 changes: 135 additions & 0 deletions video/stitcher/create_cdn_key.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#!/usr/bin/env python

# Copyright 2022 Google LLC
#
# 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.

"""Google Cloud Video Stitcher sample for creating a Media CDN key
or a Cloud CDN key. A CDN key is used to retrieve protected media.
Example usage:
python create_cdn_key.py --project_id <project-id> --location <location> \
--cdn_key_id <cdn_key_id> --hostname <hostname> \
--key_name <name> --private_key <key> [--is_cloud_cdn]
"""

# [START videostitcher_create_cdn_key]

import argparse

from google.cloud.video import stitcher_v1
from google.cloud.video.stitcher_v1.services.video_stitcher_service import (
VideoStitcherServiceClient,
)


def create_cdn_key(
project_id: str,
location: str,
cdn_key_id: str,
hostname: str,
key_name: str,
private_key: str,
is_cloud_cdn: bool,
) -> str:
"""Creates a Cloud CDN or Media CDN key.
Args:
project_id: The GCP project ID.
location: The location in which to create the CDN key.
cdn_key_id: The user-defined CDN key ID.
hostname: The hostname to which this CDN key applies.
key_name: For a Media CDN key, this is the keyset name.
For a Cloud CDN key, this is the public name of the CDN key.
private_key: For a Media CDN key, this is a 64-byte Ed25519 private
key encoded as a base64-encoded string.
See https://cloud.google.com/video-stitcher/docs/how-to/managing-cdn-keys#create-private-key-media-cdn
for more information. For a Cloud CDN key, this is a base64-encoded string secret.
is_cloud_cdn: If true, create a Cloud CDN key. If false, create a Media CDN key."""

client = VideoStitcherServiceClient()

parent = f"projects/{project_id}/locations/{location}"

cdn_key = stitcher_v1.types.CdnKey(
name=cdn_key_id,
hostname=hostname,
)

if is_cloud_cdn:
cdn_key.google_cdn_key = stitcher_v1.types.GoogleCdnKey(
key_name=key_name,
private_key=private_key,
)
else:
cdn_key.media_cdn_key = stitcher_v1.types.MediaCdnKey(
key_name=key_name,
private_key=private_key,
)

operation = client.create_cdn_key(
parent=parent, cdn_key_id=cdn_key_id, cdn_key=cdn_key
)
response = operation.result()
print(f"CDN key: {response.name}")
return response


# [END videostitcher_create_cdn_key]

if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--project_id", help="Your Cloud project ID.", required=True)
parser.add_argument(
"--location",
help="The location in which to create the CDN key.",
default="us-central1",
)
parser.add_argument(
"--cdn_key_id",
help="The user-defined CDN key ID.",
required=True,
)
parser.add_argument(
"--hostname",
help="The hostname to which this CDN key applies.",
required=True,
)
parser.add_argument(
"--key_name",
help="For a Media CDN key, this is the keyset name. For a Cloud CDN"
+ " key, this is the public name of the CDN key.",
required=True,
)
parser.add_argument(
"--private_key",
help="For a Media CDN key, this is a 64-byte Ed25519 private key"
+ "encoded as a base64-encoded string. See"
+ " https://cloud.google.com/video-stitcher/docs/how-to/managing-cdn-keys#create-private-key-media-cdn"
+ " for more information. For a Cloud CDN key, this is a"
+ " base64-encoded string secret.",
required=True,
)
parser.add_argument(
"--is_cloud_cdn",
action="store_true",
help="If included, create a Cloud CDN key. If absent, create a Media CDN key.",
)
args = parser.parse_args()
create_cdn_key(
args.project_id,
args.location,
args.cdn_key_id,
args.hostname,
args.key_name,
args.private_key,
args.is_cloud_cdn,
)
Loading