Пример #1
0
def add_content_key_policy_option(client, resource_group_name, account_name, content_key_policy_name,
                                  policy_option_name, clear_key_configuration=False, open_restriction=False,
                                  issuer=None, audience=None, token_key=None, token_key_type=None,
                                  alt_symmetric_token_keys=None, alt_rsa_token_keys=None, alt_x509_token_keys=None,
                                  token_claims=None, token_type=None, open_id_connect_discovery_document=None,
                                  widevine_template=None, ask=None, fair_play_pfx_password=None, fair_play_pfx=None,
                                  rental_and_lease_key_type=None, rental_duration=None, play_ready_template=None):

    policy = client.get_policy_properties_with_secrets(resource_group_name, account_name, content_key_policy_name)

    if not policy:
        raise CLIError(build_resource_not_found_message(
            account_name, resource_group_name, 'contentKeyPolicies', content_key_policy_name))

    options = policy.options

    policy_option = _generate_content_key_policy_option(policy_option_name, clear_key_configuration, open_restriction,
                                                        issuer, audience, token_key, token_key_type,
                                                        alt_symmetric_token_keys, alt_rsa_token_keys,
                                                        alt_x509_token_keys, token_claims, token_type,
                                                        open_id_connect_discovery_document, widevine_template,
                                                        ask, fair_play_pfx_password, fair_play_pfx,
                                                        rental_and_lease_key_type, rental_duration, play_ready_template)

    options.append(policy_option)

    return client.update(resource_group_name, account_name,
                         content_key_policy_name, options, policy.description)
Пример #2
0
def remove_content_key_policy_option(client, resource_group_name, account_name, content_key_policy_name,
                                     policy_option_id):
    policy = client.get_policy_properties_with_secrets(resource_group_name, account_name, content_key_policy_name)

    if not policy:
        raise CLIError(build_resource_not_found_message(
            account_name, resource_group_name, 'contentKeyPolicies', content_key_policy_name))

    if all(option.policy_option_id != policy_option_id for option in policy.options):
        raise CLIError('No policy option found with id "' + policy_option_id + '"')

    policy.options = list(filter(lambda option: option.policy_option_id != policy_option_id, policy.options))

    return client.update(resource_group_name, account_name,
                         content_key_policy_name, policy.options)
Пример #3
0
def update_content_key_policy_option(client,
                                     resource_group_name,
                                     account_name,
                                     content_key_policy_name,
                                     policy_option_id,
                                     policy_option_name=None,
                                     issuer=None,
                                     audience=None,
                                     token_key=None,
                                     token_key_type=None,
                                     add_alt_token_key=None,
                                     add_alt_token_key_type=None,
                                     token_claims=None,
                                     token_type=None,
                                     open_id_connect_discovery_document=None,
                                     widevine_template=None,
                                     ask=None,
                                     fair_play_pfx_password=None,
                                     fair_play_pfx=None,
                                     rental_and_lease_key_type=None,
                                     rental_duration=None,
                                     play_ready_template=None):
    policy = client.get_policy_properties_with_secrets(
        resource_group_name=resource_group_name,
        account_name=account_name,
        content_key_policy_name=content_key_policy_name)

    if not policy:
        raise CLIError(
            build_resource_not_found_message(account_name, resource_group_name,
                                             'contentKeyPolicies',
                                             content_key_policy_name))

    policy_option = next((option for option in policy.options
                          if option.policy_option_id == policy_option_id),
                         None)

    if policy_option is None:
        raise CLIError('Policy option with id "' + policy_option_id +
                       '" was not found.')

    if policy_option_name is not None:
        policy_option.name = policy_option_name

    if isinstance(policy_option.restriction, ContentKeyPolicyTokenRestriction):
        if issuer is not None:
            policy_option.restriction.issuer = issuer

        if audience is not None:
            policy_option.restriction.audience = audience

        if token_key is not None and token_key_type is not None:
            if token_key_type == 'Symmetric':
                policy_option.restriction.primary_verification_key = _symmetric_token_key_factory(
                    token_key)
            elif token_key_type == 'RSA':
                policy_option.restriction.primary_verification_key = _rsa_token_key_factory(
                    token_key)
            elif token_key_type == 'X509':
                policy_option.restriction.primary_verification_key = _x509_token_key_factory(
                    token_key)

        if add_alt_token_key is not None and add_alt_token_key_type is not None:
            if add_alt_token_key_type == 'Symmetric':
                policy_option.restriction.alternate_verification_keys.append(
                    _symmetric_token_key_factory(add_alt_token_key))
            elif add_alt_token_key_type == 'RSA':
                policy_option.restriction.alternate_verification_keys.append(
                    _rsa_token_key_factory(add_alt_token_key))
            elif add_alt_token_key_type == 'X509':
                policy_option.restriction.alternate_verification_keys.append(
                    _x509_token_key_factory(add_alt_token_key))

        if token_claims is not None:
            policy_option.restriction.token_claims = []
            for key in token_claims:
                claim = ContentKeyPolicyTokenClaim(
                    claim_type=key, claim_value=token_claims[key])
                policy_option.restriction.token_claims.append(claim)

        if token_type is not None:
            policy_option.restriction.restriction_token_type = token_type

        if open_id_connect_discovery_document is not None:
            policy_option.restriction.open_id_connect_discovery_document = open_id_connect_discovery_document

    if isinstance(policy_option.configuration,
                  ContentKeyPolicyWidevineConfiguration):
        if widevine_template is not None:
            policy_option.configuration = ContentKeyPolicyWidevineConfiguration(
                widevine_template=widevine_template)
    elif isinstance(policy_option.configuration,
                    ContentKeyPolicyFairPlayConfiguration):
        if ask is not None:
            policy_option.configuration.ask = bytearray.fromhex(ask)

        if fair_play_pfx_password is not None:
            policy_option.configuration.fair_play_pfx_password = fair_play_pfx_password

        if fair_play_pfx is not None:
            policy_option.configuration.fair_play_pfx = _b64_to_str(
                _read_binary(fair_play_pfx)).decode('ascii')

        if rental_and_lease_key_type is not None:
            policy_option.configuration.rental_and_lease_key_type = rental_and_lease_key_type

        if rental_duration is not None:
            policy_option.configuration.rental_duration = rental_duration
    elif isinstance(policy_option.configuration,
                    ContentKeyPolicyPlayReadyConfiguration):
        if play_ready_template is not None and _valid_playready_configuration(
                play_ready_template):
            _play_ready_configuration_factory(json.loads(play_ready_template))

    return client.update(resource_group_name, account_name,
                         content_key_policy_name, policy.options,
                         policy.description)