/csec_data_analytics

CSEC 4318-5318 Cybersecurity Data Analytics Course

Primary LanguagePython

Setup

PyCharm Project Setup

  1. Environment Setup

    Open the project folder in PyCharm. It should prompt you to set up a virtual environment using Python 3.11 and

  2. synchronize with the requirements.txt file present in the project root.

    Alternatively, you can manually set up the environment by executing the following commands:

    python -m venv venv
    python -m pip install -r requirements.txt
    
  3. Enable Django Support

    • Navigate to File -> Settings -> Languages and Frameworks -> Django.
    • Check the box to enable Django support.
    • Set the Django Project Root to this project folder's root.
    • For the settings, choose csec_data_analytics/settings.py.
    • Make sure the manage script points to manage.py located at the project root.
  4. Django Run Configuration

    • Go to Run -> Edit Configurations.
    • Click the plus (+) sign to add a new configuration, then select Django server.
    • Retain the default values and confirm with OK.
  5. Running the Django Server

    Press the Play (▶️) or Debug button in the top right-hand corner. The terminal should display that the

  6. server is running on port 8000.

  7. Creating and Running Management Commands

    • To create a new management command, add a Python file under csec_data_analytics_app/management/commands. Name
    • the file according to the command you intend.
    • Refer to the template in csec_data_analytics_app/management/commands/my_command.py.

    To execute your command:

    1. Go to Tools -> Run manage.py Task. This opens a terminal where you can input your command along with any
    2. desired parameters.
    3. Alternatively, adjust your Django server run configuration. In the configuration settings, click on
    4. Run custom command. Enter your command, ensuring you remove port 8000 and add any relevant parameters,
    5. especially if debugging is needed.

MongoDB Configuration

  1. Initialize Database and User

    Start MongoDB Shell by running:

    mongosh
    

    Then, execute the following commands:

    // Create a new collection
    db.createCollection("django-mongo")
    
    // Switch to the new collection
    use django-mongo;
    
    // Create a user for the collection
    db.createUser({
        user: "admin",
        pwd: "put5gwz2bjx9phe!TUD",
        roles: [
            { role: "readWrite", db: "django-mongo" },
            { role: "read", db: "django-mongo" }
        ]
    })