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

Fixes #23688: Import archive must refuse yaml technique with mismatch directory and id #5153

Conversation

fanf
Copy link
Member

@fanf fanf commented Nov 2, 2023

https://issues.rudder.io/issues/23688

Add a check that Technique ID from path pattern matches technique from descriptor for YAML and JSON case after parsing the descriptor. We already have everything, just need to test at the correct place.

The most part of the change is an unit test.

@fanf
Copy link
Member Author

fanf commented Nov 2, 2023

PR updated with a new commit

@fanf fanf requested a review from clarktsiory November 2, 2023 18:00
Comment on lines +1023 to +1046
def checkTechniqueExistSameCat() = {
techInfo.techniquesCategory.collectFirst {
case (TechniqueId(name, _), catId) if (name.value == techArchive.technique.id.name.value) => catId
} match {
case None => // technique not present, ok
ZIO.unit
} else {
Inconsistency(
s"Technique '${techArchive.technique.id.serialize}' from archive has category '${archive}' but a " +
s"technique with that name already exists in category '${existing}': it must be imported in the " +
s"same category, please update your archive."
).fail
}
case Some(catId) =>
val existing = catId.getPathFromRoot.map(_.value).tail.mkString("/")
val archive = techArchive.category.mkString("/")
if (existing == archive) {
ZIO.unit
} else {
Inconsistency(
s"Technique '${techArchive.technique.id.serialize}' from archive has category '${archive}' but a " +
s"technique with that name already exists in category '${existing}': it must be imported in the " +
s"same category, please update your archive."
).fail
}
}
}

checkTechniqueExistSameCat()
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of wrapping the method body with a more descriptive name, shouldn't it be better renaming checkTechnique to checkTechniqueExistsSameCat then ?
Or simply comment on the method ? There already is a line comment but inside the method...

Copy link
Member Author

@fanf fanf Nov 3, 2023

Choose a reason for hiding this comment

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

I change that b/c I though I would be able to just chain check here, so the shape would be:

def checkTechnique(techInfo: TechniquesInfo, techArchive: TechniqueArchive): IOResult[Unit] = { 
  def checkTechniqueExistSameCat() = { ... }
  def otherCheck() = {... }

  checkTechniqueExistSameCat() *> otherCheck()
}

I was not able to do it b/c that chek need to be done before hand, and there's no simple way to factor out all checks at the same place, but I prefer to let it that way, it will be more simple to add other checks latter on (and the cost in perf/compilation/whatever is negligible)

@clarktsiory
Copy link
Contributor

LGTM ! (apart from my comment on the method name)

@Normation-Quality-Assistant
Copy link
Contributor

This PR is not mergeable to upper versions.
Since it is "Ready for merge" you must merge it by yourself using the following command:
rudder-dev merge https://github.com/Normation/rudder/pull/5153
-- Your faithful QA
Kant merge: "Thoughts without content are empty, intuitions without concepts are blind."
(https://ci.normation.com/jenkins/job/merge-accepted-pr/75664/console)

@fanf
Copy link
Member Author

fanf commented Nov 3, 2023

OK, squash merging this PR

@fanf fanf force-pushed the arch_23688/import_archive_must_refuse_yaml_technique_with_mismatch_directory_and_id branch from 5c4bc23 to ef8e443 Compare November 3, 2023 15:19
@fanf fanf merged commit ef8e443 into Normation:branches/rudder/8.0 Nov 3, 2023
0 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants