def token_cb(token): self.indx_con = IndxClient(self.credentials['address'], self.credentials['box'], appid, token=token, client=authclient.client) return_d.callback(True)
def token_cb(token): indx = IndxClient(server_url, self.config_box, "INDX_Fitbit_Harvester", token=token, client=authclient.client) indx_d.callback(indx)
def token_cb(token): indx = IndxClient(server_url, box, "Slicer", token=token, client=authclient.client) logging.debug("Got the indx client token") indx_d.callback(indx)
def token_cb(token): if not self.indx: self.indx = IndxClient(self.args['server'], self.args['box'], self.appid, token=token, client=self.client) do_call()
def call_action(self, name, *args, **kwargs): """ Calls an action by name. """ action = self.actions[name] f = action['f'] self.check_args(action['args']) if not self.indx: self.indx = IndxClient(self.args['server'], self.args['box'], self.args['username'], self.args['password'], self.appid) return self.parse_status(name, f(*args, **kwargs))
def token_cb(remote_token): logging.debug("IndxSync sync_boxes token_cb") client = IndxClient(remote_server_url, remote_box, self.APPID, client = clientauth.client, token = remote_token, keystore = self.keystore) def updated_cb(empty): def pushed_cb(empty): def observer(data): if data.get('action') == 'diff' and data.get('operation') == 'update': diff = data['data'] def done_cb(empty): logging.debug("IndxSync updating from a websocket done.") def err_cb(failure): logging.error("IndxSync updating from a websocket error: {0}".format(failure)) self.update_to_latest_version(client, remote_server_url, remote_box, diff_in = diff).addCallbacks(done_cb, err_cb) else: logging.error("Sync: Unknown data message from WebSocket: {0}".format(data)) # auths and sets up listening for diffs, filtering them and passing them to the observer if websocket is None: wsclient = client.connect_ws(local_key['key']['private'], local_key_hash, observer, remote_encpk2, self.webserver) # open a new socket else: websocket.listen_remote(local_key['key']['private'], local_key_hash, observer, remote_encpk2) # use an existing websocket next_model(None) if not include_push_all: pushed_cb(None) return # push the whole box to the remote box def latest_cb(graph): def ver_cb(version): client.update_raw(version, graph.to_flat_json()).addCallbacks(pushed_cb, return_d.errback) client.get_version().addCallbacks(lambda resp: ver_cb(resp['data']), return_d.errback) self.root_store.get_latest(render_json = False).addCallbacks(latest_cb, return_d.errback) # compare local version to previous, and update one of them, or both self.update_to_latest_version(client, remote_server_url, remote_box).addCallbacks(updated_cb, return_d.errback)
def ver_cb(ver): def new_remote_key_cb(remote_keys): logging.debug("IndxSync link_remote_box, new_remote_key_cb, remote_keys: {0}".format(remote_keys)) # NB: no "private" in remote_keys, that never leaves the remote box. remote_keys = remote_keys['data'] # remove the Indx HTTP response padding remote_encpk = remote_keys['encpk2'] if type(remote_encpk) != type(""): remote_encpk = json.dumps(remote_encpk) remote_serverid = remote_keys['serverid'] link_uid = uuid.uuid1() local_key_uid = uuid.uuid1() remote_key_uid = uuid.uuid1() status1_uid = uuid.uuid1() status2_uid = uuid.uuid1() link_uri = "link-{0}".format(link_uid) status1_uri = "status-{0}".format(status1_uid) status2_uri = "status-{0}".format(status2_uid) # objects get updated to local box, and then synced across to the other boxes once the syncing starts new_objs = [ { "@id": link_uri, "type": [ {"@value": NS_ROOT_BOX + "link"} ], "boxes": [ {"@id": "box-{0}".format(local_key_uid)}, # links to the objs below {"@id": "box-{0}".format(remote_key_uid)}, # links to the objs below ], "statuses": [ {"@id": status1_uri}, {"@id": status2_uri} ], }, { "@id": status1_uri, "type": [ {"@value": NS_ROOT_BOX + "status"} ], "src-boxid": [ {"@value": remote_box} ], "src-server-url": [ {"@value": remote_address} ], "dst-boxid": [ {"@value": self.root_store.boxid} ], "dst-server-url": [ {"@value": self.url} ], "last-version-seen": [ {"@value": ver + 1} ], #we save this because we will push our whole box to it in a sec - it is incremented because the version is before we put this in }, { "@id": status2_uri, "type": [ {"@value": NS_ROOT_BOX + "status"} ], "dst-boxid": [ {"@value": remote_box} ], "dst-server-url": [ {"@value": remote_address} ], "src-boxid": [ {"@value": self.root_store.boxid} ], "src-server-url": [ {"@value": self.url} ], }, { "@id": "box-{0}".format(local_key_uid), "type": [ {"@value": NS_ROOT_BOX + "box"} ], "server-url": [ {"@value": self.url } ], "server-id": [ {"@value": server_id } ], "box": [ {"@value": self.root_store.boxid} ], "key": [ {"@id": local_keys['public-hash']}], # links to the key objs below }, { "@id": "box-{0}".format(remote_key_uid), "type": [ {"@value": NS_ROOT_BOX + "box"} ], "server-url": [ {"@value": remote_address } ], "server-id": [ {"@value": remote_serverid } ], "box": [ {"@value": remote_box} ], "key": [ {"@id": remote_keys['public-hash']}], # links to the key objs below }, { "@id": local_keys['public-hash'], "type": [ {"@value": NS_ROOT_BOX + "key"} ], "public-key": [ {"@value": local_keys['public']} ], # share the full public keys everywhere (private keys only in respective server's keystores) "public-hash": [ {"@value": local_keys['public-hash']} ], # share the full public keys everywhere (private keys only in respective server's keystores) }, { "@id": remote_keys['public-hash'], "type": [ {"@value": NS_ROOT_BOX + "key"} ], "public-key": [ {"@value": remote_keys['public']} ], # share the full public keys everywhere "public-hash": [ {"@value": remote_keys['public-hash']} ], # share the full public keys everywhere }, ] def update_cb(empty): def diff_cb(diff): def applied_cb(empty): def encpk_cb(empty): def remote_added_cb(empty): def local_added_cb(empty): logging.debug("IndxSync link_remote_box, local_added_cb") def added_indx_cb(empty): # start syncing/connecting using the new key self.sync_boxes([link_uri], include_push_all = True).addCallbacks(lambda empty: return_d.callback(remote_keys['public']), return_d.errback) self.database.save_linked_box(self.root_store.boxid).addCallbacks(added_indx_cb, return_d.errback) # add the local key to the local store self.keystore.put(local_keys, local_user, self.root_store.boxid).addCallbacks(local_added_cb, return_d.errback) # store in the local keystore self.keystore.put({"public": remote_keys['public'], "private": "", "public-hash": remote_keys['public-hash']}, local_user, self.root_store.boxid).addCallbacks(remote_added_cb, return_d.errback) # don't save the local encpk2 here, only give it to the remote server. # save the remote encpk2 self.database.save_encpk2(sha512_hash(remote_encpk), remote_encpk, remote_serverid).addCallbacks(encpk_cb, return_d.errback) client.apply_diff(diff).addCallbacks(applied_cb, return_d.errback) self.root_store.diff(0, None, "diff").addCallbacks(diff_cb, return_d.errback) self.root_store.update(new_objs, ver, propagate = True).addCallbacks(update_cb, return_d.errback) client = IndxClient(remote_address, remote_box, self.APPID, token = remote_token) client.generate_new_key(local_keys, local_encpk, server_id).addCallbacks(new_remote_key_cb, return_d.errback)
help="Earliest date to download in format: 2013-01-20") parser.add_argument('--debug', default=False, action="store_true", help="Enable debugging") args = vars(parser.parse_args()) password = getpass.getpass("Nike+ password: "******"INDX password: "******""" Assert data into the INDX. If the version is incorrect, the correct version will be grabbed and the update re-sent. data -- An object to assert into the box. """ global version try: response = indx.update(version, data) version = response['data']['@version'] # update the version except Exception as e: if isinstance(
def token_cb(token): indx = IndxClient(server_url, box, appid, token = token) return_d.callback(indx)