Пример #1
0
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)
Пример #2
0
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)
Пример #3
0
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)
Пример #4
0
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)
Пример #5
0
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)
Пример #6
0
def get_emails(config, email, num):
    # validate email

    # open grpc channel
    channel, key = conn.get_connection(config)
    # connect to grpc stub
    stub = badapicreds_pb2_grpc.CredentialServiceStub(channel)
    # make request
    request = badapicreds_pb2.ListEmailCredentialRequest(email=email,
                                                         maxResults=num)
    # send request
    try:
        response = stub.ListEmailCredentials(request,
                                             metadata=[('biapikey', key)])
        for cred in response:
            utils.print_json(cred)
    except grpc.RpcError as e:
        utils.print_grpc_errors(e)
Пример #7
0
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)
Пример #8
0
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)
Пример #9
0
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)
Пример #10
0
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)
Пример #11
0
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)
Пример #12
0
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)
Пример #13
0
def get_github(config, org, begin, end, viewed):
    # set default start/end date
    to_tm = datetime.datetime.utcnow()
    from_tm = to_tm - datetime.timedelta(hours=24)
    # if date provided, time to work with them
    if begin != None:
        try:
            from_tm = datetime.datetime.fromisoformat(begin)
        except:
            click.echo(
                f"Unable to convert {begin} (does it match ISO format?)")
            return
    if end != None:
        try:
            to_tm = datetime.datetime.fromisoformat(end)
        except:
            click.echo(
                f"Unable to convert {begin} (does it match ISO format?)")
            return

    # open grpc channel
    channel, key = conn.get_connection(config)
    # connect to grpc stub
    stub = github_pb2_grpc.GithubServiceStub(channel)
    # make request
    request = github_pb2.ListAlertsRequest(
        org=org,
        viewed=viewed,
        startdate=from_tm.strftime("%Y-%m-%d %H:%M:%S.%f"),
        enddate=to_tm.strftime("%Y-%m-%d %H:%M:%S.%f"))
    utils.print_json(request)
    # send request
    try:
        response = stub.ListAlerts(request, metadata=[('biapikey', key)])
        for alert in response:
            utils.print_json(alert)
    except grpc.RpcError as e:
        utils.print_grpc_errors(e)
Пример #14
0
def get_creds(config, username, fqdn, num, startdate, enddate):
    # open grpc channel
    channel, key = conn.get_connection(config)
    # connect to grpc stub
    stub = badapicreds_pb2_grpc.CredentialSearchServiceStub(channel)
    # make request
    start = ""
    end = ""
    if startdate != None:
        start = startdate.strftime("%Y-%m-%dT%H:%M:%SZ")
    if enddate != None:
        end = enddate.strftime("%Y-%m-%dT%H:%M:%SZ")
    request = badapicreds_pb2.SearchTerm(username=username,
                                         fqdn=fqdn,
                                         maxResults=num,
                                         start=start,
                                         end=end)
    # send request
    try:
        response = stub.ListCredentials(request, metadata=[('biapikey', key)])
        for cred in response:
            utils.print_json(cred)
    except grpc.RpcError as e:
        utils.print_grpc_errors(e)
Пример #15
0
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")