Add list-based composite auto-configuration (#912)

* Pull config properties out of environment repositories

In order to support multiple auto-config approaches to EnvironmentRepository configuration, we need to get the ConfigurationProperties annotation off of the EnvironmentRepository implementations. As a result, the getters and setters of these properties won't need to be on the repo implementations either. Marking them as Deprecated for now, to maintain backwards compatibility.

* Add list-based composite auto-configuration

Add support for using a list of environment repository configuration blocks, under spring.cloud.config.server.composite, to create a composite environment repository.
This commit is contained in:
Dylan Roberts
2018-03-06 02:13:43 -05:00
committed by Spencer Gibb
parent 08e9d6409e
commit b96ba4454d
44 changed files with 1545 additions and 249 deletions

View File

@@ -0,0 +1,78 @@
/*
* Copyright 2018 the original author or authors.
*
* 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 org.springframework.cloud.config.server.composite;
import java.lang.reflect.Type;
import java.util.List;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.cloud.config.server.environment.EnvironmentRepository;
import org.springframework.cloud.config.server.support.EnvironmentRepositoryProperties;
import org.springframework.core.env.Environment;
/**
* A {@link BeanFactoryPostProcessor} to register {@link EnvironmentRepository} {@link BeanDefinition}s based on the
* composite list configuration.
*
* @author Dylan Roberts
*/
public class CompositeEnvironmentBeanFactoryPostProcessor implements BeanFactoryPostProcessor {
private Environment environment;
public CompositeEnvironmentBeanFactoryPostProcessor(Environment environment) {
this.environment = environment;
}
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
List<String> typePropertyList = CompositeUtils.getCompositeTypeList(environment);
for(int i = 0; i < typePropertyList.size(); i++) {
String type = typePropertyList.get(i);
String factoryName = CompositeUtils.getFactoryName(type, beanFactory);
Type[] factoryTypes = CompositeUtils.getEnvironmentRepositoryFactoryTypeParams(beanFactory, factoryName);
Class<? extends EnvironmentRepositoryProperties> propertiesClass =
(Class<? extends EnvironmentRepositoryProperties>) factoryTypes[1];
EnvironmentRepositoryProperties properties = bindProperties(i, propertiesClass, environment);
AbstractBeanDefinition beanDefinition = BeanDefinitionBuilder
.genericBeanDefinition(EnvironmentRepository.class)
.setFactoryMethodOnBean("build", factoryName)
.addConstructorArgValue(properties)
.getBeanDefinition();
String beanName = String.format("%s-env-repo%d", type, i);
BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
registry.registerBeanDefinition(beanName, beanDefinition);
}
}
private <P extends EnvironmentRepositoryProperties> P bindProperties(
int index, Class<P> propertiesClass, Environment environment) {
Binder binder = Binder.get(environment);
String environmentConfigurationPropertyName = String.format("spring.cloud.config.server.composite[%d]", index);
P properties = binder.bind(environmentConfigurationPropertyName, propertiesClass).orElseCreate(propertiesClass);
properties.setOrder(index + 1);
return properties;
}
}

View File

@@ -0,0 +1,75 @@
/*
* Copyright 2018 the original author or authors.
*
* 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 org.springframework.cloud.config.server.composite;
import java.lang.reflect.AnnotatedType;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.cloud.config.server.environment.EnvironmentRepositoryFactory;
import org.springframework.core.env.Environment;
import org.springframework.core.type.MethodMetadata;
/**
* @author Dylan Roberts
*/
public class CompositeUtils {
public static List<String> getCompositeTypeList(Environment environment) {
List<String> repoTypes = new ArrayList<>();
for (int i = 0; i < Integer.MAX_VALUE; i++) {
String property = String.format("spring.cloud.config.server.composite[%d].type", i);
String type = environment.getProperty(property);
if (type != null) {
repoTypes.add(type);
continue;
}
break;
}
return repoTypes;
}
public static String getFactoryName(String type, ConfigurableListableBeanFactory beanFactory) {
String[] factoryNames = BeanFactoryUtils
.beanNamesForTypeIncludingAncestors(beanFactory, EnvironmentRepositoryFactory.class, true, false);
return Arrays.stream(factoryNames).filter(n -> n.startsWith(type)).findFirst().orElse(null);
}
public static Type[] getEnvironmentRepositoryFactoryTypeParams(ConfigurableListableBeanFactory beanFactory, String factoryName) {
MethodMetadata methodMetadata = (MethodMetadata) beanFactory.getBeanDefinition(factoryName).getSource();
Class<?> factoryClass = null;
try {
factoryClass = Class.forName(methodMetadata.getReturnTypeName());
} catch (ClassNotFoundException e) {
throw new IllegalStateException(e);
}
Optional<AnnotatedType> annotatedFactoryType = Arrays.stream(factoryClass.getAnnotatedInterfaces())
.filter(i -> {
ParameterizedType parameterizedType = (ParameterizedType) i.getType();
return parameterizedType.getRawType().equals(EnvironmentRepositoryFactory.class);
}).findFirst();
ParameterizedType factoryParameterizedType = (ParameterizedType) annotatedFactoryType
.orElse(factoryClass.getAnnotatedSuperclass()).getType();
return factoryParameterizedType.getActualTypeArguments();
}
}

View File

@@ -0,0 +1,34 @@
/*
* Copyright 2018 the original author or authors.
*
* 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 org.springframework.cloud.config.server.composite;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.context.annotation.Conditional;
/**
* @author Dylan Roberts
*/
@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Conditional(OnSearchPathLocatorPresent.class)
public @interface ConditionalOnMissingSearchPathLocator {
}

View File

@@ -0,0 +1,34 @@
/*
* Copyright 2018 the original author or authors.
*
* 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 org.springframework.cloud.config.server.composite;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.context.annotation.Conditional;
/**
* @author Dylan Roberts
*/
@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Conditional(OnSearchPathLocatorPresent.class)
public @interface ConditionalOnSearchPathLocator {
}

View File

@@ -0,0 +1,60 @@
/*
* Copyright 2018 the original author or authors.
*
* 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 org.springframework.cloud.config.server.composite;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.boot.autoconfigure.condition.ConditionMessage;
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
import org.springframework.cloud.config.server.environment.EnvironmentRepository;
import org.springframework.cloud.config.server.environment.SearchPathLocator;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;
/**
* @author Dylan Roberts
*/
public class OnSearchPathLocatorPresent extends SpringBootCondition {
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
List<String> types = CompositeUtils.getCompositeTypeList(context.getEnvironment());
// get EnvironmentRepository types from registered factories
List<Class<? extends EnvironmentRepository>> repositoryTypes = new ArrayList<>();
for (String type : types) {
String factoryName = CompositeUtils.getFactoryName(type, beanFactory);
Type[] actualTypeArguments = CompositeUtils.getEnvironmentRepositoryFactoryTypeParams(beanFactory, factoryName);
Class<? extends EnvironmentRepository> repositoryType =
(Class<? extends EnvironmentRepository>) actualTypeArguments[0];
repositoryTypes.add(repositoryType);
}
boolean required = metadata.isAnnotated(ConditionalOnSearchPathLocator.class.getName());
boolean foundSearchPathLocator = repositoryTypes.stream().anyMatch(SearchPathLocator.class::isAssignableFrom);
if (required && !foundSearchPathLocator) {
return ConditionOutcome.noMatch(ConditionMessage.forCondition(ConditionalOnSearchPathLocator.class).notAvailable(SearchPathLocator.class.getTypeName()));
}
if (!required && foundSearchPathLocator) {
return ConditionOutcome.noMatch(ConditionMessage.forCondition(ConditionalOnMissingSearchPathLocator.class).available(SearchPathLocator.class.getTypeName()));
}
return ConditionOutcome.match();
}
}

View File

@@ -17,6 +17,7 @@ package org.springframework.cloud.config.server.config;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2014 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,6 +15,8 @@
*/
package org.springframework.cloud.config.server.config;
import java.util.List;
import java.util.Optional;
import javax.servlet.http.HttpServletRequest;
import org.eclipse.jgit.api.TransportConfigCallback;
@@ -22,34 +24,53 @@ import org.eclipse.jgit.api.TransportConfigCallback;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.config.server.composite.CompositeEnvironmentBeanFactoryPostProcessor;
import org.springframework.cloud.config.server.composite.ConditionalOnMissingSearchPathLocator;
import org.springframework.cloud.config.server.composite.ConditionalOnSearchPathLocator;
import org.springframework.cloud.config.server.environment.CompositeEnvironmentRepository;
import org.springframework.cloud.config.server.environment.ConsulEnvironmentWatch;
import org.springframework.cloud.config.server.environment.EnvironmentRepository;
import org.springframework.cloud.config.server.environment.EnvironmentWatch;
import org.springframework.cloud.config.server.environment.JdbcEnvironmentProperties;
import org.springframework.cloud.config.server.environment.JdbcEnvironmentRepository;
import org.springframework.cloud.config.server.environment.JdbcEnvironmentRepositoryFactory;
import org.springframework.cloud.config.server.environment.MultipleJGitEnvironmentProperties;
import org.springframework.cloud.config.server.environment.MultipleJGitEnvironmentRepository;
import org.springframework.cloud.config.server.environment.MultipleJGitEnvironmentRepositoryFactory;
import org.springframework.cloud.config.server.environment.NativeEnvironmentProperties;
import org.springframework.cloud.config.server.environment.NativeEnvironmentRepository;
import org.springframework.cloud.config.server.environment.NativeEnvironmentRepositoryFactory;
import org.springframework.cloud.config.server.environment.SearchPathCompositeEnvironmentRepository;
import org.springframework.cloud.config.server.environment.SvnEnvironmentRepositoryFactory;
import org.springframework.cloud.config.server.environment.SvnKitEnvironmentProperties;
import org.springframework.cloud.config.server.environment.SvnKitEnvironmentRepository;
import org.springframework.cloud.config.server.environment.VaultEnvironmentProperties;
import org.springframework.cloud.config.server.environment.VaultEnvironmentRepository;
import org.springframework.cloud.config.server.environment.VaultEnvironmentRepositoryFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Profile;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.client.RestTemplate;
/**
* @author Dave Syer
* @author Ryan Baxter
* @author Daniel Lavoie
* @author Dylan Roberts
*
*/
@Configuration
@Import({ JdbcRepositoryConfiguration.class, VaultRepositoryConfiguration.class, SvnRepositoryConfiguration.class,
NativeRepositoryConfiguration.class, GitRepositoryConfiguration.class,
@EnableConfigurationProperties({ MultipleJGitEnvironmentProperties.class, SvnKitEnvironmentProperties.class,
JdbcEnvironmentProperties.class, NativeEnvironmentProperties.class, VaultEnvironmentProperties.class })
@Import({ CompositeRepositoryConfiguration.class, JdbcRepositoryConfiguration.class, VaultRepositoryConfiguration.class,
SvnRepositoryConfiguration.class, NativeRepositoryConfiguration.class, GitRepositoryConfiguration.class,
DefaultRepositoryConfiguration.class })
public class EnvironmentRepositoryConfiguration {
@Bean
@ConditionalOnProperty(value = "spring.cloud.config.server.health.enabled", matchIfMissing = true)
public ConfigServerHealthIndicator configServerHealthIndicator(
@@ -81,7 +102,6 @@ public class EnvironmentRepositoryConfiguration {
@Configuration
@ConditionalOnMissingBean(EnvironmentRepository.class)
class DefaultRepositoryConfiguration {
@Autowired
private ConfigurableEnvironment environment;
@@ -92,14 +112,12 @@ class DefaultRepositoryConfiguration {
private TransportConfigCallback transportConfigCallback;
@Bean
public MultipleJGitEnvironmentRepository defaultEnvironmentRepository() {
MultipleJGitEnvironmentRepository repository = new MultipleJGitEnvironmentRepository(
this.environment);
repository.setTransportConfigCallback(this.transportConfigCallback);
if (this.server.getDefaultLabel() != null) {
repository.setDefaultLabel(this.server.getDefaultLabel());
}
return repository;
public MultipleJGitEnvironmentRepository defaultEnvironmentRepository(
MultipleJGitEnvironmentProperties environmentProperties) {
MultipleJGitEnvironmentRepositoryFactory gitEnvironmentRepositoryFactory =
new MultipleJGitEnvironmentRepositoryFactory(environment, server,
Optional.ofNullable(transportConfigCallback));
return gitEnvironmentRepositoryFactory.build(environmentProperties);
}
}
@@ -107,20 +125,18 @@ class DefaultRepositoryConfiguration {
@ConditionalOnMissingBean(EnvironmentRepository.class)
@Profile("native")
class NativeRepositoryConfiguration {
@Autowired
private ConfigurableEnvironment environment;
@Autowired
private ConfigServerProperties configServerProperties;
@Bean
public NativeEnvironmentRepository nativeEnvironmentRepository() {
NativeEnvironmentRepository repository = new NativeEnvironmentRepository(
this.environment);
public NativeEnvironmentRepository nativeEnvironmentRepository(
NativeEnvironmentProperties environmentProperties) {
NativeEnvironmentRepository repository = new NativeEnvironmentRepository(this.environment,
environmentProperties);
repository.setDefaultLabel(configServerProperties.getDefaultLabel());
return repository;
}
}
@@ -140,13 +156,8 @@ class SvnRepositoryConfiguration {
private ConfigServerProperties server;
@Bean
public SvnKitEnvironmentRepository svnKitEnvironmentRepository() {
SvnKitEnvironmentRepository repository = new SvnKitEnvironmentRepository(
this.environment);
if (this.server.getDefaultLabel() != null) {
repository.setDefaultLabel(this.server.getDefaultLabel());
}
return repository;
public SvnKitEnvironmentRepository svnKitEnvironmentRepository(SvnKitEnvironmentProperties environmentProperties) {
return new SvnEnvironmentRepositoryFactory(environment, server).build(environmentProperties);
}
}
@@ -154,9 +165,9 @@ class SvnRepositoryConfiguration {
@Profile("vault")
class VaultRepositoryConfiguration {
@Bean
public VaultEnvironmentRepository vaultEnvironmentRepository(
HttpServletRequest request, EnvironmentWatch watch) {
return new VaultEnvironmentRepository(request, watch, new RestTemplate());
public VaultEnvironmentRepository vaultEnvironmentRepository(HttpServletRequest request, EnvironmentWatch watch,
VaultEnvironmentProperties environmentProperties) {
return new VaultEnvironmentRepositoryFactory(request, watch).build(environmentProperties);
}
}
@@ -164,7 +175,64 @@ class VaultRepositoryConfiguration {
@Profile("jdbc")
class JdbcRepositoryConfiguration {
@Bean
public JdbcEnvironmentRepository jdbcEnvironmentRepository(JdbcTemplate jdbc) {
return new JdbcEnvironmentRepository(jdbc);
public JdbcEnvironmentRepository jdbcEnvironmentRepository(JdbcTemplate jdbc,
JdbcEnvironmentProperties environmentProperties) {
return new JdbcEnvironmentRepositoryFactory(jdbc).build(environmentProperties);
}
}
}
@Configuration
@Profile("composite")
class CompositeRepositoryConfiguration {
@Bean
public MultipleJGitEnvironmentRepositoryFactory gitEnvironmentRepositoryFactory(
ConfigurableEnvironment environment, ConfigServerProperties server,
Optional<TransportConfigCallback> transportConfigCallback) {
return new MultipleJGitEnvironmentRepositoryFactory(environment, server, transportConfigCallback);
}
@Bean
public SvnEnvironmentRepositoryFactory svnEnvironmentRepositoryFactory(ConfigurableEnvironment environment,
ConfigServerProperties server) {
return new SvnEnvironmentRepositoryFactory(environment, server);
}
@Bean
public VaultEnvironmentRepositoryFactory vaultEnvironmentRepositoryFactory(HttpServletRequest request,
EnvironmentWatch watch) {
return new VaultEnvironmentRepositoryFactory(request, watch);
}
@Bean
public JdbcEnvironmentRepositoryFactory jdbcEnvironmentRepositoryFactory(JdbcTemplate jdbc) {
return new JdbcEnvironmentRepositoryFactory(jdbc);
}
@Bean
public NativeEnvironmentRepositoryFactory nativeEnvironmentRepositoryFactory(ConfigurableEnvironment environment) {
return new NativeEnvironmentRepositoryFactory(environment);
}
@Bean
public static CompositeEnvironmentBeanFactoryPostProcessor compositeEnvironmentRepositoryBeanFactoryPostProcessor(
Environment environment) {
return new CompositeEnvironmentBeanFactoryPostProcessor(environment);
}
@Primary
@Bean
@ConditionalOnSearchPathLocator
public SearchPathCompositeEnvironmentRepository searchPathCompositeEnvironmentRepository(
List<EnvironmentRepository> environmentRepositories) throws Exception {
return new SearchPathCompositeEnvironmentRepository(environmentRepositories);
}
@Primary
@Bean
@ConditionalOnMissingSearchPathLocator
public CompositeEnvironmentRepository compositeEnvironmentRepository(
List<EnvironmentRepository> environmentRepositories) throws Exception {
return new CompositeEnvironmentRepository(environmentRepositories);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.config.server.environment;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.server.support.AbstractScmAccessor;
import org.springframework.cloud.config.server.support.AbstractScmAccessorProperties;
import org.springframework.core.Ordered;
import org.springframework.core.env.ConfigurableEnvironment;
@@ -35,10 +35,15 @@ public abstract class AbstractScmEnvironmentRepository extends AbstractScmAccess
super(environment);
}
public AbstractScmEnvironmentRepository(ConfigurableEnvironment environment, AbstractScmAccessorProperties properties) {
super(environment, properties);
this.order = properties.getOrder();
}
@Override
public synchronized Environment findOne(String application, String profile, String label) {
NativeEnvironmentRepository delegate = new NativeEnvironmentRepository(
getEnvironment());
NativeEnvironmentRepository delegate = new NativeEnvironmentRepository(getEnvironment(),
new NativeEnvironmentProperties());
Locations locations = getLocations(application, profile, label);
delegate.setSearchLocations(locations.getLocations());
Environment result = delegate.findOne(application, profile, "");

View File

@@ -17,6 +17,7 @@ package org.springframework.cloud.config.server.environment;
import java.util.Collections;
import java.util.List;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.core.OrderComparator;

View File

@@ -0,0 +1,25 @@
/*
* Copyright 2018 the original author or authors.
*
* 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 org.springframework.cloud.config.server.environment;
import org.springframework.cloud.config.server.support.EnvironmentRepositoryProperties;
/**
* @author Dylan Roberts
*/
public interface EnvironmentRepositoryFactory<T extends EnvironmentRepository, P extends EnvironmentRepositoryProperties> {
T build(P environmentProperties) throws Exception;
}

View File

@@ -0,0 +1,58 @@
/*
* Copyright 2018 the original author or authors.
*
* 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 org.springframework.cloud.config.server.environment;
import org.springframework.cloud.config.server.support.AbstractScmAccessorProperties;
/**
* @author Dylan Roberts
*/
public class JGitEnvironmentProperties extends AbstractScmAccessorProperties {
private static final String DEFAULT_LABEL = "master";
private boolean cloneOnStart = false;
private boolean forcePull;
private int timeout = 5;
public JGitEnvironmentProperties() {
super();
setDefaultLabel(DEFAULT_LABEL);
}
public boolean getCloneOnStart() {
return cloneOnStart;
}
public void setCloneOnStart(boolean cloneOnStart) {
this.cloneOnStart = cloneOnStart;
}
public boolean getForcePull() {
return forcePull;
}
public void setForcePull(boolean forcePull) {
this.forcePull = forcePull;
}
public int getTimeout() {
return timeout;
}
public void setTimeout(int timeout) {
this.timeout = timeout;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2015 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,17 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.config.server.environment;
import static org.springframework.util.StringUtils.hasText;
import java.io.File;
import java.io.IOException;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import com.jcraft.jsch.Session;
import org.eclipse.jgit.api.CheckoutCommand;
import org.eclipse.jgit.api.CloneCommand;
import org.eclipse.jgit.api.CreateBranchCommand.SetupUpstreamMode;
@@ -52,6 +50,7 @@ import org.eclipse.jgit.transport.SshSessionFactory;
import org.eclipse.jgit.transport.TagOpt;
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
import org.eclipse.jgit.util.FileUtils;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.cloud.config.server.support.PassphraseCredentialsProvider;
import org.springframework.core.env.ConfigurableEnvironment;
@@ -59,7 +58,7 @@ import org.springframework.core.io.UrlResource;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import com.jcraft.jsch.Session;
import static org.springframework.util.StringUtils.hasText;
/**
* An {@link EnvironmentRepository} backed by a single git repository.
@@ -73,24 +72,23 @@ import com.jcraft.jsch.Session;
public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository
implements EnvironmentRepository, SearchPathLocator, InitializingBean {
private static final String DEFAULT_LABEL = "master";
private static final String FILE_URI_PREFIX = "file:";
/**
* Timeout (in seconds) for obtaining HTTP or SSH connection (if applicable). Default
* 5 seconds.
*/
private int timeout = 5;
private int timeout;
/**
* Flag to indicate that the repository should be cloned on startup (not on demand).
* Generally leads to slower startup but faster first query.
*/
private boolean cloneOnStart = false;
private boolean cloneOnStart;
private JGitEnvironmentRepository.JGitFactory gitFactory = new JGitEnvironmentRepository.JGitFactory();
private String defaultLabel = DEFAULT_LABEL;
private String defaultLabel;
/**
* The credentials provider to use to connect to the Git repository.
@@ -109,8 +107,12 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository
private boolean forcePull;
private boolean initialized;
public JGitEnvironmentRepository(ConfigurableEnvironment environment) {
super(environment);
public JGitEnvironmentRepository(ConfigurableEnvironment environment, JGitEnvironmentProperties properties) {
super(environment, properties);
this.cloneOnStart = properties.getCloneOnStart();
this.defaultLabel = properties.getDefaultLabel();
this.forcePull = properties.getForcePull();
this.timeout = properties.getTimeout();
}
public boolean isCloneOnStart() {

View File

@@ -0,0 +1,48 @@
/*
* Copyright 2018 the original author or authors.
*
* 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 org.springframework.cloud.config.server.environment;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.config.server.support.EnvironmentRepositoryProperties;
import org.springframework.core.Ordered;
/**
* @author Dylan Roberts
*/
@ConfigurationProperties("spring.cloud.config.server.jdbc")
public class JdbcEnvironmentProperties implements EnvironmentRepositoryProperties {
private static final String DEFAULT_SQL = "SELECT KEY, VALUE from PROPERTIES where APPLICATION=? and PROFILE=? and LABEL=?";
private int order = Ordered.LOWEST_PRECEDENCE - 10;
private String sql = DEFAULT_SQL;
public int getOrder() {
return order;
}
@Override
public void setOrder(int order) {
this.order = order;
}
public String getSql() {
return sql;
}
public void setSql(String sql) {
this.sql = sql;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2017 the original author or authors.
* Copyright 2016-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.config.server.environment;
import java.sql.ResultSet;
@@ -27,7 +26,6 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.environment.PropertySource;
import org.springframework.core.Ordered;
@@ -49,19 +47,18 @@ import org.springframework.util.StringUtils;
* @author Dave Syer
*
*/
@ConfigurationProperties("spring.cloud.config.server.jdbc")
public class JdbcEnvironmentRepository implements EnvironmentRepository, Ordered {
private static final String DEFAULT_SQL = "SELECT KEY, VALUE from PROPERTIES where APPLICATION=? and PROFILE=? and LABEL=?";
private int order = Ordered.LOWEST_PRECEDENCE - 10;
private int order;
private final JdbcTemplate jdbc;
private String sql = DEFAULT_SQL;
private String sql;
private final PropertiesResultSetExtractor extractor = new PropertiesResultSetExtractor();
public JdbcEnvironmentRepository(JdbcTemplate jdbc) {
public JdbcEnvironmentRepository(JdbcTemplate jdbc, JdbcEnvironmentProperties properties) {
this.jdbc = jdbc;
this.order = properties.getOrder();
this.sql = properties.getSql();
}
public void setSql(String sql) {
this.sql = sql;
}

View File

@@ -0,0 +1,35 @@
/*
* Copyright 2018 the original author or authors.
*
* 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 org.springframework.cloud.config.server.environment;
import org.springframework.jdbc.core.JdbcTemplate;
/**
* @author Dylan Roberts
*/
public class JdbcEnvironmentRepositoryFactory implements EnvironmentRepositoryFactory<JdbcEnvironmentRepository,
JdbcEnvironmentProperties> {
private JdbcTemplate jdbc;
public JdbcEnvironmentRepositoryFactory(JdbcTemplate jdbc) {
this.jdbc = jdbc;
}
@Override
public JdbcEnvironmentRepository build(JdbcEnvironmentProperties environmentProperties) {
return new JdbcEnvironmentRepository(jdbc, environmentProperties);
}
}

View File

@@ -0,0 +1,58 @@
/*
* Copyright 2018 the original author or authors.
*
* 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 org.springframework.cloud.config.server.environment;
import java.util.LinkedHashMap;
import java.util.Map;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* @author Dylan Roberts
*/
@ConfigurationProperties("spring.cloud.config.server.git")
public class MultipleJGitEnvironmentProperties extends JGitEnvironmentProperties {
private Map<String, PatternMatchingJGitEnvironmentProperties> repos = new LinkedHashMap<>();
public Map<String, PatternMatchingJGitEnvironmentProperties> getRepos() {
return repos;
}
public void setRepos(Map<String, PatternMatchingJGitEnvironmentProperties> repos) {
this.repos = repos;
}
public static class PatternMatchingJGitEnvironmentProperties extends JGitEnvironmentProperties {
private String[] pattern = new String[0];
private String name;
public String[] getPattern() {
return pattern;
}
public void setPattern(String[] pattern) {
this.pattern = pattern;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2015 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,19 +13,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.config.server.environment;
import java.io.File;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.springframework.beans.BeanUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.server.support.GitCredentialsProviderFactory;
import org.springframework.core.env.ConfigurableEnvironment;
@@ -46,18 +46,22 @@ import org.springframework.util.StringUtils;
* @author Dave Syer
*
*/
@ConfigurationProperties("spring.cloud.config.server.git")
public class MultipleJGitEnvironmentRepository extends JGitEnvironmentRepository {
/**
* Map of repository identifier to location and other properties.
*/
private Map<String, PatternMatchingJGitEnvironmentRepository> repos = new LinkedHashMap<String, PatternMatchingJGitEnvironmentRepository>();
private Map<String, PatternMatchingJGitEnvironmentRepository> repos;
private Map<String, JGitEnvironmentRepository> placeholders = new LinkedHashMap<String, JGitEnvironmentRepository>();
private Map<String, JGitEnvironmentRepository> placeholders = new LinkedHashMap<>();
public MultipleJGitEnvironmentRepository(ConfigurableEnvironment environment) {
super(environment);
public MultipleJGitEnvironmentRepository(ConfigurableEnvironment environment,
MultipleJGitEnvironmentProperties properties) {
super(environment, properties);
this.repos = properties.getRepos().entrySet().stream()
.map(e -> new AbstractMap.SimpleEntry<>(e.getKey(),
new PatternMatchingJGitEnvironmentRepository(environment, e.getValue())))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}
@Override
@@ -229,7 +233,8 @@ public class MultipleJGitEnvironmentRepository extends JGitEnvironmentRepository
private JGitEnvironmentRepository getRepository(JGitEnvironmentRepository source,
String uri) {
JGitEnvironmentRepository repository = new JGitEnvironmentRepository(null);
JGitEnvironmentRepository repository = new JGitEnvironmentRepository(null,
new JGitEnvironmentProperties());
File basedir = repository.getBasedir();
BeanUtils.copyProperties(source, repository);
repository.setUri(uri);
@@ -251,7 +256,15 @@ public class MultipleJGitEnvironmentRepository extends JGitEnvironmentRepository
private String name;
public PatternMatchingJGitEnvironmentRepository() {
super(null);
super(null, new JGitEnvironmentProperties());
}
public PatternMatchingJGitEnvironmentRepository(
ConfigurableEnvironment environment,
MultipleJGitEnvironmentProperties.PatternMatchingJGitEnvironmentProperties properties) {
super(environment, properties);
this.setPattern(properties.getPattern());
this.name = properties.getName();
}
public boolean matches(String application, String profile, String label) {

View File

@@ -0,0 +1,51 @@
/*
* Copyright 2018 the original author or authors.
*
* 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 org.springframework.cloud.config.server.environment;
import java.util.Optional;
import org.eclipse.jgit.api.TransportConfigCallback;
import org.springframework.cloud.config.server.config.ConfigServerProperties;
import org.springframework.core.env.ConfigurableEnvironment;
/**
* @author Dylan Roberts
*/
public class MultipleJGitEnvironmentRepositoryFactory implements EnvironmentRepositoryFactory<MultipleJGitEnvironmentRepository,
MultipleJGitEnvironmentProperties> {
private ConfigurableEnvironment environment;
private ConfigServerProperties server;
private Optional<TransportConfigCallback> transportConfigCallback;
public MultipleJGitEnvironmentRepositoryFactory(ConfigurableEnvironment environment, ConfigServerProperties server,
Optional<TransportConfigCallback> transportConfigCallback) {
this.environment = environment;
this.server = server;
this.transportConfigCallback = transportConfigCallback;
}
@Override
public MultipleJGitEnvironmentRepository build(MultipleJGitEnvironmentProperties environmentProperties) {
MultipleJGitEnvironmentRepository repository = new MultipleJGitEnvironmentRepository(environment,
environmentProperties);
repository.setTransportConfigCallback(transportConfigCallback.orElse(null));
if (server.getDefaultLabel() != null) {
repository.setDefaultLabel(server.getDefaultLabel());
}
return repository;
}
}

View File

@@ -0,0 +1,82 @@
/*
* Copyright 2018 the original author or authors.
*
* 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 org.springframework.cloud.config.server.environment;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.config.server.support.EnvironmentRepositoryProperties;
import org.springframework.core.Ordered;
/**
* @author Dylan Roberts
*/
@ConfigurationProperties("spring.cloud.config.server.native")
public class NativeEnvironmentProperties implements EnvironmentRepositoryProperties {
private Boolean failOnError = false;
private Boolean addLabelLocations = true;
private String defaultLabel = "master";
private String[] searchLocations = new String[0];
private String version;
private int order = Ordered.LOWEST_PRECEDENCE;
public Boolean getFailOnError() {
return failOnError;
}
public void setFailOnError(Boolean failOnError) {
this.failOnError = failOnError;
}
public Boolean getAddLabelLocations() {
return addLabelLocations;
}
public void setAddLabelLocations(Boolean addLabelLocations) {
this.addLabelLocations = addLabelLocations;
}
public String getDefaultLabel() {
return defaultLabel;
}
public void setDefaultLabel(String defaultLabel) {
this.defaultLabel = defaultLabel;
}
public String[] getSearchLocations() {
return searchLocations;
}
public void setSearchLocations(String[] searchLocations) {
this.searchLocations = searchLocations;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
public int getOrder() {
return order;
}
@Override
public void setOrder(int order) {
this.order = order;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2017 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.config.server.environment;
import java.io.File;
@@ -33,7 +32,6 @@ import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.config.ConfigFileApplicationListener;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.environment.PropertySource;
import org.springframework.context.ConfigurableApplicationContext;
@@ -54,29 +52,28 @@ import org.springframework.util.StringUtils;
* @author Venil Noronha
* @author Daniel Lavoie
*/
@ConfigurationProperties("spring.cloud.config.server.native")
public class NativeEnvironmentRepository
implements EnvironmentRepository, SearchPathLocator, Ordered {
private static Log logger = LogFactory.getLog(NativeEnvironmentRepository.class);
private String defaultLabel = "master";
private String defaultLabel;
/**
* Locations to search for configuration files. Defaults to the same as a Spring Boot
* app so [classpath:/,classpath:/config/,file:./,file:./config/].
*/
private String[] searchLocations = new String[0];
private String[] searchLocations;
/**
* Flag to determine how to handle exceptions during decryption (default false).
*/
private boolean failOnError = false;
private boolean failOnError;
/**
* Flag to determine whether label locations should be added.
*/
private boolean addLabelLocations = true;
private boolean addLabelLocations;
/**
* Version string to be reported for native repository
@@ -88,10 +85,16 @@ public class NativeEnvironmentRepository
private ConfigurableEnvironment environment;
private int order = Ordered.LOWEST_PRECEDENCE;
private int order;
public NativeEnvironmentRepository(ConfigurableEnvironment environment) {
public NativeEnvironmentRepository(ConfigurableEnvironment environment, NativeEnvironmentProperties properties) {
this.environment = environment;
this.addLabelLocations = properties.getAddLabelLocations();
this.defaultLabel = properties.getDefaultLabel();
this.failOnError = properties.getFailOnError();
this.order = properties.getOrder();
this.searchLocations = properties.getSearchLocations();
this.version = properties.getVersion();
}
public void setFailOnError(boolean failOnError) {

View File

@@ -0,0 +1,35 @@
/*
* Copyright 2018 the original author or authors.
*
* 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 org.springframework.cloud.config.server.environment;
import org.springframework.core.env.ConfigurableEnvironment;
/**
* @author Dylan Roberts
*/
public class NativeEnvironmentRepositoryFactory implements EnvironmentRepositoryFactory<NativeEnvironmentRepository,
NativeEnvironmentProperties> {
private ConfigurableEnvironment environment;
public NativeEnvironmentRepositoryFactory(ConfigurableEnvironment environment) {
this.environment = environment;
}
@Override
public NativeEnvironmentRepository build(NativeEnvironmentProperties environmentProperties) {
return new NativeEnvironmentRepository(environment, environmentProperties);
}
}

View File

@@ -0,0 +1,42 @@
/*
* Copyright 2018 the original author or authors.
*
* 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 org.springframework.cloud.config.server.environment;
import org.springframework.cloud.config.server.config.ConfigServerProperties;
import org.springframework.core.env.ConfigurableEnvironment;
/**
* @author Dylan Roberts
*/
public class SvnEnvironmentRepositoryFactory implements EnvironmentRepositoryFactory<SvnKitEnvironmentRepository,
SvnKitEnvironmentProperties> {
private ConfigurableEnvironment environment;
private ConfigServerProperties server;
public SvnEnvironmentRepositoryFactory(ConfigurableEnvironment environment, ConfigServerProperties server) {
this.environment = environment;
this.server = server;
}
@Override
public SvnKitEnvironmentRepository build(SvnKitEnvironmentProperties environmentProperties) {
SvnKitEnvironmentRepository repository = new SvnKitEnvironmentRepository(environment, environmentProperties);
if (this.server.getDefaultLabel() != null) {
repository.setDefaultLabel(this.server.getDefaultLabel());
}
return repository;
}
}

View File

@@ -0,0 +1,32 @@
/*
* Copyright 2018 the original author or authors.
*
* 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 org.springframework.cloud.config.server.environment;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.config.server.support.AbstractScmAccessorProperties;
/**
* @author Dylan Roberts
*/
@ConfigurationProperties("spring.cloud.config.server.svn")
public class SvnKitEnvironmentProperties extends AbstractScmAccessorProperties {
private static final String DEFAULT_LABEL = "trunk";
public SvnKitEnvironmentProperties() {
super();
setDefaultLabel(DEFAULT_LABEL);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2015 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,11 +20,6 @@ import java.net.URI;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.internal.wc.DefaultSVNAuthenticationManager;
@@ -35,6 +30,11 @@ import org.tmatesoft.svn.core.wc2.SvnOperationFactory;
import org.tmatesoft.svn.core.wc2.SvnTarget;
import org.tmatesoft.svn.core.wc2.SvnUpdate;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import static org.springframework.util.StringUtils.hasText;
/**
@@ -43,18 +43,15 @@ import static org.springframework.util.StringUtils.hasText;
* @author Michael Prankl
* @author Roy Clarkson
*/
@ConfigurationProperties("spring.cloud.config.server.svn")
public class SvnKitEnvironmentRepository extends AbstractScmEnvironmentRepository
implements EnvironmentRepository, InitializingBean {
private static Log logger = LogFactory.getLog(SvnKitEnvironmentRepository.class);
private static final String DEFAULT_LABEL = "trunk";
/**
* The default label for environment properties requests.
*/
private String defaultLabel = DEFAULT_LABEL;
private String defaultLabel;
public String getDefaultLabel() {
return this.defaultLabel;
@@ -64,8 +61,9 @@ public class SvnKitEnvironmentRepository extends AbstractScmEnvironmentRepositor
this.defaultLabel = defaultLabel;
}
public SvnKitEnvironmentRepository(ConfigurableEnvironment environment) {
super(environment);
public SvnKitEnvironmentRepository(ConfigurableEnvironment environment, SvnKitEnvironmentProperties properties) {
super(environment, properties);
this.defaultLabel = properties.getDefaultLabel();
}
@Override

View File

@@ -0,0 +1,91 @@
/*
* Copyright 2018 the original author or authors.
*
* 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 org.springframework.cloud.config.server.environment;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.config.server.support.EnvironmentRepositoryProperties;
import org.springframework.core.Ordered;
/**
* @author Dylan Roberts
*/
@ConfigurationProperties("spring.cloud.config.server.vault")
public class VaultEnvironmentProperties implements EnvironmentRepositoryProperties {
private String host = "127.0.0.1";
private Integer port = 8200;
private String scheme = "http";
private String backend = "secret";
private String defaultKey = "application";
private String profileSeparator = ",";
private int order = Ordered.LOWEST_PRECEDENCE;
public String getHost() {
return host;
}
public void setHost(String host) {
this.host = host;
}
public Integer getPort() {
return port;
}
public void setPort(Integer port) {
this.port = port;
}
public String getScheme() {
return scheme;
}
public void setScheme(String scheme) {
this.scheme = scheme;
}
public String getBackend() {
return backend;
}
public void setBackend(String backend) {
this.backend = backend;
}
public String getDefaultKey() {
return defaultKey;
}
public void setDefaultKey(String defaultKey) {
this.defaultKey = defaultKey;
}
public String getProfileSeparator() {
return profileSeparator;
}
public void setProfileSeparator(String profileSeparator) {
this.profileSeparator = profileSeparator;
}
public int getOrder() {
return order;
}
@Override
public void setOrder(int order) {
this.order = order;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2017 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,7 +20,6 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
import javax.servlet.http.HttpServletRequest;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@@ -31,7 +30,6 @@ import org.hibernate.validator.constraints.NotEmpty;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.environment.PropertySource;
import org.springframework.core.Ordered;
@@ -53,7 +51,6 @@ import static org.springframework.cloud.config.client.ConfigClientProperties.TOK
* @author Spencer Gibb
* @author Mark Paluch
*/
@ConfigurationProperties("spring.cloud.config.server.vault")
@Validated
public class VaultEnvironmentRepository implements EnvironmentRepository, Ordered {
@@ -61,39 +58,47 @@ public class VaultEnvironmentRepository implements EnvironmentRepository, Ordere
/** Vault host. Defaults to 127.0.0.1. */
@NotEmpty
private String host = "127.0.0.1";
private String host;
/** Vault port. Defaults to 8200. */
@Range(min = 1, max = 65535)
private int port = 8200;
private int port;
/** Vault scheme. Defaults to http. */
private String scheme = "http";
private String scheme;
/** Vault backend. Defaults to secret. */
@NotEmpty
private String backend = "secret";
private String backend;
/** The key in vault shared by all applications. Defaults to application. Set to empty to disable. */
private String defaultKey = "application";
private String defaultKey;
/** Vault profile separator. Defaults to comma. */
@NotEmpty
private String profileSeparator = ",";
private String profileSeparator;
private int order = Ordered.LOWEST_PRECEDENCE;
private int order;
private RestTemplate rest;
//TODO: move to watchState:String on findOne?
// TODO: move to watchState:String on findOne?
private HttpServletRequest request;
private EnvironmentWatch watch;
public VaultEnvironmentRepository(HttpServletRequest request, EnvironmentWatch watch, RestTemplate rest) {
public VaultEnvironmentRepository(HttpServletRequest request, EnvironmentWatch watch, RestTemplate rest,
VaultEnvironmentProperties properties) {
this.request = request;
this.watch = watch;
this.rest = rest;
this.backend = properties.getBackend();
this.defaultKey = properties.getDefaultKey();
this.host = properties.getHost();
this.order = properties.getOrder();
this.port = properties.getPort();
this.profileSeparator = properties.getProfileSeparator();
this.scheme = properties.getScheme();
}
@Override
@@ -151,7 +156,7 @@ public class VaultEnvironmentRepository implements EnvironmentRepository, Ordere
}
private void addProfiles(List<String> contexts, String baseContext,
List<String> profiles) {
List<String> profiles) {
for (String profile : profiles) {
contexts.add(baseContext + this.profileSeparator + profile);
}

View File

@@ -0,0 +1,41 @@
/*
* Copyright 2018 the original author or authors.
*
* 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 org.springframework.cloud.config.server.environment;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.client.RestTemplate;
/**
* @author Dylan Roberts
*/
public class VaultEnvironmentRepositoryFactory implements EnvironmentRepositoryFactory<VaultEnvironmentRepository,
VaultEnvironmentProperties> {
private HttpServletRequest request;
private EnvironmentWatch watch;
public VaultEnvironmentRepositoryFactory(HttpServletRequest request, EnvironmentWatch watch) {
this.request = request;
this.watch = watch;
}
@Override
public VaultEnvironmentRepository build(VaultEnvironmentProperties environmentProperties) {
VaultEnvironmentRepository repository = new VaultEnvironmentRepository(request, watch, new RestTemplate(),
environmentProperties);
return repository;
}
}

View File

@@ -27,6 +27,7 @@ import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.jgit.util.FileUtils;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.io.DefaultResourceLoader;
@@ -42,9 +43,7 @@ import org.springframework.util.StringUtils;
* @author Dave Syer
*
*/
public class AbstractScmAccessor implements ResourceLoaderAware {
private static final String[] DEFAULT_LOCATIONS = new String[] { "/" };
public abstract class AbstractScmAccessor implements ResourceLoaderAware {
protected Log logger = LogFactory.getLog(getClass());
/**
@@ -68,14 +67,14 @@ public class AbstractScmAccessor implements ResourceLoaderAware {
* Passphrase for unlocking your ssh private key.
*/
private String passphrase;
/**
* Reject incoming SSH host keys from remote servers not in the known host list.
*/
private boolean strictHostKeyChecking = true;
/**
* Reject incoming SSH host keys from remote servers not in the known host list.
*/
private boolean strictHostKeyChecking;
/**
* Search paths to use within local working copy. By default searches only the root.
*/
private String[] searchPaths = DEFAULT_LOCATIONS.clone();
private String[] searchPaths;
private ResourceLoader resourceLoader = new DefaultResourceLoader();
@@ -84,6 +83,19 @@ public class AbstractScmAccessor implements ResourceLoaderAware {
this.basedir = createBaseDir();
}
public AbstractScmAccessor(ConfigurableEnvironment environment,
AbstractScmAccessorProperties properties) {
this.environment = environment;
this.basedir = properties.getBasedir() == null ? createBaseDir()
: properties.getBasedir();
this.passphrase = properties.getPassphrase();
this.password = properties.getPassword();
this.searchPaths = properties.getSearchPaths();
this.strictHostKeyChecking = properties.getStrictHostKeyChecking();
this.uri = properties.getUri();
this.username = properties.getUsername();
}
@Override
public void setResourceLoader(ResourceLoader resourceLoader) {
this.resourceLoader = resourceLoader;
@@ -200,10 +212,10 @@ public class AbstractScmAccessor implements ResourceLoaderAware {
String label) {
String[] locations = this.searchPaths;
if (locations == null || locations.length == 0) {
locations = DEFAULT_LOCATIONS;
locations = AbstractScmAccessorProperties.DEFAULT_LOCATIONS;
}
else if (locations != DEFAULT_LOCATIONS) {
locations = StringUtils.concatenateStringArrays(DEFAULT_LOCATIONS, locations);
else if (locations != AbstractScmAccessorProperties.DEFAULT_LOCATIONS) {
locations = StringUtils.concatenateStringArrays(AbstractScmAccessorProperties.DEFAULT_LOCATIONS, locations);
}
Collection<String> output = new LinkedHashSet<String>();
for (String location : locations) {

View File

@@ -0,0 +1,110 @@
/*
* Copyright 2018 the original author or authors.
*
* 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 org.springframework.cloud.config.server.support;
import java.io.File;
import org.springframework.core.Ordered;
/**
* @author Dylan Roberts
*/
public class AbstractScmAccessorProperties implements EnvironmentRepositoryProperties {
static final String[] DEFAULT_LOCATIONS = new String[] { "/" };
private String uri;
private File basedir;
private String[] searchPaths = DEFAULT_LOCATIONS.clone();;
private String username;
private String password;
private String passphrase;
private boolean strictHostKeyChecking = true;
private int order = Ordered.LOWEST_PRECEDENCE;
private String defaultLabel;
public String getUri() {
return uri;
}
public void setUri(String uri) {
this.uri = uri;
}
public File getBasedir() {
return basedir;
}
public void setBasedir(File basedir) {
this.basedir = basedir;
}
public String[] getSearchPaths() {
return searchPaths;
}
public void setSearchPaths(String... searchPaths) {
this.searchPaths = searchPaths;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getPassphrase() {
return passphrase;
}
public void setPassphrase(String passphrase) {
this.passphrase = passphrase;
}
public boolean getStrictHostKeyChecking() {
return strictHostKeyChecking;
}
public void setStrictHostKeyChecking(boolean strictHostKeyChecking) {
this.strictHostKeyChecking = strictHostKeyChecking;
}
public int getOrder() {
return order;
}
@Override
public void setOrder(int order) {
this.order = order;
}
public String getDefaultLabel() {
return defaultLabel;
}
public void setDefaultLabel(String defaultLabel) {
this.defaultLabel = defaultLabel;
}
}

View File

@@ -0,0 +1,23 @@
/*
* Copyright 2018 the original author or authors.
*
* 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 org.springframework.cloud.config.server.support;
/**
* @author Dylan Roberts
*/
public interface EnvironmentRepositoryProperties {
void setOrder(int order);
}

View File

@@ -18,9 +18,9 @@ package org.springframework.cloud.config.server;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.server.test.ConfigServerTestUtils;
import org.springframework.test.context.ActiveProfiles;
@@ -32,53 +32,107 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
/**
* @author Ryan Baxter
* @author Dylan Roberts
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = ConfigServerApplication.class,
properties = { "spring.config.name:compositeconfigserver",
"spring.cloud.config.server.svn.uri:file:///./target/repos/svn-config-repo",
"spring.cloud.config.server.svn.order:2",
"spring.cloud.config.server.git.uri:file:./target/repos/config-repo",
"spring.cloud.config.server.git.order:1"},
webEnvironment = RANDOM_PORT)
@ActiveProfiles({ "test", "git", "subversion" })
public class CompositeConfigServerIntegrationTests {
@RunWith(SpringRunner.class)
@SpringBootTest(classes = ConfigServerApplication.class,
properties = { "spring.config.name:compositeconfigserver",
"spring.cloud.config.server.svn.uri:file:///./target/repos/svn-config-repo",
"spring.cloud.config.server.svn.order:2",
"spring.cloud.config.server.git.uri:file:./target/repos/config-repo",
"spring.cloud.config.server.git.order:1"},
webEnvironment = RANDOM_PORT)
@ActiveProfiles({ "test", "git", "subversion" })
public static class StaticConfigCompositeConfigServerIntegrationTests {
@LocalServerPort
private int port;
@LocalServerPort
private int port;
@BeforeClass
public static void init() throws Exception {
ConfigServerTestUtils.prepareLocalRepo();
ConfigServerTestUtils.prepareLocalSvnRepo("src/test/resources/svn-config-repo",
"target/repos/svn-config-repo");
}
@BeforeClass
public static void init() throws Exception {
ConfigServerTestUtils.prepareLocalRepo();
ConfigServerTestUtils.prepareLocalSvnRepo("src/test/resources/svn-config-repo",
"target/repos/svn-config-repo");
@Test
public void contextLoads() {
Environment environment = new TestRestTemplate().getForObject("http://localhost:"
+ port + "/foo/development/", Environment.class);
assertEquals(3, environment.getPropertySources().size());
assertEquals("overrides", environment.getPropertySources().get(0).getName());
assertTrue(environment.getPropertySources().get(1).getName().contains("config-repo") &&
!environment.getPropertySources().get(1).getName().contains("svn-config-repo"));
assertTrue(environment.getPropertySources().get(2).getName().contains("svn-config-repo"));
assertEquals("{spring.cloud.config.enabled=true}", environment
.getPropertySources().get(0).getSource().toString());
}
@Test
public void resourceEndpointsWork() {
//This request will get the file from the Git Repo
String text = new TestRestTemplate().getForObject("http://localhost:"
+ port + "/foo/development/composite/bar.properties", String.class);
String expected = "foo: bar";
assertEquals("invalid content", expected, text);
//This request will get the file from the SVN Repo
text = new TestRestTemplate().getForObject("http://localhost:"
+ port + "/foo/development/composite/bar.properties", String.class);
assertEquals("invalid content", expected, text);
}
}
@Test
public void contextLoads() {
Environment environment = new TestRestTemplate().getForObject("http://localhost:"
+ port + "/foo/development/", Environment.class);
assertEquals(3, environment.getPropertySources().size());
assertEquals("overrides", environment.getPropertySources().get(0).getName());
assertTrue(environment.getPropertySources().get(1).getName().contains("config-repo") &&
!environment.getPropertySources().get(1).getName().contains("svn-config-repo"));
assertTrue(environment.getPropertySources().get(2).getName().contains("svn-config-repo"));
assertEquals("{spring.cloud.config.enabled=true}", environment
.getPropertySources().get(0).getSource().toString());
@RunWith(SpringRunner.class)
@SpringBootTest(classes = ConfigServerApplication.class,
properties = { "spring.config.name:compositeconfigserver",
"spring.cloud.config.server.composite[0].uri:file:./target/repos/config-repo",
"spring.cloud.config.server.composite[0].type:git",
"spring.cloud.config.server.composite[1].uri:file:///./target/repos/svn-config-repo",
"spring.cloud.config.server.composite[1].type:svn"
},
webEnvironment = RANDOM_PORT)
@ActiveProfiles({ "test", "composite"})
public static class ListConfigCompositeConfigServerIntegrationTests {
@LocalServerPort
private int port;
@BeforeClass
public static void init() throws Exception {
ConfigServerTestUtils.prepareLocalRepo();
ConfigServerTestUtils.prepareLocalSvnRepo("src/test/resources/svn-config-repo",
"target/repos/svn-config-repo");
}
@Test
public void contextLoads() {
Environment environment = new TestRestTemplate().getForObject("http://localhost:"
+ port + "/foo/development/", Environment.class);
assertEquals(3, environment.getPropertySources().size());
assertEquals("overrides", environment.getPropertySources().get(0).getName());
assertTrue(environment.getPropertySources().get(1).getName().contains("config-repo") &&
!environment.getPropertySources().get(1).getName().contains("svn-config-repo"));
assertTrue(environment.getPropertySources().get(2).getName().contains("svn-config-repo"));
assertEquals("{spring.cloud.config.enabled=true}", environment
.getPropertySources().get(0).getSource().toString());
}
@Test
public void resourceEndpointsWork() {
//This request will get the file from the Git Repo
String text = new TestRestTemplate().getForObject("http://localhost:"
+ port + "/foo/development/composite/bar.properties", String.class);
String expected = "foo: bar";
assertEquals("invalid content", expected, text);
//This request will get the file from the SVN Repo
text = new TestRestTemplate().getForObject("http://localhost:"
+ port + "/foo/development/composite/bar.properties", String.class);
assertEquals("invalid content", expected, text);
}
}
@Test
public void resourseEndpointsWork() {
//This request will get the file from the Git Repo
String text = new TestRestTemplate().getForObject("http://localhost:"
+ port + "/foo/development/composite/bar.properties", String.class);
String expected = "foo: bar";
assertEquals("invalid content", expected, text);
//This request will get the file from the SVN Repo
text = new TestRestTemplate().getForObject("http://localhost:"
+ port + "/foo/development/composite/bar.properties", String.class);
assertEquals("invalid content", expected, text);
}
}

View File

@@ -17,9 +17,11 @@ package org.springframework.cloud.config.server.config;
import java.util.HashMap;
import java.util.List;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
@@ -29,10 +31,13 @@ import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.environment.PropertySource;
import org.springframework.cloud.config.server.EnableConfigServer;
import org.springframework.cloud.config.server.environment.EnvironmentRepository;
import org.springframework.cloud.config.server.environment.EnvironmentRepositoryFactory;
import org.springframework.cloud.config.server.support.EnvironmentRepositoryProperties;
import org.springframework.cloud.config.server.test.ConfigServerTestUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
@@ -43,56 +48,150 @@ import static org.junit.Assert.assertTrue;
/**
* @author Ryan Baxter
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = CustomCompositeEnvironmentRepositoryTests.TestApplication.class, properties = {
"spring.config.name:compositeconfigserver", "spring.cloud.config.server.git.uri:file:./target/repos/config-repo",
"spring.cloud.config.server.git.order:1" }, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles({"test", "git"})
@DirtiesContext
public class CustomCompositeEnvironmentRepositoryTests {
@LocalServerPort
private int port;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = CustomCompositeEnvironmentRepositoryTests
.StaticConfigCustomCompositeEnvironmentRepositoryTests.TestApplication.class, properties = {
"spring.config.name:compositeconfigserver",
"spring.cloud.config.server.git.uri:file:./target/repos/config-repo",
"spring.cloud.config.server.git.order:1" }, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles({"test", "git"})
@DirtiesContext
public static class StaticConfigCustomCompositeEnvironmentRepositoryTests {
@BeforeClass
public static void init() throws Exception {
ConfigServerTestUtils.prepareLocalRepo();
}
@LocalServerPort
private int port;
@Test
public void contextLoads() {
Environment environment = new TestRestTemplate().getForObject(
"http://localhost:" + port + "/foo/development/", Environment.class);
List<PropertySource> propertySources = environment.getPropertySources();
assertEquals(3, propertySources.size());
assertEquals("overrides", propertySources.get(0).getName());
assertTrue(propertySources.get(1).getName().contains("config-repo"));
assertEquals("p", propertySources.get(2).getName());
}
@Configuration
@EnableAutoConfiguration
@EnableConfigServer
protected static class TestApplication {
@Bean
public EnvironmentRepository environmentRepository() {
return new CustomEnvironmentRepository();
@BeforeClass
public static void init() throws Exception {
ConfigServerTestUtils.prepareLocalRepo();
}
public static void main(String[] args) throws Exception {
SpringApplication.run(CustomEnvironmentRepositoryTests.TestApplication.class,
args);
@Test
public void contextLoads() {
Environment environment = new TestRestTemplate().getForObject(
"http://localhost:" + port + "/foo/development/", Environment.class);
List<PropertySource> propertySources = environment.getPropertySources();
assertEquals(3, propertySources.size());
assertEquals("overrides", propertySources.get(0).getName());
assertTrue(propertySources.get(1).getName().contains("config-repo"));
assertEquals("p", propertySources.get(2).getName());
}
@Configuration
@EnableAutoConfiguration
@EnableConfigServer
protected static class TestApplication {
@Bean
public EnvironmentRepository environmentRepository() {
return new CustomEnvironmentRepository(new CustomEnvironmentProperties("p"));
}
public static void main(String[] args) throws Exception {
SpringApplication.run(CustomEnvironmentRepositoryTests.TestApplication.class,
args);
}
}
}
@RunWith(SpringRunner.class)
@SpringBootTest(classes = CustomCompositeEnvironmentRepositoryTests
.ListConfigCustomCompositeEnvironmentRepositoryTests.TestApplication.class, properties = {
"spring.config.name:compositeconfigserver",
"spring.cloud.config.server.composite[0].type:git",
"spring.cloud.config.server.composite[0].uri:file:./target/repos/config-repo",
"spring.cloud.config.server.composite[1].type:custom",
"spring.cloud.config.server.composite[1].propertySourceName:p"
}, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles({"test", "composite"})
@DirtiesContext
public static class ListConfigCustomCompositeEnvironmentRepositoryTests {
@LocalServerPort
private int port;
@BeforeClass
public static void init() throws Exception {
ConfigServerTestUtils.prepareLocalRepo();
}
@Test
public void contextLoads() {
Environment environment = new TestRestTemplate().getForObject(
"http://localhost:" + port + "/foo/development/", Environment.class);
List<PropertySource> propertySources = environment.getPropertySources();
assertEquals(3, propertySources.size());
assertEquals("overrides", propertySources.get(0).getName());
assertTrue(propertySources.get(1).getName().contains("config-repo"));
assertEquals("p", propertySources.get(2).getName());
}
@Configuration
@EnableAutoConfiguration
@EnableConfigServer
protected static class TestApplication {
@Bean
public CustomEnvironmentRepositoryFactory customEnvironmentRepositoryFactory(ConfigurableEnvironment environment)
{
return new CustomEnvironmentRepositoryFactory();
}
public static void main(String[] args) throws Exception {
SpringApplication.run(CustomEnvironmentRepositoryTests.TestApplication.class,
args);
}
}
}
static class CustomEnvironmentRepositoryFactory implements EnvironmentRepositoryFactory<CustomEnvironmentRepository,
CustomEnvironmentProperties> {
@Override
public CustomEnvironmentRepository build(CustomEnvironmentProperties environmentProperties) throws Exception {
return new CustomEnvironmentRepository(environmentProperties);
}
}
static class CustomEnvironmentProperties implements EnvironmentRepositoryProperties {
private String propertySourceName;
public CustomEnvironmentProperties() {
}
public CustomEnvironmentProperties(String propertySourceName) {
this.propertySourceName = propertySourceName;
}
public String getPropertySourceName() {
return propertySourceName;
}
public void setPropertySourceName(String propertySourceName) {
this.propertySourceName = propertySourceName;
}
@Override
public void setOrder(int order) {
}
}
static class CustomEnvironmentRepository implements EnvironmentRepository, Ordered {
private final CustomEnvironmentProperties properties;
public CustomEnvironmentRepository(CustomEnvironmentProperties properties) {
this.properties = properties;
}
@Override
public Environment findOne(String application, String profile, String label) {
Environment e = new Environment("test", new String[0], "label", "version",
"state");
PropertySource p = new PropertySource("p", new HashMap<>());
PropertySource p = new PropertySource(properties.getPropertySourceName(), new HashMap<>());
e.add(p);
return e;
}

View File

@@ -41,8 +41,8 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@@ -241,7 +241,8 @@ public class JGitEnvironmentRepositoryIntegrationTests {
.getBean(JGitEnvironmentRepository.class);
assertThat(repository.getSearchPaths(), Matchers.arrayContaining("{application}"));
assertFalse(Arrays.equals(repository.getSearchPaths(),
new JGitEnvironmentRepository(repository.getEnvironment()).getSearchPaths()));
new JGitEnvironmentRepository(repository.getEnvironment(), new JGitEnvironmentProperties())
.getSearchPaths()));
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2014 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -82,7 +82,8 @@ import static org.mockito.Mockito.when;
public class JGitEnvironmentRepositoryTests {
private StandardEnvironment environment = new StandardEnvironment();
private JGitEnvironmentRepository repository = new JGitEnvironmentRepository(this.environment);
private JGitEnvironmentRepository repository = new JGitEnvironmentRepository(this.environment,
new JGitEnvironmentProperties());
private File basedir = new File("target/config");
@@ -212,7 +213,8 @@ public class JGitEnvironmentRepositoryTests {
when(mockCloneCommand.setURI(anyString())).thenReturn(mockCloneCommand);
when(mockCloneCommand.setDirectory(any(File.class))).thenReturn(mockCloneCommand);
JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository(this.environment);
JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository(this.environment,
new JGitEnvironmentProperties());
envRepository.setGitFactory(new MockGitFactory(mockGit, mockCloneCommand));
envRepository.setUri("http://somegitserver/somegitrepo");
envRepository.setCloneOnStart(true);
@@ -228,7 +230,8 @@ public class JGitEnvironmentRepositoryTests {
when(mockCloneCommand.setURI(anyString())).thenReturn(mockCloneCommand);
when(mockCloneCommand.setDirectory(any(File.class))).thenReturn(mockCloneCommand);
JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository(this.environment);
JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository(this.environment,
new JGitEnvironmentProperties());
envRepository.setGitFactory(new MockGitFactory(mockGit, mockCloneCommand));
envRepository.setUri("http://somegitserver/somegitrepo");
envRepository.afterPropertiesSet();
@@ -244,7 +247,8 @@ public class JGitEnvironmentRepositoryTests {
when(mockCloneCommand.setURI(anyString())).thenReturn(mockCloneCommand);
when(mockCloneCommand.setDirectory(any(File.class))).thenReturn(mockCloneCommand);
JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository(this.environment);
JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository(this.environment,
new JGitEnvironmentProperties());
envRepository.setGitFactory(new MockGitFactory(mockGit, mockCloneCommand));
envRepository.setUri("file://somefilesystem/somegitrepo");
envRepository.setCloneOnStart(true);
@@ -268,7 +272,8 @@ public class JGitEnvironmentRepositoryTests {
when(statusCommand.call()).thenReturn(status);
when(status.isClean()).thenReturn(false);
JGitEnvironmentRepository repo = new JGitEnvironmentRepository(this.environment);
JGitEnvironmentRepository repo = new JGitEnvironmentRepository(this.environment,
new JGitEnvironmentProperties());
repo.setForcePull(true);
boolean shouldPull = repo.shouldPull(git);
@@ -291,7 +296,8 @@ public class JGitEnvironmentRepositoryTests {
when(statusCommand.call()).thenReturn(status);
when(status.isClean()).thenReturn(false);
JGitEnvironmentRepository repo = new JGitEnvironmentRepository(this.environment);
JGitEnvironmentRepository repo = new JGitEnvironmentRepository(this.environment,
new JGitEnvironmentProperties());
boolean shouldPull = repo.shouldPull(git);
@@ -313,7 +319,8 @@ public class JGitEnvironmentRepositoryTests {
when(statusCommand.call()).thenReturn(status);
when(status.isClean()).thenReturn(true);
JGitEnvironmentRepository repo = new JGitEnvironmentRepository(this.environment);
JGitEnvironmentRepository repo = new JGitEnvironmentRepository(this.environment,
new JGitEnvironmentProperties());
boolean shouldPull = repo.shouldPull(git);
@@ -520,7 +527,8 @@ public class JGitEnvironmentRepositoryTests {
when(mockCloneCommand.setDirectory(any(File.class))).thenReturn(mockCloneCommand);
when(mockCloneCommand.call()).thenThrow(new TransportException("failed to clone"));
JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository(this.environment);
JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository(this.environment,
new JGitEnvironmentProperties());
envRepository.setGitFactory(new MockGitFactory(mockGit, mockCloneCommand));
envRepository.setUri("http://somegitserver/somegitrepo");
envRepository.setBasedir(this.basedir);
@@ -539,7 +547,8 @@ public class JGitEnvironmentRepositoryTests {
Git mockGit = mock(Git.class);
MockCloneCommand mockCloneCommand = new MockCloneCommand(mockGit);
JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository(this.environment);
JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository(this.environment,
new JGitEnvironmentProperties());
envRepository.setGitFactory(new MockGitFactory(mockGit, mockCloneCommand));
envRepository.setUri("git+ssh://git@somegitserver/somegitrepo");
envRepository.setBasedir(new File("./mybasedir"));
@@ -570,7 +579,8 @@ public class JGitEnvironmentRepositoryTests {
Git mockGit = mock(Git.class);
MockCloneCommand mockCloneCommand = new MockCloneCommand(mockGit);
JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository(this.environment);
JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository(this.environment,
new JGitEnvironmentProperties());
envRepository.setGitFactory(new MockGitFactory(mockGit, mockCloneCommand));
envRepository.setUri("git+ssh://git@somegitserver/somegitrepo");
envRepository.setBasedir(new File("./mybasedir"));
@@ -599,7 +609,8 @@ public class JGitEnvironmentRepositoryTests {
Git mockGit = mock(Git.class);
MockCloneCommand mockCloneCommand = new MockCloneCommand(mockGit);
JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository(this.environment);
JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository(this.environment,
new JGitEnvironmentProperties());
envRepository.setGitFactory(new MockGitFactory(mockGit, mockCloneCommand));
envRepository.setUri(gitUri);
envRepository.setBasedir(new File("./mybasedir"));
@@ -629,7 +640,8 @@ public class JGitEnvironmentRepositoryTests {
final String username = "someuser";
final String password = "mypassword";
JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository(this.environment);
JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository(this.environment,
new JGitEnvironmentProperties());
envRepository.setGitFactory(new MockGitFactory(mockGit, mockCloneCommand));
envRepository.setUri("git+ssh://git@somegitserver/somegitrepo");
envRepository.setBasedir(new File("./mybasedir"));
@@ -659,7 +671,8 @@ public class JGitEnvironmentRepositoryTests {
MockCloneCommand mockCloneCommand = new MockCloneCommand(mockGit);
final String awsUri = "https://git-codecommit.us-east-1.amazonaws.com/v1/repos/test";
JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository(this.environment);
JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository(this.environment,
new JGitEnvironmentProperties());
envRepository.setGitFactory(new MockGitFactory(mockGit, mockCloneCommand));
envRepository.setUri(awsUri);
envRepository.setGitCredentialsProvider(credentialsFactory.createFor(envRepository.getUri(), null, null, null));
@@ -673,7 +686,8 @@ public class JGitEnvironmentRepositoryTests {
@Test
public void shouldPrintStacktraceIfDebugEnabled() throws Exception {
final Log mockLogger = mock(Log.class);
JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository(this.environment) {
JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository(this.environment,
new JGitEnvironmentProperties()) {
@Override
public void afterPropertiesSet() throws Exception {
this.logger = mockLogger;
@@ -703,7 +717,8 @@ public class JGitEnvironmentRepositoryTests {
when(mockCloneCommand.setDirectory(any(File.class))).thenReturn(mockCloneCommand);
TransportConfigCallback configCallback = mock(TransportConfigCallback.class);
JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository(this.environment);
JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository(this.environment,
new JGitEnvironmentProperties());
envRepository.setGitFactory(new MockGitFactory(mockGit, mockCloneCommand));
envRepository.setUri("http://somegitserver/somegitrepo");
envRepository.setTransportConfigCallback(configCallback);

View File

@@ -50,7 +50,7 @@ public class JdbcEnvironmentRepositoryTests {
@Test
public void basicProperties() {
Environment env = new JdbcEnvironmentRepository(new JdbcTemplate(dataSource))
Environment env = new JdbcEnvironmentRepository(new JdbcTemplate(dataSource), new JdbcEnvironmentProperties())
.findOne("foo", "bar", "");
assertThat(env.getName()).isEqualTo("foo");
assertThat(env.getProfiles()).isEqualTo(new String[] { "default", "bar" });
@@ -66,7 +66,7 @@ public class JdbcEnvironmentRepositoryTests {
@Test
public void defaults() {
Environment env = new JdbcEnvironmentRepository(new JdbcTemplate(dataSource))
Environment env = new JdbcEnvironmentRepository(new JdbcTemplate(dataSource), new JdbcEnvironmentProperties())
.findOne("application", "", "");
assertThat(env.getName()).isEqualTo("application");
assertThat(env.getProfiles()).isEqualTo(new String[] { "default" });

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2015 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,22 +15,23 @@
*/
package org.springframework.cloud.config.server.environment;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.HashMap;
import java.util.Map;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.server.environment.MultipleJGitEnvironmentRepository.PatternMatchingJGitEnvironmentRepository;
import org.springframework.cloud.config.server.environment.SearchPathLocator.Locations;
import org.springframework.cloud.config.server.test.ConfigServerTestUtils;
import org.springframework.core.env.StandardEnvironment;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
/**
* @author Dave Syer
*
@@ -38,8 +39,8 @@ import org.springframework.core.env.StandardEnvironment;
public class MultipleJGitEnvironmentApplicationPlaceholderRepositoryTests {
private StandardEnvironment environment = new StandardEnvironment();
private MultipleJGitEnvironmentRepository repository = new MultipleJGitEnvironmentRepository(
this.environment);
private MultipleJGitEnvironmentRepository repository = new MultipleJGitEnvironmentRepository(this.environment,
new MultipleJGitEnvironmentProperties());
@Before
public void init() throws Exception {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2016 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@ package org.springframework.cloud.config.server.environment;
import org.junit.Before;
import org.junit.Test;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.server.test.ConfigServerTestUtils;
import org.springframework.core.env.StandardEnvironment;
@@ -34,8 +35,8 @@ import static org.junit.Assert.assertTrue;
public class MultipleJGitEnvironmentLabelPlaceholderRepositoryTests {
private StandardEnvironment environment = new StandardEnvironment();
private MultipleJGitEnvironmentRepository repository = new MultipleJGitEnvironmentRepository(
this.environment);
private MultipleJGitEnvironmentRepository repository = new MultipleJGitEnvironmentRepository(this.environment,
new MultipleJGitEnvironmentProperties());
private String defaultUri;
@Before

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2015 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -44,8 +44,8 @@ import static org.junit.Assert.assertTrue;
public class MultipleJGitEnvironmentProfilePlaceholderRepositoryTests {
private StandardEnvironment environment = new StandardEnvironment();
private MultipleJGitEnvironmentRepository repository = new MultipleJGitEnvironmentRepository(
this.environment);
private MultipleJGitEnvironmentRepository repository = new MultipleJGitEnvironmentRepository(this.environment,
new MultipleJGitEnvironmentProperties());
@Before
public void init() throws Exception {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2015 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,15 +15,6 @@
*/
package org.springframework.cloud.config.server.environment;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
@@ -36,11 +27,21 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.server.environment.MultipleJGitEnvironmentRepository.PatternMatchingJGitEnvironmentRepository;
import org.springframework.cloud.config.server.test.ConfigServerTestUtils;
import org.springframework.core.env.StandardEnvironment;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
/**
* @author Andy Chan (iceycake)
* @author Dave Syer
@@ -59,7 +60,8 @@ public class MultipleJGitEnvironmentRepositoryTests {
@Before
public void init() throws Exception {
String defaultUri = ConfigServerTestUtils.prepareLocalRepo("config-repo");
this.repository = new MultipleJGitEnvironmentRepository(this.environment);
this.repository = new MultipleJGitEnvironmentRepository(this.environment,
new MultipleJGitEnvironmentProperties());
this.repository.setUri(defaultUri);
this.repository.setRepos(createRepositories());
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2017 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -42,7 +42,7 @@ public class NativeEnvironmentRepositoryTests {
ConfigurableApplicationContext context = new SpringApplicationBuilder(
NativeEnvironmentRepositoryTests.class).web(WebApplicationType.NONE)
.run();
this.repository = new NativeEnvironmentRepository(context.getEnvironment());
this.repository = new NativeEnvironmentRepository(context.getEnvironment(), new NativeEnvironmentProperties());
this.repository.setVersion("myversion");
this.repository.setDefaultLabel(null);
context.close();

View File

@@ -22,6 +22,7 @@ import java.io.IOException;
import org.eclipse.jgit.util.FileUtils;
import org.junit.Before;
import org.junit.Test;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.config.environment.Environment;
@@ -42,8 +43,8 @@ public class SVNKitEnvironmentRepositoryTests {
private static final String REPOSITORY_NAME = "svn-config-repo";
private StandardEnvironment environment = new StandardEnvironment();
private SvnKitEnvironmentRepository repository = new SvnKitEnvironmentRepository(
this.environment);
private SvnKitEnvironmentRepository repository = new SvnKitEnvironmentRepository(this.environment,
new SvnKitEnvironmentProperties());
private File basedir = new File("target/config");

View File

@@ -3,9 +3,11 @@ package org.springframework.cloud.config.server.environment;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
@@ -49,7 +51,7 @@ public class VaultEnvironmentRepositoryTests {
Mockito.eq(HttpMethod.GET), Mockito.any(HttpEntity.class), Mockito.eq(VaultEnvironmentRepository.VaultResponse.class),
Mockito.eq("secret"), Mockito.eq("application"))).thenReturn(appResp);
VaultEnvironmentRepository repo = new VaultEnvironmentRepository(configRequest, new EnvironmentWatch.Default(), rest);
VaultEnvironmentRepository repo = new VaultEnvironmentRepository(configRequest, new EnvironmentWatch.Default(), rest, new VaultEnvironmentProperties());
Environment e = repo.findOne("myapp", null, null);
assertEquals("Name should be the same as the application argument", "myapp", e.getName());
@@ -87,7 +89,7 @@ public class VaultEnvironmentRepositoryTests {
Mockito.eq(HttpMethod.GET), Mockito.any(HttpEntity.class), Mockito.eq(VaultEnvironmentRepository.VaultResponse.class),
Mockito.eq("secret"), Mockito.eq("mydefaultkey"))).thenReturn(myDefaultKeyResp);
VaultEnvironmentRepository repo = new VaultEnvironmentRepository(configRequest, new EnvironmentWatch.Default(), rest);
VaultEnvironmentRepository repo = new VaultEnvironmentRepository(configRequest, new EnvironmentWatch.Default(), rest, new VaultEnvironmentProperties());
repo.setDefaultKey("mydefaultkey");
Environment e = repo.findOne("myapp", null, null);
@@ -127,7 +129,7 @@ public class VaultEnvironmentRepositoryTests {
Mockito.eq(HttpMethod.GET), Mockito.any(HttpEntity.class), Mockito.eq(VaultEnvironmentRepository.VaultResponse.class),
Mockito.eq("secret"), Mockito.eq("application"))).thenReturn(appResp);
VaultEnvironmentRepository repo = new VaultEnvironmentRepository(configRequest, new EnvironmentWatch.Default(), rest);
VaultEnvironmentRepository repo = new VaultEnvironmentRepository(configRequest, new EnvironmentWatch.Default(), rest, new VaultEnvironmentProperties());
repo.setDefaultKey("myapp");
Environment e = repo.findOne("myapp", null, null);
@@ -151,7 +153,7 @@ public class VaultEnvironmentRepositoryTests {
Mockito.when(rest.exchange(Mockito.eq("http://127.0.0.1:8200/v1/{backend}/{key}"),
Mockito.eq(HttpMethod.GET), Mockito.any(HttpEntity.class), Mockito.eq(VaultEnvironmentRepository.VaultResponse.class),
Mockito.eq("secret"), Mockito.eq("myapp"))).thenReturn(myAppResp);
VaultEnvironmentRepository repo = new VaultEnvironmentRepository(configRequest, new EnvironmentWatch.Default(), rest);
VaultEnvironmentRepository repo = new VaultEnvironmentRepository(configRequest, new EnvironmentWatch.Default(), rest, new VaultEnvironmentProperties());
repo.findOne("myapp", null, null);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@ import org.junit.Test;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.config.server.environment.NativeEnvironmentProperties;
import org.springframework.cloud.config.server.environment.NativeEnvironmentRepository;
import org.springframework.cloud.config.server.environment.NativeEnvironmentRepositoryTests;
import org.springframework.context.ConfigurableApplicationContext;
@@ -49,7 +50,8 @@ public class GenericResourceRepositoryTests {
public void init() {
this.context = new SpringApplicationBuilder(
NativeEnvironmentRepositoryTests.class).web(WebApplicationType.NONE).run();
this.nativeRepository = new NativeEnvironmentRepository(this.context.getEnvironment());
this.nativeRepository = new NativeEnvironmentRepository(this.context.getEnvironment(),
new NativeEnvironmentProperties());
this.repository = new GenericResourceRepository(
this.nativeRepository);
this.repository.setResourceLoader(this.context);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2016 the original author or authors.
* Copyright 2015-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@ import org.junit.Test;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.config.server.environment.NativeEnvironmentProperties;
import org.springframework.cloud.config.server.environment.NativeEnvironmentRepository;
import org.springframework.cloud.config.server.environment.NativeEnvironmentRepositoryTests;
import org.springframework.context.ConfigurableApplicationContext;
@@ -53,8 +54,8 @@ public class ResourceControllerTests {
public void init() {
this.context = new SpringApplicationBuilder(
NativeEnvironmentRepositoryTests.class).web(WebApplicationType.NONE).run();
this.environmentRepository = new NativeEnvironmentRepository(
this.context.getEnvironment());
this.environmentRepository = new NativeEnvironmentRepository(this.context.getEnvironment(),
new NativeEnvironmentProperties());
this.repository = new GenericResourceRepository(this.environmentRepository);
this.repository.setResourceLoader(this.context);
this.controller = new ResourceController(this.repository,