def put_org_tag(config, org, tags): # validate org 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 = org_pb2_grpc.BimetaOrgServiceStub(channel) # break out tags tag_list = utils.split_tags(tags) for tag_name in tag_list: # make request org_tag = org_pb2.BimetaOrgTag(org_id=org_id, tag_name=tag_name, tag_value=tag_list[tag_name]) request = org_pb2.CreateBimetaOrgTagRequest(bimeta_org_tag=org_tag) # send request try: response = stub.CreateBimetaOrgTag(request, metadata=[('biapikey', key)]) except grpc.RpcError as e: utils.print_grpc_errors(e) else: utils.print_json(response.bimeta_org_tag)
def get_org_id_by_name(config, orgname): # build request request = org_pb2.ReadBimetaOrgByNameRequest(org_name=orgname) # open channel channel, key = conn.get_connection(config) # connect to stub org_client = org_pb2_grpc.BimetaOrgServiceStub(channel) # make request try: response = org_client.ReadBimetaOrgByName(request, metadata=[('biapikey', key)]) except grpc.RpcError as e: print_grpc_errors(e) return -1 else: return response.bimeta_org.id
def get_org_tag(config, org): # validate org 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 = org_pb2_grpc.BimetaOrgServiceStub(channel) # make request request = org_pb2.ListBimetaOrgTagRequest(org_id=org_id) # send request try: response = stub.ListBimetaOrgTag(request, metadata=[('biapikey', key)]) for tag in response: utils.print_json(tag.bimeta_org_tag) except grpc.RpcError as e: utils.print_grpc_errors(e)
def put_config(config, org, name, file): contents = None # validate file if file == "stdin": # read file from std in contents = sys.stdin.readlines() else: if os.path.exists(file): f = open(file) contents = f.read() f.close() if contents == None: click.echo("Unable to read file") return # validate org 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 = org_pb2_grpc.BimetaOrgServiceStub(channel) # make request org_config = org_pb2.BimetaOrgConfig(org_id=org_id, config_name=name, content=contents) request = org_pb2.CreateBimetaOrgConfigRequest( bimeta_org_config=org_config) # send request try: response = stub.CreateBimetaOrgConfig(request, metadata=[('biapikey', key)]) except grpc.RpcError as e: utils.print_grpc_errors(e) else: utils.print_json(response.bimeta_org_config)
def del_org_tag(config, org, tags): # validate org 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 = org_pb2_grpc.BimetaOrgServiceStub(channel) for tag_name in tags: # make request request = org_pb2.DeleteBimetaOrgTagRequest(org_id=org_id, tag_name=tag_name) # send request try: response = stub.DeleteBimetaOrgTag(request, metadata=[('biapikey', key)]) except grpc.RpcError as e: utils.print_grpc_errors(e) else: utils.print_json(response)
def get_config(config, org, name): # validate org 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 = org_pb2_grpc.BimetaOrgServiceStub(channel) # make request request = org_pb2.ReadBimetaOrgConfigRequest(org_id=org_id, config_name=name) # send request try: response = stub.ReadBimetaOrgConfig(request, metadata=[('biapikey', key)]) except grpc.RpcError as e: utils.print_grpc_errors(e) else: print(response.bimeta_org_config.content)