

def present(name, subscriptions=None, region=None, key=None, keyid=None, profile=None):
    "\n    Ensure the SNS topic exists.\n\n    name\n        Name of the SNS topic.\n\n    subscriptions\n        List of SNS subscriptions.\n\n        Each subscription is a dictionary with a protocol and endpoint key:\n\n        .. code-block:: python\n\n            [\n            {'protocol': 'https', 'endpoint': 'https://www.example.com/sns-endpoint'},\n            {'protocol': 'sqs', 'endpoint': 'arn:aws:sqs:us-west-2:123456789012:MyQueue'}\n            ]\n\n    region\n        Region to connect to.\n\n    key\n        Secret key to be used.\n\n    keyid\n        Access key to be used.\n\n    profile\n        A dict with region, key and keyid, or a pillar key (string)\n        that contains a dict with region, key and keyid.\n    "
    ret = {
        'name': name,
        'result': None,
        'comment': '',
        'changes': {
            
        },
    }
    is_present = __salt__['boto_sns.exists'](name, region, key, keyid, profile)
    if is_present:
        ret['result'] = True
        ret['comment'] = 'AWS SNS topic {0} present.'.format(name)
    else:
        if __opts__['test']:
            msg = 'AWS SNS topic {0} is set to be created.'.format(name)
            ret['comment'] = msg
            ret['result'] = None
            return ret
        created = __salt__['boto_sns.create'](name, region, key, keyid, profile)
        if created:
            msg = 'AWS SNS topic {0} created.'.format(subscription)
            ret['comment'] = msg
            ret['changes']['old'] = None
            ret['changes']['new'] = {
                'topic': name,
                'subscriptions': [],
            }
            ret['result'] = True
        else:
            ret['comment'] = 'Failed to create {0} AWS SNS topic'.format(name)
            ret['result'] = False
            return ret
    if (not subscriptions):
        return ret
    _subscriptions = __salt__['boto_sns.get_all_subscriptions_by_topic'](name, region=region, key=key, keyid=keyid, profile=profile)
    _subscriptions = [{
        'protocol': s['Protocol'],
        'endpoint': s['Endpoint'],
    } for s in _subscriptions]
    for subscription in subscriptions:
        _endpoint = subscription['endpoint']
        matches = re.search('https://(?P<user>\\w+):(?P<pass>\\w+)@', _endpoint)
        if (matches is not None):
            subscription['endpoint'] = _endpoint.replace(matches.groupdict()['pass'], '****')
        if (subscription not in _subscriptions):
            subscription['endpoint'] = _endpoint
            if __opts__['test']:
                msg = ' AWS SNS subscription {0}:{1} to be set on topic {2}.'.format(subscription['protocol'], subscription['endpoint'], name)
                ret['comment'] += msg
                ret['result'] = None
                continue
            created = __salt__['boto_sns.subscribe'](name, subscription['protocol'], subscription['endpoint'], region=region, key=key, keyid=keyid, profile=profile)
            if created:
                msg = ' AWS SNS subscription {0}:{1} set on topic {2}.'.format(subscription['protocol'], subscription['endpoint'], name)
                ret['comment'] += msg
                ret['changes'].setdefault('old', None)
                ret['changes'].setdefault('new', {
                    
                }).setdefault('subscriptions', []).append(subscription)
                ret['result'] = True
            else:
                ret['result'] = False
                return ret
        else:
            msg = ' AWS SNS subscription {0}:{1} already set on topic {2}.'.format(subscription['protocol'], subscription['endpoint'], name)
            ret['comment'] += msg
    return ret

dataset/ETHPy150Open saltstack/salt/salt/states/boto_sns.py present/VarMisuse@172/542 `name`->`subscription`