question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

contentKeyPolicies.createOrUpdate parameters structure

See original GitHub issue

I am trying to invoke contentKeyPolicies.createOrUpdate and I can’t figure out from the docs what the structure of parameters.options look like. This tells me it’s an array of the Key Policy options but I can’t find what Key Policy options look like.

This is what I have so far:

const AzureMediaServices = require("azure-arm-mediaservices").AzureMediaServices;
const AzureMediaServicesModels = require("azure-arm-mediaservices").AzureMediaServicesModels;

.
.
.

const azureMediaServicesClient = new AzureMediaServices(credentials, "<MASKED>");

const contentKeyPolicyPlain = {options: [{
    configuration: {
        responseCustomData: null,
        licenses: [{
            allowTestDevices: true,
            contentKeyLocation: new AzureMediaServicesModels.ContentKeyPolicyPlayReadyContentEncryptionKeyFromHeader(),
            contentType: 'UltraVioletDownload',
            licenseType: 'NonPersistent'
        }]
    },
    restriction: new AzureMediaServicesModels.ContentKeyPolicyOpenRestriction()
}]};

return azureMediaServicesClient.contentKeyPolicies.createOrUpdate("<MASKED>", "<MASKED>", "test-policy-1", contentKeyPolicyPlain)
    .then(function (result) {
        console.log("The result is:");
        console.log(result);
    }).catch(function (err) {
        console.error(err);
    });

And I am getting the following error:

Error: A type named 'configuration' could not be resolved by the model. When a model is available, each type name must resolve to a valid type.

with HTTP 400

Please advise.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
amarzaverycommented, Jun 8, 2018

I have an idea of what is going on. The problem is in the way the objects are being created with new operator for method parameters. That will simply give you empty objects (since those model classes have no properties) and will not serve the purpose.

In JS world, customers like to provide anonymous JSON objects as parameters to the method. Hence the SDK expects you to use {} and populate properties of the object at all the levels.

I do understand that this is a broken experience. We are working on a new TypeScript SDK where we only generate interfaces for models. There are no classes. Hence there will be no way to use the new operator and therefor no confusion.

For polymorphic types, the property marked as discriminator (in this case, odatatype) is a required property and it’s value must match what the service expects on the wire. To make matters worse, we don’t document the expected value for this property or atleast provide an enum in the TS type definitions that could tell you what the values are.

The way to find the value for the discriminator property is to look at the mapper function in the source code for that model class and use the serializedName of that model as the value for the discriminator property.

For example: The value for odatatype property of ContentKeyPolicyPlayReadyContentEncryptionKeyFromHeader can be found from here.

const AzureMediaServices = require("azure-arm-mediaservices").AzureMediaServices;
const AzureMediaServicesModels = require("azure-arm-mediaservices").AzureMediaServicesModels;

.
.
.

const azureMediaServicesClient = new AzureMediaServices(credentials, "<MASKED>");

const contentKeyPolicyPlain = {options: [{
    configuration: {
        responseCustomData: null,
        licenses: [{
            allowTestDevices: true,
            // This will not help..
            // contentKeyLocation: new AzureMediaServicesModels.ContentKeyPolicyPlayReadyContentEncryptionKeyFromHeader(),
           // This will work..
           contentKeyLocation: {
              odatatype: "#Microsoft.Media.ContentKeyPolicyPlayReadyContentEncryptionKeyFromHeader"
            },
            contentType: 'UltraVioletDownload',
            licenseType: 'NonPersistent'
        }]
    },
    // Same for restriction 
    restriction: {
      odatatype: "#Microsoft.Media.ContentKeyPolicyOpenRestriction"
    }
}]};

return azureMediaServicesClient.contentKeyPolicies.createOrUpdate("<MASKED>", "<MASKED>", "test-policy-1", contentKeyPolicyPlain)
    .then(function (result) {
        console.log("The result is:");
        console.log(result);
    }).catch(function (err) {
        console.error(err);
    });

I agree that this experience is not acceptable and we will provide a better experience in the new TypeScript SDK at the earliest.

0reactions
aaanicommented, Jun 8, 2018

Thanks @amarzavery. This parameters object worked for me:

const contentKeyPolicyPlain = {
    options: [{
        configuration: {
            responseCustomData: null,
            licenses: [{
                allowTestDevices: true,
                // This will not help..
                // contentKeyLocation: new AzureMediaServicesModels.ContentKeyPolicyPlayReadyContentEncryptionKeyFromHeader(),
                // This will work..
                contentKeyLocation: {
                    odatatype: "#Microsoft.Media.ContentKeyPolicyPlayReadyContentEncryptionKeyFromHeader"
                },
                contentType: 'UltraVioletDownload',
                licenseType: 'NonPersistent'
            }],
            odatatype: "#Microsoft.Media.ContentKeyPolicyPlayReadyConfiguration"
        },
        // Same for restriction
        restriction: {
            odatatype: "#Microsoft.Media.ContentKeyPolicyOpenRestriction"
        }
    }]
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

Content Key Policies - Create Or Update - Microsoft Learn
Create or update an Content Key Policy Create or update a Content Key ... URI Parameters; Request Body; Responses; Examples; Definitions.
Read more >
azure-native.media.Transform - Pulumi
A Transform encapsulates the rules or instructions for generating desired outputs from input media, such as by transcoding or by extracting ...
Read more >
Azure Resource Manager Overview | Microsoft Docs
parameters , variables , resources , and output . For more information, see Understand the structure and syntax of Azure Resource Manager Templates....
Read more >
https://raw.githubusercontent.com/MicrosoftDocs/az...
Insights/diagnosticSettings/read | Gets the diagnostic settings for the resource ... Media/mediaservices/contentKeyPolicies/write | Create or Update any ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found