This repository was archived by the owner on May 6, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
66 lines (54 loc) · 2.34 KB
/
cli.py
File metadata and controls
66 lines (54 loc) · 2.34 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import click
import requests
import json
cli = click.Group()
def login(email, password, endpoint):
click.echo("Logging in..")
response = requests.post(endpoint + "/login", json={"email": email, "password": password})
if response.ok:
click.echo("Successfully logged in!")
return response.json()
else:
click.echo(str(response.json().get('message')))
raise click.Abort()
def post_signup(email, password, endpoint):
click.echo("Signing up..")
response = requests.post(endpoint + "/user", json={"email": email, "password": password})
if response.ok:
click.echo("Successfully signed up!")
return response.json()
else:
click.echo(str(response.json().get('message')))
raise click.Abort()
def post_event_file(organization, workspace, event_file, token, endpoint):
click.echo("Updating the event file...")
json_data = {
'workspace_name': workspace,
'organization_name': organization,
'event_file': event_file
}
response = requests.post(endpoint + "/event_file", json=json_data,
headers={'Authorization': 'Bearer {}'.format(token)})
if response.ok:
click.echo("Successfully updated the event file!")
return True
else:
click.echo(str(response.json().get('message')))
raise click.Abort()
@cli.command()
@click.argument('email', type=str)
@click.argument('password', type=str)
@click.option('--endpoint', type=str, help="Eventhub endpoint", default="https://eventhub-backend-dev.herokuapp.com/")
def signup(email, password, endpoint):
post_signup(email, password, endpoint)
@cli.command()
@click.argument('event_file', type=click.File())
@click.option('-e', '--email', type=str, help="Your email")
@click.option('-p', '--password', type=str, help="Your password")
@click.option('-w', '--workspace', type=str, help="Your workspace name")
@click.option('-o', '--organization', type=str, help="Your organization name")
@click.option('--endpoint', type=str, help="Eventhub endpoint", default="https://eventhub-backend-dev.herokuapp.com/")
def push(event_file, email, password, workspace, organization, endpoint):
event_file_content = json.loads(event_file.read())
token = login(email, password, endpoint)
post_event_file(organization, workspace, event_file_content, token, endpoint)