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 #24280: When we clone a technique with resource, the clone does not really have the resource #5453

Open
wants to merge 1 commit into
base: branches/rudder/8.0
Choose a base branch
from

Conversation

VinceMacBuche
Copy link
Member

@VinceMacBuche VinceMacBuche requested a review from fanf March 7, 2024 19:08
authzToken: AuthzToken
): LiftResponse = {
(for {
techniqueId <- restExtractorService.extractString("techniqueId")(req)(Full(_)).toIO.notOptional("category parameter is missing")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
techniqueId <- restExtractorService.extractString("techniqueId")(req)(Full(_)).toIO.notOptional("category parameter is missing")
techniqueId <- restExtractorService.extractString("techniqueId")(req)(Full(_)).toIO.notOptional("technique id parameter is missing")


IOResult.attempt(s"An error occurred while copying resources of technique ${techniqueId}/${techniqueVersion} to a new draft technique ${draftId}") {
val resourceDir = gitReposProvider.rootDirectory / s"techniques/${category}/${techniqueId}/${techniqueVersion}/resources"
val workspace = gitReposProvider.rootDirectory / s"workspace/${draftId}/${techniqueVersion}"
Copy link
Member

Choose a reason for hiding this comment

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

please avoid strings for global vars. Ideally they should be services for easier testing, or at lest something provided centrally in an object.

@@ -240,6 +241,7 @@ type Msg =
| UpdateTechnique Technique
| DeleteTechnique (Result (Http.Detailed.Error String) ( Http.Metadata, TechniqueId ))
| GetTechniqueResources (Result (Http.Detailed.Error String) ( Http.Metadata, List Resource ))
| CopyResources (Result (Http.Detailed.Error Bytes) ())
Copy link
Member

Choose a reason for hiding this comment

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

I don't get why you have bytes here ? The resources remains in the backend in the case of cloning no ?

Copy link
Member Author

Choose a reason for hiding this comment

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

because i don't care about the answer and that's how you do in Elm

@fanf
Copy link
Member

fanf commented Mar 8, 2024

Can you explain the general idea here ? There's several things I don't get:

  • why does it need it's dedicated public API endpoint for something that looks like a very internal process implementation ? I would understand a general API "clone", but "copy resource when cloning" is really looking like an internal step, not an API usable by users
  • why do you need Bytes in the elm part?
  • I don't understand how cloning resources from a draft work either

@VinceMacBuche
Copy link
Member Author

Commit modified

@VinceMacBuche VinceMacBuche force-pushed the bug_24280/when_we_clone_a_technique_with_resource_the_clone_does_not_really_have_the_resource branch from 345484e to ae74ad9 Compare April 11, 2024 17:10
@VinceMacBuche
Copy link
Member Author

Commit modified

@VinceMacBuche VinceMacBuche force-pushed the bug_24280/when_we_clone_a_technique_with_resource_the_clone_does_not_really_have_the_resource branch from ae74ad9 to d909c07 Compare April 11, 2024 20:28
@fanf
Copy link
Member

fanf commented May 3, 2024

When I clone a technique with an existing resource, the resource is cloned. But as soons as I try to modify the technique name, I get a lot of error notif in UI, and the following stack trace in logs:

 -> com.normation.rudder.ncf.GitResourceFileService.$anonfun$cloneResourcesFromTechnique$1(ResourceFileService.scala:147)
 -> com.normation.zio$ZioRuntime$.$anonfun$unsafeRun$1(ZioCommons.scala:445)
 -> com.normation.zio$ZioRuntime$.unsafeRun(ZioCommons.scala:445)
 -> com.normation.zio$ZioRuntime$.runNow(ZioCommons.scala:428)
 -> com.normation.zio$UnsafeRun.runNow(ZioCommons.scala:454)
 -> com.normation.rudder.rest.RudderJsonResponse$implicits$ToLiftResponseOne.toLiftResponseOne(RudderJsonResponse.scala:220)
 -> com.normation.rudder.rest.RudderJsonResponse$implicits$ToLiftResponseOne.toLiftResponseOne(RudderJsonResponse.scala:232)
 -> com.normation.rudder.rest.lift.TechniqueApi$CopyResourcesWhenCloning$.process(TechniqueApi.scala:235)
 -> com.normation.rudder.rest.lift.TechniqueApi$CopyResourcesWhenCloning$.process(TechniqueApi.scala:216)
 -> com.normation.rudder.rest.lift.LiftApiModule.handler(LiftApiDispatcher.scala:67)
 -> com.normation.rudder.rest.lift.LiftApiModule.handler$(LiftApiDispatcher.scala:59)
 -> com.normation.rudder.rest.lift.TechniqueApi$CopyResourcesWhenCloning$.handler(TechniqueApi.scala:216)
 -> com.normation.rudder.rest.lift.TechniqueApi$CopyResourcesWhenCloning$.handler(TechniqueApi.scala:216)
 -> com.normation.rudder.rest.BuildHandler.$anonfun$buildApi$21(ApiDatastructures.scala:696)
 -> com.normation.rudder.rest.BuildHandler.$anonfun$buildApi$18(ApiDatastructures.scala:680)
 -> com.normation.rudder.rest.BuildHandler.$anonfun$buildApi$15(ApiDatastructures.scala:674)
 -> com.normation.rudder.rest.BuildHandler.$anonfun$buildApi$15$adapted(ApiDatastructures.scala:672)```


Plus, the copy API it still public, it should be private. 

The clone of template with resources works great :+1: 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants