Published Devices Client tool release: 1.1.0

This commit is contained in:
Buildbot
2020-10-06 00:51:14 +00:00
parent 62f0340b4e
commit e2bc2061f8
13 changed files with 1022 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
# Copyright 2018 Google LLC. All rights reserved.
# Desciption:
# JTS interfaces.
package(
default_visibility = ["//visibility:public"],
)
java_library(
name = "providers",
srcs = glob(["*.java"]),
runtime_deps = [
"@grpc_context//:io_grpc_grpc_context",
"@grpc_netty_all//:io_netty_netty_all",
"@io_perfmark_api//:io_perfmark_perfmark_api",
"@netty_boringssl//:io_netty_netty_tcnative_boringssl_static",
"@open_census//:io_opencensus_opencensus_contrib_http_jetty_client",
"@open_census_api//:io_opencensus_opencensus_api",
"@open_census_grpc_metrics//:io_opencensus_opencensus_contrib_grpc_metrics",
"@open_census_util//:io_opencensus_opencensus_contrib_http_util",
],
deps = [
":libwidevine_license_wvpl_sdk_lib.jar",
"//google/chrome/widevine/contentpartners/v1beta1:published_devices_grpc",
"//google/chrome/widevine/contentpartners/v1beta1:published_devices_java_proto",
"//httpclient",
"//interfaces",
"@google_guice//:com_google_inject_guice",
"@json//:org_json_json",
"@com_google_protobuf//:protobuf_java",
"@google_guava//:com_google_guava_guava",
"@grpc_core//:io_grpc_grpc_core",
"@grpc_netty//:io_grpc_grpc_netty",
"@grpc_stub//:io_grpc_grpc_stub",
"@io_grpc_grpc_java//api",
],
)

View File

@@ -0,0 +1,91 @@
// Copyright 2020 Google LLC. All rights reserved.
package com.google.video.widevine.jts.providers;
import com.google.chrome.widevine.contentpartners.v1beta1.PublishedDevices;
import com.google.chrome.widevine.contentpartners.v1beta1.PublishedDevicesRequest;
import com.google.chrome.widevine.contentpartners.v1beta1.PublishedDevicesServiceGrpc;
import com.google.inject.Inject;
import com.google.protobuf.TextFormat;
import com.google.video.widevine.jts.httpclient.Credentials;
import com.google.video.widevine.jts.interfaces.DeviceCertificate;
import com.google.video.widevine.sdk.wvpl.WvPLBaseEnvironment;
import com.google.video.widevine.sdk.wvpl.WvPLStatusException;
import io.grpc.ManagedChannel;
import io.grpc.Metadata;
import io.grpc.netty.NettyChannelBuilder;
import io.grpc.stub.MetadataUtils;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Provides the latest {@code PublishedDevices} data from the Widevine Published Devices Service.
*
* This implementation uses the Widevine Published Devices API, and support a gRPC method for
* retrieving PublishedDevices with an embedded Published Devices list.
*/
public class PublishedDevicesProvider implements DeviceCertificate {
private static final Logger logger = Logger.getLogger(PublishedDevicesProvider.class.getName());
private WvPLBaseEnvironment<?> environment = null;
private String apiServicePath = null;
private Credentials credentials = null;
/**
* PublishedDevicesProvider constructor.
*
* @param environment A WvPLBaseEnvironment object initialized with a Service Certificate.
* @param serviceAccountPath Path to a GCP Service Account json file, used in OAUTH.
* @param apiServicePath Path to a Widevine Published Devices API service.
* @throws IOException upon failure creating OAUTH credentials.
*/
@Inject
public PublishedDevicesProvider(
WvPLBaseEnvironment<?> environment, String serviceAccountPath, String apiServicePath)
throws IOException {
this.environment = environment;
this.apiServicePath = apiServicePath;
credentials = new Credentials(serviceAccountPath);
}
/**
* Get the latest {@code PublishedDevices} from the Widevine Published Devices Service.
*
* @return The latest {@code PublishedDevices} data.
* @throws InterruptedException upon RPC failure.
* @throws WvPLStatusException upon WvPLBaseEnvironment errors.
*/
@Override
public PublishedDevices getPublishedDevices() throws InterruptedException, WvPLStatusException{
ManagedChannel channel = null;
PublishedDevices devicesResponse = null;
logger.log(Level.INFO, "Getting PublishedDevices...");
try {
channel = createRpcChannel(apiServicePath);
Metadata metadata = new Metadata();
String token = "Bearer " + credentials.getAccessToken();
metadata.put(Metadata.Key.of("authorization", Metadata.ASCII_STRING_MARSHALLER), token);
PublishedDevicesServiceGrpc.PublishedDevicesServiceBlockingStub blockingStub =
PublishedDevicesServiceGrpc.newBlockingStub(channel)
.withInterceptors(MetadataUtils.newAttachHeadersInterceptor(metadata));
devicesResponse = blockingStub.getPublishedDevices(PublishedDevicesRequest.parseFrom(
environment.generateDeviceStatusListRequest()));
logger.log(Level.INFO, "GRPC Call to PublishedDevicesService.GetSignedList returned:\n %s"
+ TextFormat.printer().printToString(devicesResponse));
} catch (IOException e) {
logger.log(Level.INFO, "IOException encountered trying to retrieve the signed list: " + e);
} finally {
if (channel != null) {
channel.shutdown();
channel.awaitTermination(1, TimeUnit.SECONDS);
}
}
return devicesResponse;
}
private static ManagedChannel createRpcChannel(String host) {
return NettyChannelBuilder.forTarget(host).build();
}
}