Island: Inject local_ip_addresses into Root resource's constructor

This commit is contained in:
Shreya Malviya 2022-08-04 13:03:04 +05:30
parent 80c6ee8805
commit 4ee1450001
1 changed files with 5 additions and 2 deletions

View File

@ -1,4 +1,5 @@
import logging
from typing import Sequence
from flask import jsonify, make_response, request
@ -6,7 +7,6 @@ from monkey_island.cc.database import mongo
from monkey_island.cc.resources.AbstractResource import AbstractResource
from monkey_island.cc.resources.request_authentication import jwt_required
from monkey_island.cc.services.infection_lifecycle import get_completed_steps
from monkey_island.cc.services.utils.network_utils import get_local_ip_addresses
logger = logging.getLogger(__name__)
@ -15,6 +15,9 @@ class Root(AbstractResource):
urls = ["/api"]
def __init__(self, local_ip_addresses: Sequence[str]):
self._local_ips = local_ip_addresses
def get(self, action=None):
if not action:
action = request.args.get("action")
@ -29,7 +32,7 @@ class Root(AbstractResource):
@jwt_required
def get_server_info(self):
return jsonify(
ip_addresses=get_local_ip_addresses(),
ip_addresses=self._local_ips,
mongo=str(mongo.db),
completed_steps=get_completed_steps(),
)