Skip to content

Commit

Permalink
Merge branch 'master' into gate-saml2
Browse files Browse the repository at this point in the history
  • Loading branch information
jvz committed Apr 16, 2024
2 parents 381c3ef + 8d7be10 commit cdfd5bb
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ jobs:
"${{ env.CONTAINER_REGISTRY }}/${{ steps.build_variables.outputs.REPO }}:${{ steps.release_info.outputs.RELEASE_VERSION }}-${{ steps.build_variables.outputs.VERSION }}-java11-unvalidated-ubuntu"
- name: Create release
if: steps.release_info.outputs.SKIP_RELEASE == 'false'
uses: softprops/action-gh-release@v1
uses: softprops/action-gh-release@v2
with:
body: |
${{ steps.release_info.outputs.CHANGELOG }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,8 @@ import org.springframework.context.annotation.Primary
import org.springframework.core.Ordered
import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder
import org.springframework.session.data.redis.config.ConfigureRedisAction
import org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration
import org.springframework.util.CollectionUtils
import org.springframework.web.client.RestTemplate
import redis.clients.jedis.JedisPool
import retrofit.Endpoint

import java.util.concurrent.ExecutorService
Expand All @@ -75,57 +72,21 @@ import static retrofit.Endpoints.newFixedEndpoint
@Configuration
@Slf4j
@Import([PluginsAutoConfiguration, DeckPluginConfiguration, PluginWebConfiguration])
class GateConfig extends RedisHttpSessionConfiguration {
class GateConfig {

private ServiceClientProvider serviceClientProvider
private ConfigureRedisAction configureRedisAction

@Value('${server.session.timeout-in-seconds:3600}')
void setSessionTimeout(int maxInactiveIntervalInSeconds) {
super.setMaxInactiveIntervalInSeconds(maxInactiveIntervalInSeconds)
}

@Autowired
void setServiceClientProvider(ServiceClientProvider serviceClientProvider) {
this.serviceClientProvider = serviceClientProvider
}

void setConfigureRedisAction(ConfigureRedisAction configureRedisAction){
this.configureRedisAction = configureRedisAction;
}

@Autowired
GateConfig(@Value('${server.session.timeout-in-seconds:3600}') int maxInactiveIntervalInSeconds) {
super.setMaxInactiveIntervalInSeconds(maxInactiveIntervalInSeconds)
}

/**
* This pool is used for the rate limit storage, as opposed to the JedisConnectionFactory, which
* is a separate pool used for Spring Boot's session management.
*/
@Bean
JedisPool jedis(@Value('${redis.connection:redis://localhost:6379}') String connection,
@Value('${redis.timeout:2000}') int timeout) {
return new JedisPool(new URI(connection), timeout)
}

@Bean
@ConditionalOnMissingBean(RestTemplate)
RestTemplate restTemplate() {
new RestTemplate()
}

/**
* Always disable the ConfigureRedisAction that Spring Boot uses internally. Instead we use one
* qualified with @ConnectionPostProcessor. See
* {@link PostConnectionConfiguringJedisConnectionFactory}.
* */
@Bean
@Primary
ConfigureRedisAction springBootConfigureRedisAction() {
return ConfigureRedisAction.NO_OP
}

@Bean
ExecutorService executorService() {
Executors.newCachedThreadPool()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,29 @@

package com.netflix.spinnaker.gate.config;

import com.netflix.spinnaker.gate.config.PostConnectionConfiguringJedisConnectionFactory.ConnectionPostProcessor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.session.data.redis.config.ConfigureRedisAction;

@Configuration
@ConditionalOnProperty("redis.configuration.secure")
public class RedisConfigSecure {
public class RedisActionConfig {

/**
* Always disable the ConfigureRedisAction that Spring Boot uses internally. Instead we use one
* qualified with @ConnectionPostProcessor. See {@link
* PostConnectionConfiguringJedisConnectionFactory}.
*/
@Bean
@ConnectionPostProcessor
@Primary
public ConfigureRedisAction springBootConfigureRedisAction() {
return ConfigureRedisAction.NO_OP;
}

@Bean
@ConditionalOnProperty("redis.configuration.secure")
@PostConnectionConfiguringJedisConnectionFactory.ConnectionPostProcessor
public ConfigureRedisAction connectionPostProcessorConfigureRedisAction() {
return ConfigureRedisAction.NO_OP;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.netflix.spinnaker.gate.config;

import java.net.URI;
import java.net.URISyntaxException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration;
import redis.clients.jedis.JedisPool;

@Configuration
public class RedisConfig extends RedisHttpSessionConfiguration {

@Value("${server.session.timeout-in-seconds:3600}")
public void setSessionTimeout(int maxInactiveIntervalInSeconds) {
super.setMaxInactiveIntervalInSeconds(maxInactiveIntervalInSeconds);
}

@Autowired
public RedisConfig(
@Value("${server.session.timeout-in-seconds:3600}") int maxInactiveIntervalInSeconds) {
super.setMaxInactiveIntervalInSeconds(maxInactiveIntervalInSeconds);
}

/**
* This pool is used for the rate limit storage, as opposed to the JedisConnectionFactory, which
* is a separate pool used for Spring Boot's session management.
*/
@Bean
public JedisPool jedis(
@Value("${redis.connection:redis://localhost:6379}") String connection,
@Value("${redis.timeout:2000}") int timeout)
throws URISyntaxException {
return new JedisPool(new URI(connection), timeout);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2024 OpsMx, Inc.
*
* 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.
*/

package com.netflix.spinnaker.gate.config;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.session.data.redis.config.ConfigureRedisAction;

class RedisConfigTest {

@Test
public void testCircularDependenciesException() {
ApplicationContextRunner applicationContextRunner =
new ApplicationContextRunner()
.withUserConfiguration(RedisConfig.class, RedisActionConfig.class)
.withBean(PostConnectionConfiguringJedisConnectionFactory.class);
assertDoesNotThrow(
() ->
applicationContextRunner.run(
ctx -> assertThat(ctx).hasSingleBean(ConfigureRedisAction.class)));
}

@Test
public void testCircularDependenciesExceptionSecure() {
ApplicationContextRunner applicationContextRunner =
new ApplicationContextRunner()
.withUserConfiguration(RedisConfig.class, RedisActionConfig.class)
.withBean(PostConnectionConfiguringJedisConnectionFactory.class)
.withPropertyValues("redis.configuration.secure", "true");

assertDoesNotThrow(
() ->
applicationContextRunner.run(
ctx -> assertThat(ctx).getBeans(ConfigureRedisAction.class).hasSize(2)));
}
}
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
enablePublishing=false
fiatVersion=1.44.0
fiatVersion=1.45.0
includeProviders=basic,iap,ldap,oauth2,saml,x509
korkVersion=7.221.0
kotlinVersion=1.5.32
korkVersion=7.224.0
kotlinVersion=1.6.21
org.gradle.parallel=true
spinnakerGradleVersion=8.32.1
targetJava11=true
Expand Down
2 changes: 1 addition & 1 deletion gradle/kotlin-test.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dependencies {

compileTestKotlin {
kotlinOptions {
languageVersion = "1.5"
languageVersion = "1.6"
jvmTarget = "11"
}
}
4 changes: 2 additions & 2 deletions gradle/kotlin.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ apply plugin: "kotlin-spring"

compileKotlin {
kotlinOptions {
languageVersion = "1.5"
languageVersion = "1.6"
jvmTarget = "11"
}
}

compileTestKotlin {
kotlinOptions {
languageVersion = "1.5"
languageVersion = "1.6"
jvmTarget = "11"
}
}
Expand Down

0 comments on commit cdfd5bb

Please sign in to comment.