-
Notifications
You must be signed in to change notification settings - Fork 23
JPERF-729: Create a way to configure Jira admin user password during database setup #107
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
Changes from 1 commit
a5f1e36
761f912
e71d277
64b388b
8e2bd06
9e9fbc3
341818c
9b8ae41
10f9d35
26aeb0e
881f9b2
fb2be73
56ad890
0471a2a
13bcd56
4c49b61
bfc5e2e
f5fb3b8
64c957f
614475f
6009d11
148c9ab
9be53d5
16425ea
bab7c59
9b2fbec
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 |
|---|---|---|
|
|
@@ -41,11 +41,30 @@ class JiraUserPasswordOverridingDatabase internal constructor( | |
| if (userPassword == null) { | ||
| logger.info("Password not provided, skipping dataset update") | ||
| } else { | ||
| sqlClient.runSql(ssh, "UPDATE $cwdUserTableName SET credential='${userPassword.encrypted}' WHERE user_name='$username';") | ||
| if (shouldUseEncryption(ssh)) { | ||
| logger.info("Updating credential with encrypted password") | ||
| sqlClient.runSql(ssh, "UPDATE $cwdUserTableName SET credential='${userPassword.encrypted}' WHERE user_name='$username';") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense to remove table name parameters if there is no reason to keep it. @pczuj do you remember why you made it as a parameter?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reason was to split the responsibility from a class that knows only the structure of table, but doesn't know it's name. It was also to allow overwrites in case the table name changes in the future or is incorrect for some DBs. We are relying on something that is not really an Jira API here. We could make the fields also configurable for better portability, but then the class will have nothing specific about Jira DB.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then why isn't
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's because the table name parameter was made by me with first version of the code was created. Then @mgrzaslewicz took over the PR and his addition didn't follow the same approach. That's where the 2 parts of the code differ. I don't think YAGNI applies here. As mentioned in my previous comment there are at least 2 reasons for the delegation of table name definition (responsibility split + uncertain contract). Both of those are essentially preparing for easier modification, e.g. it would be easier to adapt the table name from the lib consumer repository rather than relying on a new release. I'd promote a quite from Matrin Fowler here: https://www.martinfowler.com/bliki/Yagni.html
|
||
| } else { | ||
| logger.info("Updating credential with plain text password") | ||
| sqlClient.runSql(ssh, "UPDATE $cwdUserTableName SET credential='${userPassword.plainText}' WHERE user_name='$username';") | ||
| } | ||
| logger.info("Password for user '$username' updated to '${userPassword.plainText}'") | ||
| } | ||
| } | ||
|
|
||
| private fun shouldUseEncryption(ssh: SshConnection): Boolean { | ||
| val dbNamePrefix = if (cwdUserTableName.contains(".")) cwdUserTableName.substringBefore(".") + "." else "" | ||
|
dagguh marked this conversation as resolved.
Outdated
|
||
| val sqlResult = sqlClient.runSql(ssh, "select attribute_value from ${dbNamePrefix}cwd_directory_attribute where attribute_name = 'user_encryption_method';").output | ||
| return when { | ||
| sqlResult.contains("plaintext") -> false | ||
| sqlResult.contains("atlassian-security") -> true | ||
| else -> { | ||
| logger.warn("Unknown user_encryption_method. Assuming encrypted password should be used") | ||
| true | ||
| } | ||
| } | ||
| } | ||
|
|
||
| class Builder( | ||
| private var databaseDelegate: Database, | ||
| private var username: String, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package com.atlassian.performance.tools.infrastructure.mock | ||
|
|
||
| import com.atlassian.performance.tools.infrastructure.database.SshSqlClient | ||
| import com.atlassian.performance.tools.ssh.api.SshConnection | ||
| import java.io.File | ||
| import java.util.* | ||
|
|
||
| class MockSshSqlClient : SshSqlClient { | ||
| private val log = mutableListOf<String>() | ||
| private val defaultSshResult = SshConnection.SshResult( | ||
| exitStatus = 0, | ||
| output = "", | ||
| errorOutput = "" | ||
| ) | ||
| private val returnedCommandResults = ArrayDeque<SshConnection.SshResult>() | ||
|
|
||
| fun queueReturnedSqlCommandResult(result: SshConnection.SshResult) { | ||
| returnedCommandResults.add(result) | ||
| } | ||
|
|
||
| override fun runSql( | ||
| ssh: SshConnection, | ||
| sql: String | ||
| ) = (if (returnedCommandResults.isEmpty()) defaultSshResult else returnedCommandResults.pop()) | ||
| .also { log.add(sql) } | ||
|
|
||
| override fun runSql( | ||
| ssh: SshConnection, | ||
| sql: File | ||
| ) = (if (returnedCommandResults.isEmpty()) defaultSshResult else returnedCommandResults.pop()) | ||
| .also { log.add(sql.readText()) } | ||
|
|
||
| fun getLog(): List<String> = log | ||
| } |
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.