File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python
2+ """
3+ Get an API key for your account
4+ """
5+ import getpass
6+ import requests
7+ from urllib .parse import urljoin
8+
9+ username = input ("Username: " )
10+ password = getpass .getpass ()
11+
12+ api_base_url = "http://localhost:8060" #"https://api.probely.com"
13+ auth_endpoint = urljoin (api_base_url , "enterprise/auth/obtain/" )
14+ keys_endpoint = urljoin (api_base_url , "keys/" )
15+
16+ # Get login token
17+ response = requests .post (auth_endpoint ,
18+ data = {'username' : username , 'password' : password })
19+ print (response .json ())
20+ token = response .json ()['token' ]
21+
22+ headers = {
23+ 'Authorization' : "JWT {}" .format (token ),
24+ 'Content-Type' : "application/json" ,
25+ }
26+
27+ api_name = input ("API key's name: " )
28+
29+ response = requests .post (
30+ keys_endpoint ,
31+ headers = headers ,
32+ json = {'name' : api_name })
33+
34+ if response .status_code == 201 :
35+ print ("\n Account API key:" , response .json ()['key' ])
36+
37+ else :
38+ print ('\n [%s]\n %s' % (response .status_code , response .text ))
You can’t perform that action at this time.
0 commit comments