Skip to content

Commit

Permalink
Rewrite SecureRestClientBuilder
Browse files Browse the repository at this point in the history
Signed-off-by: bowenlan-amzn <[email protected]>
  • Loading branch information
bowenlan-amzn committed Nov 17, 2022
1 parent 3b9cf7f commit 6c86be5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
6 changes: 4 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ dependencies {
implementation "org.apache.httpcomponents:httpcore:4.4.15"

testImplementation "org.opensearch.test:framework:${opensearch_version}"
testImplementation "org.opensearch.client:opensearch-rest-high-level-client:${opensearch_version}"
testImplementation "org.jetbrains.kotlin:kotlin-test:${kotlin_version}"
testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
testImplementation "org.mockito:mockito-core:4.7.0"
Expand Down Expand Up @@ -271,6 +272,7 @@ def securityPluginFile = new Callable<RegularFile>() {
}
}
}
// This flag indicates the existence of security plugin
def securityEnabled = System.getProperty("security", "false") == "true"
afterEvaluate {
testClusters.integTest.nodes.each { node ->
Expand Down Expand Up @@ -726,11 +728,11 @@ run {

compileKotlin {
kotlinOptions.freeCompilerArgs = ['-Xjsr305=strict']
kotlinOptions.allWarningsAsErrors = true
// kotlinOptions.allWarningsAsErrors = true
}

compileTestKotlin {
kotlinOptions.allWarningsAsErrors = true
// kotlinOptions.allWarningsAsErrors = true
}

apply from: 'build-tools/pkgbuild.gradle'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import org.opensearch.action.admin.cluster.node.tasks.list.ListTasksAction
import org.opensearch.client.Request
import org.opensearch.client.Response
import org.opensearch.client.RestClient
import org.opensearch.common.io.PathUtils
import org.opensearch.common.settings.Settings
import org.opensearch.common.xcontent.DeprecationHandler
import org.opensearch.common.xcontent.NamedXContentRegistry
Expand All @@ -23,7 +22,7 @@ import org.opensearch.commons.ConfigConstants.OPENSEARCH_SECURITY_SSL_HTTP_PEMCE
import org.opensearch.commons.rest.SecureRestClientBuilder
import org.opensearch.test.rest.OpenSearchRestTestCase
import java.io.IOException
import java.util.Date
import java.util.*

abstract class ODFERestTestCase : OpenSearchRestTestCase() {

Expand Down Expand Up @@ -117,23 +116,22 @@ abstract class ODFERestTestCase : OpenSearchRestTestCase() {
val userName = System.getProperty("user")
val password = System.getProperty("password")
println("Build client with user:password $userName:$password")
val httpsHosts = hosts.map {
hosts.map {
println("Host uri ${it.toURI()}")
HttpHost.create("https://${it.toURI()}")
}
SecureRestClientBuilder(httpsHosts.toTypedArray(), isHttps(), userName, password).setSocketTimeout(60000).build()
SecureRestClientBuilder(hosts, isHttps(), userName, password)
.setSocketTimeout(60000).build()
}
false -> {
// create client with passed user
println("Build admin client")
val userName = System.getProperty("user")
val password = System.getProperty("password")
println("Build client with user:password $userName:$password")
val httpsHosts = hosts.map {
hosts.map {
println("Host uri ${it.toURI()}")
HttpHost.create("https://${it.toURI()}")
}
SecureRestClientBuilder(httpsHosts.toTypedArray(), isHttps(), userName, password).setSocketTimeout(60000).build()
SecureRestClientBuilder(hosts, isHttps(), userName, password).setSocketTimeout(60000).build()
}
}
} else {
Expand All @@ -146,7 +144,9 @@ abstract class ODFERestTestCase : OpenSearchRestTestCase() {

override fun getTestRestCluster(): String {
val httpHostsProp = System.getProperty("tests.cluster.http_hosts")
val cluster = System.getProperty("tests.rest.cluster")
println("http prop: $httpHostsProp")
println("rest cluster: $cluster")
return httpHostsProp
}
}

0 comments on commit 6c86be5

Please sign in to comment.