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

Remove ctfd_challenge subresources (files/flags/hints) #64

Merged
merged 7 commits into from
Jun 2, 2024

Conversation

pandatix
Copy link
Member

@pandatix pandatix commented Jun 2, 2024

The current design of the ctfd_challenge, despite it proposes a unified API to manage a CTFd challenge, has many problem.
One of them is that internally, a lot of work has to be performed to follow the deltas and the CRUD operations necessary to cope with the Terraform plan.
For many reasons (and especially both a burden of maintainability and poor configuration quality) we must step back from the goal of a unified API.

This PR:

  • splits ctfd_challenge.file attribute to its own resource ctfd_file, along with lifecycle tests
  • splits ctfd_challenge.flag attribute to its own resource ctfd_flag, along with lifecycle tests
  • splits ctfd_challenge.hint attribute to its own resource ctfd_hint, along with lifecycle tests. Permit hints to be depends on one another 🎉
  • fix inconsistencies with the ctfd_challenge.decay, ctfd_challenge.minimum, ctfd_challenge.tags and ctfd_challenge.topics attributes empty/default values.

Follows an example of what this PR technically implies for end users.

Before

resource "ctfd_challenge" "http" {
  name        = "My Challenge"
  category    = "misc"
  description = "..."
  value       = 500
  decay       = 100
  minimum     = 50
  state       = "visible"
  function    = "logarithmic"

  flags = [{
    content = "CTF{some_flag}"
  }]

  topics = [
    "Misc"
  ]
  tags = [
    "misc",
    "basic"
  ]

  hints = [{
    content = "Some super-helpful hint"
    cost    = 50
    }, {
    content = "Even more helpful hint !"
    cost    = 50
  }]

  files = [{
    name       = "image.png"
    contentb64 = filebase64(".../image.png")
  }]
}

After

resource "ctfd_challenge" "http" {
  name        = "My Challenge"
  category    = "misc"
  description = "..."
  value       = 500
  decay       = 100
  minimum     = 50
  state       = "visible"
  function    = "logarithmic"

  topics = [
    "Misc"
  ]
  tags = [
    "misc",
    "basic"
  ]
}

resource "ctfd_flag" "http_flag" {
  challenge_id = ctfd_challenge.http.id
  content = "CTF{some_flag}"
}

resource "ctfd_hint" "http_hint_1" {
  challenge_id = ctfd_challenge.http.id
  content = "Some super-helpful hint"
  cost = 50
}

resource "ctfd_hint" "http_hint_2" {
  challenge_id = ctfd_challenge.http.id
  content = "Even more helpful hint !"
  cost = 50
  requirements = [ctfd_hint.http_hint_1.id]
}

resource "ctfd_file" "http_file" {
  challenge_id = ctfd_challenge.http.id
  name = "image.png"
  contentb64 = filebase64(".../image.png")
}

Documentation has been updated and make docs run.

Due to breaking changes, this PR implies for the next release to be major.

@coveralls
Copy link

coveralls commented Jun 2, 2024

Pull Request Test Coverage Report for Build 9340694681

Details

  • 478 of 681 (70.19%) changed or added relevant lines in 8 files are covered.
  • 2 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-1.2%) to 70.169%

Changes Missing Coverage Covered Lines Changed/Added Lines %
provider/challenge_data_source.go 0 4 0.0%
provider/challenge_resource.go 78 108 72.22%
provider/flag_resource.go 119 160 74.38%
provider/file_resource.go 160 222 72.07%
provider/hint_resource.go 108 174 62.07%
Files with Coverage Reduction New Missed Lines %
provider/challenge_resource.go 2 74.63%
Totals Coverage Status
Change from base Build 9330859307: -1.2%
Covered Lines: 1456
Relevant Lines: 2075

💛 - Coveralls

@pandatix pandatix force-pushed the feat/model-adhesive branch from a43756e to 778134c Compare June 2, 2024 19:05
@pandatix pandatix force-pushed the feat/model-adhesive branch 2 times, most recently from 46c40e3 to 5ce81f5 Compare June 2, 2024 19:15
@pandatix pandatix force-pushed the feat/model-adhesive branch from 5ce81f5 to 5eb11c9 Compare June 2, 2024 19:28
Copy link
Member

@NicoFgrx NicoFgrx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job !

pouet is not just a cat, it's a philosophy

@pandatix pandatix merged commit 089540e into main Jun 2, 2024
6 checks passed
@pandatix pandatix deleted the feat/model-adhesive branch June 2, 2024 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants