def put_user(config, email, name, org, title, clearance): # get the org id org_id = utils.get_org_id_by_name(config, org) if org_id == -1: return # open grpc channel channel, key = conn.get_connection(config) # connect to grpc stub stub = recipient_pb2_grpc.RecipientServiceStub(channel) # make request recipient = recipient_pb2.Recipient(email=email, recipient_name=name, org_id=org_id, title=title, clearance=clearance) request = recipient_pb2.CreateRecipientRequest(recipient=recipient) # send request try: response = stub.CreateRecipient(request, metadata=[('biapikey', key)]) except grpc.RpcError as e: utils.print_grpc_errors(e) else: utils.print_json(response.recipient)
def set_user(config, id, email, name, org, title, clearance): # validate has some data to update if email == None and name == None and org == None and title == None and clearance == None: click.echo( "Must specify at least one of --email, --name, --org, --title, or --clearance." ) return # make update map update_map = {} if email: update_map["email"] = email if name: update_map["recipient_name"] = name if org: update_map["org_name"] = org if title: update_map["title"] = title if clearance: update_map["clearance"] = clearance # open grpc channel channel, key = conn.get_connection(config) # connect to grpc stub stub = recipient_pb2_grpc.RecipientServiceStub(channel) # make request request = recipient_pb2.UpdateRecipientRequest(recipient_id=id, update_map=update_map) # send request try: response = stub.UpdateRecipient(request, metadata=[('biapikey', key)]) except grpc.RpcError as e: utils.print_grpc_errors(e) else: utils.print_json(response)
def put_recipient_tag(config, email, tags): # validate email recipient_id = utils.get_recipient_id_by_email(config, email) if recipient_id == -1: return # open grpc channel channel, key = conn.get_connection(config) # connect to grpc stub stub = recipient_pb2_grpc.RecipientServiceStub(channel) # break out tags tag_list = utils.split_tags(tags) for tag_name in tag_list: # make request recipient_tag = recipient_pb2.RecipientTag( recipient_id=recipient_id, tag_name=tag_name, tag_value=tag_list[tag_name]) request = recipient_pb2.CreateRecipientTagRequest( recipient_tag=recipient_tag) # send request try: response = stub.CreateRecipientTag(request, metadata=[('biapikey', key)]) except grpc.RpcError as e: utils.print_grpc_errors(e) else: utils.print_json(response.recipient_tag)
def del_user(config, email): # open grpc channel channel, key = conn.get_connection(config) # connect to grpc stub stub = recipient_pb2_grpc.RecipientServiceStub(channel) # make request request = recipient_pb2.DeleteRecipientByEmailRequest(email=email) # send request try: response = stub.DeleteRecipientByEmail(request, metadata=[('biapikey', key)]) except grpc.RpcError as e: utils.print_grpc_errors(e) else: utils.print_json(response)
def get_recipient_id_by_email(config, email): # open channel channel, key = conn.get_connection(config) # connect to stub stub = recipient_pb2_grpc.RecipientServiceStub(channel) # build request request = recipient_pb2.ReadRecipientByEmailRequest(email=email) # submit request try: response = stub.ReadRecipientByEmail(request, metadata=[('biapikey', key)]) except grpc.RpcError as e: print_grpc_errors(e) return -1 else: return response.recipient.id
def get_user(config, org, email, id): channel, key = conn.get_connection(config) # connect to grpc stub stub = recipient_pb2_grpc.RecipientServiceStub(channel) # get user by org if email != None: # make request request = recipient_pb2.ReadRecipientByEmailRequest(email=email) # send request try: user = stub.ReadRecipientByEmail(request, metadata=[('biapikey', key)]) utils.print_json(user) except grpc.RpcError as e: utils.print_grpc_errors(e) return elif id != None: # make request request = recipient_pb2.ReadRecipientByIDRequest(recipient_id=id) # send request try: user = stub.ReadRecipientByID(request, metadata=[('biapikey', key)]) utils.print_json(user) except grpc.RpcError as e: utils.print_grpc_errors(e) return elif org != None: # validate org org_id = utils.get_org_id_by_name(config, org) if org_id == -1: return # make request request = recipient_pb2.ListRecipientsByOrgRequest(org_id=org_id) # send request try: users = stub.ListRecipients(request, metadata=[('biapikey', key)]) for user in users: utils.print_json(user) except grpc.RpcError as e: utils.print_grpc_errors(e) return else: click.echo("One of email, id, or org must be specified")
def get_recipient_tag(config, email): # validate email recipient_id = utils.get_recipient_id_by_email(config, email) if recipient_id == -1: return # open grpc channel channel, key = conn.get_connection(config) # connect to grpc stub stub = recipient_pb2_grpc.RecipientServiceStub(channel) # make request request = recipient_pb2.ListRecipientTagRequest(recipient_id=recipient_id) # send request try: response = stub.ListRecipientTag(request, metadata=[('biapikey', key)]) for tag in response: utils.print_json(tag.recipient_tag) except grpc.RpcError as e: utils.print_grpc_errors(e)
def del_recipient_tag(config, email, tags): # validate email recipient_id = utils.get_recipient_id_by_email(config, email) if recipient_id == -1: return # open grpc channel channel, key = conn.get_connection(config) # connect to grpc stub stub = recipient_pb2_grpc.RecipientServiceStub(channel) for tag_name in tags: # make request request = recipient_pb2.DeleteRecipientTagRequest( recipient_id=recipient_id, tag_name=tag_name) # send request try: response = stub.DeleteRecipientTag(request, metadata=[('biapikey', key)]) except grpc.RpcError as e: utils.print_grpc_errors(e) else: utils.print_json(response)