[K/N] Move aws address for perf infra from code to environment

This commit is contained in:
Pavel Kunyavskiy
2022-08-26 11:37:42 +02:00
committed by Space
parent dbda8dcad1
commit 776b68f2fe
3 changed files with 24 additions and 29 deletions
@@ -1,19 +1,10 @@
/*
* Copyright 2010-2019 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
import org.jetbrains.network.*
external fun require(module: String): dynamic
external val process: dynamic
@@ -42,7 +33,20 @@ fun main(args: Array<String>) {
println("App listening on port " + port + "!")
})
app.use("/", router())
val connector = if (process.env.LOCAL_AWS != null && process.env.LOCAL_AWS != kotlin.js.undefined) {
println("Using local aws instance")
UrlNetworkConnector("http://localhost", 9200)
} else {
val host = process.env.AWS_HOST
val region = process.env.AWS_REGION
if (host !is String) throw IllegalStateException("AWS_HOST env variable is not defined")
if (region !is String) throw IllegalStateException("AWS_REGION env variable is not defined")
AWSNetworkConnector(
host, region
)
}
app.use("/", router(connector))
}
fun normalizePort(port: Int) =
@@ -1,6 +1,6 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.network
@@ -57,10 +57,7 @@ external object AWSInstance {
}
// Network connector to work with AWS resources.
class AWSNetworkConnector : NetworkConnector() {
val AWSDomain = "vpc-kotlin-perf-service-5e6ldakkdv526ii5hbclzcmpny.eu-west-1.es.amazonaws.com"
val AWSRegion = "eu-west-1"
class AWSNetworkConnector(val AWSDomain: String, val AWSRegion: String) : NetworkConnector() {
override fun <T : String?> sendBaseRequest(method: RequestMethod, path: String, user: String?, password: String?,
acceptJsonContentType: Boolean, body: String?,
errorHandler: (url: String, response: dynamic) -> Nothing?): Promise<T> {
@@ -1,6 +1,6 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
import org.w3c.xhr.*
@@ -216,17 +216,11 @@ internal fun <T> orderedValues(values: List<T>, buildElement: (T) -> CompositeBu
)
)
// ElasticSearch connector for work with custom instance.
internal val localHostElasticConnector = UrlNetworkConnector("http://localhost", 9200)
// ElasticSearch connector for work with AWS instance.
internal val awsElasticConnector = AWSNetworkConnector()
internal val networkConnector = awsElasticConnector
fun urlParameterToBaseFormat(value: dynamic) =
value.toString().replace("_", " ")
// Routing of requests to current server.
fun router() {
fun router(networkConnector: NetworkConnector) {
val express = require("express")
val router = express.Router()
val connector = ElasticSearchConnector(networkConnector)