Closed MilyMilo closed 1 year ago
Looking forward to seeing this merge, it'll simplify some CI/CD pipelines I'm hoping to release.
If you're open to changes, I had one request - could ctf install
automatically perform a ctf sync
if a challenge has a duplicate name? Currently I have to try ctf sync
for each chal, then run ctf install
if sync fails
@pl4nty Sure it's possible and an easy change, but I'm just wondering if a desirable one.
While it's better from a CI/CD point of view where you can be sure you're just installing a challenge which might already be installed. However, we're mostly using this as a CLI - in which case it's most likely just a human error (either wrong command, or a wrong challenge - and we can't know for sure). We could end-up accidentally syncing challenges that are unfinished.
I think I'd see this as either a switch or a new command. e.g
ctf challenge install-or-sync
or ctf challenge install --sync-if-exists
CC: @ColdHeat what do you think?
Thanks, a switch or new command would work well for my usecase. I'm currently grep-ing for the sync
error to detect if install
is required, which is pretty brittle (breaks on this PR)
I like the idea of having install also do a sync if asked to do so. I think there's some other questions about where is the source of truth but I think a switch is enough. What about --force
?
@ColdHeat @pl4nty I actually think that doing a sync instead of installing the challenge as a duplicate is a better behaviour for --force. I'll adjust that.
Installing from git doesn't seem to be fixed, ie pip install git+https://github.com/CTFd/ctfcli
. It was also failing before the branch was merged. Maybe this snipped is needed in pyproject.toml
?
[tool.poetry.scripts]
ctf = "ctfcli.__main__:main"
So, this is a complete refactor of ctfcli as discussed. Notable changes:
Architecture
core
module now packages logic previously found insideutils
, wrapped into classes.core
module will only print out warnings, that do not interrupt the process. Everything else will be thrown as an exception, so that they can be caught and handled however desired inside both the CLI, and other use-cases / implementations.cli
andcore
have type hints everywhere.Functionality
try/except
clause around the CLI entrypoint to catch an exception when project is not initialised. It will now ask the user if he/she would like to initialise a new project in the current directory.finalize
method as it was not useful. In the future we might replace it with something that would perhaps create a skeleton challenge.yml file, that would act as a starting point for filling it. It might pre-fill some fields that it knows, e.g the challenge name based on the directory name.deploy
can now deploy ALL deployable challenges, and that's the default behaviour if the challenge parameter is not provided.registry://registry.example.com/example-project
and the challenge name will be appended for a full location.deploy
will now also automatically login to the registry with Cloud and Registry deployments.admin@example.ctfd.io
and resolving that canonical domain name could be a hassle and introduce issues. The deployment will use the access token as the password.username
andpassword
keys inside a[registry]
section in the project config file.--hidden
switch toctf challenge install
which will deploy the challenge / challenges in a hidden state regardless of theirchallenge.yml
value.ctf challenge edit <name>
andctf challenge edit <name> --dockerfile
to open challenge.yml or Dockerfile for that challenge - which I found useful during testing and I think is really useful overall.dir
(path
) and forview
(show
) which i think will be useful.LOGLEVEL
environment variable.deploy
/install
/sync
Testing
core
module, the coverage is at 97%.Other
poetry
instead of the compile-in-docker approach.pyproject.toml
is a standardised approach to handling package definitions, which I think we should use. pep-518pathlib.Path
now - previously this was mixed with os.join, and pathlib is much more pleasant to work with, and generally superior.whatever_dir
variables have been renamed towhavever_path
- to be clear that it will return a pathlib path.typing_extensions
package has been added to support some of typing not available in python 3.10.python-fire
has been updated to 0.5.0 - because it used to print out the output of executed commands. However if we want to use it to assign the exit-code it had to be suppressed which was only possible with 0.5.0.Breaking Changes:
Remaining TODOs:
pyproject.toml
file: poetry scriptsWhen I was refactoring the code I've came-up with several other ideas for features which I'll create separate issues for.