def _key_policy(key_metadata, policy, region, key, keyid, profile):
    ret = {'result': True, 'comment': '', 'changes': {}}
    kms_key_id = key_metadata['KeyId']
    rkp = __salt__['boto_kms.get_key_policy'](
        kms_key_id, 'default', region, key, keyid, profile
    )
    if rkp['key_policy'] == policy:
        return ret
    if __opts__['test']:
        msg = '{0} Key set to have key policy updated.'
        ret['comment'] = msg.format(ret['comment'])
        ret['result'] = None
        return ret
    rpkp = __salt__['boto_kms.put_key_policy'](
        kms_key_id, 'default', policy, region, key, keyid, profile
    )
    if 'error' in rpkp:
        msg = '{0} Failed to update key policy: {1}'
        ret['result'] = False
        ret['comment'] = msg.format(ret['comment'], rpkp['error']['message'])
    else:
        ret['comment'] = 'Updated key policy.'
    return ret
dataset/ETHPy150Open saltstack/salt/salt/states/boto_kms.py/_key_policy/original