Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add the new Castlabs 'Download Keys' call#7

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
stuarthicks merged 1 commit intomasterfromdownload-keys
Jul 18, 2017
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
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
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,9 +5,11 @@

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

import com.brightcove.castlabs.client.request.*;
import com.brightcove.castlabs.client.response.DownloadKeysResponse;
import com.brightcove.castlabs.client.response.ListAccountsResponse;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.google.common.collect.Lists;
Expand DownExpand Up@@ -396,6 +398,48 @@ public ListAccountsResponse listAccounts(final String merchantUuid)
}
}

/**
* Fetch all of a merchant's keys
*
* @param merchantUuid UUID for the merchant
* @return list of responses from Castlabs
* @throws CastlabsException error reported by Castlabs
* @throws IOException network error while communicating with Castlabs REST API
*/
public List<DownloadKeysResponse> downloadKeys(final String merchantUuid)
throws IOException, CastlabsException {

final String uri = this.getUrlWithTicket(this.ingestionBaseUrl + "frontend/download-api/ingestion/query/v1/keys/" + merchantUuid + "/download");
final HttpGet httpRequest = new HttpGet(uri);

final CloseableHttpClient httpclient = HttpClients.createDefault();
try (final CloseableHttpResponse httpResponse = httpclient.execute(httpRequest)) {
final int statusCode = httpResponse.getStatusLine().getStatusCode();
final HttpEntity responseEntity = httpResponse.getEntity();
if (responseEntity == null) {
throw new CastlabsException("Empty response entity from Castlabs. HTTP Status: " + httpResponse.getStatusLine().getStatusCode());
}

final String responseBody = IOUtils.toString(responseEntity.getContent());
if (StringUtils.isBlank(responseBody)) {
throw new CastlabsException("Empty response entity from Castlabs. HTTP Status: " + httpResponse.getStatusLine().getStatusCode());
}

if (statusCode != HttpStatus.SC_OK) {
throw new CastlabsException("Unexpected status code from Castlabs: " + statusCode + ". Response body: " + responseBody);
}

// The response body is a newline-separated list of JSON objects, so we have to parse them individually
final List<DownloadKeysResponse> responses = new ArrayList<>();
final String[] keys = responseBody.split("\n");
for(String key : keys) {
responses.add(objectMapper.readValue(key, DownloadKeysResponse.class));
}

return responses;
}
}

private HttpPost createHttpPostRequest(final String uri, final Object body) throws JsonProcessingException, UnsupportedEncodingException {
final HttpPost request = new HttpPost(uri);
request.addHeader("Content-Type", "application/json");
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
package com.brightcove.castlabs.client.response;

public class DownloadKeysResponse {

public String uuid;
public String type;
public String keyId;
public String streamType;
public String assetId;
public String variantId;
public String keyRotationId;
public String ingestChannel;
public String ingestRegion;
public String auditChanged;
public String auditChangedBy;

public String getUuid() {
return uuid;
}

public void setUuid(String uuid) {
this.uuid = uuid;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public String getKeyId() {
return keyId;
}

public void setKeyId(String keyId) {
this.keyId = keyId;
}

public String getStreamType() {
return streamType;
}

public void setStreamType(String streamType) {
this.streamType = streamType;
}

public String getAssetId() {
return assetId;
}

public void setAssetId(String assetId) {
this.assetId = assetId;
}

public String getVariantId() {
return variantId;
}

public void setVariantId(String variantId) {
this.variantId = variantId;
}

public String getKeyRotationId() {
return keyRotationId;
}

public void setKeyRotationId(String keyRotationId) {
this.keyRotationId = keyRotationId;
}

public String getIngestChannel() {
return ingestChannel;
}

public void setIngestChannel(String ingestChannel) {
this.ingestChannel = ingestChannel;
}

public String getIngestRegion() {
return ingestRegion;
}

public void setIngestRegion(String ingestRegion) {
this.ingestRegion = ingestRegion;
}

public String getAuditChanged() {
return auditChanged;
}

public void setAuditChanged(String auditChanged) {
this.auditChanged = auditChanged;
}

public String getAuditChangedBy() {
return auditChangedBy;
}

public void setAuditChangedBy(String auditChangedBy) {
this.auditChangedBy = auditChangedBy;
}

@Override
public String toString() {
return "DownloadKeysResponse{" +
"uuid='" + uuid + '\'' +
", type='" + type + '\'' +
", keyId='" + keyId + '\'' +
", streamType='" + streamType + '\'' +
", assetId='" + assetId + '\'' +
", variantId='" + variantId + '\'' +
", keyRotationId='" + keyRotationId + '\'' +
", ingestChannel='" + ingestChannel + '\'' +
", ingestRegion='" + ingestRegion + '\'' +
", auditChanged='" + auditChanged + '\'' +
", auditChangedBy='" + auditChangedBy + '\'' +
'}';
}

}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,10 +9,12 @@

import java.io.FileInputStream;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.TimeUnit;

import com.brightcove.castlabs.client.request.*;
import com.brightcove.castlabs.client.response.AddSubMerchantAccountResponse;
import com.brightcove.castlabs.client.response.DownloadKeysResponse;
import com.brightcove.castlabs.client.response.ListAccountsResponse;
import com.google.common.collect.Lists;
import org.apache.commons.io.IOUtils;
Expand DownExpand Up@@ -545,6 +547,41 @@ public void testItCanHandleCastlabsErrorsWhenMakingAListAccountsRequest() throws
}
}

@Test
public void testItCanDownloadKeys() throws Exception {
final String merchantId = "merchX";
final HttpRequest expectedRequest =
request().withMethod("GET").withPath("/frontend/download-api/ingestion/query/v1/keys/" + merchantId + "/download")
.withQueryStringParameter("ticket", exampleTicket);
final String mockResponse = getTestResourceAsString("sample_download_keys_response");
mockServerClient.when(expectedRequest).respond(response().withStatusCode(200).withBody(mockResponse));

final List<DownloadKeysResponse> response = castlabsClient.downloadKeys(merchantId);

assertNotNull(response);
assertEquals(2, response.size());
assertEquals("10204c7b2c154b47a5af2ee41ecebf01", response.get(0).keyId);
assertEquals("9fa85148ebc441c7a2f361c7927be915", response.get(1).keyId);
mockServerClient.verify(expectedRequest, VerificationTimes.once());
}

@Test
public void testItCanHandleCastlabsErrorsWhenDownloadingKeys() throws Exception {
final String merchantId = "merchX";
final HttpRequest expectedRequest =
request().withMethod("GET").withPath("/frontend/download-api/ingestion/query/v1/keys/" + merchantId + "/download")
.withQueryStringParameter("ticket", exampleTicket);
mockServerClient.when(expectedRequest).respond(response().withStatusCode(403));

try {
castlabsClient.downloadKeys(merchantId);
fail("Expected a CastlabsException to be returned");
} catch(CastlabsException e) {
assertEquals(e.getMessage(), "Empty response entity from Castlabs. HTTP Status: 403");
mockServerClient.verify(expectedRequest, VerificationTimes.once());
}
}

private String getTestResourceAsString(String filename) throws IOException {
final String path = this.getClass().getClassLoader().getResource(filename).getFile();
return IOUtils.toString(new FileInputStream(path));
Expand Down
2 changes: 2 additions & 0 deletionssrc/test/resources/sample_download_keys_response
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
{"uuid":"0000f5ac-e520-3b7f-b9f1-2201210887e1","type":"CENC","keyId":"10204c7b2c154b47a5af2ee41ecebf01","streamType":"VIDEO_AUDIO","assetId":"10204c7b-2c15-4b47-a5af-2ee41ecebf0a","variantId":"playready","ingestChannel":"API","ingestRegion":"US_WEST_1","auditChanged":"2016-03-15T11:20:40.880Z","auditChangedBy":"332cf57f-0941-482c-82cd-d1c8bc32cb51"}
{"uuid":"0001a754-09a7-3457-8608-3ddf7cfd1705","type":"CENC","keyId":"9fa85148ebc441c7a2f361c7927be915","streamType":"VIDEO_AUDIO","assetId":"13cb7cfd-4b42-4f9c-a67c-3577fb431c43","variantId":"widevine","ingestChannel":"API","ingestRegion":"US_WEST_1","auditChanged":"2016-02-12T15:02:58.964Z","auditChangedBy":"332cf57f-0941-482c-82cd-d1c8bc32cb51"}

[8]ページ先頭

©2009-2025 Movatter.jp