-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.py
38 lines (28 loc) · 883 Bytes
/
client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import yeti.api
import click
class Context:
def __init__(self):
self.client = None
pass_context = click.make_pass_decorator(Context, ensure=True)
@click.group()
@click.option("--api-key", envvar="YETI_API_KEY", required=True, help="Your API key.")
@click.option(
"--endpoint", envvar="YETI_WEB_ROOT", required=True, help="The Yeti endpoint."
)
@pass_context # Add this to pass the context to subcommands
def cli(ctx, api_key, endpoint):
"""
Yeti python API client:
"""
client = yeti.api.YetiApi(endpoint)
client.auth_api_key(api_key)
ctx.client = client
@cli.command()
@click.option("--name", required=False, default="")
@pass_context
def search_indicators(ctx, name):
rules = ctx.client.search_indicators(name=name, indicator_type="yara")
for rule in rules:
print(rule["name"])
if __name__ == "__main__":
cli()