diff --git a/pom.xml b/pom.xml index 6afdb4ea..22c49622 100644 --- a/pom.xml +++ b/pom.xml @@ -48,6 +48,11 @@ org.eclipse.jgit 3.5.3.201412180710-r + + org.tmatesoft.svnkit + svnkit + 1.8.7 + diff --git a/spring-cloud-config-server/pom.xml b/spring-cloud-config-server/pom.xml index 8847efaf..c69aa640 100644 --- a/spring-cloud-config-server/pom.xml +++ b/spring-cloud-config-server/pom.xml @@ -50,6 +50,10 @@ spring-boot-starter-test test + + org.tmatesoft.svnkit + svnkit + diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/AbstractSCMEnvironmentRepository.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/AbstractSCMEnvironmentRepository.java new file mode 100644 index 00000000..11355c0c --- /dev/null +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/AbstractSCMEnvironmentRepository.java @@ -0,0 +1,160 @@ +/* + * Copyright 2013-2014 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; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.util.ArrayList; +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.beans.factory.InitializingBean; +import org.springframework.cloud.config.Environment; +import org.springframework.cloud.config.PropertySource; +import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.core.io.UrlResource; +import org.springframework.util.StringUtils; + +/** + * @author Dave Syer + * @author Michael Prankl + */ +public abstract class AbstractSCMEnvironmentRepository implements EnvironmentRepository, + InitializingBean { + private static Log logger = LogFactory.getLog(AbstractSCMEnvironmentRepository.class); + + protected File basedir; + protected String uri; + protected ConfigurableEnvironment environment; + protected String username; + protected String password; + private String[] searchPaths = new String[0]; + + public AbstractSCMEnvironmentRepository(ConfigurableEnvironment environment) { + this.environment = environment; + this.basedir = createBaseDir(); + } + + private File createBaseDir() { + try { + final File basedir = Files.createTempDirectory("config-repo-").toFile(); + Runtime.getRuntime().addShutdownHook(new Thread() { + @Override + public void run() { + try { + FileUtils.delete(basedir, FileUtils.RECURSIVE); + } + catch (IOException e) { + logger.warn("Failed to delete temporary directory on exit: " + e); + } + } + }); + return basedir; + } + catch (IOException e) { + throw new IllegalStateException("Cannot create temp dir", e); + } + } + + public void setUri(String uri) { + while (uri.endsWith("/")) { + uri = uri.substring(0, uri.length() - 1); + } + this.uri = uri; + } + + public String getUri() { + return uri; + } + + public void setBasedir(File basedir) { + this.basedir = basedir.getAbsoluteFile(); + } + + public File getBasedir() { + return basedir; + } + + public void setSearchPaths(String... searchPaths) { + this.searchPaths = searchPaths; + } + + public String[] getSearchPaths() { + return 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; + } + + protected File getWorkingDirectory() { + if (uri.startsWith("file:")) { + try { + return new UrlResource(StringUtils.cleanPath(uri)).getFile(); + } + catch (Exception e) { + throw new IllegalStateException("Cannot convert uri to file: " + uri); + } + } + return basedir; + } + + protected String[] getSearchLocations(File dir) { + List locations = new ArrayList(); + locations.add(dir.toURI().toString()); + for (String path : searchPaths) { + File file = new File(getWorkingDirectory(), path); + if (file.isDirectory()) { + locations.add(file.toURI().toString()); + } + } + return locations.toArray(new String[0]); + } + + protected Environment clean(Environment value) { + Environment result = new Environment(value.getName(), value.getLabel()); + for (PropertySource source : value.getPropertySources()) { + String name = source.getName().replace( + getWorkingDirectory().toURI().toString(), ""); + if (name.contains(("classpath:/"))) { + continue; + } + if (environment.getPropertySources().contains(name)) { + continue; + } + name = name.replace("applicationConfig: [", ""); + name = uri + "/" + name.replace("]", ""); + result.add(new PropertySource(name, source.getSource())); + } + return result; + } + +} \ No newline at end of file diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/ConfigServerConfiguration.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/ConfigServerConfiguration.java index 6ad04134..635f1871 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/ConfigServerConfiguration.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/ConfigServerConfiguration.java @@ -1,56 +1,68 @@ -/* - * Copyright 2013-2014 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; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; -import org.springframework.core.env.ConfigurableEnvironment; - -/** - * @author Dave Syer - * - */ -@Configuration -@ConditionalOnMissingBean(EnvironmentRepository.class) -@EnableConfigurationProperties(ConfigServerProperties.class) -public class ConfigServerConfiguration { - - @Configuration - @Profile("native") - protected static class NativeRepositoryConfiguration { - @Bean - public SpringApplicationEnvironmentRepository EnvironmentRepository() { - return new SpringApplicationEnvironmentRepository(); - } - } - - @Configuration - @Profile("!native") - protected static class GitRepositoryConfiguration { - - @Autowired - private ConfigurableEnvironment environment; - - @Bean - public MultipleJGitEnvironmentRepository EnvironmentRepository() { - return new MultipleJGitEnvironmentRepository(environment); - } - } +/* + * Copyright 2013-2014 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; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; +import org.springframework.core.env.ConfigurableEnvironment; + +/** + * @author Dave Syer + * + */ +@Configuration +@ConditionalOnMissingBean(EnvironmentRepository.class) +@EnableConfigurationProperties(ConfigServerProperties.class) +public class ConfigServerConfiguration { + + @Configuration + @Profile("native") + protected static class NativeRepositoryConfiguration { + @Bean + public SpringApplicationEnvironmentRepository EnvironmentRepository() { + return new SpringApplicationEnvironmentRepository(); + } + } + + @Configuration + protected static class GitRepositoryConfiguration { + + @Autowired + private ConfigurableEnvironment environment; + + @Bean + public MultipleJGitEnvironmentRepository EnvironmentRepository() { + return new MultipleJGitEnvironmentRepository(environment); + } + } + + @Configuration + @Profile("subversion") + protected static class SvnRepositoryConfiguration { + @Autowired + private ConfigurableEnvironment environment; + + @Bean + public SVNKitEnvironmentRepository EnvironmentRepository() { + return new SVNKitEnvironmentRepository(environment); + } + } + } \ No newline at end of file diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/ConfigServerTestUtils.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/ConfigServerTestUtils.java index 40dab447..9b5e5228 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/ConfigServerTestUtils.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/ConfigServerTestUtils.java @@ -17,6 +17,7 @@ package org.springframework.cloud.config.server; import org.eclipse.jgit.util.FileUtils; import org.springframework.util.FileSystemUtils; +import org.springframework.util.StringUtils; import java.io.File; import java.io.IOException; @@ -35,7 +36,7 @@ public class ConfigServerTestUtils { } public static String prepareLocalRepo(String baseDir, String buildDir, String repoPath, - String checkoutDir) throws IOException { + String checkoutDir) throws IOException { buildDir = baseDir + buildDir; new File(buildDir).mkdirs(); if (!repoPath.startsWith("/")) { @@ -64,11 +65,23 @@ public class ConfigServerTestUtils { return "file:" + buildDir + repoPath; } + public static String prepareLocalSvnRepo(String sourceDir, String checkoutDir) throws Exception { + File sourceDirFile = new File(sourceDir); + sourceDirFile.mkdirs(); + File local = new File(checkoutDir); + if (local.exists()) { + FileUtils.delete(local, FileUtils.RECURSIVE); + } + local.mkdirs(); + FileSystemUtils.copyRecursively(sourceDirFile, local); + return StringUtils.cleanPath("file:///" + local.getAbsolutePath()); + + } + public static String getBaseDirectory(String potentialRoot) { return new File(potentialRoot).exists() ? potentialRoot + "/" : "./"; } - public static String copyLocalRepo(String path) throws IOException { File dest = new File("target/repos/" + path); FileSystemUtils.deleteRecursively(dest); diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/JGitEnvironmentRepository.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/JGitEnvironmentRepository.java index bea29da7..0c9e0750 100644 --- a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/JGitEnvironmentRepository.java +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/JGitEnvironmentRepository.java @@ -16,14 +16,12 @@ package org.springframework.cloud.config.server; -import static org.springframework.util.StringUtils.hasText; - import java.io.File; import java.io.IOException; -import java.nio.file.Files; -import java.util.ArrayList; import java.util.List; +import com.jcraft.jsch.Session; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.eclipse.jgit.api.CheckoutCommand; @@ -42,15 +40,13 @@ import org.eclipse.jgit.transport.OpenSshConfig.Host; import org.eclipse.jgit.transport.SshSessionFactory; import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider; import org.eclipse.jgit.util.FileUtils; -import org.springframework.beans.factory.InitializingBean; import org.springframework.cloud.config.Environment; -import org.springframework.cloud.config.PropertySource; import org.springframework.core.env.ConfigurableEnvironment; 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. @@ -58,93 +54,14 @@ import com.jcraft.jsch.Session; * @author Dave Syer * */ -public class JGitEnvironmentRepository implements EnvironmentRepository, InitializingBean { +public class JGitEnvironmentRepository extends AbstractSCMEnvironmentRepository { private static Log logger = LogFactory.getLog(JGitEnvironmentRepository.class); - private File basedir; - - private String uri; - - private ConfigurableEnvironment environment; - - private String username; - - private String password; - private boolean initialized; - private String[] searchPaths = new String[0]; - - @Override - public void afterPropertiesSet() throws Exception { - Assert.state(uri != null, "You need to configure a uri for the git repository"); - } - public JGitEnvironmentRepository(ConfigurableEnvironment environment) { - this.environment = environment; - try { - final File basedir = Files.createTempDirectory("config-repo-").toFile(); - Runtime.getRuntime().addShutdownHook(new Thread() { - @Override - public void run() { - try { - FileUtils.delete(basedir, FileUtils.RECURSIVE); - } - catch (IOException e) { - logger.warn("Failed to delete temporary directory on exit: " + e); - } - } - }); - this.basedir = basedir; - } - catch (IOException e) { - throw new IllegalStateException("Cannot create temp dir", e); - } - } - - - public void setUri(String uri) { - while (uri.endsWith("/")) { - uri = uri.substring(0, uri.length() - 1); - } - this.uri = uri; - } - - public String getUri() { - return uri; - } - - public void setBasedir(File basedir) { - this.basedir = basedir.getAbsoluteFile(); - } - - public File getBasedir() { - return basedir; - } - - public void setSearchPaths(String... searchPaths) { - this.searchPaths = searchPaths; - } - - public String[] getSearchPaths() { - return 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; + super(environment); } protected ConfigurableEnvironment getEnvironment() { @@ -181,6 +98,11 @@ public class JGitEnvironmentRepository implements EnvironmentRepository, Initial } } + @Override + public void afterPropertiesSet() throws Exception { + Assert.state(uri != null, "You need to configure a uri for the git repository"); + } + private synchronized Environment loadEnvironment(Git git, String application, String profile, String label) throws GitAPIException { SpringApplicationEnvironmentRepository environment = new SpringApplicationEnvironmentRepository(); @@ -193,30 +115,6 @@ public class JGitEnvironmentRepository implements EnvironmentRepository, Initial return clean(environment.findOne(application, profile, "")); } - private File getWorkingDirectory() { - if (uri.startsWith("file:")) { - try { - return new UrlResource(StringUtils.cleanPath(uri)).getFile(); - } - catch (Exception e) { - throw new IllegalStateException("Cannot convert uri to file: " + uri); - } - } - return basedir; - } - - private String[] getSearchLocations(File dir) { - List locations = new ArrayList(); - locations.add(dir.toURI().toString()); - for (String path : searchPaths) { - File file = new File(getWorkingDirectory(), path); - if (file.isDirectory()) { - locations.add(file.toURI().toString()); - } - } - return locations.toArray(new String[0]); - } - private Ref checkout(Git git, String label) throws GitAPIException { CheckoutCommand checkout = git.checkout(); if (shouldTrack(git, label)) { @@ -232,7 +130,7 @@ public class JGitEnvironmentRepository implements EnvironmentRepository, Initial private boolean shouldPull(Git git, Ref ref) throws GitAPIException { return git.status().call().isClean() && ref != null - && git.getRepository().getConfig().getString("remote", "origin", "url")!=null; + && git.getRepository().getConfig().getString("remote", "origin", "url") != null; } private boolean shouldTrack(Git git, String label) throws GitAPIException { @@ -251,8 +149,13 @@ public class JGitEnvironmentRepository implements EnvironmentRepository, Initial pull.call(); } catch (Exception e) { - logger.warn("Could not pull remote for " + label + " (current ref=" + ref - + "), remote: " + git.getRepository().getConfig().getString("remote", "origin", "url")); + logger.warn("Could not pull remote for " + + label + + " (current ref=" + + ref + + "), remote: " + + git.getRepository().getConfig() + .getString("remote", "origin", "url")); } } @@ -370,21 +273,4 @@ public class JGitEnvironmentRepository implements EnvironmentRepository, Initial } return false; } - - private Environment clean(Environment value) { - Environment result = new Environment(value.getName(), value.getLabel()); - for (PropertySource source : value.getPropertySources()) { - String name = source.getName().replace(getWorkingDirectory().toURI().toString(), ""); - if (name.contains(("classpath:/"))) { - continue; - } - if (environment.getPropertySources().contains(name)) { - continue; - } - name = name.replace("applicationConfig: [", ""); - name = uri + "/" + name.replace("]", ""); - result.add(new PropertySource(name, source.getSource())); - } - return result; - } } diff --git a/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/SVNKitEnvironmentRepository.java b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/SVNKitEnvironmentRepository.java new file mode 100644 index 00000000..00d40444 --- /dev/null +++ b/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/SVNKitEnvironmentRepository.java @@ -0,0 +1,127 @@ +/* + * Copyright 2013-2014 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; + +import java.io.File; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.cloud.config.Environment; +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; +import org.tmatesoft.svn.core.wc2.SvnCheckout; +import org.tmatesoft.svn.core.wc2.SvnOperationFactory; +import org.tmatesoft.svn.core.wc2.SvnTarget; +import org.tmatesoft.svn.core.wc2.SvnUpdate; + +import static org.springframework.util.StringUtils.hasText; + +/** + * Subversion-backed {@link EnvironmentRepository}. + * + * @author Michael Prankl + */ +@ConfigurationProperties("spring.cloud.config.server.svn") +public class SVNKitEnvironmentRepository extends AbstractSCMEnvironmentRepository { + + private static Log logger = LogFactory.getLog(SVNKitEnvironmentRepository.class); + + @Override + public Environment findOne(String application, String profile, String label) { + SvnOperationFactory svnOperationFactory = new SvnOperationFactory(); + if (hasText(getUsername())) { + svnOperationFactory + .setAuthenticationManager(new DefaultSVNAuthenticationManager(null, + false, getUsername(), getPassword())); + } + try { + if (new File(getWorkingDirectory(), ".svn").exists()) { + update(svnOperationFactory); + } + else { + checkout(svnOperationFactory); + } + return clean(loadEnvironment(application, profile, label)); + } + catch (SVNException e) { + throw new IllegalStateException("Cannot checkout repository", e); + } + finally { + svnOperationFactory.dispose(); + } + } + + private Environment loadEnvironment(String application, String profile, String label) { + final SpringApplicationEnvironmentRepository environmentRepository = new SpringApplicationEnvironmentRepository(); + environmentRepository.setSearchLocations(getSearchLocations(getSvnPath( + getWorkingDirectory(), label))); + return environmentRepository.findOne(application, profile, label); + } + + private void checkout(SvnOperationFactory svnOperationFactory) throws SVNException { + logger.debug("Checking out " + getUri() + " to: " + + getWorkingDirectory().getAbsolutePath()); + final SvnCheckout checkout = svnOperationFactory.createCheckout(); + checkout.setSource(SvnTarget.fromURL(SVNURL.parseURIEncoded(getUri()))); + checkout.setSingleTarget(SvnTarget.fromFile(getWorkingDirectory())); + checkout.run(); + } + + private void update(SvnOperationFactory svnOperationFactory) throws SVNException { + logger.debug("Repo already checked out - updating instead."); + final SvnUpdate update = svnOperationFactory.createUpdate(); + update.setSingleTarget(SvnTarget.fromFile(getWorkingDirectory())); + update.run(); + } + + @Override + public void afterPropertiesSet() throws Exception { + Assert.state( + getUri() != null, + "You need to configure a uri for the subversion repository (e.g. 'http://example.com/svn/')"); + resolveRelativeFileUri(); + } + + private void resolveRelativeFileUri() { + if (getUri().startsWith("file:///./")) { + String path = getUri().substring(8); + String absolutePath = new File(path).getAbsolutePath(); + setUri("file:///" + StringUtils.cleanPath(absolutePath)); + } + + } + + public SVNKitEnvironmentRepository(ConfigurableEnvironment environment) { + super(environment); + } + + @Override + protected File getWorkingDirectory() { + return this.basedir; + } + + private File getSvnPath(File workingDirectory, String label) { + // use label as path relative to repository root + return new File(workingDirectory, label); + } + +} diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/SVNKitEnvironmentRepositoryIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/SVNKitEnvironmentRepositoryIntegrationTests.java new file mode 100644 index 00000000..b908d58b --- /dev/null +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/SVNKitEnvironmentRepositoryIntegrationTests.java @@ -0,0 +1,125 @@ +/* + * Copyright 2013-2014 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; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +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; +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 static org.junit.Assert.assertEquals; + +/** + * @author Michael Prankl + * + */ +public class SVNKitEnvironmentRepositoryIntegrationTests { + + private ConfigurableApplicationContext context; + + private File workingDir; + + @Before + public void init() { + workingDir = new File("target/repos/svn-config-repo-update"); + if (workingDir.exists()) { + FileSystemUtils.deleteRecursively(workingDir); + } + } + + @After + public void close() { + if (context != null) { + context.close(); + } + } + + @Test + public void vanilla() throws Exception { + String uri = ConfigServerTestUtils.prepareLocalSvnRepo( + "src/test/resources/svn-config-repo", "target/config"); + context = new SpringApplicationBuilder(TestConfiguration.class).web(false) + .profiles("subversion") + .run("--spring.cloud.config.server.svn.uri=" + uri); + EnvironmentRepository repository = context.getBean(EnvironmentRepository.class); + repository.findOne("bar", "staging", "trunk"); + Environment environment = repository.findOne("bar", "staging", "trunk"); + assertEquals(2, environment.getPropertySources().size()); + } + + @Test + public void update() throws Exception { + String uri = ConfigServerTestUtils.prepareLocalSvnRepo( + "src/test/resources/svn-config-repo", "target/config"); + context = new SpringApplicationBuilder(TestConfiguration.class).web(false) + .profiles("subversion") + .run("--spring.cloud.config.server.svn.uri=" + uri); + EnvironmentRepository repository = context.getBean(EnvironmentRepository.class); + repository.findOne("bar", "staging", "trunk"); + Environment environment = repository.findOne("bar", "staging", "trunk"); + assertEquals("bar", environment.getPropertySources().get(0).getSource() + .get("foo")); + updateRepoForUpdate(uri); + environment = repository.findOne("bar", "staging", "trunk"); + assertEquals("foo", environment.getPropertySources().get(0).getSource() + .get("foo")); + } + + private void updateRepoForUpdate(String uri) throws SVNException, + FileNotFoundException, IOException { + SvnOperationFactory svnFactory = new SvnOperationFactory(); + final SvnCheckout checkout = svnFactory.createCheckout(); + checkout.setSource(SvnTarget.fromURL(SVNURL.parseURIEncoded(uri))); + checkout.setSingleTarget(SvnTarget.fromFile(workingDir)); + checkout.run(); + + // update bar.properties + File barProps = new File(workingDir, "trunk/bar.properties"); + StreamUtils.copy("foo: foo", Charset.defaultCharset(), new FileOutputStream( + barProps)); + // commit to repo + SvnCommit svnCommit = svnFactory.createCommit(); + svnCommit.setCommitMessage("update bar.properties"); + svnCommit.setSingleTarget(SvnTarget.fromFile(barProps)); + svnCommit.run(); + } + + @Configuration + @Import({ PropertyPlaceholderAutoConfiguration.class, ConfigServerConfiguration.class }) + protected static class TestConfiguration { + } + +} diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/SVNKitEnvironmentRepositoryTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/SVNKitEnvironmentRepositoryTests.java new file mode 100644 index 00000000..6c02aaba --- /dev/null +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/SVNKitEnvironmentRepositoryTests.java @@ -0,0 +1,94 @@ +/* + * Copyright 2013-2014 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; + +import java.io.File; + +import org.eclipse.jgit.util.FileUtils; +import org.junit.Before; +import org.junit.Test; +import org.springframework.cloud.config.Environment; +import org.springframework.core.env.StandardEnvironment; + +import static org.junit.Assert.assertTrue; + +import static org.junit.Assert.assertEquals; + +/** + * @author Michael Prankl + * + */ +public class SVNKitEnvironmentRepositoryTests { + + private StandardEnvironment environment = new StandardEnvironment(); + private SVNKitEnvironmentRepository repository = new SVNKitEnvironmentRepository( + environment); + + private File basedir = new File("target/config"); + + @Before + public void init() throws Exception { + String uri = ConfigServerTestUtils.prepareLocalSvnRepo( + "src/test/resources/svn-config-repo", "target/repos/svn-config-repo"); + repository.setUri(uri); + if (basedir.exists()) { + FileUtils.delete(basedir, FileUtils.RECURSIVE | FileUtils.RETRY); + } + } + + @Test + public void vanilla() { + Environment environment = repository.findOne("bar", "staging", "trunk"); + assertEquals(2, environment.getPropertySources().size()); + assertTrue(environment.getPropertySources().get(0).getName() + .contains("bar.properties")); + assertTrue(environment.getPropertySources().get(1).getName() + .contains("application.yml")); + } + + @Test + public void basedir() { + repository.setBasedir(basedir); + Environment environment = repository.findOne("bar", "staging", "trunk"); + assertEquals(2, environment.getPropertySources().size()); + assertTrue(environment.getPropertySources().get(0).getName() + .contains("bar.properties")); + assertTrue(environment.getPropertySources().get(1).getName() + .contains("application.yml")); + } + + @Test + public void branch() { + Environment environment = repository.findOne("bar", "staging", + "branches/demobranch"); + assertEquals(1, environment.getPropertySources().size()); + assertTrue(environment.getPropertySources().get(0).getName() + .contains("bar.properties")); + } + + @Test + public void vanilla_with_update() { + repository.findOne("bar", "staging", "trunk"); + Environment environment = repository.findOne("bar", "staging", "trunk"); + assertEquals(2, environment.getPropertySources().size()); + assertTrue(environment.getPropertySources().get(0).getName() + .contains("bar.properties")); + assertTrue(environment.getPropertySources().get(1).getName() + .contains("application.yml")); + } + +} diff --git a/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/SubversionConfigServerIntegrationTests.java b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/SubversionConfigServerIntegrationTests.java new file mode 100644 index 00000000..8dcb4e23 --- /dev/null +++ b/spring-cloud-config-server/src/test/java/org/springframework/cloud/config/server/SubversionConfigServerIntegrationTests.java @@ -0,0 +1,45 @@ +package org.springframework.cloud.config.server; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +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; +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; + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(classes = ConfigServerApplication.class) +@IntegrationTest({ "server.port:0", "spring.config.name:configserver", + "spring.cloud.config.server.svn.uri:file:///./target/repos/svn-config-repo" }) +@WebAppConfiguration +@ActiveProfiles("subversion") +public class SubversionConfigServerIntegrationTests { + + @Value("${local.server.port}") + private int port; + + @BeforeClass + public static void init() throws Exception { + 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); + assertFalse(environment.getPropertySources().isEmpty()); + assertEquals("overrides", environment.getPropertySources().get(0).getName()); + assertEquals("{spring.cloud.config.enabled=true}", environment + .getPropertySources().get(0).getSource().toString()); + } + +} diff --git a/spring-cloud-config-server/src/test/resources/configserver-subversion.yml b/spring-cloud-config-server/src/test/resources/configserver-subversion.yml new file mode 100644 index 00000000..babc3d9b --- /dev/null +++ b/spring-cloud-config-server/src/test/resources/configserver-subversion.yml @@ -0,0 +1,10 @@ +spring: + cloud: + config: + server: + defaultLabel: trunk + overrides: + spring: + cloud: + config: + enabled: true \ No newline at end of file diff --git a/spring-cloud-config-server/src/test/resources/svn-config-repo/.svn/entries b/spring-cloud-config-server/src/test/resources/svn-config-repo/.svn/entries new file mode 100644 index 00000000..3cacc0b9 --- /dev/null +++ b/spring-cloud-config-server/src/test/resources/svn-config-repo/.svn/entries @@ -0,0 +1 @@ +12 \ No newline at end of file diff --git a/spring-cloud-config-server/src/test/resources/svn-config-repo/.svn/format b/spring-cloud-config-server/src/test/resources/svn-config-repo/.svn/format new file mode 100644 index 00000000..3cacc0b9 --- /dev/null +++ b/spring-cloud-config-server/src/test/resources/svn-config-repo/.svn/format @@ -0,0 +1 @@ +12 \ No newline at end of file diff --git a/spring-cloud-config-server/src/test/resources/svn-config-repo/.svn/pristine/4b/4ba5f6a617dee5e5e8d382f6bbc07531d5f968c4.svn-base b/spring-cloud-config-server/src/test/resources/svn-config-repo/.svn/pristine/4b/4ba5f6a617dee5e5e8d382f6bbc07531d5f968c4.svn-base new file mode 100644 index 00000000..d6acc405 --- /dev/null +++ b/spring-cloud-config-server/src/test/resources/svn-config-repo/.svn/pristine/4b/4ba5f6a617dee5e5e8d382f6bbc07531d5f968c4.svn-base @@ -0,0 +1,3 @@ +info: + foo: bar +raw: true diff --git a/spring-cloud-config-server/src/test/resources/svn-config-repo/.svn/pristine/cb/cbddbad2c491aab236e1025ad5b9ace129ea5667.svn-base b/spring-cloud-config-server/src/test/resources/svn-config-repo/.svn/pristine/cb/cbddbad2c491aab236e1025ad5b9ace129ea5667.svn-base new file mode 100644 index 00000000..7daacd5d --- /dev/null +++ b/spring-cloud-config-server/src/test/resources/svn-config-repo/.svn/pristine/cb/cbddbad2c491aab236e1025ad5b9ace129ea5667.svn-base @@ -0,0 +1 @@ +foo: bar \ No newline at end of file diff --git a/spring-cloud-config-server/src/test/resources/svn-config-repo/.svn/wc.db b/spring-cloud-config-server/src/test/resources/svn-config-repo/.svn/wc.db new file mode 100644 index 00000000..654ccf58 Binary files /dev/null and b/spring-cloud-config-server/src/test/resources/svn-config-repo/.svn/wc.db differ diff --git a/spring-cloud-config-server/src/test/resources/svn-config-repo/README.txt b/spring-cloud-config-server/src/test/resources/svn-config-repo/README.txt new file mode 100644 index 00000000..4deaac3e --- /dev/null +++ b/spring-cloud-config-server/src/test/resources/svn-config-repo/README.txt @@ -0,0 +1,5 @@ +This is a Subversion repository; use the 'svnadmin' and 'svnlook' +tools to examine it. Do not add, delete, or modify files here +unless you know how to avoid corrupting the repository. + +Visit http://subversion.apache.org/ for more information. diff --git a/spring-cloud-config-server/src/test/resources/svn-config-repo/conf/authz b/spring-cloud-config-server/src/test/resources/svn-config-repo/conf/authz new file mode 100644 index 00000000..90d88388 --- /dev/null +++ b/spring-cloud-config-server/src/test/resources/svn-config-repo/conf/authz @@ -0,0 +1,32 @@ +### This file is an example authorization file for svnserve. +### Its format is identical to that of mod_authz_svn authorization +### files. +### As shown below each section defines authorizations for the path and +### (optional) repository specified by the section name. +### The authorizations follow. An authorization line can refer to: +### - a single user, +### - a group of users defined in a special [groups] section, +### - an alias defined in a special [aliases] section, +### - all authenticated users, using the '$authenticated' token, +### - only anonymous users, using the '$anonymous' token, +### - anyone, using the '*' wildcard. +### +### A match can be inverted by prefixing the rule with '~'. Rules can +### grant read ('r') access, read-write ('rw') access, or no access +### (''). + +[aliases] +# joe = /C=XZ/ST=Dessert/L=Snake City/O=Snake Oil, Ltd./OU=Research Institute/CN=Joe Average + +[groups] +# harry_and_sally = harry,sally +# harry_sally_and_joe = harry,sally,&joe + +# [/foo/bar] +# harry = rw +# &joe = r +# * = + +# [repository:/baz/fuz] +# @harry_and_sally = rw +# * = r diff --git a/spring-cloud-config-server/src/test/resources/svn-config-repo/conf/hooks-env.tmpl b/spring-cloud-config-server/src/test/resources/svn-config-repo/conf/hooks-env.tmpl new file mode 100644 index 00000000..378694c0 --- /dev/null +++ b/spring-cloud-config-server/src/test/resources/svn-config-repo/conf/hooks-env.tmpl @@ -0,0 +1,19 @@ +### This file is an example hook script environment configuration file. +### Hook scripts run in an empty environment by default. +### As shown below each section defines environment variables for a +### particular hook script. The [default] section defines environment +### variables for all hook scripts, unless overridden by a hook-specific +### section. + +### This example configures a UTF-8 locale for all hook scripts, so that +### special characters, such as umlauts, may be printed to stderr. +### If UTF-8 is used with a mod_dav_svn server, the SVNUseUTF8 option must +### also be set to 'yes' in httpd.conf. +### With svnserve, the LANG environment variable of the svnserve process +### must be set to the same value as given here. +[default] +LANG = en_US.UTF-8 + +### This sets the PATH environment variable for the pre-commit hook. +[pre-commit] +PATH = /usr/local/bin:/usr/bin:/usr/sbin diff --git a/spring-cloud-config-server/src/test/resources/svn-config-repo/conf/passwd b/spring-cloud-config-server/src/test/resources/svn-config-repo/conf/passwd new file mode 100644 index 00000000..d22bafc5 --- /dev/null +++ b/spring-cloud-config-server/src/test/resources/svn-config-repo/conf/passwd @@ -0,0 +1,8 @@ +### This file is an example password file for svnserve. +### Its format is similar to that of svnserve.conf. As shown in the +### example below it contains one section labelled [users]. +### The name and password for each user follow, one account per line. + +[users] +# harry = harryssecret +# sally = sallyssecret diff --git a/spring-cloud-config-server/src/test/resources/svn-config-repo/conf/svnserve.conf b/spring-cloud-config-server/src/test/resources/svn-config-repo/conf/svnserve.conf new file mode 100644 index 00000000..7d49c385 --- /dev/null +++ b/spring-cloud-config-server/src/test/resources/svn-config-repo/conf/svnserve.conf @@ -0,0 +1,76 @@ +### This file controls the configuration of the svnserve daemon, if you +### use it to allow access to this repository. (If you only allow +### access through http: and/or file: URLs, then this file is +### irrelevant.) + +### Visit http://subversion.apache.org/ for more information. + +[general] +### The anon-access and auth-access options control access to the +### repository for unauthenticated (a.k.a. anonymous) users and +### authenticated users, respectively. +### Valid values are "write", "read", and "none". +### Setting the value to "none" prohibits both reading and writing; +### "read" allows read-only access, and "write" allows complete +### read/write access to the repository. +### The sample settings below are the defaults and specify that anonymous +### users have read-only access to the repository, while authenticated +### users have read and write access to the repository. +# anon-access = read +# auth-access = write +### The password-db option controls the location of the password +### database file. Unless you specify a path starting with a /, +### the file's location is relative to the directory containing +### this configuration file. +### If SASL is enabled (see below), this file will NOT be used. +### Uncomment the line below to use the default password file. +# password-db = passwd +### The authz-db option controls the location of the authorization +### rules for path-based access control. Unless you specify a path +### starting with a /, the file's location is relative to the +### directory containing this file. The specified path may be a +### repository relative URL (^/) or an absolute file:// URL to a text +### file in a Subversion repository. If you don't specify an authz-db, +### no path-based access control is done. +### Uncomment the line below to use the default authorization file. +# authz-db = authz +### The groups-db option controls the location of the groups file. +### Unless you specify a path starting with a /, the file's location is +### relative to the directory containing this file. The specified path +### may be a repository relative URL (^/) or an absolute file:// URL to a +### text file in a Subversion repository. +# groups-db = groups +### This option specifies the authentication realm of the repository. +### If two repositories have the same authentication realm, they should +### have the same password database, and vice versa. The default realm +### is repository's uuid. +# realm = My First Repository +### The force-username-case option causes svnserve to case-normalize +### usernames before comparing them against the authorization rules in the +### authz-db file configured above. Valid values are "upper" (to upper- +### case the usernames), "lower" (to lowercase the usernames), and +### "none" (to compare usernames as-is without case conversion, which +### is the default behavior). +# force-username-case = none +### The hooks-env options specifies a path to the hook script environment +### configuration file. This option overrides the per-repository default +### and can be used to configure the hook script environment for multiple +### repositories in a single file, if an absolute path is specified. +### Unless you specify an absolute path, the file's location is relative +### to the directory containing this file. +# hooks-env = hooks-env + +[sasl] +### This option specifies whether you want to use the Cyrus SASL +### library for authentication. Default is false. +### This section will be ignored if svnserve is not built with Cyrus +### SASL support; to check, run 'svnserve --version' and look for a line +### reading 'Cyrus SASL authentication is available.' +# use-sasl = true +### These options specify the desired strength of the security layer +### that you want SASL to provide. 0 means no encryption, 1 means +### integrity-checking only, values larger than 1 are correlated +### to the effective key length for encryption (e.g. 128 means 128-bit +### encryption). The values below are the defaults. +# min-encryption = 0 +# max-encryption = 256 diff --git a/spring-cloud-config-server/src/test/resources/svn-config-repo/db/current b/spring-cloud-config-server/src/test/resources/svn-config-repo/db/current new file mode 100644 index 00000000..0cfbf088 --- /dev/null +++ b/spring-cloud-config-server/src/test/resources/svn-config-repo/db/current @@ -0,0 +1 @@ +2 diff --git a/spring-cloud-config-server/src/test/resources/svn-config-repo/db/format b/spring-cloud-config-server/src/test/resources/svn-config-repo/db/format new file mode 100644 index 00000000..3fc1fa47 --- /dev/null +++ b/spring-cloud-config-server/src/test/resources/svn-config-repo/db/format @@ -0,0 +1,2 @@ +6 +layout sharded 1000 diff --git a/spring-cloud-config-server/src/test/resources/svn-config-repo/db/fs-type b/spring-cloud-config-server/src/test/resources/svn-config-repo/db/fs-type new file mode 100644 index 00000000..4fdd9531 --- /dev/null +++ b/spring-cloud-config-server/src/test/resources/svn-config-repo/db/fs-type @@ -0,0 +1 @@ +fsfs diff --git a/spring-cloud-config-server/src/test/resources/svn-config-repo/db/fsfs.conf b/spring-cloud-config-server/src/test/resources/svn-config-repo/db/fsfs.conf new file mode 100644 index 00000000..9795d8fe --- /dev/null +++ b/spring-cloud-config-server/src/test/resources/svn-config-repo/db/fsfs.conf @@ -0,0 +1,125 @@ +### This file controls the configuration of the FSFS filesystem. + +[memcached-servers] +### These options name memcached servers used to cache internal FSFS +### data. See http://www.danga.com/memcached/ for more information on +### memcached. To use memcached with FSFS, run one or more memcached +### servers, and specify each of them as an option like so: +# first-server = 127.0.0.1:11211 +# remote-memcached = mymemcached.corp.example.com:11212 +### The option name is ignored; the value is of the form HOST:PORT. +### memcached servers can be shared between multiple repositories; +### however, if you do this, you *must* ensure that repositories have +### distinct UUIDs and paths, or else cached data from one repository +### might be used by another accidentally. Note also that memcached has +### no authentication for reads or writes, so you must ensure that your +### memcached servers are only accessible by trusted users. + +[caches] +### When a cache-related error occurs, normally Subversion ignores it +### and continues, logging an error if the server is appropriately +### configured (and ignoring it with file:// access). To make +### Subversion never ignore cache errors, uncomment this line. +# fail-stop = true + +[rep-sharing] +### To conserve space, the filesystem can optionally avoid storing +### duplicate representations. This comes at a slight cost in +### performance, as maintaining a database of shared representations can +### increase commit times. The space savings are dependent upon the size +### of the repository, the number of objects it contains and the amount of +### duplication between them, usually a function of the branching and +### merging process. +### +### The following parameter enables rep-sharing in the repository. It can +### be switched on and off at will, but for best space-saving results +### should be enabled consistently over the life of the repository. +### 'svnadmin verify' will check the rep-cache regardless of this setting. +### rep-sharing is enabled by default. +# enable-rep-sharing = true + +[deltification] +### To conserve space, the filesystem stores data as differences against +### existing representations. This comes at a slight cost in performance, +### as calculating differences can increase commit times. Reading data +### will also create higher CPU load and the data will be fragmented. +### Since deltification tends to save significant amounts of disk space, +### the overall I/O load can actually be lower. +### +### The options in this section allow for tuning the deltification +### strategy. Their effects on data size and server performance may vary +### from one repository to another. Versions prior to 1.8 will ignore +### this section. +### +### The following parameter enables deltification for directories. It can +### be switched on and off at will, but for best space-saving results +### should be enabled consistently over the life of the repository. +### Repositories containing large directories will benefit greatly. +### In rarely read repositories, the I/O overhead may be significant as +### cache hit rates will most likely be low +### directory deltification is disabled by default. +# enable-dir-deltification = false +### +### The following parameter enables deltification for properties on files +### and directories. Overall, this is a minor tuning option but can save +### some disk space if you merge frequently or frequently change node +### properties. You should not activate this if rep-sharing has been +### disabled because this may result in a net increase in repository size. +### property deltification is disabled by default. +# enable-props-deltification = false +### +### During commit, the server may need to walk the whole change history of +### of a given node to find a suitable deltification base. This linear +### process can impact commit times, svnadmin load and similar operations. +### This setting limits the depth of the deltification history. If the +### threshold has been reached, the node will be stored as fulltext and a +### new deltification history begins. +### Note, this is unrelated to svn log. +### Very large values rarely provide significant additional savings but +### can impact performance greatly - in particular if directory +### deltification has been activated. Very small values may be useful in +### repositories that are dominated by large, changing binaries. +### Should be a power of two minus 1. A value of 0 will effectively +### disable deltification. +### For 1.8, the default value is 1023; earlier versions have no limit. +# max-deltification-walk = 1023 +### +### The skip-delta scheme used by FSFS tends to repeatably store redundant +### delta information where a simple delta against the latest version is +### often smaller. By default, 1.8+ will therefore use skip deltas only +### after the linear chain of deltas has grown beyond the threshold +### specified by this setting. +### Values up to 64 can result in some reduction in repository size for +### the cost of quickly increasing I/O and CPU costs. Similarly, smaller +### numbers can reduce those costs at the cost of more disk space. For +### rarely read repositories or those containing larger binaries, this may +### present a better trade-off. +### Should be a power of two. A value of 1 or smaller will cause the +### exclusive use of skip-deltas (as in pre-1.8). +### For 1.8, the default value is 16; earlier versions use 1. +# max-linear-deltification = 16 + +[packed-revprops] +### This parameter controls the size (in kBytes) of packed revprop files. +### Revprops of consecutive revisions will be concatenated into a single +### file up to but not exceeding the threshold given here. However, each +### pack file may be much smaller and revprops of a single revision may be +### much larger than the limit set here. The threshold will be applied +### before optional compression takes place. +### Large values will reduce disk space usage at the expense of increased +### latency and CPU usage reading and changing individual revprops. They +### become an advantage when revprop caching has been enabled because a +### lot of data can be read in one go. Values smaller than 4 kByte will +### not improve latency any further and quickly render revprop packing +### ineffective. +### revprop-pack-size is 64 kBytes by default for non-compressed revprop +### pack files and 256 kBytes when compression has been enabled. +# revprop-pack-size = 64 +### +### To save disk space, packed revprop files may be compressed. Standard +### revprops tend to allow for very effective compression. Reading and +### even more so writing, become significantly more CPU intensive. With +### revprop caching enabled, the overhead can be offset by reduced I/O +### unless you often modify revprops after packing. +### Compressing packed revprops is disabled by default. +# compress-packed-revprops = false diff --git a/spring-cloud-config-server/src/test/resources/svn-config-repo/db/min-unpacked-rev b/spring-cloud-config-server/src/test/resources/svn-config-repo/db/min-unpacked-rev new file mode 100644 index 00000000..573541ac --- /dev/null +++ b/spring-cloud-config-server/src/test/resources/svn-config-repo/db/min-unpacked-rev @@ -0,0 +1 @@ +0 diff --git a/spring-cloud-config-server/src/test/resources/svn-config-repo/db/rep-cache.db b/spring-cloud-config-server/src/test/resources/svn-config-repo/db/rep-cache.db new file mode 100644 index 00000000..8e67f0c5 Binary files /dev/null and b/spring-cloud-config-server/src/test/resources/svn-config-repo/db/rep-cache.db differ diff --git a/spring-cloud-config-server/src/test/resources/svn-config-repo/db/revprops/0/0 b/spring-cloud-config-server/src/test/resources/svn-config-repo/db/revprops/0/0 new file mode 100644 index 00000000..7c70b065 --- /dev/null +++ b/spring-cloud-config-server/src/test/resources/svn-config-repo/db/revprops/0/0 @@ -0,0 +1,5 @@ +K 8 +svn:date +V 27 +2015-02-01T16:16:43.445604Z +END diff --git a/spring-cloud-config-server/src/test/resources/svn-config-repo/db/revprops/0/1 b/spring-cloud-config-server/src/test/resources/svn-config-repo/db/revprops/0/1 new file mode 100644 index 00000000..874508d4 --- /dev/null +++ b/spring-cloud-config-server/src/test/resources/svn-config-repo/db/revprops/0/1 @@ -0,0 +1,13 @@ +K 10 +svn:author +V 7 +Michael +K 8 +svn:date +V 27 +2015-02-01T16:21:33.720207Z +K 7 +svn:log +V 14 +add properties +END diff --git a/spring-cloud-config-server/src/test/resources/svn-config-repo/db/revprops/0/2 b/spring-cloud-config-server/src/test/resources/svn-config-repo/db/revprops/0/2 new file mode 100644 index 00000000..e9314ef4 --- /dev/null +++ b/spring-cloud-config-server/src/test/resources/svn-config-repo/db/revprops/0/2 @@ -0,0 +1,13 @@ +K 10 +svn:author +V 7 +Michael +K 8 +svn:date +V 27 +2015-02-01T20:51:56.036661Z +K 7 +svn:log +V 0 + +END diff --git a/spring-cloud-config-server/src/test/resources/svn-config-repo/db/revs/0/0 b/spring-cloud-config-server/src/test/resources/svn-config-repo/db/revs/0/0 new file mode 100644 index 00000000..10f5c45f --- /dev/null +++ b/spring-cloud-config-server/src/test/resources/svn-config-repo/db/revs/0/0 @@ -0,0 +1,11 @@ +PLAIN +END +ENDREP +id: 0.0.r0/17 +type: dir +count: 0 +text: 0 0 4 4 2d2977d1c96f487abe4a1e202dd03b4e +cpath: / + + +17 107 diff --git a/spring-cloud-config-server/src/test/resources/svn-config-repo/db/revs/0/1 b/spring-cloud-config-server/src/test/resources/svn-config-repo/db/revs/0/1 new file mode 100644 index 00000000..851f2a5a Binary files /dev/null and b/spring-cloud-config-server/src/test/resources/svn-config-repo/db/revs/0/1 differ diff --git a/spring-cloud-config-server/src/test/resources/svn-config-repo/db/revs/0/2 b/spring-cloud-config-server/src/test/resources/svn-config-repo/db/revs/0/2 new file mode 100644 index 00000000..0f9ba01d --- /dev/null +++ b/spring-cloud-config-server/src/test/resources/svn-config-repo/db/revs/0/2 @@ -0,0 +1,104 @@ +id: 4-2.0.r2/0 +type: file +count: 0 +text: 1 0 20 8 e1dcf98b4c823827be0a0524052ae95a cbddbad2c491aab236e1025ad5b9ace129ea5667 1-1/_b +cpath: /branches/demobranch/bar.properties +copyroot: 0 / + +PLAIN +K 14 +bar.properties +V 15 +file 4-2.0.r2/0 +END +ENDREP +id: 2-2.0.r2/247 +type: dir +count: 0 +text: 2 189 45 0 b81dd010d3e089eb3fcd04ca3a23c7a0 +cpath: /branches/demobranch +copyroot: 0 / + +PLAIN +K 10 +demobranch +V 16 +dir 2-2.0.r2/247 +END +ENDREP +id: 1-2.0.r2/431 +type: dir +count: 0 +text: 2 376 42 0 1b635f8d96875ae074d7cc4052ba7888 +cpath: /branches +copyroot: 0 / + +id: 7-2.0.r2/549 +type: file +count: 0 +text: 1 33 40 28 13bec2d9ad81465f3114cbae20b6c7da 4ba5f6a617dee5e5e8d382f6bbc07531d5f968c4 1-1/_c +cpath: /trunk/application.yml +copyroot: 0 / + +id: 9-2.0.r2/729 +type: file +count: 0 +text: 1 0 20 8 e1dcf98b4c823827be0a0524052ae95a cbddbad2c491aab236e1025ad5b9ace129ea5667 1-1/_a +cpath: /trunk/bar.properties +copyroot: 0 / + +PLAIN +K 15 +application.yml +V 17 +file 7-2.0.r2/549 +K 14 +bar.properties +V 17 +file 9-2.0.r2/729 +END +ENDREP +id: 6-2.0.r2/1010 +type: dir +count: 0 +text: 2 906 91 0 0dc6340175a4fc841f8f8ddb9ab4f826 +cpath: /trunk +copyroot: 0 / + +PLAIN +K 8 +branches +V 16 +dir 1-2.0.r2/431 +K 5 +trunk +V 17 +dir 6-2.0.r2/1010 +END +ENDREP +id: 0.0.r2/1211 +type: dir +pred: 0.0.r1/533 +count: 2 +text: 2 1126 72 0 a8927d430ec09518c534d157c6e49580 +cpath: / +copyroot: 0 / + +0-1.0.r1/86 delete-file false false /application.yml + +2-1.0.r1/259 delete-file false false /bar.properties + +_1.0.t1-1 add-dir false false /branches + +_2.0.t1-1 add-dir false false /branches/demobranch + +_4.0.t1-1 add-file true false /branches/demobranch/bar.properties + +_6.0.t1-1 add-dir false false /trunk + +_7.0.t1-1 add-file true false /trunk/application.yml + +_9.0.t1-1 add-file true false /trunk/bar.properties + + +1211 1338 diff --git a/spring-cloud-config-server/src/test/resources/svn-config-repo/db/txn-current b/spring-cloud-config-server/src/test/resources/svn-config-repo/db/txn-current new file mode 100644 index 00000000..0cfbf088 --- /dev/null +++ b/spring-cloud-config-server/src/test/resources/svn-config-repo/db/txn-current @@ -0,0 +1 @@ +2 diff --git a/spring-cloud-config-server/src/test/resources/svn-config-repo/db/txn-current-lock b/spring-cloud-config-server/src/test/resources/svn-config-repo/db/txn-current-lock new file mode 100644 index 00000000..e69de29b diff --git a/spring-cloud-config-server/src/test/resources/svn-config-repo/db/uuid b/spring-cloud-config-server/src/test/resources/svn-config-repo/db/uuid new file mode 100644 index 00000000..e9b8cfbb --- /dev/null +++ b/spring-cloud-config-server/src/test/resources/svn-config-repo/db/uuid @@ -0,0 +1 @@ +f6a79cb7-4270-194d-8be4-17f24dfac039 diff --git a/spring-cloud-config-server/src/test/resources/svn-config-repo/db/write-lock b/spring-cloud-config-server/src/test/resources/svn-config-repo/db/write-lock new file mode 100644 index 00000000..e69de29b diff --git a/spring-cloud-config-server/src/test/resources/svn-config-repo/format b/spring-cloud-config-server/src/test/resources/svn-config-repo/format new file mode 100644 index 00000000..7ed6ff82 --- /dev/null +++ b/spring-cloud-config-server/src/test/resources/svn-config-repo/format @@ -0,0 +1 @@ +5 diff --git a/spring-cloud-config-server/src/test/resources/svn-config-repo/hooks/post-commit.tmpl b/spring-cloud-config-server/src/test/resources/svn-config-repo/hooks/post-commit.tmpl new file mode 100644 index 00000000..c3192cdf --- /dev/null +++ b/spring-cloud-config-server/src/test/resources/svn-config-repo/hooks/post-commit.tmpl @@ -0,0 +1,52 @@ +#!/bin/sh + +# POST-COMMIT HOOK +# +# The post-commit hook is invoked after a commit. Subversion runs +# this hook by invoking a program (script, executable, binary, etc.) +# named 'post-commit' (for which this file is a template) with the +# following ordered arguments: +# +# [1] REPOS-PATH (the path to this repository) +# [2] REV (the number of the revision just committed) +# [3] TXN-NAME (the name of the transaction that has become REV) +# +# The default working directory for the invocation is undefined, so +# the program should set one explicitly if it cares. +# +# Because the commit has already completed and cannot be undone, +# the exit code of the hook program is ignored. The hook program +# can use the 'svnlook' utility to help it examine the +# newly-committed tree. +# +# On a Unix system, the normal procedure is to have 'post-commit' +# invoke other programs to do the real work, though it may do the +# work itself too. +# +# Note that 'post-commit' must be executable by the user(s) who will +# invoke it (typically the user httpd runs as), and that user must +# have filesystem-level permission to access the repository. +# +# On a Windows system, you should name the hook program +# 'post-commit.bat' or 'post-commit.exe', +# but the basic idea is the same. +# +# The hook program typically does not inherit the environment of +# its parent process. For example, a common problem is for the +# PATH environment variable to not be set to its usual value, so +# that subprograms fail to launch unless invoked via absolute path. +# If you're having unexpected problems with a hook program, the +# culprit may be unusual (or missing) environment variables. +# +# Here is an example hook script, for a Unix /bin/sh interpreter. +# For more examples and pre-written hooks, see those in +# the Subversion repository at +# http://svn.apache.org/repos/asf/subversion/trunk/tools/hook-scripts/ and +# http://svn.apache.org/repos/asf/subversion/trunk/contrib/hook-scripts/ + + +REPOS="$1" +REV="$2" +TXN_NAME="$3" + +mailer.py commit "$REPOS" "$REV" /path/to/mailer.conf diff --git a/spring-cloud-config-server/src/test/resources/svn-config-repo/hooks/post-lock.tmpl b/spring-cloud-config-server/src/test/resources/svn-config-repo/hooks/post-lock.tmpl new file mode 100644 index 00000000..65a7d40e --- /dev/null +++ b/spring-cloud-config-server/src/test/resources/svn-config-repo/hooks/post-lock.tmpl @@ -0,0 +1,44 @@ +#!/bin/sh + +# POST-LOCK HOOK +# +# The post-lock hook is run after a path is locked. Subversion runs +# this hook by invoking a program (script, executable, binary, etc.) +# named 'post-lock' (for which this file is a template) with the +# following ordered arguments: +# +# [1] REPOS-PATH (the path to this repository) +# [2] USER (the user who created the lock) +# +# The paths that were just locked are passed to the hook via STDIN (as +# of Subversion 1.2, only one path is passed per invocation, but the +# plan is to pass all locked paths at once, so the hook program +# should be written accordingly). +# +# The default working directory for the invocation is undefined, so +# the program should set one explicitly if it cares. +# +# Because the lock has already been created and cannot be undone, +# the exit code of the hook program is ignored. The hook program +# can use the 'svnlook' utility to help it examine the +# newly-created lock. +# +# On a Unix system, the normal procedure is to have 'post-lock' +# invoke other programs to do the real work, though it may do the +# work itself too. +# +# Note that 'post-lock' must be executable by the user(s) who will +# invoke it (typically the user httpd runs as), and that user must +# have filesystem-level permission to access the repository. +# +# On a Windows system, you should name the hook program +# 'post-lock.bat' or 'post-lock.exe', +# but the basic idea is the same. +# +# Here is an example hook script, for a Unix /bin/sh interpreter: + +REPOS="$1" +USER="$2" + +# Send email to interested parties, let them know a lock was created: +mailer.py lock "$REPOS" "$USER" /path/to/mailer.conf diff --git a/spring-cloud-config-server/src/test/resources/svn-config-repo/hooks/post-revprop-change.tmpl b/spring-cloud-config-server/src/test/resources/svn-config-repo/hooks/post-revprop-change.tmpl new file mode 100644 index 00000000..be2b54a5 --- /dev/null +++ b/spring-cloud-config-server/src/test/resources/svn-config-repo/hooks/post-revprop-change.tmpl @@ -0,0 +1,56 @@ +#!/bin/sh + +# POST-REVPROP-CHANGE HOOK +# +# The post-revprop-change hook is invoked after a revision property +# has been added, modified or deleted. Subversion runs this hook by +# invoking a program (script, executable, binary, etc.) named +# 'post-revprop-change' (for which this file is a template), with the +# following ordered arguments: +# +# [1] REPOS-PATH (the path to this repository) +# [2] REV (the revision that was tweaked) +# [3] USER (the username of the person tweaking the property) +# [4] PROPNAME (the property that was changed) +# [5] ACTION (the property was 'A'dded, 'M'odified, or 'D'eleted) +# +# [STDIN] PROPVAL ** the old property value is passed via STDIN. +# +# Because the propchange has already completed and cannot be undone, +# the exit code of the hook program is ignored. The hook program +# can use the 'svnlook' utility to help it examine the +# new property value. +# +# On a Unix system, the normal procedure is to have 'post-revprop-change' +# invoke other programs to do the real work, though it may do the +# work itself too. +# +# Note that 'post-revprop-change' must be executable by the user(s) who will +# invoke it (typically the user httpd runs as), and that user must +# have filesystem-level permission to access the repository. +# +# On a Windows system, you should name the hook program +# 'post-revprop-change.bat' or 'post-revprop-change.exe', +# but the basic idea is the same. +# +# The hook program typically does not inherit the environment of +# its parent process. For example, a common problem is for the +# PATH environment variable to not be set to its usual value, so +# that subprograms fail to launch unless invoked via absolute path. +# If you're having unexpected problems with a hook program, the +# culprit may be unusual (or missing) environment variables. +# +# Here is an example hook script, for a Unix /bin/sh interpreter. +# For more examples and pre-written hooks, see those in +# the Subversion repository at +# http://svn.apache.org/repos/asf/subversion/trunk/tools/hook-scripts/ and +# http://svn.apache.org/repos/asf/subversion/trunk/contrib/hook-scripts/ + + +REPOS="$1" +REV="$2" +USER="$3" +PROPNAME="$4" +ACTION="$5" + +mailer.py propchange2 "$REPOS" "$REV" "$USER" "$PROPNAME" "$ACTION" /path/to/mailer.conf diff --git a/spring-cloud-config-server/src/test/resources/svn-config-repo/hooks/post-unlock.tmpl b/spring-cloud-config-server/src/test/resources/svn-config-repo/hooks/post-unlock.tmpl new file mode 100644 index 00000000..5821be83 --- /dev/null +++ b/spring-cloud-config-server/src/test/resources/svn-config-repo/hooks/post-unlock.tmpl @@ -0,0 +1,42 @@ +#!/bin/sh + +# POST-UNLOCK HOOK +# +# The post-unlock hook runs after a path is unlocked. Subversion runs +# this hook by invoking a program (script, executable, binary, etc.) +# named 'post-unlock' (for which this file is a template) with the +# following ordered arguments: +# +# [1] REPOS-PATH (the path to this repository) +# [2] USER (the user who destroyed the lock) +# +# The paths that were just unlocked are passed to the hook via STDIN +# (as of Subversion 1.2, only one path is passed per invocation, but +# the plan is to pass all unlocked paths at once, so the hook program +# should be written accordingly). +# +# The default working directory for the invocation is undefined, so +# the program should set one explicitly if it cares. +# +# Because the lock has already been destroyed and cannot be undone, +# the exit code of the hook program is ignored. +# +# On a Unix system, the normal procedure is to have 'post-unlock' +# invoke other programs to do the real work, though it may do the +# work itself too. +# +# Note that 'post-unlock' must be executable by the user(s) who will +# invoke it (typically the user httpd runs as), and that user must +# have filesystem-level permission to access the repository. +# +# On a Windows system, you should name the hook program +# 'post-unlock.bat' or 'post-unlock.exe', +# but the basic idea is the same. +# +# Here is an example hook script, for a Unix /bin/sh interpreter: + +REPOS="$1" +USER="$2" + +# Send email to interested parties, let them know a lock was removed: +mailer.py unlock "$REPOS" "$USER" /path/to/mailer.conf diff --git a/spring-cloud-config-server/src/test/resources/svn-config-repo/hooks/pre-commit.tmpl b/spring-cloud-config-server/src/test/resources/svn-config-repo/hooks/pre-commit.tmpl new file mode 100644 index 00000000..776968d1 --- /dev/null +++ b/spring-cloud-config-server/src/test/resources/svn-config-repo/hooks/pre-commit.tmpl @@ -0,0 +1,81 @@ +#!/bin/sh + +# PRE-COMMIT HOOK +# +# The pre-commit hook is invoked before a Subversion txn is +# committed. Subversion runs this hook by invoking a program +# (script, executable, binary, etc.) named 'pre-commit' (for which +# this file is a template), with the following ordered arguments: +# +# [1] REPOS-PATH (the path to this repository) +# [2] TXN-NAME (the name of the txn about to be committed) +# +# [STDIN] LOCK-TOKENS ** the lock tokens are passed via STDIN. +# +# If STDIN contains the line "LOCK-TOKENS:\n" (the "\n" denotes a +# single newline), the lines following it are the lock tokens for +# this commit. The end of the list is marked by a line containing +# only a newline character. +# +# Each lock token line consists of a URI-escaped path, followed +# by the separator character '|', followed by the lock token string, +# followed by a newline. +# +# The default working directory for the invocation is undefined, so +# the program should set one explicitly if it cares. +# +# If the hook program exits with success, the txn is committed; but +# if it exits with failure (non-zero), the txn is aborted, no commit +# takes place, and STDERR is returned to the client. The hook +# program can use the 'svnlook' utility to help it examine the txn. +# +# On a Unix system, the normal procedure is to have 'pre-commit' +# invoke other programs to do the real work, though it may do the +# work itself too. +# +# *** NOTE: THE HOOK PROGRAM MUST NOT MODIFY THE TXN, EXCEPT *** +# *** FOR REVISION PROPERTIES (like svn:log or svn:author). *** +# +# This is why we recommend using the read-only 'svnlook' utility. +# In the future, Subversion may enforce the rule that pre-commit +# hooks should not modify the versioned data in txns, or else come +# up with a mechanism to make it safe to do so (by informing the +# committing client of the changes). However, right now neither +# mechanism is implemented, so hook writers just have to be careful. +# +# Note that 'pre-commit' must be executable by the user(s) who will +# invoke it (typically the user httpd runs as), and that user must +# have filesystem-level permission to access the repository. +# +# On a Windows system, you should name the hook program +# 'pre-commit.bat' or 'pre-commit.exe', +# but the basic idea is the same. +# +# The hook program typically does not inherit the environment of +# its parent process. For example, a common problem is for the +# PATH environment variable to not be set to its usual value, so +# that subprograms fail to launch unless invoked via absolute path. +# If you're having unexpected problems with a hook program, the +# culprit may be unusual (or missing) environment variables. +# +# Here is an example hook script, for a Unix /bin/sh interpreter. +# For more examples and pre-written hooks, see those in +# the Subversion repository at +# http://svn.apache.org/repos/asf/subversion/trunk/tools/hook-scripts/ and +# http://svn.apache.org/repos/asf/subversion/trunk/contrib/hook-scripts/ + + +REPOS="$1" +TXN="$2" + +# Make sure that the log message contains some text. +SVNLOOK=/usr/local/bin/svnlook +$SVNLOOK log -t "$TXN" "$REPOS" | \ + grep "[a-zA-Z0-9]" > /dev/null || exit 1 + +# Check that the author of this commit has the rights to perform +# the commit on the files and directories being modified. +commit-access-control.pl "$REPOS" "$TXN" commit-access-control.cfg || exit 1 + +# All checks passed, so allow the commit. +exit 0 diff --git a/spring-cloud-config-server/src/test/resources/svn-config-repo/hooks/pre-lock.tmpl b/spring-cloud-config-server/src/test/resources/svn-config-repo/hooks/pre-lock.tmpl new file mode 100644 index 00000000..8ced86cb --- /dev/null +++ b/spring-cloud-config-server/src/test/resources/svn-config-repo/hooks/pre-lock.tmpl @@ -0,0 +1,73 @@ +#!/bin/sh + +# PRE-LOCK HOOK +# +# The pre-lock hook is invoked before an exclusive lock is +# created. Subversion runs this hook by invoking a program +# (script, executable, binary, etc.) named 'pre-lock' (for which +# this file is a template), with the following ordered arguments: +# +# [1] REPOS-PATH (the path to this repository) +# [2] PATH (the path in the repository about to be locked) +# [3] USER (the user creating the lock) +# [4] COMMENT (the comment of the lock) +# [5] STEAL-LOCK (1 if the user is trying to steal the lock, else 0) +# +# If the hook program outputs anything on stdout, the output string will +# be used as the lock token for this lock operation. If you choose to use +# this feature, you must guarantee the tokens generated are unique across +# the repository each time. +# +# The default working directory for the invocation is undefined, so +# the program should set one explicitly if it cares. +# +# If the hook program exits with success, the lock is created; but +# if it exits with failure (non-zero), the lock action is aborted +# and STDERR is returned to the client. + +# On a Unix system, the normal procedure is to have 'pre-lock' +# invoke other programs to do the real work, though it may do the +# work itself too. +# +# Note that 'pre-lock' must be executable by the user(s) who will +# invoke it (typically the user httpd runs as), and that user must +# have filesystem-level permission to access the repository. +# +# On a Windows system, you should name the hook program +# 'pre-lock.bat' or 'pre-lock.exe', +# but the basic idea is the same. +# +# Here is an example hook script, for a Unix /bin/sh interpreter: + +REPOS="$1" +PATH="$2" +USER="$3" +COMMENT="$4" +STEAL="$5" + +# If a lock exists and is owned by a different person, don't allow it +# to be stolen (e.g., with 'svn lock --force ...'). + +# (Maybe this script could send email to the lock owner?) +SVNLOOK=/usr/local/bin/svnlook +GREP=/bin/grep +SED=/bin/sed + +LOCK_OWNER=`$SVNLOOK lock "$REPOS" "$PATH" | \ + $GREP '^Owner: ' | $SED 's/Owner: //'` + +# If we get no result from svnlook, there's no lock, allow the lock to +# happen: +if [ "$LOCK_OWNER" = "" ]; then + exit 0 +fi + +# If the person locking matches the lock's owner, allow the lock to +# happen: +if [ "$LOCK_OWNER" = "$USER" ]; then + exit 0 +fi + +# Otherwise, we've got an owner mismatch, so return failure: +echo "Error: $PATH already locked by ${LOCK_OWNER}." 1>&2 +exit 1 diff --git a/spring-cloud-config-server/src/test/resources/svn-config-repo/hooks/pre-revprop-change.tmpl b/spring-cloud-config-server/src/test/resources/svn-config-repo/hooks/pre-revprop-change.tmpl new file mode 100644 index 00000000..9aa7c95d --- /dev/null +++ b/spring-cloud-config-server/src/test/resources/svn-config-repo/hooks/pre-revprop-change.tmpl @@ -0,0 +1,66 @@ +#!/bin/sh + +# PRE-REVPROP-CHANGE HOOK +# +# The pre-revprop-change hook is invoked before a revision property +# is added, modified or deleted. Subversion runs this hook by invoking +# a program (script, executable, binary, etc.) named 'pre-revprop-change' +# (for which this file is a template), with the following ordered +# arguments: +# +# [1] REPOS-PATH (the path to this repository) +# [2] REV (the revision being tweaked) +# [3] USER (the username of the person tweaking the property) +# [4] PROPNAME (the property being set on the revision) +# [5] ACTION (the property is being 'A'dded, 'M'odified, or 'D'eleted) +# +# [STDIN] PROPVAL ** the new property value is passed via STDIN. +# +# If the hook program exits with success, the propchange happens; but +# if it exits with failure (non-zero), the propchange doesn't happen. +# The hook program can use the 'svnlook' utility to examine the +# existing value of the revision property. +# +# WARNING: unlike other hooks, this hook MUST exist for revision +# properties to be changed. If the hook does not exist, Subversion +# will behave as if the hook were present, but failed. The reason +# for this is that revision properties are UNVERSIONED, meaning that +# a successful propchange is destructive; the old value is gone +# forever. We recommend the hook back up the old value somewhere. +# +# On a Unix system, the normal procedure is to have 'pre-revprop-change' +# invoke other programs to do the real work, though it may do the +# work itself too. +# +# Note that 'pre-revprop-change' must be executable by the user(s) who will +# invoke it (typically the user httpd runs as), and that user must +# have filesystem-level permission to access the repository. +# +# On a Windows system, you should name the hook program +# 'pre-revprop-change.bat' or 'pre-revprop-change.exe', +# but the basic idea is the same. +# +# The hook program typically does not inherit the environment of +# its parent process. For example, a common problem is for the +# PATH environment variable to not be set to its usual value, so +# that subprograms fail to launch unless invoked via absolute path. +# If you're having unexpected problems with a hook program, the +# culprit may be unusual (or missing) environment variables. +# +# Here is an example hook script, for a Unix /bin/sh interpreter. +# For more examples and pre-written hooks, see those in +# the Subversion repository at +# http://svn.apache.org/repos/asf/subversion/trunk/tools/hook-scripts/ and +# http://svn.apache.org/repos/asf/subversion/trunk/contrib/hook-scripts/ + + +REPOS="$1" +REV="$2" +USER="$3" +PROPNAME="$4" +ACTION="$5" + +if [ "$ACTION" = "M" -a "$PROPNAME" = "svn:log" ]; then exit 0; fi + +echo "Changing revision properties other than svn:log is prohibited" >&2 +exit 1 diff --git a/spring-cloud-config-server/src/test/resources/svn-config-repo/hooks/pre-unlock.tmpl b/spring-cloud-config-server/src/test/resources/svn-config-repo/hooks/pre-unlock.tmpl new file mode 100644 index 00000000..8617b22e --- /dev/null +++ b/spring-cloud-config-server/src/test/resources/svn-config-repo/hooks/pre-unlock.tmpl @@ -0,0 +1,65 @@ +#!/bin/sh + +# PRE-UNLOCK HOOK +# +# The pre-unlock hook is invoked before an exclusive lock is +# destroyed. Subversion runs this hook by invoking a program +# (script, executable, binary, etc.) named 'pre-unlock' (for which +# this file is a template), with the following ordered arguments: +# +# [1] REPOS-PATH (the path to this repository) +# [2] PATH (the path in the repository about to be unlocked) +# [3] USER (the user destroying the lock) +# [4] TOKEN (the lock token to be destroyed) +# [5] BREAK-UNLOCK (1 if the user is breaking the lock, else 0) +# +# The default working directory for the invocation is undefined, so +# the program should set one explicitly if it cares. +# +# If the hook program exits with success, the lock is destroyed; but +# if it exits with failure (non-zero), the unlock action is aborted +# and STDERR is returned to the client. + +# On a Unix system, the normal procedure is to have 'pre-unlock' +# invoke other programs to do the real work, though it may do the +# work itself too. +# +# Note that 'pre-unlock' must be executable by the user(s) who will +# invoke it (typically the user httpd runs as), and that user must +# have filesystem-level permission to access the repository. +# +# On a Windows system, you should name the hook program +# 'pre-unlock.bat' or 'pre-unlock.exe', +# but the basic idea is the same. +# +# Here is an example hook script, for a Unix /bin/sh interpreter: + +REPOS="$1" +PATH="$2" +USER="$3" +TOKEN="$4" +BREAK="$5" + +# If a lock is owned by a different person, don't allow it be broken. +# (Maybe this script could send email to the lock owner?) + +SVNLOOK=/usr/local/bin/svnlook +GREP=/bin/grep +SED=/bin/sed + +LOCK_OWNER=`$SVNLOOK lock "$REPOS" "$PATH" | \ + $GREP '^Owner: ' | $SED 's/Owner: //'` + +# If we get no result from svnlook, there's no lock, return success: +if [ "$LOCK_OWNER" = "" ]; then + exit 0 +fi + +# If the person unlocking matches the lock's owner, return success: +if [ "$LOCK_OWNER" = "$USER" ]; then + exit 0 +fi + +# Otherwise, we've got an owner mismatch, so return failure: +echo "Error: $PATH locked by ${LOCK_OWNER}." 1>&2 +exit 1 diff --git a/spring-cloud-config-server/src/test/resources/svn-config-repo/hooks/start-commit.tmpl b/spring-cloud-config-server/src/test/resources/svn-config-repo/hooks/start-commit.tmpl new file mode 100644 index 00000000..176906a6 --- /dev/null +++ b/spring-cloud-config-server/src/test/resources/svn-config-repo/hooks/start-commit.tmpl @@ -0,0 +1,71 @@ +#!/bin/sh + +# START-COMMIT HOOK +# +# The start-commit hook is invoked immediately after a Subversion txn is +# created and populated with initial revprops in the process of doing a +# commit. Subversion runs this hook by invoking a program (script, +# executable, binary, etc.) named 'start-commit' (for which this file +# is a template) with the following ordered arguments: +# +# [1] REPOS-PATH (the path to this repository) +# [2] USER (the authenticated user attempting to commit) +# [3] CAPABILITIES (a colon-separated list of capabilities reported +# by the client; see note below) +# [4] TXN-NAME (the name of the commit txn just created) +# +# Note: The CAPABILITIES parameter is new in Subversion 1.5, and 1.5 +# clients will typically report at least the "mergeinfo" capability. +# If there are other capabilities, then the list is colon-separated, +# e.g.: "mergeinfo:some-other-capability" (the order is undefined). +# +# Note: The TXN-NAME parameter is new in Subversion 1.8. Prior to version +# 1.8, the start-commit hook was invoked before the commit txn was even +# created, so the ability to inspect the commit txn and its metadata from +# within the start-commit hook was not possible. +# +# The list is self-reported by the client. Therefore, you should not +# make security assumptions based on the capabilities list, nor should +# you assume that clients reliably report every capability they have. +# +# The working directory for this hook program's invocation is undefined, +# so the program should set one explicitly if it cares. +# +# If the hook program exits with success, the commit continues; but +# if it exits with failure (non-zero), the commit is stopped before +# a Subversion txn is created, and STDERR is returned to the client. +# +# On a Unix system, the normal procedure is to have 'start-commit' +# invoke other programs to do the real work, though it may do the +# work itself too. +# +# Note that 'start-commit' must be executable by the user(s) who will +# invoke it (typically the user httpd runs as), and that user must +# have filesystem-level permission to access the repository. +# +# On a Windows system, you should name the hook program +# 'start-commit.bat' or 'start-commit.exe', +# but the basic idea is the same. +# +# The hook program typically does not inherit the environment of +# its parent process. For example, a common problem is for the +# PATH environment variable to not be set to its usual value, so +# that subprograms fail to launch unless invoked via absolute path. +# If you're having unexpected problems with a hook program, the +# culprit may be unusual (or missing) environment variables. +# +# Here is an example hook script, for a Unix /bin/sh interpreter. +# For more examples and pre-written hooks, see those in +# the Subversion repository at +# http://svn.apache.org/repos/asf/subversion/trunk/tools/hook-scripts/ and +# http://svn.apache.org/repos/asf/subversion/trunk/contrib/hook-scripts/ + + +REPOS="$1" +USER="$2" + +commit-allower.pl --repository "$REPOS" --user "$USER" || exit 1 +special-auth-check.py --user "$USER" --auth-level 3 || exit 1 + +# All checks passed, so allow the commit. +exit 0 diff --git a/spring-cloud-config-server/src/test/resources/svn-config-repo/locks/db-logs.lock b/spring-cloud-config-server/src/test/resources/svn-config-repo/locks/db-logs.lock new file mode 100644 index 00000000..536ac36a --- /dev/null +++ b/spring-cloud-config-server/src/test/resources/svn-config-repo/locks/db-logs.lock @@ -0,0 +1,3 @@ +This file is not used by Subversion 1.3.x or later. +However, its existence is required for compatibility with +Subversion 1.2.x or earlier. diff --git a/spring-cloud-config-server/src/test/resources/svn-config-repo/locks/db.lock b/spring-cloud-config-server/src/test/resources/svn-config-repo/locks/db.lock new file mode 100644 index 00000000..536ac36a --- /dev/null +++ b/spring-cloud-config-server/src/test/resources/svn-config-repo/locks/db.lock @@ -0,0 +1,3 @@ +This file is not used by Subversion 1.3.x or later. +However, its existence is required for compatibility with +Subversion 1.2.x or earlier. diff --git a/spring-cloud-config-server/src/test/resources/svn-config-repo/svn.ico b/spring-cloud-config-server/src/test/resources/svn-config-repo/svn.ico new file mode 100644 index 00000000..ba63376b Binary files /dev/null and b/spring-cloud-config-server/src/test/resources/svn-config-repo/svn.ico differ