def _get_smart(): if not USE_SMART: return None sess = _get_session() if sess is None: logging.info("There is no session") return None # configure SMART client api_base = sess.get('api_base') if not api_base: logging.info("No api_base is set") return None # we're not using SMART if 'none' == api_base: return None # find server credentials and store in session cons_key = sess.get('consumer_key') cons_sec = sess.get('consumer_secret') if not cons_key or not cons_sec: server = None for ep in ENDPOINTS: if ep.get('url') == api_base: server = ep break if server is None: logging.error("There is no server with base URI %s" % api_base) return None sess['consumer_key'] = cons_key = server.get('consumer_key') sess['consumer_secret'] = cons_sec = server.get('consumer_secret') # init client config = { 'consumer_key': cons_key, 'consumer_secret': cons_sec } try: smart = SMARTClient(os.environ.get('USE_APP_ID'), api_base, config) smart.record_id = sess.get('record_id') except Exception as e: logging.warning("Failed to instantiate SMART client: %s" % e) smart = None # if we have tokens, update the client token = sess.get('token') if token is not None: smart.update_token(token) return smart
def _get_smart(): if not USE_SMART: return None sess = _get_session() if sess is None: logging.info("There is no session") return None # configure SMART client api_base = sess.get('api_base') if not api_base: logging.info("No api_base is set") return None # we're not using SMART if 'none' == api_base: return None # find server credentials and store in session cons_key = sess.get('consumer_key') cons_sec = sess.get('consumer_secret') if not cons_key or not cons_sec: server = None for ep in ENDPOINTS: if ep.get('url') == api_base: server = ep break if server is None: logging.error("There is no server with base URI %s" % api_base) return None sess['consumer_key'] = cons_key = server.get('consumer_key') sess['consumer_secret'] = cons_sec = server.get('consumer_secret') # init client config = {'consumer_key': cons_key, 'consumer_secret': cons_sec} try: smart = SMARTClient(os.environ.get('USE_APP_ID'), api_base, config) smart.record_id = sess.get('record_id') except Exception as e: logging.warning("Failed to instantiate SMART client: %s" % e) smart = None # if we have tokens, update the client token = sess.get('token') if token is not None: smart.update_token(token) return smart
pass print '-> Using "%s"' % ep['name'] # only one endpoint, use it elif len(ENDPOINTS) > 0: ep = ENDPOINTS[0] if ep is None: print "x> There are no SMART containers configured, stopping here" print forever_alone() sys.exit(1) # init SMART client ep_url = ep.get('url') smart = SMARTClient(ep.get('app_id'), ep_url, ep) # -------------------------------------------------------------------------- Background App # loop over all records and test against our rules if _BG: for record_id in smart.loop_over_records(): record = TestRecord(smart) print "-> Record", record.record_id for rule in rules: print "--> Testing against", rule.name if rule.match_against(record): print "==> Record %s matches rule %s" % (record_id, rule.name) print rule.perform_actions(record) sys.exit(0)