Refactor server into packages

Also removes getDefaultLabel() from EnvironmentRepository.
This commit is contained in:
Dave Syer
2015-10-01 11:20:35 +01:00
parent b024788be9
commit d4ce149f2d
56 changed files with 261 additions and 249 deletions

View File

@@ -34,8 +34,8 @@ import java.util.LinkedHashSet;
import java.util.Set;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.config.server.AbstractScmEnvironmentRepository;
import org.springframework.cloud.config.server.NativeEnvironmentRepository;
import org.springframework.cloud.config.server.environment.AbstractScmEnvironmentRepository;
import org.springframework.cloud.config.server.environment.NativeEnvironmentRepository;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.context.SmartLifecycle;
import org.springframework.context.annotation.Configuration;

View File

@@ -10,7 +10,7 @@ import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext;
import org.springframework.boot.test.IntegrationTest;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.TestRestTemplate;
import org.springframework.cloud.config.server.ConfigServerTestUtils;
import org.springframework.cloud.config.server.test.ConfigServerTestUtils;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;

View File

@@ -15,7 +15,7 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext;
import org.springframework.boot.test.IntegrationTest;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.cloud.config.server.ConfigServerTestUtils;
import org.springframework.cloud.config.server.test.ConfigServerTestUtils;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.config.server;
package org.springframework.cloud.config.server.bootstrap;
import java.util.Collections;

View File

@@ -13,12 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.config.server;
package org.springframework.cloud.config.server.bootstrap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.config.client.ConfigClientProperties;
import org.springframework.cloud.config.server.config.ConfigServerProperties;
import org.springframework.cloud.config.server.config.EnvironmentRepositoryConfiguration;
import org.springframework.cloud.config.server.environment.EnvironmentRepository;
import org.springframework.cloud.config.server.environment.EnvironmentRepositoryPropertySourceLocator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
@@ -52,20 +55,18 @@ public class ConfigServerBootstrapConfiguration {
@Bean
public EnvironmentRepositoryPropertySourceLocator environmentRepositoryPropertySourceLocator() {
return new EnvironmentRepositoryPropertySourceLocator(repository,
client.getName(), client.getProfile(), getDefaultLabel());
return new EnvironmentRepositoryPropertySourceLocator(this.repository,
this.client.getName(), this.client.getProfile(), getDefaultLabel());
}
private String getDefaultLabel() {
if (StringUtils.hasText(client.getLabel())) {
return client.getLabel();
if (StringUtils.hasText(this.client.getLabel())) {
return this.client.getLabel();
}
else if (StringUtils.hasText(server.getDefaultLabel())) {
return server.getDefaultLabel();
}
else {
return repository.getDefaultLabel();
else if (StringUtils.hasText(this.server.getDefaultLabel())) {
return this.server.getDefaultLabel();
}
return null;
}
}

View File

@@ -17,7 +17,6 @@
package org.springframework.cloud.config.server.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.config.server.ConfigServerProperties;
import org.springframework.cloud.config.server.encryption.EncryptionController;
import org.springframework.cloud.config.server.encryption.TextEncryptorLocator;
import org.springframework.context.annotation.Bean;
@@ -39,7 +38,10 @@ public class ConfigServerEncryptionConfiguration {
@Bean
public EncryptionController encryptionController() {
return new EncryptionController(this.encryptor, this.properties);
EncryptionController controller = new EncryptionController(this.encryptor);
controller.setDefaultApplicationName(this.properties.getDefaultApplicationName());
controller.setDefaultProfile(this.properties.getDefaultProfile());
return controller;
}
}

View File

@@ -1,13 +1,5 @@
package org.springframework.cloud.config.server;
package org.springframework.cloud.config.server.config;
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.environment.PropertySource;
import org.springframework.util.CollectionUtils;
import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -15,6 +7,16 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.PostConstruct;
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.environment.PropertySource;
import org.springframework.cloud.config.server.environment.EnvironmentRepository;
import org.springframework.util.CollectionUtils;
/**
* @author Spencer Gibb
*/
@@ -31,8 +33,8 @@ public class ConfigServerHealthIndicator extends AbstractHealthIndicator {
@PostConstruct
public void init() {
if (repositories.isEmpty()) {
repositories.put("app", new Repository());
if (this.repositories.isEmpty()) {
this.repositories.put("app", new Repository());
}
}
@@ -40,14 +42,13 @@ public class ConfigServerHealthIndicator extends AbstractHealthIndicator {
protected void doHealthCheck(Health.Builder builder) throws Exception {
builder.up();
List<Map<String, Object>> details = new ArrayList<>();
for (String name : repositories.keySet()) {
Repository repository = repositories.get(name);
for (String name : this.repositories.keySet()) {
Repository repository = this.repositories.get(name);
String application = (repository.getName() == null)? name : repository.getName();
String profiles = repository.getProfiles();
String label = (repository.getLabel() == null)? environmentRepository.getDefaultLabel() : repository.getLabel();
try {
Environment environment = environmentRepository.findOne(application, profiles, label);
Environment environment = this.environmentRepository.findOne(application, profiles, null);
HashMap<String, Object> detail = new HashMap<>();
detail.put("name", environment.getName());
@@ -68,7 +69,6 @@ public class ConfigServerHealthIndicator extends AbstractHealthIndicator {
HashMap<String, String> map = new HashMap<>();
map.put("application", application);
map.put("profiles", profiles);
map.put("label", label);
builder.withDetail("repository", map);
builder.down(e);
return;
@@ -79,7 +79,7 @@ public class ConfigServerHealthIndicator extends AbstractHealthIndicator {
}
public Map<String, Repository> getRepositories() {
return repositories;
return this.repositories;
}
public void setRepositories(Map<String, Repository> repositories) {
@@ -94,7 +94,7 @@ public class ConfigServerHealthIndicator extends AbstractHealthIndicator {
public Repository() { }
public String getName() {
return name;
return this.name;
}
public void setName(String name) {
@@ -102,7 +102,7 @@ public class ConfigServerHealthIndicator extends AbstractHealthIndicator {
}
public String getProfiles() {
return profiles;
return this.profiles;
}
public void setProfiles(String profiles) {
@@ -110,7 +110,7 @@ public class ConfigServerHealthIndicator extends AbstractHealthIndicator {
}
public String getLabel() {
return label;
return this.label;
}
public void setLabel(String label) {

View File

@@ -17,13 +17,12 @@ package org.springframework.cloud.config.server.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.cloud.config.server.ConfigServerProperties;
import org.springframework.cloud.config.server.EnvironmentController;
import org.springframework.cloud.config.server.EnvironmentEncryptorEnvironmentRepository;
import org.springframework.cloud.config.server.EnvironmentRepository;
import org.springframework.cloud.config.server.ResourceController;
import org.springframework.cloud.config.server.ResourceRepository;
import org.springframework.cloud.config.server.encryption.EnvironmentEncryptor;
import org.springframework.cloud.config.server.environment.EnvironmentController;
import org.springframework.cloud.config.server.environment.EnvironmentEncryptorEnvironmentRepository;
import org.springframework.cloud.config.server.environment.EnvironmentRepository;
import org.springframework.cloud.config.server.resource.ResourceController;
import org.springframework.cloud.config.server.resource.ResourceRepository;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.config.server;
package org.springframework.cloud.config.server.config;
import java.util.LinkedHashMap;
import java.util.Map;

View File

@@ -19,17 +19,14 @@ 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.ConfigServerHealthIndicator;
import org.springframework.cloud.config.server.ConfigServerProperties;
import org.springframework.cloud.config.server.EnvironmentRepository;
import org.springframework.cloud.config.server.MultipleJGitEnvironmentRepository;
import org.springframework.cloud.config.server.NativeEnvironmentRepository;
import org.springframework.cloud.config.server.SvnKitEnvironmentRepository;
import org.springframework.cloud.config.server.environment.EnvironmentRepository;
import org.springframework.cloud.config.server.environment.MultipleJGitEnvironmentRepository;
import org.springframework.cloud.config.server.environment.NativeEnvironmentRepository;
import org.springframework.cloud.config.server.environment.SvnKitEnvironmentRepository;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.util.StringUtils;
/**
* @author Dave Syer
@@ -46,22 +43,6 @@ public class EnvironmentRepositoryConfiguration {
return new ConfigServerHealthIndicator(repository);
}
protected static class BaseRepositoryConfiguration {
@Autowired
private ConfigServerProperties server;
protected String getDefaultLabel(EnvironmentRepository repository) {
if (StringUtils.hasText(this.server.getDefaultLabel())) {
return this.server.getDefaultLabel();
}
else {
return repository.getDefaultLabel();
}
}
}
@Configuration
@Profile("native")
protected static class NativeRepositoryConfiguration {
@@ -78,29 +59,39 @@ public class EnvironmentRepositoryConfiguration {
@Configuration
@ConditionalOnMissingBean(EnvironmentRepository.class)
protected static class GitRepositoryConfiguration extends BaseRepositoryConfiguration {
protected static class GitRepositoryConfiguration {
@Autowired
private ConfigurableEnvironment environment;
@Autowired
private ConfigServerProperties server;
@Bean
public EnvironmentRepository environmentRepository() {
MultipleJGitEnvironmentRepository repository = new MultipleJGitEnvironmentRepository(this.environment);
repository.setDefaultLabel(getDefaultLabel(repository));
if (this.server.getDefaultLabel()!=null) {
repository.setDefaultLabel(this.server.getDefaultLabel());
}
return repository;
}
}
@Configuration
@Profile("subversion")
protected static class SvnRepositoryConfiguration extends BaseRepositoryConfiguration {
protected static class SvnRepositoryConfiguration {
@Autowired
private ConfigurableEnvironment environment;
@Autowired
private ConfigServerProperties server;
@Bean
public EnvironmentRepository environmentRepository() {
SvnKitEnvironmentRepository repository = new SvnKitEnvironmentRepository(this.environment);
repository.setDefaultLabel(getDefaultLabel(repository));
if (this.server.getDefaultLabel()!=null) {
repository.setDefaultLabel(this.server.getDefaultLabel());
}
return repository;
}
}

View File

@@ -17,10 +17,9 @@ package org.springframework.cloud.config.server.config;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.config.server.ConfigServerProperties;
import org.springframework.cloud.config.server.GenericResourceRepository;
import org.springframework.cloud.config.server.ResourceLocationService;
import org.springframework.cloud.config.server.ResourceRepository;
import org.springframework.cloud.config.server.environment.SearchPathLocator;
import org.springframework.cloud.config.server.resource.GenericResourceRepository;
import org.springframework.cloud.config.server.resource.ResourceRepository;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -34,7 +33,7 @@ import org.springframework.context.annotation.Configuration;
public class ResourceRepositoryConfiguration {
@Bean
public ResourceRepository resourceRepository(ResourceLocationService service) {
public ResourceRepository resourceRepository(SearchPathLocator service) {
return new GenericResourceRepository(service);
}
}

View File

@@ -23,7 +23,6 @@ import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.cloud.config.server.ConfigServerProperties;
import org.springframework.cloud.context.encrypt.KeyFormatException;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
@@ -53,20 +52,28 @@ public class EncryptionController {
volatile private TextEncryptorLocator encryptor;
private final ConfigServerProperties properties;
private EnvironmentPrefixHelper helper = new EnvironmentPrefixHelper();
public EncryptionController(TextEncryptorLocator encryptor,
ConfigServerProperties configServerProperties) {
private String defaultApplicationName = "application";
private String defaultProfile = "default";
public EncryptionController(TextEncryptorLocator encryptor) {
this.encryptor = encryptor;
this.properties = configServerProperties;
}
public void setDefaultApplicationName(String defaultApplicationName) {
this.defaultApplicationName = defaultApplicationName;
}
public void setDefaultProfile(String defaultProfile) {
this.defaultProfile = defaultProfile;
}
@RequestMapping(value = "/key", method = RequestMethod.GET)
public String getPublicKey() {
TextEncryptor encryptor = this.encryptor.locate(this.helper.getEncryptorKeys(
"application", "default", ""));
TextEncryptor encryptor = this.encryptor
.locate(this.helper.getEncryptorKeys("application", "default", ""));
if (!(encryptor instanceof RsaKeyHolder)) {
throw new KeyNotAvailableException();
}
@@ -75,8 +82,8 @@ public class EncryptionController {
@RequestMapping(value = "/key/{name}/{profiles}", method = RequestMethod.GET)
public String getPublicKey(@PathVariable String name, @PathVariable String profiles) {
TextEncryptor encryptor = this.encryptor.locate(this.helper.getEncryptorKeys(
name, profiles, ""));
TextEncryptor encryptor = this.encryptor
.locate(this.helper.getEncryptorKeys(name, profiles, ""));
if (!(encryptor instanceof RsaKeyHolder)) {
throw new KeyNotAvailableException();
}
@@ -111,8 +118,7 @@ public class EncryptionController {
public String encrypt(@RequestBody String data,
@RequestHeader("Content-Type") MediaType type) {
return encrypt(this.properties.getDefaultApplicationName(),
this.properties.getDefaultProfile(), data, type);
return encrypt(this.defaultApplicationName, this.defaultProfile, data, type);
}
@RequestMapping(value = "/encrypt/{name}/{profiles}", method = RequestMethod.POST)
@@ -121,10 +127,10 @@ public class EncryptionController {
checkEncryptorInstalled(name, profiles);
try {
String input = stripFormData(data, type, false);
Map<String, String> keys = this.helper
.getEncryptorKeys(name, profiles, input);
String encrypted = this.helper.addPrefix(keys, this.encryptor.locate(keys)
.encrypt(input));
Map<String, String> keys = this.helper.getEncryptorKeys(name, profiles,
input);
String encrypted = this.helper.addPrefix(keys,
this.encryptor.locate(keys).encrypt(input));
logger.info("Encrypted data");
return encrypted;
}
@@ -137,8 +143,7 @@ public class EncryptionController {
public String decrypt(@RequestBody String data,
@RequestHeader("Content-Type") MediaType type) {
return decrypt(this.properties.getDefaultApplicationName(),
this.properties.getDefaultProfile(), data, type);
return decrypt(this.defaultApplicationName, this.defaultProfile, data, type);
}
@RequestMapping(value = "/decrypt/{name}/{profiles}", method = RequestMethod.POST)
@@ -162,9 +167,8 @@ public class EncryptionController {
private void checkEncryptorInstalled(String name, String profiles) {
if (this.encryptor == null
|| this.encryptor
.locate(this.helper.getEncryptorKeys(name, profiles, ""))
.encrypt("FOO").equals("FOO")) {
|| this.encryptor.locate(this.helper.getEncryptorKeys(name, profiles, ""))
.encrypt("FOO").equals("FOO")) {
throw new KeyNotInstalledException();
}
}

View File

@@ -14,9 +14,10 @@
* limitations under the License.
*/
package org.springframework.cloud.config.server;
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.core.env.ConfigurableEnvironment;
/**
@@ -24,7 +25,7 @@ import org.springframework.core.env.ConfigurableEnvironment;
*
*/
public abstract class AbstractScmEnvironmentRepository extends AbstractScmAccessor
implements EnvironmentRepository, ResourceLocationService {
implements EnvironmentRepository, SearchPathLocator {
private EnvironmentCleaner cleaner = new EnvironmentCleaner();

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.config.server;
package org.springframework.cloud.config.server.environment;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.environment.PropertySource;

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.config.server;
package org.springframework.cloud.config.server.environment;
import java.io.IOException;
import java.util.ArrayList;
@@ -83,15 +83,12 @@ public class EnvironmentController {
@RequestMapping("/{name}/{profiles:.*[^-].*}")
public Environment defaultLabel(@PathVariable String name,
@PathVariable String profiles) {
return labelled(name, profiles, this.repository.getDefaultLabel());
return labelled(name, profiles, null);
}
@RequestMapping("/{name}/{profiles}/{label:.*}")
public Environment labelled(@PathVariable String name, @PathVariable String profiles,
@PathVariable String label) {
if (label == null) {
label = this.repository.getDefaultLabel();
}
if (label != null && label.contains("(_)")) {
// "(_)" is uncommon in a git branch name, but "/" cannot be matched
// by Spring MVC
@@ -104,7 +101,7 @@ public class EnvironmentController {
@RequestMapping("/{name}-{profiles}.properties")
public ResponseEntity<String> properties(@PathVariable String name,
@PathVariable String profiles) throws IOException {
return labelledProperties(name, profiles, this.repository.getDefaultLabel());
return labelledProperties(name, profiles, null);
}
@RequestMapping("/{label}/{name}-{profiles}.properties")
@@ -120,7 +117,7 @@ public class EnvironmentController {
@RequestMapping("{name}-{profiles}.json")
public ResponseEntity<Map<String, Object>> jsonProperties(@PathVariable String name,
@PathVariable String profiles) throws Exception {
return labelledJsonProperties(name, profiles, this.repository.getDefaultLabel());
return labelledJsonProperties(name, profiles, null);
}
@RequestMapping("/{label}/{name}-{profiles}.json")
@@ -147,7 +144,7 @@ public class EnvironmentController {
@RequestMapping({ "/{name}-{profiles}.yml", "/{name}-{profiles}.yaml" })
public ResponseEntity<String> yaml(@PathVariable String name,
@PathVariable String profiles) throws Exception {
return labelledYaml(name, profiles, this.repository.getDefaultLabel());
return labelledYaml(name, profiles, null);
}
@RequestMapping({ "/{label}/{name}-{profiles}.yml",

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.config.server;
package org.springframework.cloud.config.server.environment;
import java.util.HashMap;
import java.util.LinkedHashMap;
@@ -48,16 +48,8 @@ public class EnvironmentEncryptorEnvironmentRepository implements EnvironmentRep
this.environmentEncryptor = environmentEncryptor;
}
@Override
public String getDefaultLabel() {
return this.delegate.getDefaultLabel();
}
@Override
public Environment findOne(String name, String profiles, String label) {
if (label == null) {
label = getDefaultLabel();
}
Environment environment = this.delegate.findOne(name, profiles, label);
if (this.environmentEncryptor != null) {
environment = this.environmentEncryptor.decrypt(environment);

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.config.server;
package org.springframework.cloud.config.server.environment;
import org.springframework.cloud.config.environment.Environment;
@@ -23,8 +23,6 @@ import org.springframework.cloud.config.environment.Environment;
*/
public interface EnvironmentRepository {
String getDefaultLabel();
Environment findOne(String application, String profile, String label);
}

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.config.server;
package org.springframework.cloud.config.server.environment;
import java.util.Map;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.config.server;
package org.springframework.cloud.config.server.environment;
import static org.springframework.util.StringUtils.hasText;
@@ -53,7 +53,7 @@ import com.jcraft.jsch.Session;
* @author Roy Clarkson
*/
public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository
implements EnvironmentRepository, ResourceLocationService, InitializingBean {
implements EnvironmentRepository, SearchPathLocator, InitializingBean {
private static final String DEFAULT_LABEL = "master";
private static final String FILE_URI_PREFIX = "file:";
@@ -104,7 +104,6 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository
this.gitFactory = gitFactory;
}
@Override
public String getDefaultLabel() {
return this.defaultLabel;
}
@@ -115,6 +114,9 @@ public class JGitEnvironmentRepository extends AbstractScmEnvironmentRepository
@Override
public String[] getLocations(String application, String profile, String label) {
if (label==null) {
label = this.defaultLabel;
}
refresh(application, label);
return getSearchLocations(getWorkingDirectory());
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.config.server;
package org.springframework.cloud.config.server.environment;
import java.util.ArrayList;
import java.util.Collection;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.config.server;
package org.springframework.cloud.config.server.environment;
import java.io.File;
import java.util.ArrayList;
@@ -48,7 +48,7 @@ import org.springframework.util.StringUtils;
*/
@ConfigurationProperties("spring.cloud.config.server.native")
public class NativeEnvironmentRepository
implements EnvironmentRepository, ResourceLocationService {
implements EnvironmentRepository, SearchPathLocator {
private static Log logger = LogFactory.getLog(NativeEnvironmentRepository.class);
@@ -82,7 +82,6 @@ public class NativeEnvironmentRepository
return this.failOnError;
}
@Override
public String getDefaultLabel() {
return DEFAULT_LABEL;
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.config.server;
package org.springframework.cloud.config.server.environment;
/**
* @author Dave Syer

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.config.server;
package org.springframework.cloud.config.server.environment;
import java.util.Arrays;
import java.util.HashSet;
@@ -54,7 +54,6 @@ public class PassthruEnvironmentRepository implements EnvironmentRepository {
this.environment = environment;
}
@Override
public String getDefaultLabel() {
return DEFAULT_LABEL;
}
@@ -62,9 +61,9 @@ public class PassthruEnvironmentRepository implements EnvironmentRepository {
@Override
public Environment findOne(String application, String env, String label) {
Environment result = new Environment(application, StringUtils.commaDelimitedListToStringArray(env), label);
for (org.springframework.core.env.PropertySource<?> source : environment.getPropertySources()) {
for (org.springframework.core.env.PropertySource<?> source : this.environment.getPropertySources()) {
String name = source.getName();
if (!standardSources.contains(name) && source instanceof MapPropertySource) {
if (!this.standardSources.contains(name) && source instanceof MapPropertySource) {
result.add(new PropertySource(name, (Map<?, ?>) source.getSource()));
}
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.config.server;
package org.springframework.cloud.config.server.environment;
/**
* @author Dave Syer

View File

@@ -14,13 +14,16 @@
* limitations under the License.
*/
package org.springframework.cloud.config.server;
package org.springframework.cloud.config.server.environment;
/**
* Strategy for locating a search path for resource (e.g. in the file system or
* classpath).
*
* @author Dave Syer
*
*/
public interface ResourceLocationService {
public interface SearchPathLocator {
String[] getLocations(String application, String profile, String label);

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.config.server;
package org.springframework.cloud.config.server.environment;
import java.util.Map;

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.config.server;
package org.springframework.cloud.config.server.environment;
import static org.springframework.util.StringUtils.hasText;
@@ -50,7 +50,6 @@ public class SvnKitEnvironmentRepository extends AbstractScmEnvironmentRepositor
private String defaultLabel = DEFAULT_LABEL;
@Override
public String getDefaultLabel() {
return this.defaultLabel ;
}
@@ -61,6 +60,9 @@ public class SvnKitEnvironmentRepository extends AbstractScmEnvironmentRepositor
@Override
public String[] getLocations(String application, String profile, String label) {
if (label==null) {
label = this.defaultLabel;
}
SvnOperationFactory svnOperationFactory = new SvnOperationFactory();
if (hasText(getUsername())) {
svnOperationFactory

View File

@@ -14,20 +14,21 @@
* limitations under the License.
*/
package org.springframework.cloud.config.server;
package org.springframework.cloud.config.server.resource;
import java.io.IOException;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.Set;
import org.springframework.cloud.config.server.environment.SearchPathLocator;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.util.StringUtils;
/**
* An {@link ResourceRepository} backed by a {@link ResourceLocationService}.
* An {@link ResourceRepository} backed by a {@link SearchPathLocator}.
*
* @author Dave Syer
*/
@@ -36,9 +37,9 @@ public class GenericResourceRepository
private ResourceLoader resourceLoader;
private ResourceLocationService service;
private SearchPathLocator service;
public GenericResourceRepository(ResourceLocationService service) {
public GenericResourceRepository(SearchPathLocator service) {
this.service = service;
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.config.server;
package org.springframework.cloud.config.server.resource;
/**
* @author Dave Syer

View File

@@ -14,13 +14,14 @@
* limitations under the License.
*/
package org.springframework.cloud.config.server;
package org.springframework.cloud.config.server.resource;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Map;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.server.environment.EnvironmentRepository;
import org.springframework.core.env.PropertySource;
import org.springframework.core.env.StandardEnvironment;
import org.springframework.core.io.Resource;
@@ -38,7 +39,7 @@ import org.springframework.web.bind.annotation.RestController;
* repository. Can be used to supply config files for consumption by a wide variety of
* applications and services. A {@link ResourceRepository} is used to locate a
* {@link Resource}, specific to an application, and the contents are transformed to text.
* Then an {@link EnvironmentController} is used to supply key-value pairs which are used
* Then an {@link EnvironmentRepository} is used to supply key-value pairs which are used
* to replace placeholders in the resource text.
*
* @author Dave Syer

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.config.server;
package org.springframework.cloud.config.server.resource;
import org.springframework.core.io.Resource;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.config.server;
package org.springframework.cloud.config.server.support;
import java.io.File;
import java.io.IOException;
@@ -72,11 +72,11 @@ public class AbstractScmAccessor {
}
}
protected ConfigurableEnvironment getEnvironment() {
public ConfigurableEnvironment getEnvironment() {
return this.environment;
}
protected void setEnvironment(ConfigurableEnvironment environment) {
public void setEnvironment(ConfigurableEnvironment environment) {
this.environment = environment;
}

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.config.server;
package org.springframework.cloud.config.server.test;
import org.eclipse.jgit.util.FileUtils;
import org.springframework.util.FileSystemUtils;

View File

@@ -1,10 +1,10 @@
# Bootstrap components
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
org.springframework.cloud.config.server.ConfigServerBootstrapConfiguration
org.springframework.cloud.config.server.bootstrap.ConfigServerBootstrapConfiguration
# Application listeners
org.springframework.context.ApplicationListener=\
org.springframework.cloud.config.server.ConfigServerBootstrapApplicationListener
org.springframework.cloud.config.server.bootstrap.ConfigServerBootstrapApplicationListener
# Autoconfiguration
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\

View File

@@ -14,7 +14,7 @@ import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.TestRestTemplate;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.server.ConfigServerApplication;
import org.springframework.cloud.config.server.ConfigServerTestUtils;
import org.springframework.cloud.config.server.test.ConfigServerTestUtils;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;

View File

@@ -20,6 +20,9 @@ import org.springframework.boot.test.TestRestTemplate;
import org.springframework.cloud.config.client.ConfigServicePropertySourceLocator;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.server.ConfigClientOffIntegrationTests.TestConfiguration;
import org.springframework.cloud.config.server.environment.EnvironmentRepository;
import org.springframework.cloud.config.server.resource.ResourceRepository;
import org.springframework.cloud.config.server.test.ConfigServerTestUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

View File

@@ -20,6 +20,9 @@ import org.springframework.boot.test.TestRestTemplate;
import org.springframework.cloud.config.client.ConfigServicePropertySourceLocator;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.server.ConfigClientOnIntegrationTests.TestConfiguration;
import org.springframework.cloud.config.server.environment.EnvironmentRepository;
import org.springframework.cloud.config.server.resource.ResourceRepository;
import org.springframework.cloud.config.server.test.ConfigServerTestUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

View File

@@ -15,7 +15,7 @@ import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.TestRestTemplate;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.server.ConfigServerApplication;
import org.springframework.cloud.config.server.ConfigServerTestUtils;
import org.springframework.cloud.config.server.test.ConfigServerTestUtils;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.ActiveProfiles;

View File

@@ -15,24 +15,25 @@
*/
package org.springframework.cloud.config.server;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.IntegrationTest;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.TestRestTemplate;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.server.environment.SvnKitEnvironmentRepository;
import org.springframework.cloud.config.server.test.ConfigServerTestUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
/**
* @author Michael Prankl
* @author Dave Syer
@@ -61,7 +62,7 @@ public class SubversionConfigServerIntegrationTests {
@Test
public void contextLoads() {
Environment environment = new TestRestTemplate().getForObject("http://localhost:"
+ port + "/foo/development/", Environment.class);
+ this.port + "/foo/development/", Environment.class);
assertFalse(environment.getPropertySources().isEmpty());
assertEquals("overrides", environment.getPropertySources().get(0).getName());
assertEquals("{spring.cloud.config.enabled=true}", environment
@@ -70,7 +71,7 @@ public class SubversionConfigServerIntegrationTests {
@Test
public void defaultLabel() throws Exception {
EnvironmentRepository repository = context.getBean(EnvironmentRepository.class);
SvnKitEnvironmentRepository repository = this.context.getBean(SvnKitEnvironmentRepository.class);
assertEquals("trunk", repository.getDefaultLabel());
}

View File

@@ -14,7 +14,7 @@ import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.TestRestTemplate;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.server.ConfigServerApplication;
import org.springframework.cloud.config.server.ConfigServerTestUtils;
import org.springframework.cloud.config.server.test.ConfigServerTestUtils;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;

View File

@@ -1,4 +1,4 @@
package org.springframework.cloud.config.server;
package org.springframework.cloud.config.server.config;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
@@ -10,6 +10,8 @@ import org.mockito.Answers;
import org.mockito.Mock;
import org.springframework.boot.actuate.health.Status;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.server.config.ConfigServerHealthIndicator;
import org.springframework.cloud.config.server.environment.EnvironmentRepository;
/**
* @author Spencer Gibb

View File

@@ -4,7 +4,6 @@ import static org.junit.Assert.assertEquals;
import static org.springframework.http.MediaType.TEXT_PLAIN;
import org.junit.Test;
import org.springframework.cloud.config.server.ConfigServerProperties;
import org.springframework.security.crypto.encrypt.Encryptors;
/**
@@ -14,9 +13,8 @@ import org.springframework.security.crypto.encrypt.Encryptors;
public class EncryptionControllerMultiTextEncryptorTests {
ConfigServerProperties properties = new ConfigServerProperties();
EncryptionController controller = new EncryptionController(
new SingleTextEncryptorLocator(Encryptors.noOpText()), this.properties);
new SingleTextEncryptorLocator(Encryptors.noOpText()));
String application = "application";
String profiles = "profile1,profile2";
@@ -25,8 +23,8 @@ public class EncryptionControllerMultiTextEncryptorTests {
@Test
public void shouldEncryptUsingApplicationAndProfiles() {
this.controller = new EncryptionController(new SingleTextEncryptorLocator(
Encryptors.text("application", "11")), this.properties);
this.controller = new EncryptionController(
new SingleTextEncryptorLocator(Encryptors.text("application", "11")));
// when
String encrypted = this.controller.encrypt(this.application, this.profiles,

View File

@@ -22,7 +22,6 @@ import static org.junit.Assert.assertTrue;
import java.util.Map;
import org.junit.Test;
import org.springframework.cloud.config.server.ConfigServerProperties;
import org.springframework.http.MediaType;
import org.springframework.security.crypto.encrypt.Encryptors;
import org.springframework.security.crypto.encrypt.TextEncryptor;
@@ -34,9 +33,8 @@ import org.springframework.security.rsa.crypto.RsaSecretEncryptor;
*/
public class EncryptionControllerTests {
private ConfigServerProperties properties = new ConfigServerProperties();
private EncryptionController controller = new EncryptionController(
new SingleTextEncryptorLocator(Encryptors.noOpText()), this.properties);
new SingleTextEncryptorLocator(Encryptors.noOpText()));
@Test(expected = KeyNotInstalledException.class)
public void cannotDecryptWithoutKey() {
@@ -50,24 +48,24 @@ public class EncryptionControllerTests {
@Test
public void sunnyDayRsaKey() {
this.controller = new EncryptionController(new SingleTextEncryptorLocator(
new RsaSecretEncryptor()), this.properties);
this.controller = new EncryptionController(
new SingleTextEncryptorLocator(new RsaSecretEncryptor()));
String cipher = this.controller.encrypt("foo", MediaType.TEXT_PLAIN);
assertEquals("foo", this.controller.decrypt(cipher, MediaType.TEXT_PLAIN));
}
@Test
public void publicKey() {
this.controller = new EncryptionController(new SingleTextEncryptorLocator(
new RsaSecretEncryptor()), this.properties);
this.controller = new EncryptionController(
new SingleTextEncryptorLocator(new RsaSecretEncryptor()));
String key = this.controller.getPublicKey();
assertTrue("Wrong key format: " + key, key.startsWith("ssh-rsa"));
}
@Test
public void appAndProfile() {
this.controller = new EncryptionController(new SingleTextEncryptorLocator(
new RsaSecretEncryptor()), this.properties);
this.controller = new EncryptionController(
new SingleTextEncryptorLocator(new RsaSecretEncryptor()));
// Add space to input
String cipher = this.controller.encrypt("app", "default", "foo bar",
MediaType.TEXT_PLAIN);
@@ -78,8 +76,8 @@ public class EncryptionControllerTests {
@Test
public void formDataIn() {
this.controller = new EncryptionController(new SingleTextEncryptorLocator(
new RsaSecretEncryptor()), this.properties);
this.controller = new EncryptionController(
new SingleTextEncryptorLocator(new RsaSecretEncryptor()));
// Add space to input
String cipher = this.controller.encrypt("foo bar=",
MediaType.APPLICATION_FORM_URLENCODED);
@@ -90,8 +88,8 @@ public class EncryptionControllerTests {
@Test
public void formDataInWithPrefix() {
this.controller = new EncryptionController(new SingleTextEncryptorLocator(
new RsaSecretEncryptor()), this.properties);
this.controller = new EncryptionController(
new SingleTextEncryptorLocator(new RsaSecretEncryptor()));
// Add space to input
String cipher = this.controller.encrypt("{key:test}foo bar=",
MediaType.APPLICATION_FORM_URLENCODED);
@@ -111,7 +109,7 @@ public class EncryptionControllerTests {
return this.encryptor;
}
};
this.controller = new EncryptionController(locator, this.properties);
this.controller = new EncryptionController(locator);
// Add space to input
String cipher = this.controller.encrypt("app", "default", "foo bar",
MediaType.TEXT_PLAIN);

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.config.server;
package org.springframework.cloud.config.server.environment;
import org.hamcrest.Matchers;
import org.junit.Before;
@@ -25,7 +25,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.server.EnvironmentControllerIntegrationTests.ControllerConfiguration;
import org.springframework.cloud.config.server.environment.EnvironmentControllerIntegrationTests.ControllerConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
@@ -56,26 +56,25 @@ public class EnvironmentControllerIntegrationTests {
@Before
public void init() {
Mockito.reset(this.repository);
Mockito.when(this.repository.getDefaultLabel()).thenReturn("master");
this.mvc = MockMvcBuilders.webAppContextSetup(this.context).build();
}
@Test
public void environmentNoLabel() throws Exception {
Mockito.when(this.repository.findOne("foo", "default", "master")).thenReturn(
Mockito.when(this.repository.findOne("foo", "default", null)).thenReturn(
new Environment("foo", "default"));
this.mvc.perform(MockMvcRequestBuilders.get("/foo/default")).andExpect(
MockMvcResultMatchers.status().isOk());
Mockito.verify(this.repository).findOne("foo", "default", "master");
Mockito.verify(this.repository).findOne("foo", "default", null);
}
@Test
public void propertiesNoLabel() throws Exception {
Mockito.when(this.repository.findOne("foo", "default", "master")).thenReturn(
Mockito.when(this.repository.findOne("foo", "default", null)).thenReturn(
new Environment("foo", "default"));
this.mvc.perform(MockMvcRequestBuilders.get("/foo-default.properties")).andExpect(
MockMvcResultMatchers.status().isOk());
Mockito.verify(this.repository).findOne("foo", "default", "master");
Mockito.verify(this.repository).findOne("foo", "default", null);
}
@Test
@@ -129,7 +128,6 @@ public class EnvironmentControllerIntegrationTests {
@Bean
public EnvironmentRepository environmentRepository() {
EnvironmentRepository repository = Mockito.mock(EnvironmentRepository.class);
Mockito.when(repository.getDefaultLabel()).thenReturn("master");
return repository;
}

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.config.server;
package org.springframework.cloud.config.server.environment;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -53,7 +53,6 @@ public class EnvironmentControllerTests {
@Before
public void init() {
Mockito.when(this.repository.getDefaultLabel()).thenReturn("master");
this.controller = new EnvironmentController(this.repository);
}
@@ -62,7 +61,7 @@ public class EnvironmentControllerTests {
Map<String, Object> map = new HashMap<String, Object>();
map.put("a.b.c", "d");
this.environment.add(new PropertySource("one", map));
Mockito.when(this.repository.findOne("foo", "bar", "master")).thenReturn(this.environment);
Mockito.when(this.repository.findOne("foo", "bar", null)).thenReturn(this.environment);
String yaml = this.controller.yaml("foo", "bar").getBody();
assertEquals("a:\n b:\n c: d\n", yaml);
}
@@ -74,7 +73,7 @@ public class EnvironmentControllerTests {
this.environment.add(new PropertySource("one", map));
this.environment.addFirst(new PropertySource("two", Collections.singletonMap("a.b.c",
"e")));
Mockito.when(this.repository.findOne("foo", "bar", "master")).thenReturn(this.environment);
Mockito.when(this.repository.findOne("foo", "bar", null)).thenReturn(this.environment);
String yaml = this.controller.yaml("foo", "bar").getBody();
assertEquals("a:\n b:\n c: e\n", yaml);
}
@@ -85,7 +84,7 @@ public class EnvironmentControllerTests {
map.put("a.b[0]", "c");
map.put("a.b[1]", "d");
this.environment.add(new PropertySource("one", map));
Mockito.when(this.repository.findOne("foo", "bar", "master")).thenReturn(this.environment);
Mockito.when(this.repository.findOne("foo", "bar", null)).thenReturn(this.environment);
String yaml = this.controller.yaml("foo", "bar").getBody();
assertEquals("a:\n b:\n - c\n - d\n", yaml);
}
@@ -95,7 +94,7 @@ public class EnvironmentControllerTests {
Map<String, Object> map = new LinkedHashMap<String, Object>();
map.put("document", "blah");
this.environment.add(new PropertySource("one", map));
Mockito.when(this.repository.findOne("foo", "bar", "master")).thenReturn(this.environment);
Mockito.when(this.repository.findOne("foo", "bar", null)).thenReturn(this.environment);
String yaml = this.controller.yaml("foo", "bar").getBody();
assertEquals("blah\n", yaml);
}
@@ -106,7 +105,7 @@ public class EnvironmentControllerTests {
map.put("document[0]", "c");
map.put("document[1]", "d");
this.environment.add(new PropertySource("one", map));
Mockito.when(this.repository.findOne("foo", "bar", "master")).thenReturn(this.environment);
Mockito.when(this.repository.findOne("foo", "bar", null)).thenReturn(this.environment);
String yaml = this.controller.yaml("foo", "bar").getBody();
assertEquals("- c\n- d\n", yaml);
}
@@ -117,7 +116,7 @@ public class EnvironmentControllerTests {
map.put("document[0].a", "c");
map.put("document[1].a", "d");
this.environment.add(new PropertySource("one", map));
Mockito.when(this.repository.findOne("foo", "bar", "master")).thenReturn(this.environment);
Mockito.when(this.repository.findOne("foo", "bar", null)).thenReturn(this.environment);
String yaml = this.controller.yaml("foo", "bar").getBody();
assertEquals("- a: c\n- a: d\n", yaml);
}
@@ -129,7 +128,7 @@ public class EnvironmentControllerTests {
map.put("a.b[0].d", "e");
map.put("a.b[1].c", "d");
this.environment.add(new PropertySource("one", map));
Mockito.when(this.repository.findOne("foo", "bar", "master")).thenReturn(this.environment);
Mockito.when(this.repository.findOne("foo", "bar", null)).thenReturn(this.environment);
String yaml = this.controller.yaml("foo", "bar").getBody();
assertTrue("Wrong output: " + yaml,
"a:\n b:\n - d: e\n c: d\n - c: d\n".equals(yaml)
@@ -142,7 +141,7 @@ public class EnvironmentControllerTests {
map.put("b[0].c", "d");
map.put("b[1].c", "d");
this.environment.add(new PropertySource("one", map));
Mockito.when(this.repository.findOne("foo", "bar", "master")).thenReturn(this.environment);
Mockito.when(this.repository.findOne("foo", "bar", null)).thenReturn(this.environment);
String yaml = this.controller.yaml("foo", "bar").getBody();
assertEquals("b:\n- c: d\n- c: d\n", yaml);
}
@@ -153,14 +152,14 @@ public class EnvironmentControllerTests {
map.put("x.a.b[0].c", "d");
map.put("x.a.b[1].c", "d");
this.environment.add(new PropertySource("one", map));
Mockito.when(this.repository.findOne("foo", "bar", "master")).thenReturn(this.environment);
Mockito.when(this.repository.findOne("foo", "bar", null)).thenReturn(this.environment);
String yaml = this.controller.yaml("foo", "bar").getBody();
assertEquals("x:\n a:\n b:\n - c: d\n - c: d\n", yaml);
}
@Test
public void mappingForEnvironment() throws Exception {
Mockito.when(this.repository.findOne("foo", "bar", "master")).thenReturn(this.environment);
Mockito.when(this.repository.findOne("foo", "bar", null)).thenReturn(this.environment);
MockMvc mvc = MockMvcBuilders.standaloneSetup(this.controller).build();
mvc.perform(MockMvcRequestBuilders.get("/foo/bar")).andExpect(
MockMvcResultMatchers.status().isOk());
@@ -176,7 +175,7 @@ public class EnvironmentControllerTests {
@Test
public void mappingForYaml() throws Exception {
Mockito.when(this.repository.findOne("foo", "bar", "master")).thenReturn(this.environment);
Mockito.when(this.repository.findOne("foo", "bar", null)).thenReturn(this.environment);
MockMvc mvc = MockMvcBuilders.standaloneSetup(this.controller).build();
mvc.perform(MockMvcRequestBuilders.get("/foo-bar.yml"))
.andExpect(
@@ -186,7 +185,7 @@ public class EnvironmentControllerTests {
@Test
public void mappingForJson() throws Exception {
Mockito.when(this.repository.findOne("foo", "bar", "master")).thenReturn(this.environment);
Mockito.when(this.repository.findOne("foo", "bar", null)).thenReturn(this.environment);
MockMvc mvc = MockMvcBuilders.standaloneSetup(this.controller).build();
mvc.perform(MockMvcRequestBuilders.get("/foo-bar.json"))
.andExpect(
@@ -214,7 +213,7 @@ public class EnvironmentControllerTests {
@Test
public void mappingForProperties() throws Exception {
Mockito.when(this.repository.findOne("foo", "bar", "master")).thenReturn(this.environment);
Mockito.when(this.repository.findOne("foo", "bar", null)).thenReturn(this.environment);
MockMvc mvc = MockMvcBuilders.standaloneSetup(this.controller).build();
mvc.perform(MockMvcRequestBuilders.get("/foo-bar.properties")).andExpect(
MockMvcResultMatchers.content().contentType(MediaType.TEXT_PLAIN));
@@ -239,7 +238,7 @@ public class EnvironmentControllerTests {
@Test
public void mappingforJsonProperties() throws Exception {
Mockito.when(this.repository.findOne("foo", "bar", "master")).thenReturn(this.environment);
Mockito.when(this.repository.findOne("foo", "bar", null)).thenReturn(this.environment);
MockMvc mvc = MockMvcBuilders.standaloneSetup(this.controller).build();
mvc.perform(MockMvcRequestBuilders.get("/foo-bar.json")).andExpect(
MockMvcResultMatchers.content().contentType(MediaType.APPLICATION_JSON));

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.config.server;
package org.springframework.cloud.config.server.environment;
import static org.junit.Assert.assertEquals;
@@ -46,7 +46,6 @@ public class EnvironmentEncryptorEnvironmentRepositoryTests {
@Before
public void init() {
Mockito.when(this.repository.getDefaultLabel()).thenReturn("master");
this.controller = new EnvironmentEncryptorEnvironmentRepository(this.repository);
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.config.server;
package org.springframework.cloud.config.server.environment;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
@@ -34,6 +34,8 @@ import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfigurati
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.server.config.EnvironmentRepositoryConfiguration;
import org.springframework.cloud.config.server.environment.EnvironmentRepository;
import org.springframework.cloud.config.server.test.ConfigServerTestUtils;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.config.server;
package org.springframework.cloud.config.server.environment;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
@@ -34,6 +34,7 @@ import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfigurati
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.server.config.EnvironmentRepositoryConfiguration;
import org.springframework.cloud.config.server.test.ConfigServerTestUtils;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
@@ -122,8 +123,8 @@ public class JGitEnvironmentRepositoryIntegrationTests {
String uri = ConfigServerTestUtils.prepareLocalRepo();
this.context = new SpringApplicationBuilder(TestConfiguration.class).web(false)
.properties("spring.cloud.config.server.git.uri:" + uri).run();
EnvironmentRepository repository = this.context
.getBean(EnvironmentRepository.class);
JGitEnvironmentRepository repository = this.context
.getBean(JGitEnvironmentRepository.class);
assertEquals("master", repository.getDefaultLabel());
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.config.server;
package org.springframework.cloud.config.server.environment;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -34,6 +34,8 @@ import org.eclipse.jgit.util.FileUtils;
import org.junit.Before;
import org.junit.Test;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.server.environment.JGitEnvironmentRepository;
import org.springframework.cloud.config.server.test.ConfigServerTestUtils;
import org.springframework.core.env.StandardEnvironment;
/**

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.config.server;
package org.springframework.cloud.config.server.environment;
import static org.junit.Assert.assertEquals;
@@ -31,6 +31,8 @@ import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfigurati
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.server.config.EnvironmentRepositoryConfiguration;
import org.springframework.cloud.config.server.environment.EnvironmentRepository;
import org.springframework.cloud.config.server.test.ConfigServerTestUtils;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.config.server;
package org.springframework.cloud.config.server.environment;
import static org.junit.Assert.assertEquals;
@@ -24,9 +24,9 @@ import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.server.ConfigServerTestUtils;
import org.springframework.cloud.config.server.MultipleJGitEnvironmentRepository;
import org.springframework.cloud.config.server.MultipleJGitEnvironmentRepository.PatternMatchingJGitEnvironmentRepository;
import org.springframework.cloud.config.server.environment.MultipleJGitEnvironmentRepository;
import org.springframework.cloud.config.server.environment.MultipleJGitEnvironmentRepository.PatternMatchingJGitEnvironmentRepository;
import org.springframework.cloud.config.server.test.ConfigServerTestUtils;
import org.springframework.core.env.StandardEnvironment;
/**

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.config.server;
package org.springframework.cloud.config.server.environment;
import static org.junit.Assert.assertEquals;
@@ -21,6 +21,7 @@ import org.junit.Before;
import org.junit.Test;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.server.environment.NativeEnvironmentRepository;
import org.springframework.context.ConfigurableApplicationContext;
/**

View File

@@ -14,7 +14,9 @@
* limitations under the License.
*/
package org.springframework.cloud.config.server;
package org.springframework.cloud.config.server.environment;
import static org.junit.Assert.assertEquals;
import java.io.File;
import java.io.FileNotFoundException;
@@ -25,23 +27,22 @@ import java.nio.charset.Charset;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.server.config.EnvironmentRepositoryConfiguration;
import org.springframework.cloud.config.server.test.ConfigServerTestUtils;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.util.FileSystemUtils;
import org.springframework.util.StreamUtils;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.wc2.SvnCheckout;
import org.tmatesoft.svn.core.wc2.SvnCommit;
import org.tmatesoft.svn.core.wc2.SvnOperationFactory;
import org.tmatesoft.svn.core.wc2.SvnTarget;
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.server.config.EnvironmentRepositoryConfiguration;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.util.FileSystemUtils;
import org.springframework.util.StreamUtils;
import static org.junit.Assert.assertEquals;
/**
* @author Michael Prankl
@@ -55,16 +56,16 @@ public class SVNKitEnvironmentRepositoryIntegrationTests {
@Before
public void init() {
workingDir = new File("target/repos/svn-config-repo-update");
if (workingDir.exists()) {
FileSystemUtils.deleteRecursively(workingDir);
this.workingDir = new File("target/repos/svn-config-repo-update");
if (this.workingDir.exists()) {
FileSystemUtils.deleteRecursively(this.workingDir);
}
}
@After
public void close() {
if (context != null) {
context.close();
if (this.context != null) {
this.context.close();
}
}
@@ -72,10 +73,10 @@ public class SVNKitEnvironmentRepositoryIntegrationTests {
public void vanilla() throws Exception {
String uri = ConfigServerTestUtils.prepareLocalSvnRepo(
"src/test/resources/svn-config-repo", "target/config");
context = new SpringApplicationBuilder(TestConfiguration.class).web(false)
this.context = new SpringApplicationBuilder(TestConfiguration.class).web(false)
.profiles("subversion")
.run("--spring.cloud.config.server.svn.uri=" + uri);
EnvironmentRepository repository = context.getBean(EnvironmentRepository.class);
EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class);
repository.findOne("bar", "staging", "trunk");
Environment environment = repository.findOne("bar", "staging", "trunk");
assertEquals(2, environment.getPropertySources().size());
@@ -85,10 +86,10 @@ public class SVNKitEnvironmentRepositoryIntegrationTests {
public void update() throws Exception {
String uri = ConfigServerTestUtils.prepareLocalSvnRepo(
"src/test/resources/svn-config-repo", "target/config");
context = new SpringApplicationBuilder(TestConfiguration.class).web(false)
this.context = new SpringApplicationBuilder(TestConfiguration.class).web(false)
.profiles("subversion")
.run("--spring.cloud.config.server.svn.uri=" + uri);
EnvironmentRepository repository = context.getBean(EnvironmentRepository.class);
EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class);
repository.findOne("bar", "staging", "trunk");
Environment environment = repository.findOne("bar", "staging", "trunk");
assertEquals("bar", environment.getPropertySources().get(0).getSource()
@@ -104,11 +105,11 @@ public class SVNKitEnvironmentRepositoryIntegrationTests {
SvnOperationFactory svnFactory = new SvnOperationFactory();
final SvnCheckout checkout = svnFactory.createCheckout();
checkout.setSource(SvnTarget.fromURL(SVNURL.parseURIEncoded(uri)));
checkout.setSingleTarget(SvnTarget.fromFile(workingDir));
checkout.setSingleTarget(SvnTarget.fromFile(this.workingDir));
checkout.run();
// update bar.properties
File barProps = new File(workingDir, "trunk/bar.properties");
File barProps = new File(this.workingDir, "trunk/bar.properties");
StreamUtils.copy("foo: foo", Charset.defaultCharset(), new FileOutputStream(
barProps));
// commit to repo
@@ -122,10 +123,10 @@ public class SVNKitEnvironmentRepositoryIntegrationTests {
public void defaultLabel() throws Exception {
String uri = ConfigServerTestUtils.prepareLocalSvnRepo(
"src/test/resources/svn-config-repo", "target/config");
context = new SpringApplicationBuilder(TestConfiguration.class).web(false)
this.context = new SpringApplicationBuilder(TestConfiguration.class).web(false)
.profiles("subversion")
.run("--spring.cloud.config.server.svn.uri=" + uri);
EnvironmentRepository repository = context.getBean(EnvironmentRepository.class);
SvnKitEnvironmentRepository repository = this.context.getBean(SvnKitEnvironmentRepository.class);
assertEquals("trunk", repository.getDefaultLabel());
}
@@ -133,10 +134,10 @@ public class SVNKitEnvironmentRepositoryIntegrationTests {
public void invalidLabel() throws Exception {
String uri = ConfigServerTestUtils.prepareLocalSvnRepo(
"src/test/resources/svn-config-repo", "target/config");
context = new SpringApplicationBuilder(TestConfiguration.class).web(false)
this.context = new SpringApplicationBuilder(TestConfiguration.class).web(false)
.profiles("subversion")
.run("--spring.cloud.config.server.svn.uri=" + uri);
EnvironmentRepository repository = context.getBean(EnvironmentRepository.class);
EnvironmentRepository repository = this.context.getBean(EnvironmentRepository.class);
repository.findOne("bar", "staging", "unknownlabel");
Environment environment = repository.findOne("bar", "staging", "unknownlabel");
assertEquals(0, environment.getPropertySources().size());

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.config.server;
package org.springframework.cloud.config.server.environment;
import java.io.File;
@@ -23,6 +23,9 @@ import org.junit.Before;
import org.junit.Test;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.cloud.config.server.environment.NoSuchLabelException;
import org.springframework.cloud.config.server.environment.SvnKitEnvironmentRepository;
import org.springframework.cloud.config.server.test.ConfigServerTestUtils;
import org.springframework.core.env.StandardEnvironment;
import static org.junit.Assert.assertEquals;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.config.server;
package org.springframework.cloud.config.server.resource;
import static org.junit.Assert.assertNotNull;
@@ -22,6 +22,10 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.config.server.environment.NativeEnvironmentRepository;
import org.springframework.cloud.config.server.environment.NativeEnvironmentRepositoryTests;
import org.springframework.cloud.config.server.resource.GenericResourceRepository;
import org.springframework.cloud.config.server.resource.NoSuchResourceException;
import org.springframework.context.ConfigurableApplicationContext;
/**

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.config.server;
package org.springframework.cloud.config.server.resource;
import static org.junit.Assert.assertEquals;
@@ -22,6 +22,10 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.config.server.environment.NativeEnvironmentRepository;
import org.springframework.cloud.config.server.environment.NativeEnvironmentRepositoryTests;
import org.springframework.cloud.config.server.resource.GenericResourceRepository;
import org.springframework.cloud.config.server.resource.ResourceController;
import org.springframework.context.ConfigurableApplicationContext;
/**