forked from arXiv/arxiv-filemanager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_token.py
More file actions
77 lines (70 loc) · 3.04 KB
/
generate_token.py
File metadata and controls
77 lines (70 loc) · 3.04 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
67
68
69
70
71
72
73
74
75
76
77
import click
from pytz import UTC
import uuid
from datetime import timedelta, datetime
from arxiv.users import auth, domain
from filemanager.factory import create_web_app
app = create_web_app()
app.app_context().push()
@app.cli.command()
@click.option('--user_id', prompt='Numeric user ID')
@click.option('--email', prompt='Email address')
@click.option('--username', prompt='Username')
@click.option('--first_name', prompt='First name', default='Jane')
@click.option('--last_name', prompt='Last name', default='Doe')
@click.option('--suffix_name', prompt='Name suffix', default='IV')
@click.option('--affiliation', prompt='Affiliation',
default='Cornell University')
@click.option('--rank', prompt='Numeric rank', default=3)
@click.option('--country', prompt='Alpha-2 country code', default='us')
@click.option('--default_category', prompt='Default category',
default='astro-ph.GA')
@click.option('--submission_groups', prompt='Submission groups (comma delim)',
default='grp_physics')
@click.option('--endorsements', prompt='Endorsement categories (comma delim)',
default='astro-ph.CO,astro-ph.GA')
@click.option('--scope', prompt='Authorization scope (comma delim)',
default='upload:read,upload:write,upload:admin')
def generate_token(user_id: str, email: str, username: str,
first_name: str = 'Jane', last_name: str = 'Doe',
suffix_name: str = 'IV',
affiliation: str = 'Cornell University',
rank: int = 3,
country: str = 'us',
default_category: str = 'astro-ph.GA',
submission_groups: str = 'grp_physics',
endorsements: str = 'astro-ph.CO,astro-ph.GA',
scope: str = 'upload:read,upload:write,upload:admin') \
-> None:
# Specify the validity period for the session.
start = datetime.now(tz=UTC)
end = start + timedelta(seconds=36000) # Make this as long as you want.
# Create a user with endorsements in astro-ph.CO and .GA.
session = domain.Session(
session_id=str(uuid.uuid4()),
start_time=start, end_time=end,
user=domain.User(
user_id=user_id,
email=email,
username=username,
name=domain.UserFullName(first_name, last_name, suffix_name),
profile=domain.UserProfile(
affiliation=affiliation,
rank=int(rank),
country=country,
default_category=domain.Category(
*default_category.split('.', 1)
),
submission_groups=submission_groups.split(',')
)
),
authorizations=domain.Authorizations(
scopes=[scope.split(',')],
endorsements=[domain.Category(cat.split('.', 1))
for cat in endorsements.split(',')]
)
)
token = auth.tokens.encode(session, app.config['JWT_SECRET'])
click.echo(token)
if __name__ == '__main__':
generate_token()