Start CLI implementation
This commit is contained in:
@@ -1 +1 @@
|
|||||||
{"session_cookie": {"session": "m4rjEuzC595awmTv39qVOhjiiQYDcq3PT7ObB1_S6Bs"}, "client_id": "9ce7d233"}
|
{"session_cookie": {"session": "m-RSGMraIhk3P9RQ5oN5CSbgUBYlFpe9P2aOxm6ayU8"}, "client_id": "9ce7d233"}
|
||||||
25
cli.py
25
cli.py
@@ -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() )
|
|
||||||
8
cli/cli.ini
Normal file
8
cli/cli.ini
Normal file
@@ -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
|
||||||
33
cli/cli.py
Normal file
33
cli/cli.py
Normal file
@@ -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()
|
||||||
7
cli/config.py
Normal file
7
cli/config.py
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# Lucas Mathews - Fontys Student ID: 5023572
|
||||||
|
# Banking System Config Parser
|
||||||
|
|
||||||
|
import configparser
|
||||||
|
|
||||||
|
CONFIG = configparser.ConfigParser()
|
||||||
|
CONFIG.read("cli/cli.ini")
|
||||||
14
cli/connection.py
Normal file
14
cli/connection.py
Normal file
@@ -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
|
||||||
Reference in New Issue
Block a user