Skip to content

Commit

Permalink
WIP: refactor: use backend to perform actions on CM
Browse files Browse the repository at this point in the history
  • Loading branch information
NicoFgrx committed Jul 21, 2024
1 parent 74ee472 commit 2ed1b73
Show file tree
Hide file tree
Showing 15 changed files with 669 additions and 724 deletions.
26 changes: 8 additions & 18 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
import requests
from .api import user_namespace, admin_namespace
from .utils.setup import setup_default_configs
from .utils.challenge_store import query_challenges
from .models import DynamicIaCChallenge, DynamicIaCValueChallenge




def load(app):

app.config['RESTX_ERROR_404_HELP'] = False
Expand Down Expand Up @@ -68,27 +70,15 @@ def admin_settings():
@page_blueprint.route('/admin/instances')
@admins_only
def admin_instances():
cm_api_url = get_config("chall-manager:chall-manager_api_url")
url = f"{cm_api_url}/challenge"

s = requests.Session()
result = query_challenges()
# print(result)

instances = list()

retries = 0
try:
with s.get(url, headers=None, stream=True) as resp:
for line in resp.iter_lines():
if line:
res = line.decode("utf-8")
res = json.loads(res)

if res['result']['instances'] :
instances_of_current_chall = res['result']['instances']
for i in instances_of_current_chall:
instances.append(i)
except requests.ConnectionError as e:
print(f"ConnectionError: {e}") # Debug print

for challenge in result:
for instance in challenge["instances"]:
instances.append(instance)

user_mode = get_config("user_mode")
for i in instances:
Expand Down
Loading

0 comments on commit 2ed1b73

Please sign in to comment.