def main(args): appkey='tdlst' db = nimbella.redis() print('log A') item=args.get("content","") if item=='': return {"body":{"response":{"result":"error","description":"item not valid"}}} usercode=args.get("user-code","") if usercode=='': return {"body":{"response":{"result":"error","description":"user not valid"}}} code=args.get("code","") if code=='': return {"body":{"response":{"result":"error","description":"item code not valid"}}} print('log B') key = appkey+":item:"+usercode+":"+code to_update=search_item(key) print(to_update) if to_update==None: return {"body":{"response":{"result":"error","description":"item not found"}}} value = json.dumps({ "item": item, "user-code": usercode, "code": code}) print('before save') rsuccess=db.set(key, value) print('after save') return {"body":{"response":{"result":"ok","code":code}}}
def main(args): db = nimbella.redis() keys = db.keys("address:*") data = db.mget(keys) return { "body": [json.loads(i.decode('utf-8')) for i in data] }
def main(args): res = {"error": "nothing to do"} try: # check auth r = redis() if not "token" in args or args["token"] != r.get("tag_token").decode( 'utf-8'): raise Exception("unauthorized") # tags tags = [] if "yes_really_remove_all" in args: tags = [i.decode('utf-8')[4:] for i in r.keys("tag:?*")] elif "tag" in args: if "url" in args: url = args['url'] tag = args['tag'] n = r.lrem("tag:%s" % tag, 1, url) r.hincrby("tag_index", tag, -int(n)) res = {"del": n, "url": url, "tag": tag} else: tags = [args['tag']] if len(tags) > 0: for tag in tags: r.hdel("tag_index", tag) res = {"del": r.delete("tag:%s" % tag), "tags": tags} except KeyError: res = {"error": "missing argument"} except Exception as e: res = {"error": str(e)} except: res = {"error": "unknown"} return {"body": res}
def main(args): appkey = 'tdlst' db = nimbella.redis() print('log A') usercode = args.get("user-code", "") if usercode == '': return { "body": { "response": { "result": "error", "description": "user not valid" } } } items = search_items(usercode) print(items) return { "body": { "response": { "result": "ok", "user-code": usercode, "items": [json.loads(i.decode('utf-8')) for i in items] } } }
def main(args): red = redis() connectors = red.get('connectors') connectors = connectors.decode("utf-8").split(",") if connectors else [] return {"body": {"details": {"connectors": connectors}}}
def main(args): db = nimbella.redis() key = "address:"+args.get("name", "") value = json.dumps({ "name": args.get("name", ""), "company": args.get("company", ""), "phone": args.get("phone", "") }) return { "body": db.set(key, value) }
def main(args): red = redis() res = {} if "set" in args: arg = args["set"] [k, v] = arg.split("=", 1) v = json.dumps(v).encode("utf-8") #print{}} res = {} if red.set(k, v): res["set:%s" % arg] = True else: res["error"] = "cannot set %s to %s" % (k, v) elif "get" in args: k = args["get"] v = red.get(k) if v: v = json.loads(v.decode("utf-8")) try: res[k] = json.loads(v) except: res[k] = v else: res["error"] = "cannot find %s" % k elif "del" in args: k = args["del"] if red.delete(k): res["del:%s" % k] = True else: res["error"] = "cannot delete %s" % k elif "scan" in args: pattern = args["scan"] (cur, ls) = red.scan(0, match=pattern) out = [i.decode('utf-8') for i in ls] while cur > 0: (cur, ls) = red.scan(cur, match=pattern) for i in ls: out.append(i.decode('utf-8')) res["scan"] = out elif "clean" in args: pattern = args["clean"] (cur, ls) = red.scan(0, match=pattern) out = [i.decode('utf-8') for i in ls] while cur > 0: (cur, ls) = red.scan(cur, match=pattern) for i in ls: out.append(i.decode('utf-8')) res = {} for i in out: res[i] = red.delete(i) == 1 if "__ow_method" in args: return {"body": json.dumps(res)} return res
def search_user(username): appkey='tdlst' db = nimbella.redis() keys = db.keys(appkey+":user:*") data = db.mget(keys) res_user=None for user in data: d = json.loads(user.decode('utf-8')) print(d) if username==d['username']: res_user=d return res_user
def main(args): red = redis() body = args["__ow_body"] if args["__ow_headers"]["content-type"] == "application/json": body = base64.b64decode(body).decode("utf-8") body = json.loads(body) # with open("import.json", "r") as f: body = json.loads(f.read()) data = [("message:%s" % m["fiscal_code"], m) for m in body["data"]] res = {} for (k, v) in data: v = json.dumps(v).encode("utf-8") res[k] = red.set(k, v) return {"body": res}
def main(args): dest = args.get("fiscal_code") subj = args.get("subject") mesg = args.get("markdown") if dest and subj and mesg: id = str(zlib.crc32(dest.encode("utf-8"))) red = redis() data = {"subject": subj, "markdown": mesg, "fiscal_code": dest} data = json.dumps(data).encode("utf-8") red.set("sent:%s" % dest, data) return {"body": {"id": id}} return {"body": {"detail": "validation errors"}}
def main(args): appkey='tdlst' print('log A') usercode=args.get("user-code","") if usercode=='': return {"body":{"response":{"result":"error","description":"user not valid"}}} code=args.get("code","") if code=='': return {"body":{"response":{"result":"error","description":"item code not valid"}}} db = nimbella.redis() key = appkey+":item:"+usercode+":"+code db.delete(key) return {"body":{"response":{"result":"ok","code":code}}}
def main(args): body = args["__ow_body"] if args["__ow_headers"]["content-type"] == "application/json": body = base64.b64decode(body).decode("utf-8") body = json.loads(body) if ( body.get("fiscal_code") and body.get("content") and body.get("content").get("subject") and body.get("content").get("markdown") and body.get("content").get("due_date") ): code = body["fiscal_code"] id = str(zlib.crc32(code.encode("utf-8"))) red = redis() data = json.dumps(body).encode("utf-8") red.set("message:%s" % code, data) return {"body": {"id": id} } return { "body": { "detail": "validation errors"}}
def main(args): try: # check auth r = redis() if not "token" in args or args["token"] != r.get("tag_token").decode( 'utf-8'): raise Exception("unauthorized") # tags hash = r.hgetall("tag_index") list = [[k.decode('utf-8'), int(hash[k].decode('utf-8'))] for k in hash.keys()] res = {"tags": list} except KeyError: res = {"error": "missing argument"} except Exception as e: res = {"error": str(e)} except: res = {"error": "unknown"} return {"body": res}
def main(args): try: # check auth r = redis() if not "token" in args or args["token"] != r.get("tag_token").decode( 'utf-8'): raise Exception("unauthorized") # tag tag = args['tag'] key = "tag:%s" % tag count = r.llen(key) list = [i.decode('utf-8') for i in r.lrange(key, 0, count)] res = {tag: list} except KeyError: res = {"error": "missing argument"} except Exception as e: res = {"error": str(e)} except: res = {"error": "unknown"} return {"body": res}
def main(args): password = args["nimbelicious_password"] r = nimbella.redis() if r.exists("tag_token"): token = r.get("tag_token").decode('utf-8') else: token = secrets.token_hex(16) r.set("tag_token", token) res = {"error": "no args"} if "password" in args: if args["password"] == password: res = {"token": token} else: res = {"error": "bad password"} if "token" in args: if args['token'] == token: res = {"ok": True} else: res = {"error": "bad token"} return {"body": res}
def main(args): try: # check auth r = redis() if not "token" in args or args["token"] != r.get("tag_token").decode( 'utf-8'): raise Exception("unauthorized") # tag tag = args['tag'] url = args['url'] key = "tag:%s" % tag r.lpush(key, url) res = {"add": r.hincrby("tag_index", tag, 1)} except KeyError: res = {"error": "missing argument"} except Exception as e: res = {"error": str(e)} except: res = {"error": "unknown"} return {"body": res}
def main(args): connectors = args.get('connectors') if not connectors: return {"body": {"detail": "connectors list is empty"}} github_service = GithubService() connectors_response = github_service.get_connectors() valid_connectors = [connector for connector in connectors_response if connector['name'] in connectors ] if not valid_connectors: return {"body": {"detail": "no valid connectors names provided"}} ow_service = OWService() red = redis() responses = [] created_connectors = [] for connector in valid_connectors: binary_connector = github_service.get_connector_file( connector['file_path'] ) create_response = ow_service.create_action( connector, binary_connector ) responses.append(create_response) if 'error' not in create_response: created_connectors.append(connector['name']) red.set('connectors', ",".join(created_connectors)) return {"body": {"detail": responses}}
def main(args): appkey='tdlst' db = nimbella.redis() print('log A') username=args.get("username","") if username=='': return {"body":{"response":{"result":"error","description":"username not valid"}}} searchuser=search_user(username) print('log B') if searchuser: return {"body":{"response":{"result":"ok","code": searchuser['code'],"username":searchuser['username']}}} print('log C') n = random.randint(0,10000000) code="code-"+str(n) key = appkey+":user:"******"username": username, "code": code}) print('before save') rsuccess=db.set(key, value) print('after save') return {"body":{"response":{"result":"ok","code":code,"username":username}}}
def search_items(user_code): appkey = 'tdlst' db = nimbella.redis() keys = db.keys(appkey + ":item:" + user_code + ":*") data = db.mget(keys) return data
def main(args): db = nimbella.redis() key = "address:" + args.get("name", "") return {"body": db.delete(key)}
def main(args): db = nimbella.redis() key = "address:" + args.get("name", "") value = db.get(key).decode('utf-8') return {"body": json.loads(value)}
def search_item(key): db = nimbella.redis() value = db.get(key) return value