@ -1,3 +1,8 @@ |
|||||||
*.sw? |
*.sw? |
||||||
.DS_Store |
.DS_Store |
||||||
index.json |
index.json |
||||||
|
*.pyc |
||||||
|
*.xml |
||||||
|
report.html |
||||||
|
log.html |
||||||
|
*.pdf |
||||||
|
After Width: | Height: | Size: 30 KiB |
After Width: | Height: | Size: 5.5 KiB |
After Width: | Height: | Size: 5.1 KiB |
After Width: | Height: | Size: 38 KiB |
After Width: | Height: | Size: 28 KiB |
After Width: | Height: | Size: 57 KiB |
After Width: | Height: | Size: 162 KiB |
After Width: | Height: | Size: 73 KiB |
After Width: | Height: | Size: 70 KiB |
After Width: | Height: | Size: 54 KiB |
After Width: | Height: | Size: 136 KiB |
After Width: | Height: | Size: 204 KiB |
After Width: | Height: | Size: 77 KiB |
After Width: | Height: | Size: 235 KiB |
After Width: | Height: | Size: 130 KiB |
After Width: | Height: | Size: 77 KiB |
After Width: | Height: | Size: 67 KiB |
After Width: | Height: | Size: 46 KiB |
After Width: | Height: | Size: 59 KiB |
After Width: | Height: | Size: 164 KiB |
After Width: | Height: | Size: 90 KiB |
After Width: | Height: | Size: 128 KiB |
After Width: | Height: | Size: 116 KiB |
After Width: | Height: | Size: 154 KiB |
After Width: | Height: | Size: 157 KiB |
After Width: | Height: | Size: 124 KiB |
After Width: | Height: | Size: 40 KiB |
After Width: | Height: | Size: 57 KiB |
After Width: | Height: | Size: 43 KiB |
After Width: | Height: | Size: 371 KiB |
After Width: | Height: | Size: 175 KiB |
After Width: | Height: | Size: 101 KiB |
After Width: | Height: | Size: 82 KiB |
After Width: | Height: | Size: 128 KiB |
After Width: | Height: | Size: 172 KiB |
After Width: | Height: | Size: 80 KiB |
After Width: | Height: | Size: 128 KiB |
After Width: | Height: | Size: 122 KiB |
After Width: | Height: | Size: 66 KiB |
After Width: | Height: | Size: 61 KiB |
After Width: | Height: | Size: 100 KiB |
After Width: | Height: | Size: 75 KiB |
After Width: | Height: | Size: 78 KiB |
After Width: | Height: | Size: 86 KiB |
After Width: | Height: | Size: 70 KiB |
After Width: | Height: | Size: 253 KiB |
After Width: | Height: | Size: 105 KiB |
After Width: | Height: | Size: 134 KiB |
After Width: | Height: | Size: 80 KiB |
After Width: | Height: | Size: 106 KiB |
After Width: | Height: | Size: 120 KiB |
After Width: | Height: | Size: 126 KiB |
After Width: | Height: | Size: 91 KiB |
After Width: | Height: | Size: 107 KiB |
After Width: | Height: | Size: 82 KiB |
After Width: | Height: | Size: 64 KiB |
After Width: | Height: | Size: 79 KiB |
After Width: | Height: | Size: 65 KiB |
After Width: | Height: | Size: 90 KiB |
After Width: | Height: | Size: 69 KiB |
After Width: | Height: | Size: 50 KiB |
After Width: | Height: | Size: 44 KiB |
After Width: | Height: | Size: 91 KiB |
After Width: | Height: | Size: 7.6 KiB |
After Width: | Height: | Size: 74 KiB |
After Width: | Height: | Size: 115 KiB |
After Width: | Height: | Size: 47 KiB |
After Width: | Height: | Size: 80 KiB |
After Width: | Height: | Size: 1.6 MiB |
After Width: | Height: | Size: 54 KiB |
After Width: | Height: | Size: 272 KiB |
After Width: | Height: | Size: 8.4 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 497 KiB |
After Width: | Height: | Size: 902 KiB |
After Width: | Height: | Size: 22 KiB |
After Width: | Height: | Size: 1.4 MiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 4.5 KiB |
After Width: | Height: | Size: 7.6 KiB |
After Width: | Height: | Size: 4.5 KiB |
After Width: | Height: | Size: 6.1 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 200 KiB |
After Width: | Height: | Size: 2.0 MiB |
After Width: | Height: | Size: 39 KiB |
@ -0,0 +1,270 @@ |
|||||||
|
digraph UnclePhil { |
||||||
|
kafka [color=gray, label="Kafka"]; |
||||||
|
|
||||||
|
selector1 [label="Selector"]; |
||||||
|
selector2 [label="Selector"]; |
||||||
|
selector3 [label="Selector"]; |
||||||
|
selector4 [label="Selector"]; |
||||||
|
selector5 [label="Selector"]; |
||||||
|
selector6 [label="Selector"]; |
||||||
|
selector7 [label="Selector"]; |
||||||
|
selector8 [label="Selector"]; |
||||||
|
selector9 [label="Selector"]; |
||||||
|
selector10 [label="Selector"]; |
||||||
|
selector11 [label="Selector"]; |
||||||
|
selector12 [label="Selector"]; |
||||||
|
|
||||||
|
process1 [label="ProcessMessages"]; |
||||||
|
process2 [label="ProcessMessages"]; |
||||||
|
process3 [label="ProcessMessages"]; |
||||||
|
process4 [label="ProcessMessages"]; |
||||||
|
process5 [label="ProcessMessages"]; |
||||||
|
process6 [label="ProcessMessages"]; |
||||||
|
process7 [label="ProcessMessages"]; |
||||||
|
process8 [label="ProcessMessages"]; |
||||||
|
process9 [label="ProcessMessages"]; |
||||||
|
process10 [label="ProcessMessages"]; |
||||||
|
process11 [label="ProcessMessages"]; |
||||||
|
process12 [label="ProcessMessages"]; |
||||||
|
|
||||||
|
splitter1 [label="MessageSpliter"]; |
||||||
|
splitter2 [label="MessageSpliter"]; |
||||||
|
splitter3 [label="MessageSpliter"]; |
||||||
|
splitter4 [label="MessageSpliter"]; |
||||||
|
splitter5 [label="MessageSpliter"]; |
||||||
|
splitter6 [label="MessageSpliter"]; |
||||||
|
splitter7 [label="MessageSpliter"]; |
||||||
|
splitter8 [label="MessageSpliter"]; |
||||||
|
splitter9 [label="MessageSpliter"]; |
||||||
|
splitter10 [label="MessageSpliter"]; |
||||||
|
splitter11 [label="MessageSpliter"]; |
||||||
|
splitter12 [label="MessageSpliter"]; |
||||||
|
|
||||||
|
extract1 [label="MetricExtractor"]; |
||||||
|
extract2 [label="MetricExtractor"]; |
||||||
|
extract3 [label="MetricExtractor"]; |
||||||
|
extract4 [label="MetricExtractor"]; |
||||||
|
extract5 [label="MetricExtractor"]; |
||||||
|
extract6 [label="MetricExtractor"]; |
||||||
|
extract7 [label="MetricExtractor"]; |
||||||
|
extract8 [label="MetricExtractor"]; |
||||||
|
extract9 [label="MetricExtractor"]; |
||||||
|
extract10 [label="MetricExtractor"]; |
||||||
|
extract11 [label="MetricExtractor"]; |
||||||
|
extract12 [label="MetricExtractor"]; |
||||||
|
|
||||||
|
keyby [label="keyBy/Hash"]; |
||||||
|
|
||||||
|
window1 [label="Window"]; |
||||||
|
window2 [label="Window"]; |
||||||
|
window3 [label="Window"]; |
||||||
|
window4 [label="Window"]; |
||||||
|
window5 [label="Window"]; |
||||||
|
window6 [label="Window"]; |
||||||
|
window7 [label="Window"]; |
||||||
|
window8 [label="Window"]; |
||||||
|
window9 [label="Window"]; |
||||||
|
window10 [label="Window"]; |
||||||
|
window11 [label="Window"]; |
||||||
|
window12 [label="Window"]; |
||||||
|
|
||||||
|
reduce1 [label="Reduce"]; |
||||||
|
reduce2 [label="Reduce"]; |
||||||
|
reduce3 [label="Reduce"]; |
||||||
|
reduce4 [label="Reduce"]; |
||||||
|
reduce5 [label="Reduce"]; |
||||||
|
reduce6 [label="Reduce"]; |
||||||
|
reduce7 [label="Reduce"]; |
||||||
|
reduce8 [label="Reduce"]; |
||||||
|
reduce9 [label="Reduce"]; |
||||||
|
reduce10 [label="Reduce"]; |
||||||
|
reduce11 [label="Reduce"]; |
||||||
|
reduce12 [label="Reduce"]; |
||||||
|
|
||||||
|
sink1 [label="Sink"]; |
||||||
|
sink2 [label="Sink"]; |
||||||
|
sink3 [label="Sink"]; |
||||||
|
sink4 [label="Sink"]; |
||||||
|
sink5 [label="Sink"]; |
||||||
|
sink6 [label="Sink"]; |
||||||
|
sink7 [label="Sink"]; |
||||||
|
sink8 [label="Sink"]; |
||||||
|
sink9 [label="Sink"]; |
||||||
|
sink10 [label="Sink"]; |
||||||
|
sink11 [label="Sink"]; |
||||||
|
sink12 [label="Sink"]; |
||||||
|
|
||||||
|
kafka -> selector1; |
||||||
|
kafka -> selector2; |
||||||
|
kafka -> selector3; |
||||||
|
kafka -> selector4; |
||||||
|
kafka -> selector5; |
||||||
|
kafka -> selector6; |
||||||
|
kafka -> selector7; |
||||||
|
kafka -> selector8; |
||||||
|
kafka -> selector9; |
||||||
|
kafka -> selector10; |
||||||
|
kafka -> selector11; |
||||||
|
kafka -> selector12; |
||||||
|
|
||||||
|
selector1 -> process1; |
||||||
|
selector2 -> process2; |
||||||
|
selector3 -> process3; |
||||||
|
selector4 -> process4; |
||||||
|
selector5 -> process5; |
||||||
|
selector6 -> process6; |
||||||
|
selector7 -> process7; |
||||||
|
selector8 -> process8; |
||||||
|
selector9 -> process9; |
||||||
|
selector10 -> process10; |
||||||
|
selector11 -> process11; |
||||||
|
selector12 -> process12; |
||||||
|
|
||||||
|
process1 -> splitter1; |
||||||
|
process2 -> splitter2; |
||||||
|
process3 -> splitter3; |
||||||
|
process4 -> splitter4; |
||||||
|
process5 -> splitter5; |
||||||
|
process6 -> splitter6; |
||||||
|
process7 -> splitter7; |
||||||
|
process8 -> splitter8; |
||||||
|
process9 -> splitter9; |
||||||
|
process10 -> splitter10; |
||||||
|
process11 -> splitter11; |
||||||
|
process12 -> splitter12; |
||||||
|
|
||||||
|
splitter1 -> extract1; |
||||||
|
splitter1 -> extract1; |
||||||
|
splitter1 -> extract1; |
||||||
|
|
||||||
|
splitter2 -> extract2; |
||||||
|
splitter2 -> extract2; |
||||||
|
splitter2 -> extract2; |
||||||
|
|
||||||
|
splitter3 -> extract3; |
||||||
|
splitter3 -> extract3; |
||||||
|
splitter3 -> extract3; |
||||||
|
|
||||||
|
splitter4 -> extract4; |
||||||
|
splitter4 -> extract4; |
||||||
|
splitter4 -> extract4; |
||||||
|
|
||||||
|
splitter5 -> extract5; |
||||||
|
splitter5 -> extract5; |
||||||
|
splitter5 -> extract5; |
||||||
|
|
||||||
|
splitter6 -> extract6; |
||||||
|
splitter6 -> extract6; |
||||||
|
splitter6 -> extract6; |
||||||
|
|
||||||
|
splitter7 -> extract7; |
||||||
|
splitter7 -> extract7; |
||||||
|
splitter7 -> extract7; |
||||||
|
|
||||||
|
splitter8 -> extract8; |
||||||
|
splitter8 -> extract8; |
||||||
|
splitter8 -> extract8; |
||||||
|
|
||||||
|
splitter9 -> extract9; |
||||||
|
splitter9 -> extract9; |
||||||
|
splitter9 -> extract9; |
||||||
|
|
||||||
|
splitter10 -> extract10; |
||||||
|
splitter10 -> extract10; |
||||||
|
splitter10 -> extract10; |
||||||
|
|
||||||
|
splitter11 -> extract11; |
||||||
|
splitter11 -> extract11; |
||||||
|
splitter11 -> extract11; |
||||||
|
|
||||||
|
splitter12 -> extract12; |
||||||
|
splitter12 -> extract12; |
||||||
|
splitter12 -> extract12; |
||||||
|
|
||||||
|
extract1 -> keyby; |
||||||
|
extract1 -> keyby; |
||||||
|
extract1 -> keyby; |
||||||
|
|
||||||
|
extract2 -> keyby; |
||||||
|
extract2 -> keyby; |
||||||
|
extract2 -> keyby; |
||||||
|
|
||||||
|
extract3 -> keyby; |
||||||
|
extract3 -> keyby; |
||||||
|
extract3 -> keyby; |
||||||
|
|
||||||
|
extract4 -> keyby; |
||||||
|
extract4 -> keyby; |
||||||
|
extract4 -> keyby; |
||||||
|
|
||||||
|
extract5 -> keyby; |
||||||
|
extract5 -> keyby; |
||||||
|
extract5 -> keyby; |
||||||
|
|
||||||
|
extract6 -> keyby; |
||||||
|
extract6 -> keyby; |
||||||
|
extract6 -> keyby; |
||||||
|
|
||||||
|
extract7 -> keyby; |
||||||
|
extract7 -> keyby; |
||||||
|
extract7 -> keyby; |
||||||
|
|
||||||
|
extract8 -> keyby; |
||||||
|
extract8 -> keyby; |
||||||
|
extract8 -> keyby; |
||||||
|
|
||||||
|
extract9 -> keyby; |
||||||
|
extract9 -> keyby; |
||||||
|
extract9 -> keyby; |
||||||
|
|
||||||
|
extract10 -> keyby; |
||||||
|
extract10 -> keyby; |
||||||
|
extract10 -> keyby; |
||||||
|
|
||||||
|
extract11 -> keyby; |
||||||
|
extract11 -> keyby; |
||||||
|
extract11 -> keyby; |
||||||
|
|
||||||
|
extract12 -> keyby; |
||||||
|
extract12 -> keyby; |
||||||
|
extract12 -> keyby; |
||||||
|
|
||||||
|
keyby -> window1; |
||||||
|
keyby -> window2; |
||||||
|
keyby -> window3; |
||||||
|
keyby -> window4; |
||||||
|
keyby -> window5; |
||||||
|
keyby -> window6; |
||||||
|
keyby -> window7; |
||||||
|
keyby -> window8; |
||||||
|
keyby -> window9; |
||||||
|
keyby -> window10; |
||||||
|
keyby -> window11; |
||||||
|
keyby -> window12; |
||||||
|
|
||||||
|
window1 -> reduce1; |
||||||
|
window2 -> reduce2; |
||||||
|
window3 -> reduce3; |
||||||
|
window4 -> reduce4; |
||||||
|
window5 -> reduce5; |
||||||
|
window6 -> reduce6; |
||||||
|
window7 -> reduce7; |
||||||
|
window8 -> reduce8; |
||||||
|
window9 -> reduce9; |
||||||
|
window10 -> reduce10; |
||||||
|
window11 -> reduce11; |
||||||
|
window12 -> reduce12; |
||||||
|
|
||||||
|
reduce1 -> sink1; |
||||||
|
reduce2 -> sink2; |
||||||
|
reduce3 -> sink3; |
||||||
|
reduce4 -> sink4; |
||||||
|
reduce5 -> sink5; |
||||||
|
reduce6 -> sink6; |
||||||
|
reduce7 -> sink7; |
||||||
|
reduce8 -> sink8; |
||||||
|
reduce9 -> sink9; |
||||||
|
reduce10 -> sink10; |
||||||
|
reduce11 -> sink11; |
||||||
|
reduce12 -> sink12; |
||||||
|
} |
@ -0,0 +1 @@ |
|||||||
|
<mxfile userAgent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:59.0) Gecko/20100101 Firefox/59.0" version="8.5.0" editor="www.draw.io" type="device"><diagram id="7fd0e512-99a9-914d-b755-72f1f563e955" name="Page-1">5Zpdb5swFIZ/DbcT2BDCZZt1282kSb1Yd+mBC1YNjhynSffrZ8Dmy0RCFTCPchN8bPzxnFfHPgQHHvLrV46O2XeWYOoAN7k68LMDgAfgXv6UlrfastuHtSHlJFGNWsMj+YOV0VXWM0nwqddQMEYFOfaNMSsKHIueDXHOLv1mz4z2Rz2iFBuGxxhR0/qTJCKrrfvAbe3fMEkzPbLnqprfKH5JOTsXajwHwOfqqqtzpPtS7U8ZStilY4IPDjxwxkR9l18PmJZsNbb6uS83apt5c1yIKQ8oP70iesZ6xtW8xJtmUa0Gl+1dB95fMiLw4xHFZe1Fel/aMpFTWfLkbcxyEqv7k+DsBR8YZbzqCUbV1dRoslBa1DQwF/h6cyleA0gKD7McC/4mm6gHfDeoH1GaCxXiS+vASJmyru+gMiKlmbTpueUmbxS6cYyRgdGTq7rTqujQlOsTfWR9TAUrZMv7Z0LpwIQoSQtZjCUPLO33JS0iNXunKnKSJOUwoz7qe7HrphnQw6CPfmei90fQgxnIe952FQzcFSXsge2ChHBNkNAMBv4HDgZetGI08E32wQdmD8GK7AOT/e4Ds/eDFdnvFgre7ljwdqvLCN4zcdSMbp8lmn2xi9GfA2O4WYzeyFliOY5LpRUWcPTX5GjmFZvhuF+Row6xG+QIRnb45TgulWxZwHHNfUZj2yBHuOY+A8xUazMc19xngJk2bYbjqvuMmQJthaO/6j4z4RyOi+SufNMvSzFFp1PJycwou1DwlYinzv2vEuynoCwVcoJPinNVaOvqgXFi/GEwACknx848bjPfyiYQT7Fqth/n3QEajPDUNo4pEuS1P4sxyGqEH4zI+bXuBIPzVzDwUz179VTrKrOjcNCRO+ioXrLRUeXzZtnTZDAhjbBcBqFlMmj6Ud6L3qmC0B2oAAaLqWBCEmS5CvamCrwb0fffyMB48W2hDvQU/2MdRJZHAy+cSQZgt5wMJuSgdstA78T2hoPmOwybw8GEHNpyHegvW+zVwXsPiWvGgwnvACzXAbBeB3MdE5fUwYR3GJbrAI7oANikAzjXMXFJHUx4B2O5DnzrdTDXORFGy+lgwl/ilusgMHVgVbrgz3VMnE8Gsth+PFs3b79Qhg9/AQ==</diagram></mxfile> |
@ -0,0 +1,25 @@ |
|||||||
|
import mainsource |
||||||
|
|
||||||
|
|
||||||
|
class TestingSource(object): |
||||||
|
def __init__(self): |
||||||
|
self.username = None |
||||||
|
self.password = None |
||||||
|
self.last_exception = None |
||||||
|
|
||||||
|
def set_username(self, username): |
||||||
|
self.username = username |
||||||
|
|
||||||
|
def set_password(self, password): |
||||||
|
self.password = password |
||||||
|
|
||||||
|
def create_user(self): |
||||||
|
try: |
||||||
|
mainsource.create_user(self.username, self.password) |
||||||
|
except mainsource.UserCreationError as exc: |
||||||
|
self.last_exception = exc |
||||||
|
|
||||||
|
def is_invalid_password(self): |
||||||
|
return (self.last_exception and |
||||||
|
isinstance(self.last_exception, |
||||||
|
mainsource.PasswordIsNotStrongEnough)) |
@ -0,0 +1,24 @@ |
|||||||
|
*** Settings *** |
||||||
|
Library TestingSource.py |
||||||
|
|
||||||
|
*** Test Cases *** |
||||||
|
Invalid password |
||||||
|
Given that I have a username foo |
||||||
|
And that I have a password test123 |
||||||
|
When I try to create a user |
||||||
|
Then I should get an error of invalid password |
||||||
|
|
||||||
|
*** Keywords *** |
||||||
|
That I have a username |
||||||
|
[Arguments] ${username} |
||||||
|
set username ${username} |
||||||
|
|
||||||
|
That I have a password |
||||||
|
[Arguments] ${password} |
||||||
|
Set password ${password} |
||||||
|
|
||||||
|
I try to create a user |
||||||
|
Create user |
||||||
|
|
||||||
|
I should get an error of invalid password |
||||||
|
Is invalid password |
@ -0,0 +1,7 @@ |
|||||||
|
Feature: Testing passwords |
||||||
|
|
||||||
|
Scenario: Invalid password |
||||||
|
Given that I have a username foo |
||||||
|
And that I have a password test123 |
||||||
|
When I try to create an user |
||||||
|
Then I should get an error of invalid password |
@ -0,0 +1,34 @@ |
|||||||
|
# -*- encoding: utf-8 -*- |
||||||
|
|
||||||
|
"""Behave steps.""" |
||||||
|
|
||||||
|
import behave |
||||||
|
import mainsource |
||||||
|
|
||||||
|
|
||||||
|
@behave.given("that I have a username {name}") |
||||||
|
def set_username(context, name): |
||||||
|
context.username = name |
||||||
|
return |
||||||
|
|
||||||
|
|
||||||
|
@behave.given("that I have a password {password}") |
||||||
|
def set_password(context, password): |
||||||
|
context.password = password |
||||||
|
return |
||||||
|
|
||||||
|
|
||||||
|
@behave.when("I try to create an user") |
||||||
|
def create_user(context): |
||||||
|
try: |
||||||
|
mainsource.create_user(context.username, context.password) |
||||||
|
except mainsource.UserCreationError as exc: |
||||||
|
context.last_exception = exc |
||||||
|
return |
||||||
|
|
||||||
|
|
||||||
|
@behave.then("I should get an error of invalid password") |
||||||
|
def is_invalid_password(context): |
||||||
|
assert hasattr(context, 'last_exception') |
||||||
|
assert isinstance(context.last_exception, |
||||||
|
mainsource.PasswordIsNotStrongEnough) |
@ -0,0 +1,100 @@ |
|||||||
|
#!/usr/bin/env python |
||||||
|
# -*- encoding: utf-8 -*- |
||||||
|
|
||||||
|
"""This is a sample code that simulates a user being created.""" |
||||||
|
|
||||||
|
from __future__ import print_function |
||||||
|
|
||||||
|
import argparse |
||||||
|
import json |
||||||
|
|
||||||
|
from collections import Counter |
||||||
|
from unicodedata import category |
||||||
|
|
||||||
|
LOWERCASE_CHARS = "Ll" |
||||||
|
UPCASE_CHARS = "Lu" |
||||||
|
NUMBERS = "Nd" |
||||||
|
|
||||||
|
|
||||||
|
class UserCreationError(Exception): |
||||||
|
"""Base class for all exceptions in this module.""" |
||||||
|
pass |
||||||
|
|
||||||
|
|
||||||
|
class PasswordIsNotStrongEnough(UserCreationError): |
||||||
|
"""The password used is not strong enough.""" |
||||||
|
pass |
||||||
|
|
||||||
|
|
||||||
|
class UserAlreadyExists(UserCreationError): |
||||||
|
"""The user already exists in the database.""" |
||||||
|
pass |
||||||
|
|
||||||
|
|
||||||
|
def password_is_strong(password): |
||||||
|
"""Check if the password have enough strength.""" |
||||||
|
number_of = Counter(category(ch) for ch in password) |
||||||
|
return (number_of[LOWERCASE_CHARS] >= 1 and |
||||||
|
number_of[UPCASE_CHARS] >= 2 and |
||||||
|
number_of[NUMBERS] >= 1 and |
||||||
|
len(password) >= 12) |
||||||
|
|
||||||
|
|
||||||
|
def get_users(): |
||||||
|
"""Retrieve the list of users in the system.""" |
||||||
|
data = {} |
||||||
|
try: |
||||||
|
with open('users.json') as origin: |
||||||
|
data = json.load(origin) |
||||||
|
except IOError: |
||||||
|
# File does not exist, so we just assume it's empty |
||||||
|
pass |
||||||
|
return data |
||||||
|
|
||||||
|
|
||||||
|
def save_users(user_list): |
||||||
|
"""Save the user list back to the 'database'.""" |
||||||
|
with open('users.json', 'w') as target: |
||||||
|
json.dump(user_list, target) |
||||||
|
return |
||||||
|
|
||||||
|
|
||||||
|
def create_user(user, password): |
||||||
|
"""'Create' and user.""" |
||||||
|
if not password_is_strong(password.decode('utf-8')): |
||||||
|
raise PasswordIsNotStrongEnough |
||||||
|
|
||||||
|
users = get_users() |
||||||
|
if user in users: |
||||||
|
raise UserAlreadyExists |
||||||
|
|
||||||
|
users[user] = password |
||||||
|
save_users(users) |
||||||
|
return |
||||||
|
|
||||||
|
|
||||||
|
def main(): |
||||||
|
"""Expose the functions back in command line options.""" |
||||||
|
parser = argparse.ArgumentParser() |
||||||
|
parser.add_argument('-u', '--user', |
||||||
|
dest='user', |
||||||
|
help='Username to be created', |
||||||
|
required=True) |
||||||
|
parser.add_argument('-p', '--password', |
||||||
|
dest='password', |
||||||
|
help='Password for the user', |
||||||
|
required=True) |
||||||
|
args = parser.parse_args() |
||||||
|
try: |
||||||
|
create_user(args.user, args.password) |
||||||
|
except PasswordIsNotStrongEnough: |
||||||
|
print("That password is not strong enough") |
||||||
|
except UserAlreadyExists: |
||||||
|
print("Username already used") |
||||||
|
else: |
||||||
|
print("User created") |
||||||
|
return |
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__": |
||||||
|
main() |