Skip to content

Commit acf3de6

Browse files
authored
Merge pull request #47 from web-push-libs/bug/46
bug: Update main.py for new calls.
2 parents 9117149 + d59611b commit acf3de6

File tree

3 files changed

+19
-27
lines changed

3 files changed

+19
-27
lines changed

python/py_vapid/main.py

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,20 @@
99
from py_vapid import Vapid01, Vapid02, b64urlencode
1010

1111

12+
def prompt(prompt):
13+
# Not sure why, but python3 throws and exception if you try to
14+
# monkeypatch for this. It's ugly, but this seems to play nicer.
15+
try:
16+
return input(prompt)
17+
except NameError:
18+
return raw_input(prompt) # noqa: F821
19+
20+
1221
def main():
1322
parser = argparse.ArgumentParser(description="VAPID tool")
1423
parser.add_argument('--sign', '-s', help='claims file to sign')
1524
parser.add_argument('--gen', '-g', help='generate new key pairs',
1625
default=False, action="store_true")
17-
parser.add_argument('--validate', '-v', help='dashboard token to validate')
1826
parser.add_argument('--version2', '-2', help="use VAPID spec Draft-02",
1927
default=False, action="store_true")
2028
parser.add_argument('--version1', '-1', help="use VAPID spec Draft-01",
@@ -27,10 +35,6 @@ def main():
2735
args = parser.parse_args()
2836

2937
# Added to solve 2.7 => 3.* incompatibility
30-
try:
31-
input = raw_input
32-
except NameError:
33-
pass
3438
Vapid = Vapid01
3539
if args.version2:
3640
Vapid = Vapid02
@@ -39,38 +43,26 @@ def main():
3943
print("No private_key.pem file found.")
4044
answer = None
4145
while answer not in ['y', 'n']:
42-
answer = input("Do you want me to create one for you? "
43-
"(Y/n)")
46+
answer = prompt("Do you want me to create one for you? (Y/n)")
4447
if not answer:
4548
answer = 'y'
4649
answer = answer.lower()[0]
4750
if answer == 'n':
4851
print("Sorry, can't do much for you then.")
4952
exit(1)
53+
vapid = Vapid()
54+
vapid.generate_keys()
5055
print("Generating private_key.pem")
51-
Vapid().save_key('private_key.pem')
52-
vapid = Vapid.from_file('private_key.pem')
53-
if args.gen or not os.path.exists('public_key.pem'):
54-
if not args.gen:
55-
print("No public_key.pem file found. You'll need this to access "
56-
"the developer dashboard.")
57-
answer = None
58-
while answer not in ['y', 'n']:
59-
answer = input("Do you want me to create one for you? "
60-
"(Y/n)")
61-
if not answer:
62-
answer = 'y'
63-
answer = answer.lower()[0]
64-
if answer == 'n':
65-
print("Exiting...")
66-
exit(0)
56+
vapid.save_key('private_key.pem')
6757
print("Generating public_key.pem")
6858
vapid.save_public_key('public_key.pem')
59+
vapid = Vapid.from_file('private_key.pem')
6960
claim_file = args.sign
7061
result = dict()
7162
if args.applicationServerKey:
63+
raw_pub = vapid.public_key.public_numbers().encode_point()
7264
print("Application Server Key = {}\n\n".format(
73-
b64urlencode(vapid.public_key.to_string())))
65+
b64urlencode(raw_pub)))
7466
if claim_file:
7567
if not os.path.exists(claim_file):
7668
print("No {} file found.".format(claim_file))

python/py_vapid/tests/test_vapid.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ def test_sign_01(self):
145145
eq_(result['Crypto-Key'],
146146
'id=previous;p256ecdsa=' + T_PUBLIC_RAW.decode('utf8'))
147147
pkey = binascii.b2a_base64(
148-
v.public_key.public_numbers().encode_point()
149-
).decode('utf8').replace('+', '-').replace('/', '_').strip()
148+
v.public_key.public_numbers().encode_point()
149+
).decode('utf8').replace('+', '-').replace('/', '_').strip()
150150
items = decode(result['Authorization'].split(' ')[1], pkey)
151151
eq_(items, claims)
152152
result = v.sign(claims)

python/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from setuptools import setup, find_packages
55

6-
__version__ = "1.2.1"
6+
__version__ = "1.2.2"
77

88

99
def read_from(file):

0 commit comments

Comments
 (0)