Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into mirror-api
Browse files Browse the repository at this point in the history
  • Loading branch information
jrhee17 committed Jun 13, 2024
2 parents c80bd88 + f47657e commit f0184f0
Show file tree
Hide file tree
Showing 16 changed files with 73 additions and 47 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ configure(projectsWithFlags('java')) {
testImplementation libs.slf4j2.jul.to.slf4j
testImplementation libs.slf4j2.jcl.over.slf4j
testImplementation libs.slf4j2.log4j.over.slf4j
testRuntimeOnly libs.logback14
testRuntimeOnly libs.logback15
configurations.configureEach {
resolutionStrategy {
force libs.slf4j2.api.get()
force libs.slf4j2.jul.to.slf4j.get()
force libs.slf4j2.jcl.over.slf4j.get()
force libs.slf4j2.log4j.over.slf4j.get()
force libs.logback14.get()
force libs.logback15.get()
}
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public final class Util {
* End with an alphanumeric character.
*/
private static final Pattern PROJECT_AND_REPO_NAME_PATTERN =
Pattern.compile("^[0-9A-Za-z](?:[-+_0-9A-Za-z.]*[0-9A-Za-z])?$");
Pattern.compile("^(?!.*\\.git$)[0-9A-Za-z](?:[-+_0-9A-Za-z.]*[0-9A-Za-z])?$");

public static String validateFileName(String name, String paramName) {
requireNonNull(name, paramName);
Expand Down
33 changes: 17 additions & 16 deletions dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
# If its classes are exposed in Javadoc, update offline links as well.
#
[versions]
armeria = "1.28.4"
assertj = "3.25.3"
armeria = "1.29.0"
assertj = "3.26.0"
awaitility = "4.2.1"
bouncycastle = "1.78.1"
caffeine = "2.9.3"
checkstyle = "10.3.3"
controlplane = "1.0.44"
controlplane = "1.0.45"
curator = "5.6.0"
# Do not upgrade cron-utils until there's another CVE or Armeria's SLF4J and Logback are upgraded.
cron-utils = "9.2.0"
Expand All @@ -20,12 +20,12 @@ dropwizard-metrics = "4.2.21"
eddsa = "0.3.0"
findbugs = "3.0.2"
futures-completable = "0.3.6"
guava = "33.1.0-jre"
guava = "33.2.1-jre"
guava-failureaccess = "1.0.1"
hamcrest-library = "2.2"
hibernate-validator6 = "6.2.5.Final"
hibernate-validator8 = "8.0.1.Final"
jackson = "2.17.0"
jackson = "2.17.1"
javassist = "3.30.2-GA"
javax-annotation = "1.3.2"
javax-inject = "1"
Expand All @@ -44,9 +44,9 @@ jmh-core = "1.37"
jmh-gradle-plugin = "0.7.2"
jxr = "0.2.1"
logback12 = { strictly = "1.2.13" }
logback14 = { strictly = "1.4.14" }
logback15 = { strictly = "1.5.5" }
logback = "1.2.13"
micrometer = "1.12.4"
micrometer = "1.13.0"
mina-sshd = "2.12.1"
mockito = "4.11.0"
nexus-publish-plugin = "2.0.0"
Expand All @@ -57,15 +57,15 @@ quartz = "2.3.2"
shadow-gradle-plugin = "7.1.2"
shiro = "1.3.2"
slf4j1 = { strictly = "1.7.36" }
slf4j2 = { strictly = "2.0.7" }
slf4j2 = { strictly = "2.0.12" }
# Ensure that we use the same Snappy version as what Curator depends on.
# See: https://github.com/apache/curator/blob/master/pom.xml
snappy = "1.1.10.4"
sphinx = "2.10.1"
spring-boot2 = "2.7.18"
spring-boot3 = "3.2.4"
spring-boot3 = "3.3.0"
spring-test-junit5 = "1.5.0"
testcontainers = "1.19.7"
testcontainers = "1.19.8"
thrift09 = { strictly = "0.9.3-1" }
zookeeper = "3.7.2"

Expand All @@ -81,14 +81,15 @@ javadocs = "https://www.javadoc.io/doc/com.linecorp.armeria/armeria-javadoc/1.27
module = "com.linecorp.armeria:armeria-grpc"
[libraries.armeria-junit5]
module = "com.linecorp.armeria:armeria-junit5"
[libraries.armeria-prometheus1]
module = "com.linecorp.armeria:armeria-prometheus1"
[libraries.armeria-saml]
module = "com.linecorp.armeria:armeria-saml"
[libraries.armeria-thrift09]
module = "com.linecorp.armeria:armeria-thrift0.9"
[libraries.armeria-xds]
module = "com.linecorp.armeria:armeria-xds"


[libraries.assertj]
module = "org.assertj:assertj-core"
version.ref = "assertj"
Expand Down Expand Up @@ -290,10 +291,10 @@ module = "org.junit.platform:junit-platform-launcher"
module = "ch.qos.logback:logback-classic"
version.ref = "logback12"
javadocs = "https://www.javadoc.io/doc/ch.qos.logback/logback-classic/1.2.12/"
[libraries.logback14]
[libraries.logback15]
module = "ch.qos.logback:logback-classic"
version.ref = "logback14"
javadocs = "https://www.javadoc.io/doc/ch.qos.logback/logback-classic/1.4.11/"
version.ref = "logback15"
javadocs = "https://www.javadoc.io/doc/ch.qos.logback/logback-classic/1.5.4/"

[libraries.controlplane-cache]
module = "io.envoyproxy.controlplane:cache"
Expand All @@ -305,11 +306,11 @@ version.ref = "controlplane"
[libraries.micrometer-core]
module = "io.micrometer:micrometer-core"
version.ref = "micrometer"
javadocs = "https://www.javadoc.io/doc/io.micrometer/micrometer-core/1.11.3/"
javadocs = "https://www.javadoc.io/doc/io.micrometer/micrometer-core/1.13.0/"
[libraries.micrometer-prometheus]
module = "io.micrometer:micrometer-registry-prometheus"
version.ref = "micrometer"
javadocs = "https://www.javadoc.io/doc/io.micrometer/micrometer-registry-prometheus/1.11.3/"
javadocs = "https://www.javadoc.io/doc/io.micrometer/micrometer-registry-prometheus/1.13.0/"

[libraries.mina-sshd-core]
module = "org.apache.sshd:sshd-core"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,13 @@ void remoteToLocal() throws Exception {

@Test
void remoteToLocal_gitignore() throws Exception {
pushMirrorSettings(null, "/first", "\"/exclude_if_root.txt\\nexclude_dir\"");
pushMirrorSettings(null, "/first#master", "\"/exclude_if_root.txt\\nexclude_dir\"");
checkGitignore();
}

@Test
void remoteToLocal_gitignore_with_array() throws Exception {
pushMirrorSettings(null, "/first", "[\"/exclude_if_root.txt\", \"exclude_dir\"]");
pushMirrorSettings(null, "/first#master", "[\"/exclude_if_root.txt\", \"exclude_dir\"]");
checkGitignore();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,9 @@ void mirrorRemoteToLocal(
changes.put(mirrorStatePath, Change.ofJsonUpsert(
mirrorStatePath, "{ \"sourceRevision\": \"" + headCommitId.name() + "\" }"));
// Construct the log message and log.
summary = "Mirror " + abbrId + ", " + remoteRepoUri() + '#' + remoteBranch() +
" to the repository '" + localRepo().name() + '\'';
final String branchName = getRemoteBranchName(headBranchRef);
summary = "Mirror " + abbrId + ", '" + remoteRepoUri() + '#' + branchName +
"' to the repository '" + localRepo().name() + '\'';
final RevCommit headCommit = revWalk.parseCommit(headCommitId);
detail = generateCommitDetail(headCommit);
logger.info(summary);
Expand Down Expand Up @@ -723,6 +724,18 @@ static void updateRef(org.eclipse.jgit.lib.Repository jGitRepository, RevWalk re
}
}

private String getRemoteBranchName(Ref headBranchRef) {
final String remoteBranch = remoteBranch();
if (remoteBranch != null && !remoteBranch.isEmpty()) {
return remoteBranch;
}
final String headBranchName = headBranchRef.getName();
if (headBranchName.startsWith(Constants.R_HEADS)) {
return headBranchName.substring(Constants.R_HEADS.length());
}
return headBranchName;
}

private static final class InsertText extends PathEdit {
private final ObjectInserter inserter;
private final String text;
Expand Down
1 change: 1 addition & 0 deletions server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ dependencies {

// Armeria
api libs.armeria
api libs.armeria.prometheus1
api libs.armeria.thrift09
testImplementation libs.armeria.junit5

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
import com.linecorp.armeria.common.MediaType;
import com.linecorp.armeria.common.ServerCacheControl;
import com.linecorp.armeria.common.metric.MeterIdPrefixFunction;
import com.linecorp.armeria.common.metric.PrometheusMeterRegistries;
import com.linecorp.armeria.common.prometheus.PrometheusMeterRegistries;
import com.linecorp.armeria.common.util.EventLoopGroups;
import com.linecorp.armeria.common.util.Exceptions;
import com.linecorp.armeria.common.util.StartStopSupport;
Expand All @@ -104,7 +104,7 @@
import com.linecorp.armeria.server.healthcheck.SettableHealthChecker;
import com.linecorp.armeria.server.logging.AccessLogWriter;
import com.linecorp.armeria.server.metric.MetricCollectingService;
import com.linecorp.armeria.server.metric.PrometheusExpositionService;
import com.linecorp.armeria.server.prometheus.PrometheusExpositionService;
import com.linecorp.armeria.server.thrift.THttpService;
import com.linecorp.armeria.server.thrift.ThriftCallService;
import com.linecorp.centraldogma.common.ShuttingDownException;
Expand Down Expand Up @@ -173,7 +173,7 @@
import io.micrometer.core.instrument.binder.system.ProcessorMetrics;
import io.micrometer.core.instrument.binder.system.UptimeMetrics;
import io.micrometer.core.instrument.composite.CompositeMeterRegistry;
import io.micrometer.prometheus.PrometheusMeterRegistry;
import io.micrometer.prometheusmetrics.PrometheusMeterRegistry;
import io.netty.util.concurrent.DefaultThreadFactory;
import io.netty.util.concurrent.GlobalEventExecutor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public final class CreateRepositoryCommand extends ProjectCommand<Void> {
@JsonProperty("author") @Nullable Author author,
@JsonProperty("projectName") String projectName,
@JsonProperty("repositoryName") String repositoryName) {

super(CommandType.CREATE_REPOSITORY, timestamp, author, projectName);
this.repositoryName = requireNonNull(repositoryName, "repositoryName");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public final class GitHttpService {
// TODO(minwoox): Add the headers in this class to Armeria.
private static final AggregatedHttpResponse CAPABILITY_ADVERTISEMENT_RESPONSE = AggregatedHttpResponse.of(
ResponseHeaders.builder(200)
.add(HttpHeaderNames.CONTENT_TYPE, "application/x-git-upload-pack-advertisement")
.contentType(MediaType.GIT_UPLOAD_PACK_ADVERTISEMENT)
.add(HttpHeaderNames.CACHE_CONTROL, ServerCacheControl.REVALIDATED.asHeaderValue())
.build(),
HttpData.ofUtf8(capabilityAdvertisement()));
Expand Down Expand Up @@ -132,14 +132,14 @@ private static String maybeRemoveGitSuffix(String repoName) {
public HttpResponse gitUploadPack(AggregatedHttpRequest req,
@Param String projectName, @Param String repoName) {
repoName = maybeRemoveGitSuffix(repoName);
final String gitProtocol = req.headers().get("git-protocol");
final String gitProtocol = req.headers().get(HttpHeaderNames.GIT_PROTOCOL);
if (gitProtocol == null || !gitProtocol.contains(VERSION_2_REQUEST)) {
return HttpResponse.of(HttpStatus.BAD_REQUEST, MediaType.PLAIN_TEXT_UTF_8,
"Unsupported git-protocol: " + gitProtocol);
}

final MediaType contentType = req.headers().contentType();
if (contentType == null || !"application/x-git-upload-pack-request".equals(contentType.toString())) {
if (MediaType.GIT_UPLOAD_PACK_REQUEST != contentType) {
return HttpResponse.of(HttpStatus.BAD_REQUEST, MediaType.PLAIN_TEXT_UTF_8,
"Unsupported content-type: " + contentType);
}
Expand Down Expand Up @@ -182,7 +182,7 @@ public HttpResponse gitUploadPack(AggregatedHttpRequest req,
});
return HttpResponse.of(
ResponseHeaders.builder(200)
.add(HttpHeaderNames.CONTENT_TYPE, "application/x-git-upload-pack-result")
.contentType(MediaType.GIT_UPLOAD_PACK_RESULT)
.add(HttpHeaderNames.CACHE_CONTROL,
ServerCacheControl.REVALIDATED.asHeaderValue())
.build(), body);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public abstract class DirectoryBasedStorageManager<T> implements StorageManager<
Pattern.compile("^[0-9A-Za-z](?:[-+_0-9A-Za-z.]*[0-9A-Za-z])?$");
private static final String SUFFIX_REMOVED = ".removed";
private static final String SUFFIX_PURGED = ".purged";
private static final String GIT_EXTENSION = ".git";

private final String childTypeName;
private final File rootDir;
Expand Down Expand Up @@ -437,7 +438,8 @@ private static boolean isValidChildName(String name) {
return false;
}

return !name.endsWith(SUFFIX_REMOVED) && !name.endsWith(SUFFIX_PURGED);
return !name.endsWith(SUFFIX_REMOVED) && !name.endsWith(SUFFIX_PURGED) &&
!name.endsWith(GIT_EXTENSION); // Git repository whose name ends with '.git' is not allowed.
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import static com.google.common.base.MoreObjects.firstNonNull;
import static com.linecorp.centraldogma.common.Author.SYSTEM;
import static com.linecorp.centraldogma.common.Revision.HEAD;
import static com.linecorp.centraldogma.internal.Util.validateProjectName;
import static com.linecorp.centraldogma.internal.Util.validateRepositoryName;
import static com.linecorp.centraldogma.server.internal.api.ContentServiceV1.checkPush;
import static com.linecorp.centraldogma.server.internal.api.RepositoryServiceV1.increaseCounterIfOldRevisionUsed;
import static com.linecorp.centraldogma.server.internal.thrift.Converter.convert;
Expand Down Expand Up @@ -121,6 +123,7 @@ private static void handleAsVoidResult(CompletableFuture<?> future, AsyncMethodC

@Override
public void createProject(String name, AsyncMethodCallback resultHandler) {
validateProjectName(name, "name");
// ProjectInitializingCommandExecutor initializes a metadata for the specified project.
handle(projectApiManager.createProject(name, SYSTEM), resultHandler);
}
Expand Down Expand Up @@ -161,6 +164,7 @@ public void listRemovedProjects(AsyncMethodCallback resultHandler) {
@Override
public void createRepository(String projectName, String repositoryName,
AsyncMethodCallback resultHandler) {
validateRepositoryName(repositoryName, "repositoryName");
// HTTP v1 API will return '403 forbidden' in this case, but we deal it as '400 bad request' here.
if (isReservedRepoName(repositoryName)) {
resultHandler.onError(convert(RESERVED_REPOSITORY_EXCEPTION));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@

import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.composite.CompositeMeterRegistry;
import io.micrometer.prometheus.PrometheusMeterRegistry;
import io.prometheus.client.exporter.common.TextFormat;
import io.micrometer.prometheusmetrics.PrometheusMeterRegistry;

@FlakyTest
@Timeout(30)
Expand Down Expand Up @@ -67,7 +66,7 @@ void metrics() {
final AggregatedHttpResponse res = dogma.httpClient().get("/monitor/metrics").aggregate().join();
String content = res.contentUtf8();
assertThat(res.status()).isEqualTo(HttpStatus.OK);
assertThat(res.contentType()).isEqualTo(MediaType.parse(TextFormat.CONTENT_TYPE_004));
assertThat(res.contentType()).isEqualTo(MediaType.parse("text/plain; version=0.0.4; charset=utf-8"));
assertThat(content).isNotEmpty();
assertThat(content).doesNotContain(
"com.linecorp.centraldogma.server.internal.api.WatchContentServiceV1");
Expand Down
Loading

0 comments on commit f0184f0

Please sign in to comment.