Skip to content

Commit

Permalink
upstream: b=main,r=5621a56f8bab5584a863eac5fb01fa9c98aa43b3,t=2024-11…
Browse files Browse the repository at this point in the history
…-15-1342-47707
  • Loading branch information
sonatype-zion committed Nov 15, 2024
1 parent 4820a1e commit aeac8dd
Show file tree
Hide file tree
Showing 177 changed files with 2,238 additions and 2,523 deletions.
18 changes: 0 additions & 18 deletions buildsupport/commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,30 +72,12 @@
<version>1.5</version>
</dependency>

<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.4</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.7.0</version>
</dependency>

<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.2</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
Expand Down
12 changes: 0 additions & 12 deletions buildsupport/other/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,6 @@
<version>6.2.0.Final</version>
</dependency>

<dependency>
<groupId>commons-validator</groupId>
<artifactId>commons-validator</artifactId>
<version>1.7</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
Expand Down
6 changes: 6 additions & 0 deletions buildsupport/rest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,12 @@
<version>${jackson2.version}</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-toml</artifactId>
<version>${jackson2.version}</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.io.InputStream;
import java.nio.file.Path;
import java.time.Duration;
import java.time.OffsetDateTime;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;
Expand Down Expand Up @@ -299,6 +300,12 @@ default Blob makeBlobPermanent(final BlobId blobId, final Map<String, String> he
*/
Stream<BlobId> getBlobIdUpdatedSinceStream(Duration duration);

/**
* Get a {@link Stream} of {@link BlobId} for blobs contained in this blob store that have been updated within the provided from date
* and under the specified path prefix.
*/
Stream<BlobId> getBlobIdUpdatedSinceStream(String prefix, OffsetDateTime fromDateTime);

/**
* Get a {@link Stream} of direct-path {@link BlobId}s under the specified path prefix.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,15 @@ public Stream<BlobId> getBlobIdUpdatedSinceStream(final Duration duration) {
}
}

@Override
public Stream<BlobId> getBlobIdUpdatedSinceStream(String prefix, OffsetDateTime fromDateTime) {
DateBasedWalkFile dateBasedWalkFile = new DateBasedWalkFile(contentDir.toString(), fromDateTime);
Map<String, OffsetDateTime> dateBasedBlobIds =
dateBasedWalkFile.getBlobIdToDateRef(contentDir.resolve(prefix).toString());
return reconciliationLogger.getBlobsCreatedSince(reconciliationLogDir, fromDateTime.toLocalDateTime(),
dateBasedBlobIds);
}

@Override
public Stream<BlobId> getDirectPathBlobIdStream(final String prefix) {
checkArgument(!prefix.contains(".."), "path traversal not allowed");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,45 @@ public class DateBasedWalkFile

private final Duration duration;

private final OffsetDateTime fromDateTime;

public DateBasedWalkFile(final String contentDir, final Duration duration) {
this.fromDateTime = null;
checkNotNull(contentDir);
this.contentDir = StringUtils.appendIfMissing(contentDir, File.separator);
this.duration = checkNotNull(duration);
}

public DateBasedWalkFile(final String contentDir, final OffsetDateTime fromDateTime) {
this.duration = null;
this.fromDateTime = checkNotNull(fromDateTime);
checkNotNull(contentDir);
this.contentDir = StringUtils.appendIfMissing(contentDir, File.separator);
}

public Map<String, OffsetDateTime> getBlobIdToDateRef() {
OffsetDateTime now = UTC.now();
OffsetDateTime fromDateTime = now.minusSeconds(duration.getSeconds());
String datePathPrefix = contentDir + DateBasedHelper.getDatePathPrefix(fromDateTime, now);
OffsetDateTime from;

if (duration != null) {
from = now.minusSeconds(duration.getSeconds());
}
else {
from = this.fromDateTime;
}
String datePathPrefix = contentDir + DateBasedHelper.getDatePathPrefix(from, now);

try {
return getAllFiles(datePathPrefix, from);
}
catch (IOException e) {
throw new UncheckedIOException(e);
}
}

public Map<String, OffsetDateTime> getBlobIdToDateRef(String datePathPrefix) {
try {
return getAllFiles(datePathPrefix, fromDateTime);
return getAllFiles(datePathPrefix, this.fromDateTime);
}
catch (IOException e) {
throw new UncheckedIOException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@
*/
package org.sonatype.nexus.blobstore;

import java.time.Duration;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;

/**
* Helper class to build date-based prefix based on the given date range.
* For more details, see {@link DateBasedLocationStrategy}
* Helper class to build date-based prefix based on the given date range. For more details, see
* {@link DateBasedLocationStrategy}
*/
public class DateBasedHelper
{
Expand Down Expand Up @@ -50,4 +55,53 @@ public static String getDatePathPrefix(final OffsetDateTime fromDateTime, final

return toDateTime.format(dateTimeFormatter);
}
}

public static List<String> generatePrefixes(final OffsetDateTime now, final Duration duration) {
OffsetDateTime utcDateTime = now.withOffsetSameInstant(ZoneOffset.UTC); // Convert to UTC

List<String> prefixes = new ArrayList<>();
OffsetDateTime startTime = utcDateTime.minus(duration).truncatedTo(ChronoUnit.MINUTES);
OffsetDateTime endTime = utcDateTime.truncatedTo(ChronoUnit.MINUTES);

if (duration.toDays() > 0) {
while (isApplicable(startTime, endTime, ChronoUnit.DAYS)) {
prefixes.add(startTime.format(DateTimeFormatter.ofPattern("yyyy/MM/dd"))); // Only days
startTime = startTime.plusDays(1);
}
}
else if (duration.toHours() > 0) {
while (isApplicable(startTime, endTime, ChronoUnit.HOURS)) {
prefixes.add(startTime.format(DateTimeFormatter.ofPattern("yyyy/MM/dd/HH")));
startTime = startTime.plusHours(1);
}
}
else {
while (isApplicable(startTime, endTime, ChronoUnit.MINUTES)) {
// Check if we need to round up minutes to the next hour
if (duration.toMinutes() > 30) {
// Add the remaining minutes as an hour if > 30 minutes
startTime = startTime.plusHours(1);
prefixes.add(startTime.format(DateTimeFormatter.ofPattern("yyyy/MM/dd/HH")));
break;
}
else {
prefixes.add(startTime.format(DateTimeFormatter.ofPattern("yyyy/MM/dd/HH/mm")));
startTime = startTime.plusMinutes(1);
}
}
}

return prefixes;
}

private static boolean isApplicable(
final OffsetDateTime startTime, final OffsetDateTime endTime,
final ChronoUnit granularity)
{

if (startTime.truncatedTo(granularity).equals(endTime.truncatedTo(granularity))) {
return true;
}
return startTime.isBefore(endTime) || startTime.equals(endTime);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import java.io.InputStream;
import java.nio.file.Path;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.EnumMap;
Expand Down Expand Up @@ -463,6 +464,14 @@ public Stream<BlobId> getBlobIdUpdatedSinceStream(final java.time.Duration durat
.flatMap((BlobStore member) -> member.getBlobIdUpdatedSinceStream(duration));
}

@Override
public Stream<BlobId> getBlobIdUpdatedSinceStream(final String prefix, final OffsetDateTime fromDateTime) {
return members
.get()
.stream()
.flatMap((BlobStore member) -> member.getBlobIdUpdatedSinceStream(prefix, fromDateTime));
}

@Override
public Stream<BlobId> getDirectPathBlobIdStream(final String prefix) {
return members.get().stream()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.sonatype.nexus.blobstore;

import java.time.Duration;
import java.time.OffsetDateTime;
import java.util.List;

import org.junit.Test;

import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.MatcherAssert.assertThat;

public class DateBasedHelperTest
{
public static final OffsetDateTime NOW = OffsetDateTime.parse("2024-10-25T14:30:30Z");

@Test
public void testGeneratePrefixesMinutesLess30() {
Duration duration = Duration.ofMinutes(1);
List<String> prefixes = DateBasedHelper.generatePrefixes(NOW, duration);
assertThat(prefixes, containsInAnyOrder("2024/10/25/14/29", "2024/10/25/14/30"));

duration = Duration.ofMinutes(5);
prefixes = DateBasedHelper.generatePrefixes(NOW, duration);
assertThat(prefixes,
containsInAnyOrder("2024/10/25/14/30", "2024/10/25/14/29", "2024/10/25/14/28", "2024/10/25/14/27",
"2024/10/25/14/26", "2024/10/25/14/25"));
}

@Test
public void testGeneratePrefixesMinutesOver30() {
Duration duration = Duration.ofMinutes(31);
List<String> prefixes = DateBasedHelper.generatePrefixes(NOW, duration);
assertThat(prefixes, containsInAnyOrder("2024/10/25/14"));
}

@Test
public void testGeneratePrefixesHoursLess24() {
Duration duration = Duration.ofHours(3);
List<String> prefixes = DateBasedHelper.generatePrefixes(NOW, duration);
assertThat(prefixes, containsInAnyOrder("2024/10/25/14", "2024/10/25/13", "2024/10/25/11", "2024/10/25/12"));
}

@Test
public void testGeneratePrefixesHoursOver24() {
Duration duration = Duration.ofHours(25);
List<String> prefixes = DateBasedHelper.generatePrefixes(NOW, duration);
assertThat(prefixes, containsInAnyOrder("2024/10/25", "2024/10/24"));
}

@Test
public void testGeneratePrefixesHoursOne() {
Duration duration = Duration.ofHours(1);
// sometimes current hour were not generated as prefix, so define specific value
OffsetDateTime currentTime = OffsetDateTime.parse("2024-10-25T14:32:30Z");
List<String> prefixes = DateBasedHelper.generatePrefixes(currentTime, duration);
assertThat(prefixes, containsInAnyOrder("2024/10/25/14", "2024/10/25/13"));
}

@Test
public void testGeneratePrefixesMinutesOne() {
Duration duration = Duration.ofMinutes(1);
// sometimes current hour were not generated as prefix, so define specific value
OffsetDateTime currentTime = OffsetDateTime.parse("2024-10-25T14:32:30Z");
List<String> prefixes = DateBasedHelper.generatePrefixes(currentTime, duration);
assertThat(prefixes, containsInAnyOrder("2024/10/25/14/32", "2024/10/25/14/31"));
}

@Test
public void testGeneratePrefixesDaysOne() {
Duration duration = Duration.ofDays(1);
// sometimes current hour were not generated as prefix, so define specific value
OffsetDateTime currentTime = OffsetDateTime.parse("2024-10-25T14:32:30Z");
List<String> prefixes = DateBasedHelper.generatePrefixes(currentTime, duration);
assertThat(prefixes, containsInAnyOrder("2024/10/25", "2024/10/24"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ public interface FeatureFlags

String MALWARE_RISK_ON_DISK_ENABLED_NAMED = "${nexus.malware.risk.on.disk.enabled:-true}";

String MALWARE_RISK_ON_DISK_NONADMIN_OVERRIDE_ENABLED = "nexus.malware.risk.on.disk.nonadmin.override.enabled";

String MALWARE_RISK_ON_DISK_NONADMIN_OVERRIDE_ENABLED_NAMED =
"${nexus.malware.risk.on.disk.nonadmin.override.enabled:-false}";

String CONAN_V2_ENABLED = "nexus.conan.v2.enabled";

String CONAN_V2_ENABLED_NAMED = "${nexus.conan.v2.enabled:-false}";
Expand Down
5 changes: 5 additions & 0 deletions components/nexus-extdirect/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@
<artifactId>httpclient</artifactId>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
</dependency>

<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.sonatype.nexus.rest.ValidationErrorsException;

import com.softwarementors.extjs.djn.api.RegisteredMethod;
import org.apache.commons.collections.ListUtils;
import org.apache.commons.collections4.ListUtils;
import org.apache.http.conn.HttpHostConnectException;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authz.UnauthenticatedException;
Expand All @@ -49,7 +49,7 @@ public class ExtDirectExceptionHandler
{
private static final Logger log = LoggerFactory.getLogger(ExtDirectExceptionHandler.class);

private static final List<Class<Throwable>> SUPPRESSED_EXCEPTIONS = ListUtils.unmodifiableList(
private static final List<Class<? extends RuntimeException>> SUPPRESSED_EXCEPTIONS = ListUtils.unmodifiableList(
Arrays.asList(UnauthenticatedException.class, AuthenticationException.class, ValidationErrorsException.class));

public Response handleException(final RegisteredMethod method, final Throwable e) {
Expand Down
2 changes: 1 addition & 1 deletion components/nexus-rapture/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"luxon": "1.28.1",
"react": "17.0.2",
"react-dom": "17.0.2",
"xstate": "4.16.0"
"xstate": "4.38.3"
},
"devDependencies": {
"@babel/core": "7.17.5",
Expand Down
Loading

0 comments on commit aeac8dd

Please sign in to comment.