Skip to content

Commit

Permalink
chore(*): Apply codestyles (#799)
Browse files Browse the repository at this point in the history
* chore(*): Apply codestyles

Most files were picked up by applyin to the base
project in the prior PR, so it's just these two
kotlin files.

* chore(*): Turn on codestyle enforcement
  • Loading branch information
ezimanyi committed May 14, 2019
1 parent c421f53 commit 000f9e6
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 42 deletions.
6 changes: 0 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,4 @@ allprojects {
}
}

subprojects { project ->
spinnakerCodeStyle {
enabled = false
}
}

defaultTasks ':gate-web:run'
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ import java.security.KeyStore
import java.security.cert.X509Certificate
import java.util.concurrent.TimeUnit
import javax.annotation.PostConstruct
import javax.net.ssl.*
import javax.net.ssl.KeyManagerFactory
import javax.net.ssl.SSLContext
import javax.net.ssl.TrustManager
import javax.net.ssl.TrustManagerFactory
import javax.net.ssl.X509TrustManager

@Configuration
@EnableConfigurationProperties(
Expand Down Expand Up @@ -54,29 +58,30 @@ data class ProxyConfigurationProperties(var proxies: List<ProxyConfig> = mutable
}
}

data class ProxyConfig(var id: String? = null,
var uri: String? = null,
var skipHostnameVerification: Boolean = false,
var keyStore: String? = null,
var keyStoreType: String = KeyStore.getDefaultType(),
var keyStorePassword: String? = null,
var keyStorePasswordFile: String? = null,
var trustStore: String? = null,
var trustStoreType: String = KeyStore.getDefaultType(),
var trustStorePassword: String? = null,
var trustStorePasswordFile: String? = null,
var methods: List<String> = mutableListOf(),
var connectTimeoutMs: Long = 30_000,
var readTimeoutMs: Long = 59_000,
var writeTimeoutMs: Long = 30_000) {
data class ProxyConfig(
var id: String? = null,
var uri: String? = null,
var skipHostnameVerification: Boolean = false,
var keyStore: String? = null,
var keyStoreType: String = KeyStore.getDefaultType(),
var keyStorePassword: String? = null,
var keyStorePasswordFile: String? = null,
var trustStore: String? = null,
var trustStoreType: String = KeyStore.getDefaultType(),
var trustStorePassword: String? = null,
var trustStorePasswordFile: String? = null,
var methods: List<String> = mutableListOf(),
var connectTimeoutMs: Long = 30_000,
var readTimeoutMs: Long = 59_000,
var writeTimeoutMs: Long = 30_000
) {

companion object {
val logger = LoggerFactory.getLogger(ProxyConfig::class.java)
}

var okHttpClient = OkHttpClient()


fun init() {
okHttpClient.setConnectTimeout(connectTimeoutMs, TimeUnit.MILLISECONDS)
okHttpClient.setReadTimeout(readTimeoutMs, TimeUnit.MILLISECONDS)
Expand Down Expand Up @@ -105,10 +110,10 @@ data class ProxyConfig(var id: String? = null,
}

val kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm())
kmf.init(kStore, keyStorePassword!!.toCharArray());
kmf.init(kStore, keyStorePassword!!.toCharArray())

val keyManagers = kmf.keyManagers
var trustManagers : Array<TrustManager>? = null
var trustManagers: Array<TrustManager>? = null

if (!trustStore.isNullOrEmpty()) {
if (trustStore.equals("*")) {
Expand All @@ -135,7 +140,7 @@ data class ProxyConfig(var id: String? = null,
}

val sslContext = SSLContext.getInstance("TLS")
sslContext.init(keyManagers, trustManagers, null);
sslContext.init(keyManagers, trustManagers, null)

this.okHttpClient = okHttpClient.setSslSocketFactory(sslContext.socketFactory)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,50 @@ package com.netflix.spinnaker.gate.controllers

import com.fasterxml.jackson.databind.ObjectMapper
import com.netflix.spectator.api.Registry
import com.squareup.okhttp.Request
import org.springframework.web.bind.annotation.*
import org.springframework.web.servlet.HandlerMapping
import javax.servlet.http.HttpServletRequest

import com.netflix.spinnaker.config.ProxyConfigurationProperties
import com.netflix.spinnaker.kork.web.exceptions.InvalidRequestException
import com.squareup.okhttp.Request
import com.squareup.okhttp.RequestBody
import com.squareup.okhttp.internal.http.HttpMethod
import org.springframework.http.HttpHeaders
import org.springframework.http.HttpStatus
import org.springframework.http.MediaType
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestMethod.GET
import org.springframework.web.bind.annotation.RequestMethod.POST
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.servlet.HandlerMapping
import java.net.SocketException
import java.util.stream.Collectors

import org.springframework.web.bind.annotation.RequestMethod.*
import javax.servlet.http.HttpServletRequest

@RestController
@RequestMapping(value = ["/proxies"])
class ProxyController(val objectMapper: ObjectMapper,
val registry: Registry,
val proxyConfigurationProperties: ProxyConfigurationProperties) {
class ProxyController(
val objectMapper: ObjectMapper,
val registry: Registry,
val proxyConfigurationProperties: ProxyConfigurationProperties
) {

val proxyInvocationsId = registry.createId("proxy.invocations")

@RequestMapping(value = ["/{proxy}/**"], method = [GET, POST])
fun any(@PathVariable(value = "proxy") proxy: String,
@RequestParam requestParams: Map<String, String>,
httpServletRequest: HttpServletRequest): ResponseEntity<Any> {
fun any(
@PathVariable(value = "proxy") proxy: String,
@RequestParam requestParams: Map<String, String>,
httpServletRequest: HttpServletRequest
): ResponseEntity<Any> {
return request(proxy, requestParams, httpServletRequest)
}

private fun request(proxy: String,
requestParams: Map<String, String>,
httpServletRequest: HttpServletRequest): ResponseEntity<Any> {
private fun request(
proxy: String,
requestParams: Map<String, String>,
httpServletRequest: HttpServletRequest
): ResponseEntity<Any> {
val proxyConfig = proxyConfigurationProperties
.proxies
.find { it.id.equals(proxy, true) } ?: throw InvalidRequestException("No proxy config found with id '$proxy'")
Expand Down

0 comments on commit 000f9e6

Please sign in to comment.