From 60114d6ef2265a5b1136c364e05ae73e7ea2aefa Mon Sep 17 00:00:00 2001 From: Lucas Mathews Date: Thu, 30 May 2024 11:03:17 +0200 Subject: [PATCH] Start CLI implementation --- application/session_data.json | 2 +- cli.py | 25 ------------------------- cli/cli.ini | 8 ++++++++ cli/cli.py | 33 +++++++++++++++++++++++++++++++++ cli/config.py | 7 +++++++ cli/connection.py | 14 ++++++++++++++ 6 files changed, 63 insertions(+), 26 deletions(-) delete mode 100644 cli.py create mode 100644 cli/cli.ini create mode 100644 cli/cli.py create mode 100644 cli/config.py create mode 100644 cli/connection.py diff --git a/application/session_data.json b/application/session_data.json index 349ebf8..407fb53 100644 --- a/application/session_data.json +++ b/application/session_data.json @@ -1 +1 @@ -{"session_cookie": {"session": "m4rjEuzC595awmTv39qVOhjiiQYDcq3PT7ObB1_S6Bs"}, "client_id": "9ce7d233"} \ No newline at end of file +{"session_cookie": {"session": "m-RSGMraIhk3P9RQ5oN5CSbgUBYlFpe9P2aOxm6ayU8"}, "client_id": "9ce7d233"} \ No newline at end of file diff --git a/cli.py b/cli.py deleted file mode 100644 index dbe5241..0000000 --- a/cli.py +++ /dev/null @@ -1,25 +0,0 @@ -# Lucas Mathews - Fontys Student ID: 5023572 -# Banking System CLI Utility - -import requests -import argparse -import sys -from config import CONFIG - -SERVER_URL = "http://127.0.0.1:81" - -def main(): - username = "john" - password = "doe" - print(f"Login with {username} and {password}:") - response = requests.get( f"{SERVER_URL}/login?username={username}&password={password}") - print(f"{response}, {response.content}") - - print(f"Logout:") - response = requests.get( f"{SERVER_URL}/logout") - print(f"{response}, {response.content}") - print(f"Closing") -main() - -if __name__ == "__main__": - sys.exit( main() ) \ No newline at end of file diff --git a/cli/cli.ini b/cli/cli.ini new file mode 100644 index 0000000..675afdc --- /dev/null +++ b/cli/cli.ini @@ -0,0 +1,8 @@ +[server] +ip = 0.0.0.0 +port = 81 +url = http://127.0.0.1:81 + +[client] +default_id = 9ce7d233 +default_password = Happymeal1 \ No newline at end of file diff --git a/cli/cli.py b/cli/cli.py new file mode 100644 index 0000000..cdeaec6 --- /dev/null +++ b/cli/cli.py @@ -0,0 +1,33 @@ +# Lucas Mathews - Fontys Student ID: 5023572 +# Banking System CLI Utility + +import argparse +import sys +from connection import login, logout + +def main(): + parser = argparse.ArgumentParser(description='Banking System CLI Utility') + parser.add_argument('-u', '--username', type=str, help='Username for login') + parser.add_argument('-p', '--password', type=str, help='Password for login') + + subparsers = parser.add_subparsers(dest='command') + + login_parser = subparsers.add_parser('login', help='Login to the system') + logout_parser = subparsers.add_parser('logout', help='Logout from the system') + + args = parser.parse_args() + + if args.command == 'login': + if not args.username or not args.password: + print("Username and password are required for login.") + sys.exit(1) + response = login(args.username, args.password) + print(f"{response.status_code}: {response.content}") + elif args.command == 'logout': + response = logout() + print(f"{response.status_code}: {response.content}") + else: + print("Invalid command. Use 'login' or 'logout'.") + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/cli/config.py b/cli/config.py new file mode 100644 index 0000000..cd8fe0e --- /dev/null +++ b/cli/config.py @@ -0,0 +1,7 @@ +# Lucas Mathews - Fontys Student ID: 5023572 +# Banking System Config Parser + +import configparser + +CONFIG = configparser.ConfigParser() +CONFIG.read("cli/cli.ini") diff --git a/cli/connection.py b/cli/connection.py new file mode 100644 index 0000000..a89f8e7 --- /dev/null +++ b/cli/connection.py @@ -0,0 +1,14 @@ +# api_client.py +import requests +from config import CONFIG + +def login(username, password): + url = f"{CONFIG['server']['url']}/login" + payload = {'username': username, 'password': password} + response = requests.get(url, params=payload) + return response + +def logout(): + url = f"{CONFIG['server']['url']}/logout" + response = requests.get(url) + return response