def _key_present(
        name,
        policy,
        description,
        key_usage,
        key_rotation,
        enabled,
        region,
        key,
        keyid,
        profile):
    ret = {'result': True, 'comment': '', 'changes': {}}
    alias = 'alias/{0}'.format(name)
    r = __salt__['boto_kms.key_exists'](alias, region, key, keyid, profile)
    if 'error' in r:
        ret['result'] = False
        ret['comment'] = 'Error when attempting to find key: {0}.'.format(
            r['error']['message']
        )
        return ret
    if not r['result']:
        if __opts__['test']:
            ret['comment'] = 'Key is set to be created.'
            ret['result'] = None
            return ret
        rc = __salt__['boto_kms.create_key'](
            policy, description, key_usage, region, key, keyid, profile
        )
        key_metadata = rc['key_metadata']
        kms_key_id = key_metadata['KeyId']
        if 'error' in rc:
            ret['result'] = False
            ret['comment'] = 'Failed to create key: {0}'.format(
                rc['error']['message']
            )
            return ret
        rn = __salt__['boto_kms.create_alias'](
            alias, kms_key_id, region, key, keyid, profile
        )
        if 'error' in rn:
            # We can't recover from this. KMS only exposes enable/disable
            # and disable is not necessarily a great action here. AWS sucks
            # for not including alias in the create_key call.
            msg = ('Failed to create key alias for key_id {0}.'
                   ' This resource will be left dangling. Please clean'
                   ' manually. Error: {1}')
            ret['result'] = False
            ret['comment'] = msg.format(kms_key_id, rn['error']['message'])
            return ret
        ret['changes']['old'] = {'key': None}
        ret['changes']['new'] = {'key': name}
        ret['comment'] = 'Key {0} created.'.format(name)
    else:
        rd = __salt__['boto_kms.describe_key'](
            alias, region, key, keyid, profile
        )
        key_metadata = rd['key_metadata']
        if 'error' in rd:
            ret['result'] = False
            ret['comment'] = 'Failed to update key: {0}.'.format(
                rd['error']['message']
            )
            return ret
        _ret = _key_description(
            key_metadata, description, region, key, keyid, profile
        )
        ret['changes'] = dictupdate.update(ret['changes'], _ret['changes'])
        ret['comment'] = ' '.join([ret['comment'], _ret['comment']])
        if not _ret['result']:
            ret['result'] = _ret['result']
            if ret['result'] is False:
                return ret
        _ret = _key_policy(
            key_metadata, policy, region, key, keyid, profile
        )
        ret['changes'] = dictupdate.update(ret['changes'], _ret['changes'])
        ret['comment'] = ' '.join([ret['comment'], _ret['comment']])
        if not _ret['result']:
            ret['result'] = _ret['result']
            if ret['result'] is False:
                return ret
    # Actions that need to occur whether creating or updating
    _ret = _key_enabled(
        key_metadata, enabled, region, key, keyid, profile
    )
    ret['changes'] = dictupdate.update(ret['changes'], _ret['changes'])
    ret['comment'] = ' '.join([ret['comment'], _ret['comment']])
    if not _ret['result']:
        ret['result'] = _ret['result']
        if ret['result'] is False:
            return ret
    _ret = _key_rotation(
        key_metadata, key_rotation, region, key, keyid, profile
    )
    ret['changes'] = dictupdate.update(ret['changes'], _ret['changes'])
    ret['comment'] = ' '.join([ret['comment'], _ret['comment']])
    if not _ret['result']:
        ret['result'] = _ret['result']
    return ret
dataset/ETHPy150Open saltstack/salt/salt/states/boto_kms.py/_key_present/original