/**
  * @covers WindowsAzure\MediaServices\Models\AssetDeliveryPolicy::getAssetDeliveryConfiguration
  * @covers WindowsAzure\MediaServices\Models\AssetDeliveryPolicy::setAssetDeliveryConfiguration
  */
 public function testGetSetAssetDeliveryConfiguration()
 {
     // Setup
     $expected = '<root>sample configuration</root>';
     $assetDeliveryPolicy = new AssetDeliveryPolicy();
     // Test
     $assetDeliveryPolicy->setAssetDeliveryConfiguration($expected);
     $result = $assetDeliveryPolicy->getAssetDeliveryConfiguration();
     // Assert
     $this->assertEquals($expected, $result);
 }
 private function makeProgram($name, $channel)
 {
     $asset = new Asset(Asset::OPTIONS_NONE);
     $asset->setName(TestResources::MEDIA_SERVICES_ASSET_NAME . $this->createSuffix());
     $asset = $this->createAsset($asset);
     $policy = new AssetDeliveryPolicy();
     $policy->setName("Clear Policy");
     $policy->setAssetDeliveryProtocol(AssetDeliveryProtocol::SMOOTH_STREAMING | AssetDeliveryProtocol::DASH | AssetDeliveryProtocol::HLS);
     $policy->setAssetDeliveryPolicyType(AssetDeliveryPolicyType::NO_DYNAMIC_ENCRYPTION);
     $policy = $this->createAssetDeliveryPolicy($policy);
     $this->restProxy->linkDeliveryPolicyToAsset($asset, $policy);
     $program = new Program();
     $program->setName($name);
     $program->setAssetId($asset->getId());
     $program->setArchiveWindowLength(new \DateInterval("PT1H"));
     $program->setChannelId($channel->getId());
     return $program;
 }
 /**
  * Get AssetDeliveryPolicy list linked to an Asset 
  *
  * @param \WindowsAzure\MediaServices\Models\Asset|string $asset Asset data or
  * Asset Id to retrieve the linked delivery policies.
  *
  * @return array
  */
 public function getAssetLinkedDeliveryPolicy($asset)
 {
     $assetId = Utilities::getEntityId($asset, 'WindowsAzure\\MediaServices\\Models\\Asset');
     $propertyList = $this->_getEntityList("Assets('{$assetId}')/DeliveryPolicies");
     $result = array();
     foreach ($propertyList as $properties) {
         $result[] = AssetDeliveryPolicy::createFromOptions($properties);
     }
     return $result;
 }
 /**
  * 
  * @covers WindowsAzure\MediaServices\MediaServicesRestProxy::deleteAssetDeliveryPolicy
  */
 public function testDeleteAssetDeliveryPolicy()
 {
     // Setup
     $countBefore = count($this->restProxy->getAssetDeliveryPolicyList());
     $name = TestResources::MEDIA_SERVICES_ASSET_DELIVERY_POLICY_NAME . $this->createSuffix();
     $policy = new AssetDeliveryPolicy();
     $policy->setName($name);
     $policy->setAssetDeliveryProtocol(AssetDeliveryProtocol::ALL);
     $policy->setAssetDeliveryPolicyType(AssetDeliveryPolicyType::BLOCKED);
     $result = $this->restProxy->createAssetDeliveryPolicy($policy);
     $countMiddle = count($this->restProxy->getAssetDeliveryPolicyList());
     // Test
     $this->restProxy->deleteAssetDeliveryPolicy($result);
     $countAfter = count($this->restProxy->getAssetDeliveryPolicyList());
     // Assert
     $this->assertEquals($countMiddle - 1, $countBefore);
     $this->assertEquals($countBefore, $countAfter);
     $this->assertEquals($countMiddle - 1, $countAfter);
 }
 /**
  * Create AssetDeliveryPolicy from array
  *
  * @param array $options Array containing values for object properties
  *
  * @return AssetDeliveryPolicy
  */
 public static function createFromOptions($options)
 {
     $assetDeliveryPolicy = new AssetDeliveryPolicy();
     $assetDeliveryPolicy->fromArray($options);
     return $assetDeliveryPolicy;
 }
function createAssetDeliveryPolicy($restProxy, $encodedAsset, $contentKey, $fairPlayIV)
{
    // 5.1 Get the acquisition URL
    $acquisitionUrl = $restProxy->getKeyDeliveryUrl($contentKey, ContentKeyDeliveryType::FAIRPLAY);
    $acquisitionUrl = str_replace_first("https", "skd", $acquisitionUrl);
    // remove query string
    if (strpos($acquisitionUrl, '?') !== false) {
        $acquisitionUrl = substr($acquisitionUrl, 0, strrpos($acquisitionUrl, "?"));
    }
    // 5.2 Generate the AssetDeliveryPolicy Configuration Key
    $configuration = [AssetDeliveryPolicyConfigurationKey::FAIRPLAY_BASE_LICENSE_ACQUISITION_URL => $acquisitionUrl, AssetDeliveryPolicyConfigurationKey::COMMON_ENCRYPTION_IV_FOR_CBCS => $fairPlayIV];
    $confJson = AssetDeliveryPolicyConfigurationKey::stringifyAssetDeliveryPolicyConfiguartionKey($configuration);
    // 5.3 Create the AssetDeliveryPolicy
    $adpolicy = new AssetDeliveryPolicy();
    $adpolicy->setName('Asset Delivery Policy');
    $adpolicy->setAssetDeliveryProtocol(AssetDeliveryProtocol::HLS);
    $adpolicy->setAssetDeliveryPolicyType(AssetDeliveryPolicyType::DYNAMIC_COMMON_ENCRYPTION_CBCS);
    $adpolicy->setAssetDeliveryConfiguration($confJson);
    $adpolicy = $restProxy->createAssetDeliveryPolicy($adpolicy);
    // 5.4 Link the AssetDeliveryPolicy to the Asset
    $restProxy->linkDeliveryPolicyToAsset($encodedAsset, $adpolicy->getId());
    echo "Added Asset Delivery Policy: name={$adpolicy->getName()} id={$adpolicy->getId()}" . PHP_EOL;
}
function createAssetDeliveryPolicy($restProxy, $encodedAsset, $contentKey)
{
    // 5.1 Get the acquisition URL
    $acquisitionUrl = $restProxy->getKeyDeliveryUrl($contentKey, ContentKeyDeliveryType::BASELINE_HTTP);
    // 5.2 Generate the AssetDeliveryPolicy Configuration Key
    $randomKey = Utilities::generateCryptoKey(16);
    $configuration = [AssetDeliveryPolicyConfigurationKey::ENVELOPE_KEY_ACQUISITION_URL => $acquisitionUrl, AssetDeliveryPolicyConfigurationKey::ENVELOPE_ENCRYPTION_IV_AS_BASE64 => base64_encode($randomKey)];
    $confJson = AssetDeliveryPolicyConfigurationKey::stringifyAssetDeliveryPolicyConfiguartionKey($configuration);
    // 5.3 Create the AssetDeliveryPolicy
    $adpolicy = new AssetDeliveryPolicy();
    $adpolicy->setName('Asset Delivery Policy');
    $adpolicy->setAssetDeliveryProtocol(AssetDeliveryProtocol::SMOOTH_STREAMING | AssetDeliveryProtocol::DASH | AssetDeliveryProtocol::HLS);
    $adpolicy->setAssetDeliveryPolicyType(AssetDeliveryPolicyType::DYNAMIC_ENVELOPE_ENCRYPTION);
    $adpolicy->setAssetDeliveryConfiguration($confJson);
    $adpolicy = $restProxy->createAssetDeliveryPolicy($adpolicy);
    // 5.4 Link the AssetDeliveryPolicy to the Asset
    $restProxy->linkDeliveryPolicyToAsset($encodedAsset, $adpolicy->getId());
    print "Added Asset Delivery Policy: name={$adpolicy->getName()} id={$adpolicy->getId()}\r\n";
}
$ckapolicy = $restProxy->createContentKeyAuthorizationPolicy($ckapolicy);
// 4.4 Link the ContentKeyAuthorizationPolicyOption to the ContentKeyAuthorizationPolicy
$restProxy->linkOptionsToContentKeyAuthorizationPolicy($option, $ckapolicy);
// 4.5 Associate the ContentKeyAuthorizationPolicy with the ContentKey
$contentKey->setAuthorizationPolicyId($ckapolicy->getId());
$restProxy->updateContentKey($contentKey);
print "Added Content Key Authorization Policy: name={$ckapolicy->getName()} id={$ckapolicy->getId()}\r\n";
// Phase 5 - Create the AssetDeliveryPolicy
// 5.1 Get the acquisition URL
$acquisitionUrl = $restProxy->getKeyDeliveryUrl($contentKey, ContentKeyDeliveryType::BASELINE_HTTP);
// 5.2 Generate the AssetDeliveryPolicy Configuration Key
$randomKey = Utilities::generateCryptoKey(16);
$configuration = [AssetDeliveryPolicyConfigurationKey::ENVELOPE_KEY_ACQUISITION_URL => $acquisitionUrl, AssetDeliveryPolicyConfigurationKey::ENVELOPE_ENCRYPTION_IV_AS_BASE64 => base64_encode($randomKey)];
$confJson = AssetDeliveryPolicyConfigurationKey::stringifyAssetDeliveryPolicyConfiguartionKey($configuration);
// 5.3 Create the AssetDeliveryPolicy
$adpolicy = new AssetDeliveryPolicy();
$adpolicy->setName('Asset Delivery Policy');
$adpolicy->setAssetDeliveryProtocol(AssetDeliveryProtocol::SMOOTH_STREAMING | AssetDeliveryProtocol::DASH | AssetDeliveryProtocol::HLS);
$adpolicy->setAssetDeliveryPolicyType(AssetDeliveryPolicyType::DYNAMIC_ENVELOPE_ENCRYPTION);
$adpolicy->setAssetDeliveryConfiguration($confJson);
$adpolicy = $restProxy->createAssetDeliveryPolicy($adpolicy);
// 5.4 Link the AssetDeliveryPolicy to the Asset
$restProxy->linkDeliveryPolicyToAsset($encodedAsset, $adpolicy->getId());
print "Added Asset Delivery Policy: name={$adpolicy->getName()} id={$adpolicy->getId()}\r\n";
// Phase 6 - Publish
// 6.1 Get the .ISM AssetFile
$files = $restProxy->getAssetFileList();
$manifestFile = null;
foreach ($files as $file) {
    //print "File {$file->getName()} assetId={$file->getParentAssetId()}\r\n";
    if ($file->getParentAssetId() === $encodedAsset->getId() && endsWith(strtolower($file->getName()), '.ism')) {
function createAssetDeliveryPolicy($restProxy, $encodedAsset, $contentKey)
{
    // 5.1 Get the acquisition URL
    $acquisitionUrl = $restProxy->getKeyDeliveryUrl($contentKey, ContentKeyDeliveryType::PLAYREADY_LICENSE);
    $widevineURl = $restProxy->getKeyDeliveryUrl($contentKey, ContentKeyDeliveryType::WIDEVINE);
    // 5.2 Generate the AssetDeliveryPolicy Configuration Key
    $configuration = [AssetDeliveryPolicyConfigurationKey::PLAYREADY_LICENSE_ACQUISITION_URL => $acquisitionUrl, AssetDeliveryPolicyConfigurationKey::WIDEVINE_LICENSE_ACQUISITION_URL => $widevineURl];
    $confJson = AssetDeliveryPolicyConfigurationKey::stringifyAssetDeliveryPolicyConfiguartionKey($configuration);
    // 5.3 Create the AssetDeliveryPolicy
    $adpolicy = new AssetDeliveryPolicy();
    $adpolicy->setName('Asset Delivery Policy');
    $adpolicy->setAssetDeliveryProtocol(AssetDeliveryProtocol::DASH);
    $adpolicy->setAssetDeliveryPolicyType(AssetDeliveryPolicyType::DYNAMIC_COMMON_ENCRYPTION);
    $adpolicy->setAssetDeliveryConfiguration($confJson);
    $adpolicy = $restProxy->createAssetDeliveryPolicy($adpolicy);
    // 5.4 Link the AssetDeliveryPolicy to the Asset
    $restProxy->linkDeliveryPolicyToAsset($encodedAsset, $adpolicy->getId());
    print "Added Asset Delivery Policy: name={$adpolicy->getName()} id={$adpolicy->getId()}\r\n";
}
function createAssetDeliveryPolicy($restProxy, $encodedAsset, $contentKey)
{
    // 5.1 Get the acquisition URL
    $acquisitionUrl = $restProxy->getKeyDeliveryUrl($contentKey, ContentKeyDeliveryType::PLAYREADY_LICENSE);
    $widevineUrl = $restProxy->getKeyDeliveryUrl($contentKey, ContentKeyDeliveryType::WIDEVINE);
    // remove query string
    if (strpos($widevineUrl, '?') !== false) {
        $widevineUrl = substr($widevineUrl, 0, strrpos($widevineUrl, "?"));
    }
    // 5.2 Generate the AssetDeliveryPolicy Configuration Key
    $configuration = [AssetDeliveryPolicyConfigurationKey::PLAYREADY_LICENSE_ACQUISITION_URL => $acquisitionUrl, AssetDeliveryPolicyConfigurationKey::WIDEVINE_BASE_LICENSE_ACQUISITION_URL => $widevineUrl];
    $confJson = AssetDeliveryPolicyConfigurationKey::stringifyAssetDeliveryPolicyConfiguartionKey($configuration);
    // 5.3 Create the AssetDeliveryPolicy
    $adpolicy = new AssetDeliveryPolicy();
    $adpolicy->setName('Asset Delivery Policy');
    $adpolicy->setAssetDeliveryProtocol(AssetDeliveryProtocol::DASH);
    $adpolicy->setAssetDeliveryPolicyType(AssetDeliveryPolicyType::DYNAMIC_COMMON_ENCRYPTION);
    $adpolicy->setAssetDeliveryConfiguration($confJson);
    $adpolicy = $restProxy->createAssetDeliveryPolicy($adpolicy);
    // 5.4 Link the AssetDeliveryPolicy to the Asset
    $restProxy->linkDeliveryPolicyToAsset($encodedAsset, $adpolicy->getId());
    echo "Added Asset Delivery Policy: name={$adpolicy->getName()} id={$adpolicy->getId()}" . PHP_EOL;
}