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 #25886: Migrate Environment variable from lift-json to zio-json #6022

Conversation

fanf
Copy link
Member

@fanf fanf commented Nov 17, 2024

@fanf fanf requested a review from clarktsiory November 17, 2024 15:17
@fanf fanf force-pushed the arch_25886/migrate_environment_variable_from_lift_json_to_zio_json branch from d24a211 to 3557fd4 Compare November 17, 2024 17:29
|inventoryDate: 20180717000031.000Z
|receiveDate: 20180717000527.050Z
|lastLoggedUserTime: 20000714084300.000Z
|softwareUpdate: {"name":"rudder-agent","version":"7.0.0-realease","from":"yum","arch":"x86_64","kind":"none","description":"Local privilege escalation in pkexec","severity":"low","date":"2022-01-26T00:00:00Z","ids":["RHSA-2020-4566","CVE-2021-4034"]}
|softwareUpdate: {"name":"rudder-agent","version":"7.0.0-realease","arch":"x86_64","from":"yum","kind":"none","description":"Local privilege escalation in pkexec","severity":"low","date":"2022-01-26T00:00:00Z","ids":["RHSA-2020-4566","CVE-2021-4034"]}
Copy link
Member Author

Choose a reason for hiding this comment

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

the change was needed because of the idempotency tests, but the previous line still works

@@ -530,7 +530,7 @@ class TestCoreNodeFactInventory extends Specification with BeforeAfterAll {
.getAttributeValue("environmentVariable") must beEqualTo("""{"name":"envVAR","value":"envVALUE"}""")) and
(mockLdapFactStorage.testServer
.getEntry("nodeId=node7,ou=Nodes,ou=Accepted Inventories,ou=Inventories,cn=rudder-configuration")
.getAttributeValue("process") must beEqualTo("""{"pid":4242,"commandName":"process 4242 command line"}""")) and
.getAttributeValue("process") must beEqualTo("""{"pid":4242,"name":"process 4242 command line"}""")) and
Copy link
Member Author

Choose a reason for hiding this comment

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

we're still able to read commandName, but we write name now.

@fanf
Copy link
Member Author

fanf commented Nov 17, 2024

PR updated with a new commit

@fanf fanf force-pushed the arch_25886/migrate_environment_variable_from_lift_json_to_zio_json branch from f80d204 to 2624c12 Compare November 18, 2024 08:13
Comment on lines 842 to +843
// convert the processes
node.processes.map(x => Serialization.write(x))
node.processes.map(_.toJson)
Copy link
Contributor

Choose a reason for hiding this comment

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

yes ! this could have already been changed since a while now 😅

Comment on lines 1033 to 1030
ev = entry.valuesFor(A_EV).toSeq.map(Serialization.read[EnvironmentVariable](_))
process = entry.valuesFor(A_PROCESS).toSeq.map(Serialization.read[Process](_))
ev = entry.valuesFor(A_EV).toSeq.map(_.fromJson[EnvironmentVariable]).collect { case Right(ev) => ev }
process = entry.valuesFor(A_PROCESS).toSeq.map(_.fromJson[Process]).collect { case Right(p) => p }
Copy link
Contributor

Choose a reason for hiding this comment

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

Since the Serialization.read method throws, the equivalent would instead be a traverse/ZIO.foreach here instead of failing silently ?

Copy link
Member Author

Choose a reason for hiding this comment

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

the previous case was just a bug I think.
So what do we want ? Not a full error and an unreadable inventory because a mear process / env var was uncorectly written in base and can't be read back, because it's completely unactionnable by the user. It's even possible that just sending an other inventory doesn't solve the problem by overriding datas, since we read existing one before writting (which means, we may have other problems). Ok, let's write a test on that.

I can log before ignoring, but I'm pretty sure that log either won't be read ever, or will cause major error like filling disks.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added logs and a test to ensure we can deserialize inventories in presence of incorrect data.
Alos, did the same for custom properties which were ignored too.

@@ -51,7 +51,6 @@ import com.normation.ldap.sdk.schema.LDAPObjectClass
import com.softwaremill.quicklens.*
import com.unboundid.ldap.sdk.{Version as _, *}
import java.net.InetAddress
import net.liftweb.json.*
Copy link
Contributor

Choose a reason for hiding this comment

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

🔥

Copy link
Contributor

@clarktsiory clarktsiory left a comment

Choose a reason for hiding this comment

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

LGTM apart from the non-iso error handling ! I'm eagerly waiting for the merge 😇

@fanf fanf force-pushed the arch_25886/migrate_environment_variable_from_lift_json_to_zio_json branch from 4ca371a to 25a44da Compare November 22, 2024 22:38
Copy link
Contributor

@clarktsiory clarktsiory left a comment

Choose a reason for hiding this comment

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

OK then the change looks good to me

diff.toArray() must beEmpty
}

"correctly unserialize a node even with malformed env var, process, soft update" in {
Copy link
Contributor

Choose a reason for hiding this comment

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

okay, I guess if someone is having this problem we haven't heard about it yet 😇

@Normation-Quality-Assistant
Copy link
Contributor

OK, merging this PR

@Normation-Quality-Assistant Normation-Quality-Assistant merged commit 782eba3 into Normation:master Nov 25, 2024
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants