Initial commit

This commit is contained in:
github-classroom[bot] 2024-10-18 16:01:25 +00:00 committed by GitHub
commit 5be5c0595f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 112 additions and 0 deletions

7
README.md Normal file
View File

@ -0,0 +1,7 @@
# sio_2425_project
# Group members
- A
- B
- C

1
delivery1/README.md Normal file
View File

@ -0,0 +1 @@

1
delivery2/README.md Normal file
View File

@ -0,0 +1 @@

1
delivery3/README.md Normal file
View File

@ -0,0 +1 @@

89
example/client.py Normal file
View File

@ -0,0 +1,89 @@
import os
import sys
import argparse
import logging
import json
import requests
logging.basicConfig(format='%(levelname)s\t- %(message)s')
logger = logging.getLogger()
logger.setLevel(logging.INFO)
def load_state():
state = {}
state_dir = os.path.join(os.path.expanduser('~'), '.sio')
state_file = os.path.join(state_dir, 'state.json')
logger.debug('State folder: ' + state_dir)
logger.debug('State file: ' + state_file)
if os.path.exists(state_file):
logger.debug('Loading state')
with open(state_file,'r') as f:
state = json.loads(f.read())
if state is None:
state = {}
return state
def parse_env(state):
if 'REP_ADDRESS' in os.environ:
state['REP_ADDRESS'] = os.getenv('REP_ADDRESS')
logger.debug('Setting REP_ADDRESS from Environment to: ' + state['REP_ADDRESS'])
if 'REP_PUB_KEY' in os.environ:
rep_pub_key = os.getenv('REP_PUB_KEY')
logger.debug('Loading REP_PUB_KEY fron: ' + state['REP_PUB_KEY'])
if os.path.exists(rep_pub_key):
with open(rep_pub_key, 'r') as f:
state['REP_PUB_KEY'] = f.read()
logger.debug('Loaded REP_PUB_KEY from Environment')
return state
def parse_args(state):
parser = argparse.ArgumentParser()
parser.add_argument("-k", '--key', nargs=1, help="Path to the key file")
parser.add_argument("-r", '--repo', nargs=1, help="Address:Port of the repository")
parser.add_argument("-v", '--verbose', help="Increase verbosity", action="store_true")
args = parser.parse_args()
if args.verbose:
logger.setLevel(logging.DEBUG)
logger.info('Setting log level to DEBUG')
if args.key:
if not os.path.exists(args.key[0]) or not os.path.isfile(args.key[0]):
logger.error(f'Key file not found or invalid: {args.key[0]}')
sys.exit(-1)
with open(args.key[0], 'r') as f:
state['REP_PUB_KEY'] = f.read()
logger.info('Overriding REP_PUB_KEY from command line')
if args.repo:
state['REP_ADDRESS'] = args.repo[0]
logger.info('Overriding REP_ADDRESS from command line')
def save(state):
state_dir = os.path.join(os.path.expanduser('~'), '.sio')
state_file = os.path.join(state_dir, 'state.json')
if not os.path.exists(state_dir):
logger.debug('Creating state folder')
os.mkdir(state_dir)
with open(state_file, 'w') as f:
f.write(json.dumps(state, indent=4))
state = load_state()
state = parse_env(state)
state = parse_args(state)
""" Do something """
req = requests.get(f'http://{state['REP_ADDRESS']}/organization/list')
print(req.json)
save(state)

13
example/repository.py Normal file
View File

@ -0,0 +1,13 @@
from flask import Flask
import json
app = Flask(__name__)
organizations = {}
@app.route("/organization/list")
def org_list():
return json.dumps(organizations)
#@app.route("/organization/create")
#...