Welcome to the refactoring module! This challenge will serve as the first tutorial to how you will mainly be completing the challenges in this specific module. "Start" this challenge, and then you can interact with it by clicking on "Workspace" in the site's navigation bar or "VSCode Workspace" in the pop-up after the challenge has successfully started.
Start by running the checker
Python executable by doing the following in the terminal:
$ cd /challenge
$ ./checker
The executable will then give you further instructions.
NOTE: For a Python file, you would usually run it by doing $ python3 [filename]
. For this environment and platform, due to how permissions are handled so that you cannot simply read the flag, you MUST run checker
by doing $ ./checker
so that it can successfully read the flag and print it in the terminal. If you complete the tasks for the challenges but use $ python3 checker
, you will get an error in the terminal (the file won't actually be executed).
In addition, you will get an error if you try to read the checker
file / open it up in VSCode. This is intentional. Again, you MUST run checker
as specified above.
Scenario
These challenges will ask you to refactor certain aspects of each challenge's provided 'codebase'. In this scenario, you will be refactoring a simplified version of a security information and event management (SIEM) solution, also known as a logging solution. Examples of these include Splunk, Datadog, and Wazuh.
To assist with these refactoring challenges, we will introduce you to the 'ruff' linter that will be checking your code to adhere to certain properties. You will be told what needs to be refactored, as if this is your first week on the job. To learn more about ruff: https://docs.astral.sh/ruff/.
Note that there are many other linters and code formatters out there, with different ones available for different programming languages. We happened to pick ruff as it is both a linter and formatter for Python with over hundreds of built-in rules and is used in major open-source projects. If you are not yet familiar with working with these kinds of tools for software development, these challenges are also designed to introduce and expose you to tools created and used by other developers.
In this tutorial, all you have to do is remove some unused imports. While unused imports can be helpful for future convenience, they end up adding some additional performance overhead, which can certainly stack up if you have a lot of them. They also add unnecessary clutter to the code, and you can easily add them back when you really need them.
This challenge will run the following command against 'simple_siem.py':
$ ruff check --select F401 /challenge/simple_siem.py
Run checker
in the challenge environment to get a more in-depth breakdown!
Tasks
- Remove the unused imports in
simple_siem.py
.