def delete_right(callerPriv): ''' Delete a right item. parameters: token name product return: {results:OK} ''' user=request.params.get("name") product=request.params.get("product") if user==None or product==None: return {"results":{"error":{"code":13,"msg":"Parameter missing."}}} uInfo=brauth.getUser(name=user) if uInfo==None: return {"results":{"error":{"code":23,"msg":"Can not find the target user."}}} elif "error" in uInfo: return {"results":uInfo} pInfo=brauth.getProduct(name=product) if pInfo==None: return {"results":{"error":{"code":24,"msg":"Can not find the target product."}}} elif "error" in pInfo: return {"results":pInfo} brauth.removeRight(callerPriv=callerPriv,uid=uInfo['_id'],pid=pInfo['_id']) return {"results":"OK"}
def add_mapping(callerPriv): ''' Add mapping item. parameters: token product server project return: ''' product=request.params.get("product") server=request.params.get("server") project=request.params.get("project") if product==None or server==None or project==None: return {"results":{"error":{"code":13,"msg":"Parameter missing."}}} if server not in brauth.mantis_server: return {"results":{"error":"Unknown server name!"}} pInfo=brauth.getProduct(name=product) if pInfo==None: return {"results":{"error":{"code":16,"msg":"Add fail."}}} brauth.addMapping(pid=pInfo['_id'],project='%s@%s'%(project,server)) return {"results":"OK"}
def getRight(callerPriv): ''' List rights items. parameters: name token return: {user:string,products:[p1,p2]} ''' user=request.params.get("name") if user==None: return {"results":{"error":{"code":13,"msg":"Parameter missing."}}} userInfo=brauth.getUser(name=user) if userInfo==None: return {"results":{"error":{"code":21,"msg":"Can not find the user."}}} pids=brauth.getRight(callerPriv=callerPriv,uid=userInfo['_id']) products=[] if pids!=None: for pid in pids: product=brauth.getProduct(pid) if product!=None: products.append(product['name']) return {"results":{"user":user,"products":products}}
def addRight(callerPriv): ''' Add a right item. parameters: token name: such as b999 product: ''' user=request.params.get("name") product=request.params.get("product") if user==None or product==None: return {"results":{"error":{"code":13,"msg":"Parameter missing."}}} uInfo=brauth.getUser(name=user) if uInfo==None: return {"results":{"error":{"code":23,"msg":"Can not find the target user."}}} elif "error" in uInfo: return {"results":uInfo} pInfo=brauth.getProduct(name=product) if pInfo==None: return {"results":{"error":{"code":24,"msg":"Can not find the target product."}}} elif "error" in pInfo: return {"results":pInfo} try: brauth.addRight(callerPriv=callerPriv,uid=uInfo["_id"],pid=pInfo["_id"]) return {"results":'OK'} except Exception,e: print str(e) return {"results":{"error":{"code":16,"msg":"Add fail."}}}
def add_mapping(callerPriv): ''' Add mapping item. parameters: token product server project return: ''' product = request.params.get("product") server = request.params.get("server") project = request.params.get("project") if product == None or server == None or project == None: return { "results": { "error": { "code": 13, "msg": "Parameter missing." } } } if server not in brauth.mantis_server: return {"results": {"error": "Unknown server name!"}} pInfo = brauth.getProduct(name=product) if pInfo == None: return {"results": {"error": {"code": 16, "msg": "Add fail."}}} brauth.addMapping(pid=pInfo['_id'], project='%s@%s' % (project, server)) return {"results": "OK"}
def delete_mapping(callerPriv): ''' Delete a mapping item. parameters: token product project return: {results:OK} ''' product = request.params.get("product") project = request.params.get("project") if product == None or project == None: return { "results": { "error": { "code": 13, "msg": "Parameter missing." } } } pInfo = brauth.getProduct(name=product) if pInfo == None: return { "results": { "error": { "code": 24, "msg": "Can not find the target product." } } } brauth.removeMapping(pid=pInfo['_id'], project=project) return {"results": "OK"}
def list_mappings(callerPriv): ''' List mapping items. parameters: token product return: {results:{product:string,projects:[]}} ''' product = request.params.get("product") if product == None: return { "results": { "error": { "code": 13, "msg": "Parameter missing." } } } pInfo = brauth.getProduct(name=product) if pInfo == None: return {"results": {"product": product, "projects": []}} mappings = brauth.getMapping(pid=pInfo['_id']) if mappings == None: return {"results": {"product": product, "projects": []}} ret = [] for item in mappings: ret.append(item['project_at_server']) return {"results": {"product": product, "projects": ret}}
def addRight(callerPriv): ''' Add a right item. parameters: token name: such as b999 product: ''' user = request.params.get("name") product = request.params.get("product") if user == None or product == None: return { "results": { "error": { "code": 13, "msg": "Parameter missing." } } } uInfo = brauth.getUser(name=user) if uInfo == None: return { "results": { "error": { "code": 23, "msg": "Can not find the target user." } } } elif "error" in uInfo: return {"results": uInfo} pInfo = brauth.getProduct(name=product) if pInfo == None: return { "results": { "error": { "code": 24, "msg": "Can not find the target product." } } } elif "error" in pInfo: return {"results": pInfo} try: brauth.addRight(callerPriv=callerPriv, uid=uInfo["_id"], pid=pInfo["_id"]) return {"results": 'OK'} except Exception, e: print str(e) return {"results": {"error": {"code": 16, "msg": "Add fail."}}}
def delete_right(callerPriv): ''' Delete a right item. parameters: token name product return: {results:OK} ''' user = request.params.get("name") product = request.params.get("product") if user == None or product == None: return { "results": { "error": { "code": 13, "msg": "Parameter missing." } } } uInfo = brauth.getUser(name=user) if uInfo == None: return { "results": { "error": { "code": 23, "msg": "Can not find the target user." } } } elif "error" in uInfo: return {"results": uInfo} pInfo = brauth.getProduct(name=product) if pInfo == None: return { "results": { "error": { "code": 24, "msg": "Can not find the target product." } } } elif "error" in pInfo: return {"results": pInfo} brauth.removeRight(callerPriv=callerPriv, uid=uInfo['_id'], pid=pInfo['_id']) return {"results": "OK"}
def list_products(callerPriv): ''' List products. parameters: token return: {results:[{_id:int,name:string},{_id:int,name:string}]} ''' ret=[] products=brauth.getProduct() if products!=None: ret=products return {"results":ret}
def list_products(callerPriv): ''' List products. parameters: token return: {results:[{_id:int,name:string},{_id:int,name:string}]} ''' ret = [] products = brauth.getProduct() if products != None: ret = products return {"results": ret}
def delete_mapping(callerPriv): ''' Delete a mapping item. parameters: token product project return: {results:OK} ''' product=request.params.get("product") project=request.params.get("project") if product==None or project==None: return {"results":{"error":{"code":13,"msg":"Parameter missing."}}} pInfo=brauth.getProduct(name=product) if pInfo==None: return {"results":{"error":{"code":24,"msg":"Can not find the target product."}}} brauth.removeMapping(pid=pInfo['_id'],project=project) return {"results":"OK"}
def getRight(callerPriv): ''' List rights items. parameters: name token return: {user:string,products:[p1,p2]} ''' user = request.params.get("name") if user == None: return { "results": { "error": { "code": 13, "msg": "Parameter missing." } } } userInfo = brauth.getUser(name=user) if userInfo == None: return { "results": { "error": { "code": 21, "msg": "Can not find the user." } } } pids = brauth.getRight(callerPriv=callerPriv, uid=userInfo['_id']) products = [] if pids != None: for pid in pids: product = brauth.getProduct(pid) if product != None: products.append(product['name']) return {"results": {"user": user, "products": products}}
def list_mappings(callerPriv): ''' List mapping items. parameters: token product return: {results:{product:string,projects:[]}} ''' product=request.params.get("product") if product==None: return {"results":{"error":{"code":13,"msg":"Parameter missing."}}} pInfo=brauth.getProduct(name=product) if pInfo==None: return {"results":{"product":product,"projects":[]}} mappings=brauth.getMapping(pid=pInfo['_id']) if mappings==None: return {"results":{"product":product,"projects":[]}} ret=[] for item in mappings: ret.append(item['project_at_server']) return {"results":{"product":product,"projects":ret}}