<s> '''<STR_LIT>''' <EOL> from __future__ import absolute_import <EOL> import logging <EOL> log = logging . getLogger ( __name__ ) <EOL> try : <EOL> import boto <EOL> import boto . sns <EOL> logging . getLogger ( '<STR_LIT>' ) . setLevel ( logging . CRITICAL ) <EOL> HAS_BOTO = True <EOL> except ImportError : <EOL> HAS_BOTO = False <EOL> def __virtual__ ( ) : <EOL> '''<STR_LIT>''' <EOL> if not HAS_BOTO : <EOL> return ( False , '<STR_LIT>' ) <EOL> __utils__ [ '<STR_LIT>' ] ( __name__ , '<STR_LIT>' , pack = __salt__ ) <EOL> return True <EOL> def get_all_topics ( region = None , key = None , keyid = None , profile = None ) : <EOL> '''<STR_LIT>''' <EOL> cache_key = _cache_get_key ( ) <EOL> try : <EOL> return __context__ [ cache_key ] <EOL> except KeyError : <EOL> pass <EOL> conn = _get_conn ( region = region , key = key , keyid = keyid , profile = profile ) <EOL> __context__ [ cache_key ] = { } <EOL> topics = conn . get_all_topics ( ) <EOL> for t in topics [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] : <EOL> short_name = t [ '<STR_LIT>' ] . split ( '<STR_LIT::>' ) [ - <NUM_LIT:1> ] <EOL> __context__ [ cache_key ] [ short_name ] = t [ '<STR_LIT>' ] <EOL> return __context__ [ cache_key ] <EOL> def exists ( name , region = None , key = None , keyid = None , profile = None ) : <EOL> '''<STR_LIT>''' <EOL> topics = get_all_topics ( region = region , key = key , keyid = keyid , <EOL> profile = profile ) <EOL> if name . startswith ( '<STR_LIT>' ) : <EOL> return name in list ( topics . values ( ) ) <EOL> else : <EOL> return name in list ( topics . keys ( ) ) <EOL> def create ( name , region = None , key = None , keyid = None , profile = None ) : <EOL> '''<STR_LIT>''' <EOL> conn = _get_conn ( region = region , key = key , keyid = keyid , profile = profile ) <EOL> conn . create_topic ( name ) <EOL> log . info ( '<STR_LIT>' . format ( name ) ) <EOL> _invalidate_cache ( ) <EOL> return True <EOL> def delete ( name , region = None , key = None , keyid = None , profile = None ) : <EOL> '''<STR_LIT>''' <EOL> conn = _get_conn ( region = region , key = key , keyid = keyid , profile = profile ) <EOL> conn . delete_topic ( get_arn ( name , region , key , keyid , profile ) ) <EOL> log . info ( '<STR_LIT>' . format ( name ) ) <EOL> _invalidate_cache ( ) <EOL> return True <EOL> def get_all_subscriptions_by_topic ( name , region = None , key = None , keyid = None , profile = None ) : <EOL> '''<STR_LIT>''' <EOL> cache_key = _subscriptions_cache_key ( name ) <EOL> try : <EOL> return __context__ [ cache_key ] <EOL> except KeyError : <EOL> pass <EOL> conn = _get_conn ( region = region , key = key , keyid = keyid , profile = profile ) <EOL> ret = conn . get_all_subscriptions_by_topic ( get_arn ( name , region , key , keyid , profile ) ) <EOL> __context__ [ cache_key ] = ret [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> return __context__ [ cache_key ] <EOL> def subscribe ( topic , protocol , endpoint , region = None , key = None , keyid = None , profile = None ) : <EOL> '''<STR_LIT>''' <EOL> conn = _get_conn ( region = region , key = key , keyid = keyid , profile = profile ) <EOL> conn . subscribe ( get_arn ( topic , region , key , keyid , profile ) , protocol , endpoint ) <EOL> log . info ( '<STR_LIT>' . format ( protocol , endpoint , topic ) ) <EOL> try : <EOL> del __context__ [ _subscriptions_cache_key ( topic ) ] <EOL> except KeyError : <EOL> pass <EOL> return True <EOL> def get_arn ( name , region = None , key = None , keyid = None , profile = None ) : <EOL> '''<STR_LIT>''' <EOL> if name . startswith ( '<STR_LIT>' ) : <EOL> return name <EOL> account_id = __salt__ [ '<STR_LIT>' ] ( <EOL> region = region , key = key , keyid = keyid , profile = profile <EOL> ) <EOL> return '<STR_LIT>' . format ( _get_region ( region , profile ) , <EOL> account_id , name ) <EOL> def _get_region ( region = None , profile = None ) : <EOL> if profile and '<STR_LIT>' in profile : <EOL> return profile [ '<STR_LIT>' ] <EOL> if not region and __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' ) : <EOL> region = __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' ) <EOL> if not region : <EOL> region = '<STR_LIT>' <EOL> return region <EOL> def _subscriptions_cache_key ( name ) : <EOL> return '<STR_LIT>' . format ( _cache_get_key ( ) , name ) <EOL> def _invalidate_cache ( ) : <EOL> try : <EOL> del __context__ [ _cache_get_key ( ) ] <EOL> except KeyError : <EOL> pass <EOL> def _cache_get_key ( ) : <EOL> return '<STR_LIT>' </s>
