def get_target_users(self, note: Notification) -> List[Entity]: """ This is gonna get complex. The target users are a combination of: - the list in note.target - workspace admins (if it comes from a workspace) - everyone, if it's global - mark as _global_ feed. TODO: add adapters, maybe subclass notifications to handle each source? """ fanout = None cfg = get_config() if note.source == cfg.service_workspace: fanout = WorkspaceFanout(note) elif note.source == cfg.service_groups: fanout = GroupsFanout(note) elif note.source == cfg.service_jobs: fanout = JobsFanout(note) elif note.source == cfg.service_kbase: fanout = KBaseFanout(note) if fanout is not None: user_list = fanout.get_target_users() else: user_list = list(note.users) return user_list
def get_app_names(app_ids: List[str]) -> Dict[str, str]: """ Expects ids to be of the form Module.Method (not Module/Method. Yeah, I know it's harder.) Returns a dict mapping from app id -> app name. Values are None if they don't exist. Errors during lookup will raise a CatalogError. """ cfg = get_config() # maps from Mod.Meth app ids (provided by services) -> Mod/Meth app ids (used in lookup) # If the id is given as Mod/Meth, just maps to itself. slash_app_ids = dict() for app_id in app_ids: if '/' in app_id: slash_app_ids[app_id] = app_id else: slash_app_ids[app_id] = app_id.replace('.', '/') nms = NarrativeMethodStore(url=cfg.nms_url) try: names = dict() infos = nms.get_method_brief_info( {"ids": list(set(slash_app_ids.values()))}) for info in infos: if info is not None: names[info['id']] = info['name'] ret_names = dict() for app_id in app_ids: ret_names[app_id] = names.get(slash_app_ids[app_id]) return ret_names except ServerError as e: raise CatalogError( "An error occurred while retrieving app names: {}".format( e.message))
def fetch_global_notifications(count=0) -> dict: """ Always returns notifications in user view. """ cfg = get_config() if count == 0: count = cfg.default_max_notes global_feed = get_global_feed() global_notes = global_feed.get_notifications(count=count, user_view=True) return global_notes
def __init__(self): self.cfg = get_config() log.log( __name__, "opening MongoDB connection {} {}".format(self.cfg.db_host, self.cfg.db_port)) self.conn = MongoClient(host=self.cfg.db_host, port=self.cfg.db_port, username=self.cfg.db_user, password=self.cfg.db_pw, authSource=self.cfg.db_name) self.db = self.conn[self.cfg.db_name] self._setup_indexes() self._setup_schema()
def test_get_config(dummy_config, dummy_auth_token): cfg_path = dummy_config(GOOD_CONFIG) path_backup = os.environ.get('FEEDS_CONFIG') os.environ['FEEDS_CONFIG'] = cfg_path config.__config = None cfg = config.get_config() assert cfg.db_host == 'foo' assert cfg.db_port == 5 assert cfg.auth_url == 'baz' assert cfg.auth_token == FAKE_AUTH_TOKEN del os.environ['FEEDS_CONFIG'] if path_backup is not None: os.environ['FEEDS_CONFIG'] = path_backup config.__config = None
def setup_redis(): ''' Starts the connection pool for the configured redis server ''' config = get_config() pool = redis.ConnectionPool( host=config.db_host, port=config.db_port, password=config.db_pw, db=config.db_name # decode_responses=config.get('decode_responses', True), # # connection options # socket_timeout=config.get('socket_timeout', None), # socket_connect_timeout=config.get('socket_connect_timeout', None), # socket_keepalive=config.get('socket_keepalive', False), # socket_keepalive_options=config.get('socket_keepalive_options', None), # retry_on_timeout=config.get('retry_on_timeout', False), ) return pool
def _default_lifespan(self) -> int: """ Returns the default lifespan of this notification in ms. """ return get_config().lifespan * 24 * 60 * 60 * 1000
def get_global_feed() -> NotificationFeed: cfg = get_config() return NotificationFeed(cfg.global_feed, cfg.global_feed_type)
import flask from flask import request from flask_cors import cross_origin import json from feeds.activity.notification import Notification from feeds.managers.notification_manager import NotificationManager from feeds.feeds.notification.notification_feed import NotificationFeed from feeds.external_api.auth import (get_auth_token, is_feeds_admin) from feeds.exceptions import (InvalidTokenError) from feeds.config import get_config from .util import (parse_notification_params, parse_expire_notifications_params) from feeds.entity.entity import Entity cfg = get_config() admin_v1 = flask.Blueprint('admin_v1', __name__) @admin_v1.route('/', methods=['GET']) def root(): resp = { 'routes': { 'root': 'GET /admin/api/V1', 'add_global_notification': 'POST /admin/api/V1/notification/global', 'get_specific_notification': 'GET /admin/api/V1/notification/<note_id>', 'expire_notifications': 'POST /admin/api/V1/notifications/expire' } }
def get_target_users(self): cfg = get_config() return [Entity(cfg.global_feed, cfg.global_feed_type)]
def get_target_users(self): cfg = get_config() ws = Workspace(url=cfg.ws_url) return list(set(self.note.users + self.note.target))