Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Island: Use MONGO_URL instead of hard-coded values for flask-security #4172

Merged
merged 1 commit into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions monkey/monkey_island/cc/mongo_consts.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import os

MONGO_DB_NAME = "monkey_island"
MONGO_DB_HOST = "localhost"
MONGO_DB_PORT = 27017
DEFAULT_MONGO_DB_NAME = "monkey_island"
DEFAULT_MONGO_DB_HOST = "localhost"
DEFAULT_MONGO_DB_PORT = 27017
MONGO_URL = os.environ.get(
"MONKEY_MONGO_URL",
"mongodb://{0}:{1}/{2}".format(MONGO_DB_HOST, MONGO_DB_PORT, MONGO_DB_NAME),
f"mongodb://{0}:{1}/{2}".format(
DEFAULT_MONGO_DB_HOST, DEFAULT_MONGO_DB_PORT, DEFAULT_MONGO_DB_NAME
),
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
import secrets
from pathlib import Path
from typing import Any, Dict
from urllib.parse import urlparse

from flask.sessions import SecureCookieSessionInterface
from flask_mongoengine import MongoEngine
from flask_security import ConfirmRegisterForm, MongoEngineUserDatastore, Security, UserDatastore
from monkeytoolbox import open_new_securely_permissioned_file
from wtforms import StringField

from monkey_island.cc.mongo_consts import MONGO_DB_HOST, MONGO_DB_NAME, MONGO_DB_PORT, MONGO_URL
from monkey_island.cc.mongo_consts import MONGO_URL

from . import AccountRole
from .role import Role
Expand Down Expand Up @@ -71,11 +72,12 @@ def to_dict(self, only_user):

def _setup_flask_mongo(app):
app.config["MONGO_URI"] = MONGO_URL
url = urlparse(MONGO_URL)
app.config["MONGODB_SETTINGS"] = [
{
"db": MONGO_DB_NAME,
"host": MONGO_DB_HOST,
"port": MONGO_DB_PORT,
"db": url.path.strip("/"),
"host": url.hostname,
"port": url.port,
}
]

Expand Down