-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Unhide setting js.interpretation.enabled
#12605
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
base: 4.20
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,11 @@ | |
|
|
||
| import java.io.InputStream; | ||
| import java.sql.Connection; | ||
| import java.sql.PreparedStatement; | ||
| import java.sql.ResultSet; | ||
| import java.sql.SQLException; | ||
|
|
||
| import com.cloud.utils.crypt.DBEncryptionUtil; | ||
| import com.cloud.utils.exception.CloudRuntimeException; | ||
|
|
||
| public class Upgrade42020to42030 extends DbUpgradeAbstractImpl implements DbUpgrade, DbUpgradeSystemVmTemplate { | ||
|
|
@@ -51,6 +55,44 @@ public InputStream[] getPrepareScripts() { | |
|
|
||
| @Override | ||
| public void performDataMigration(Connection conn) { | ||
| unhideJsInterpretationEnabled(conn); | ||
| } | ||
|
|
||
| protected void unhideJsInterpretationEnabled(Connection conn) { | ||
| String value = getJsInterpretationEnabled(conn); | ||
| if (value != null) { | ||
| updateJsInterpretationEnabledFields(conn, value); | ||
| } | ||
| } | ||
|
|
||
| protected String getJsInterpretationEnabled(Connection conn) { | ||
| String query = "SELECT value FROM cloud.configuration WHERE name = 'js.interpretation.enabled' AND category = 'Hidden';"; | ||
|
|
||
| try (PreparedStatement pstmt = conn.prepareStatement(query)) { | ||
| ResultSet rs = pstmt.executeQuery(); | ||
| if (rs.next()) { | ||
| return rs.getString("value"); | ||
| } | ||
| logger.debug("Unable to retrieve value of hidden configuration 'js.interpretation.enabled'. The configuration may already be unhidden."); | ||
| return null; | ||
| } catch (SQLException e) { | ||
| throw new CloudRuntimeException("Error while retrieving value of hidden configuration 'js.interpretation.enabled'.", e); | ||
| } | ||
| } | ||
|
|
||
| protected void updateJsInterpretationEnabledFields(Connection conn, String encryptedValue) { | ||
| String query = "UPDATE cloud.configuration SET value = ?, category = 'System' WHERE name = 'js.interpretation.enabled' AND category = 'Hidden';"; | ||
|
|
||
| try (PreparedStatement pstmt = conn.prepareStatement(query)) { | ||
| String decryptedValue = DBEncryptionUtil.decrypt(encryptedValue); | ||
| logger.info("Updating setting 'js.interpretation.enabled' to decrypted value [{}], and category 'System'.", decryptedValue); | ||
| pstmt.setString(1, decryptedValue); | ||
| pstmt.executeUpdate(); | ||
| } catch (SQLException e) { | ||
| throw new CloudRuntimeException("Error while unhiding configuration 'js.interpretation.enabled'.", e); | ||
| } catch (CloudRuntimeException e) { | ||
| logger.warn("Error while decrypting configuration 'js.interpretation.enabled'. The configuration may already be decrypted."); | ||
| } | ||
|
Comment on lines
+93
to
+95
|
||
| } | ||
|
|
||
| @Override | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The SQL UPDATE statement only updates the 'value' and 'category' fields, but according to the PR description and the new ConfigKey definition in JsInterpreterHelper, the 'component' field should also be updated from 'ManagementServer' to 'JsInterpreter', and the 'is_dynamic' field should be updated to 1 (true). The SQL query should be: "UPDATE cloud.configuration SET value = ?, category = 'System', component = 'JsInterpreter', is_dynamic = 1 WHERE name = 'js.interpretation.enabled' AND category = 'Hidden';"