Skip to content

Commit a8621ff

Browse files
committed
Ensure that ccompat and v2 APIs do not return DRAFT content
1 parent db9adeb commit a8621ff

19 files changed

+231
-105
lines changed

app/src/main/java/io/apicurio/registry/auth/AuthConfig.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ public class AuthConfig {
1717
Logger log;
1818

1919
@ConfigProperty(name = "quarkus.oidc.tenant-enabled", defaultValue = "false")
20-
@Info(category = "auth", description = "Enable auth", availableSince = "0.1.18-SNAPSHOT", registryAvailableSince = "2.0.0.Final", studioAvailableSince = "1.0.0")
20+
@Info(category = "auth", description = "Enable auth", availableSince = "0.1.18", registryAvailableSince = "2.0.0.Final", studioAvailableSince = "1.0.0")
2121
boolean oidcAuthEnabled;
2222

2323
@Dynamic(label = "HTTP basic authentication", description = "When selected, users are permitted to authenticate using HTTP basic authentication (in addition to OAuth).", requires = "apicurio.authn.enabled=true")
2424
@ConfigProperty(name = "apicurio.authn.basic-client-credentials.enabled", defaultValue = "false")
25-
@Info(category = "auth", description = "Enable basic auth client credentials", availableSince = "0.1.18-SNAPSHOT", registryAvailableSince = "2.1.0.Final", studioAvailableSince = "1.0.0")
25+
@Info(category = "auth", description = "Enable basic auth client credentials", availableSince = "0.1.18", registryAvailableSince = "2.1.0.Final", studioAvailableSince = "1.0.0")
2626
Supplier<Boolean> basicClientCredentialsAuthEnabled;
2727

2828
@ConfigProperty(name = "quarkus.http.auth.basic", defaultValue = "false")
29-
@Info(category = "auth", description = "Enable basic auth", availableSince = "1.1.X-SNAPSHOT", registryAvailableSince = "3.X.X.Final", studioAvailableSince = "1.0.0")
29+
@Info(category = "auth", description = "Enable basic auth", availableSince = "1.1.x", registryAvailableSince = "3.0.0", studioAvailableSince = "1.0.0")
3030
boolean basicAuthEnabled;
3131

3232
@ConfigProperty(name = "apicurio.auth.role-based-authorization", defaultValue = "false")
@@ -96,7 +96,7 @@ public class AuthConfig {
9696
String adminOverrideClaimValue;
9797

9898
@ConfigProperty(name = "apicurio.auth.admin-override.user", defaultValue = "admin")
99-
@Info(category = "auth", description = "Auth admin override user name", availableSince = "3.0.0.Final")
99+
@Info(category = "auth", description = "Auth admin override user name", availableSince = "3.0.0")
100100
String adminOverrideUser;
101101

102102
@PostConstruct

app/src/main/java/io/apicurio/registry/ccompat/rest/v7/impl/AbstractResource.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ protected boolean isArtifactActive(String artifactId, String groupId) {
238238
protected String getLatestArtifactVersionForSubject(String artifactId, String groupId) {
239239
try {
240240
GAV latestGAV = storage.getBranchTip(new GA(groupId, artifactId), BranchId.LATEST,
241-
RetrievalBehavior.SKIP_DISABLED_LATEST);
241+
RetrievalBehavior.ACTIVE_STATES);
242242
return latestGAV.getRawVersionId();
243243
} catch (ArtifactNotFoundException ex) {
244244
throw new VersionNotFoundException(groupId, artifactId, "latest");

app/src/main/java/io/apicurio/registry/ccompat/rest/v7/impl/SubjectVersionsResourceImpl.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import io.apicurio.registry.metrics.health.liveness.ResponseErrorLivenessCheck;
2020
import io.apicurio.registry.metrics.health.readiness.ResponseTimeoutReadinessCheck;
2121
import io.apicurio.registry.model.GA;
22+
import io.apicurio.registry.storage.RegistryStorage.RetrievalBehavior;
2223
import io.apicurio.registry.storage.dto.ArtifactVersionMetaDataDto;
2324
import io.apicurio.registry.storage.dto.StoredArtifactVersionDto;
2425
import io.apicurio.registry.storage.error.ArtifactNotFoundException;
@@ -37,8 +38,6 @@
3738

3839
import static io.apicurio.common.apps.logging.audit.AuditingConstants.KEY_ARTIFACT_ID;
3940
import static io.apicurio.common.apps.logging.audit.AuditingConstants.KEY_VERSION;
40-
import static io.apicurio.registry.storage.RegistryStorage.RetrievalBehavior.DEFAULT;
41-
import static io.apicurio.registry.storage.RegistryStorage.RetrievalBehavior.SKIP_DISABLED_LATEST;
4241

4342
@Interceptors({ ResponseErrorLivenessCheck.class, ResponseTimeoutReadinessCheck.class })
4443
@Logged
@@ -55,13 +54,15 @@ public List<Integer> listVersions(String subject, String groupId, Boolean delete
5554

5655
List<Integer> rval;
5756
if (fdeleted) {
58-
rval = storage.getArtifactVersions(ga.getRawGroupIdWithNull(), ga.getRawArtifactId(), DEFAULT)
57+
rval = storage
58+
.getArtifactVersions(ga.getRawGroupIdWithNull(), ga.getRawArtifactId(),
59+
RetrievalBehavior.NON_DRAFT_STATES)
5960
.stream().map(VersionUtil::toLong).map(converter::convertUnsigned).sorted()
6061
.collect(Collectors.toList());
6162
} else {
6263
rval = storage
6364
.getArtifactVersions(ga.getRawGroupIdWithNull(), ga.getRawArtifactId(),
64-
SKIP_DISABLED_LATEST)
65+
RetrievalBehavior.ACTIVE_STATES)
6566
.stream().map(VersionUtil::toLong).map(converter::convertUnsigned).sorted()
6667
.collect(Collectors.toList());
6768
}

app/src/main/java/io/apicurio/registry/rest/RestConfig.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
public class RestConfig {
1212

1313
@ConfigProperty(name = "apicurio.rest.artifact.download.max-size.bytes", defaultValue = "1000000")
14-
@Info(category = "rest", description = "Max size of the artifact allowed to be downloaded from URL", availableSince = "2.2.6-SNAPSHOT")
14+
@Info(category = "rest", description = "Max size of the artifact allowed to be downloaded from URL", availableSince = "2.2.6")
1515
int downloadMaxSize;
1616

1717
@ConfigProperty(name = "apicurio.rest.artifact.download.ssl-validation.disabled", defaultValue = "false")
18-
@Info(category = "rest", description = "Skip SSL validation when downloading artifacts from URL", availableSince = "2.2.6-SNAPSHOT")
18+
@Info(category = "rest", description = "Skip SSL validation when downloading artifacts from URL", availableSince = "2.2.6")
1919
boolean downloadSkipSSLValidation;
2020

2121
@Dynamic(label = "Delete group", description = "When selected, users are permitted to delete groups.")

app/src/main/java/io/apicurio/registry/rest/v2/GroupsResourceImpl.java

+30-4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import io.apicurio.registry.model.BranchId;
1717
import io.apicurio.registry.model.GA;
1818
import io.apicurio.registry.model.GAV;
19+
import io.apicurio.registry.model.VersionExpressionParser;
1920
import io.apicurio.registry.rest.HeadersHack;
2021
import io.apicurio.registry.rest.MissingRequiredParameterException;
2122
import io.apicurio.registry.rest.ParametersConflictException;
@@ -182,7 +183,7 @@ public Response getLatestArtifact(String groupId, String artifactId, Boolean der
182183

183184
try {
184185
GAV latestGAV = storage.getBranchTip(new GA(groupId, artifactId), BranchId.LATEST,
185-
RetrievalBehavior.SKIP_DISABLED_LATEST);
186+
RetrievalBehavior.ACTIVE_STATES);
186187
ArtifactVersionMetaDataDto metaData = storage.getArtifactVersionMetaData(
187188
latestGAV.getRawGroupIdWithNull(), latestGAV.getRawArtifactId(),
188189
latestGAV.getRawVersionId());
@@ -261,6 +262,13 @@ public ArtifactMetaData updateArtifact(String groupId, String artifactId, String
261262
@Override
262263
public List<ArtifactReference> getArtifactVersionReferences(String groupId, String artifactId,
263264
String version, ReferenceType refType) {
265+
266+
if ("latest".equals(version)) {
267+
var gav = VersionExpressionParser.parse(new GA(groupId, artifactId), "branch=latest",
268+
(ga, branchId) -> storage.getBranchTip(ga, branchId, RetrievalBehavior.ALL_STATES));
269+
version = gav.getRawVersionId();
270+
}
271+
264272
if (refType == null || refType == ReferenceType.OUTBOUND) {
265273
return storage.getArtifactVersionContent(defaultGroupIdToNull(groupId), artifactId, version)
266274
.getReferences().stream().map(V2ApiUtil::referenceDtoToReference)
@@ -324,7 +332,7 @@ public ArtifactMetaData getArtifactMetaData(String groupId, String artifactId) {
324332

325333
ArtifactMetaDataDto dto = storage.getArtifactMetaData(defaultGroupIdToNull(groupId), artifactId);
326334
GAV latestGAV = storage.getBranchTip(new GA(groupId, artifactId), BranchId.LATEST,
327-
RetrievalBehavior.SKIP_DISABLED_LATEST);
335+
RetrievalBehavior.ACTIVE_STATES);
328336
ArtifactVersionMetaDataDto vdto = storage.getArtifactVersionMetaData(
329337
latestGAV.getRawGroupIdWithNull(), latestGAV.getRawArtifactId(), latestGAV.getRawVersionId());
330338

@@ -352,7 +360,7 @@ public ArtifactMetaData getArtifactMetaData(String groupId, String artifactId) {
352360
@Authorized(style = AuthorizedStyle.GroupAndArtifact, level = AuthorizedLevel.Write)
353361
public void updateArtifactMetaData(String groupId, String artifactId, EditableMetaData data) {
354362
GAV latestGAV = storage.getBranchTip(new GA(groupId, artifactId), BranchId.LATEST,
355-
RetrievalBehavior.DEFAULT);
363+
RetrievalBehavior.ALL_STATES);
356364
storage.updateArtifactVersionMetaData(groupId, artifactId, latestGAV.getRawVersionId(),
357365
EditableVersionMetaDataDto.builder().name(data.getName()).description(data.getDescription())
358366
.labels(V2ApiUtil.toV3Labels(data.getLabels(), data.getProperties())).build());
@@ -614,7 +622,7 @@ public void updateArtifactState(String groupId, String artifactId, UpdateState d
614622

615623
// Possible race condition here. Worst case should be that the update fails with a reasonable message.
616624
GAV latestGAV = storage.getBranchTip(new GA(defaultGroupIdToNull(groupId), artifactId),
617-
BranchId.LATEST, RetrievalBehavior.DEFAULT);
625+
BranchId.LATEST, RetrievalBehavior.ALL_STATES);
618626
updateArtifactVersionState(groupId, artifactId, latestGAV.getRawVersionId(), data);
619627
}
620628

@@ -662,6 +670,12 @@ public Response getArtifactVersion(String groupId, String artifactId, String ver
662670
dereference = Boolean.FALSE;
663671
}
664672

673+
if ("latest".equals(version)) {
674+
var gav = VersionExpressionParser.parse(new GA(groupId, artifactId), "branch=latest",
675+
(ga, branchId) -> storage.getBranchTip(ga, branchId, RetrievalBehavior.ALL_STATES));
676+
version = gav.getRawVersionId();
677+
}
678+
665679
ArtifactVersionMetaDataDto metaData = storage
666680
.getArtifactVersionMetaData(defaultGroupIdToNull(groupId), artifactId, version);
667681
if (VersionState.DISABLED.equals(metaData.getState())) {
@@ -726,6 +740,12 @@ public VersionMetaData getArtifactVersionMetaData(String groupId, String artifac
726740
requireParameter("artifactId", artifactId);
727741
requireParameter("version", version);
728742

743+
if ("latest".equals(version)) {
744+
var gav = VersionExpressionParser.parse(new GA(groupId, artifactId), "branch=latest",
745+
(ga, branchId) -> storage.getBranchTip(ga, branchId, RetrievalBehavior.ALL_STATES));
746+
version = gav.getRawVersionId();
747+
}
748+
729749
ArtifactVersionMetaDataDto dto = storage.getArtifactVersionMetaData(defaultGroupIdToNull(groupId),
730750
artifactId, version);
731751
return V2ApiUtil.dtoToVersionMetaData(defaultGroupIdToNull(groupId), artifactId,
@@ -813,6 +833,12 @@ public List<Comment> getArtifactVersionComments(String groupId, String artifactI
813833
requireParameter("artifactId", artifactId);
814834
requireParameter("version", version);
815835

836+
if ("latest".equals(version)) {
837+
var gav = VersionExpressionParser.parse(new GA(groupId, artifactId), "branch=latest",
838+
(ga, branchId) -> storage.getBranchTip(ga, branchId, RetrievalBehavior.ALL_STATES));
839+
version = gav.getRawVersionId();
840+
}
841+
816842
return storage.getArtifactVersionComments(defaultGroupIdToNull(groupId), artifactId, version).stream()
817843
.map(V2ApiUtil::commentDtoToComment).collect(Collectors.toList());
818844
}

app/src/main/java/io/apicurio/registry/rest/v3/GroupsResourceImpl.java

+12-19
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public List<ArtifactReference> getArtifactVersionReferences(String groupId, Stri
160160
String versionExpression, ReferenceType refType) {
161161

162162
var gav = VersionExpressionParser.parse(new GA(groupId, artifactId), versionExpression,
163-
(ga, branchId) -> storage.getBranchTip(ga, branchId, RetrievalBehavior.DEFAULT));
163+
(ga, branchId) -> storage.getBranchTip(ga, branchId, RetrievalBehavior.ALL_STATES));
164164

165165
if (refType == null || refType == ReferenceType.OUTBOUND) {
166166
return storage
@@ -540,9 +540,9 @@ public void updateArtifactVersionContent(String groupId, String artifactId, Stri
540540
HttpMethod.GET, (String[]) null);
541541
}
542542

543-
// Resolve the GAV info
543+
// Resolve the GAV info (only look for DRAFT versions)
544544
var gav = VersionExpressionParser.parse(new GA(groupId, artifactId), versionExpression,
545-
(ga, branchId) -> storage.getBranchTip(ga, branchId, RetrievalBehavior.SKIP_DISABLED_LATEST));
545+
(ga, branchId) -> storage.getBranchTip(ga, branchId, RetrievalBehavior.ALL_STATES));
546546

547547
// Ensure the artifact version is in DRAFT status
548548
ArtifactVersionMetaDataDto vmd = storage.getArtifactVersionMetaData(gav.getRawGroupIdWithNull(),
@@ -586,7 +586,7 @@ public void deleteArtifactVersion(String groupId, String artifactId, String vers
586586
requireParameter("version", version);
587587

588588
var gav = VersionExpressionParser.parse(new GA(groupId, artifactId), version,
589-
(ga, branchId) -> storage.getBranchTip(ga, branchId, RetrievalBehavior.DEFAULT));
589+
(ga, branchId) -> storage.getBranchTip(ga, branchId, RetrievalBehavior.ALL_STATES));
590590

591591
storage.deleteArtifactVersion(gav.getRawGroupIdWithNull(), gav.getRawArtifactId(),
592592
gav.getRawVersionId());
@@ -626,7 +626,7 @@ public void updateArtifactVersionMetaData(String groupId, String artifactId, Str
626626
requireParameter("versionExpression", versionExpression);
627627

628628
var gav = VersionExpressionParser.parse(new GA(groupId, artifactId), versionExpression,
629-
(ga, branchId) -> storage.getBranchTip(ga, branchId, RetrievalBehavior.DEFAULT));
629+
(ga, branchId) -> storage.getBranchTip(ga, branchId, RetrievalBehavior.SKIP_DISABLED_LATEST));
630630

631631
EditableVersionMetaDataDto dto = new EditableVersionMetaDataDto();
632632
dto.setName(data.getName());
@@ -645,7 +645,7 @@ public WrappedVersionState getArtifactVersionState(String groupId, String artifa
645645
requireParameter("version", versionExpression);
646646

647647
var gav = VersionExpressionParser.parse(new GA(groupId, artifactId), versionExpression,
648-
(ga, branchId) -> storage.getBranchTip(ga, branchId, RetrievalBehavior.DEFAULT));
648+
(ga, branchId) -> storage.getBranchTip(ga, branchId, RetrievalBehavior.ALL_STATES));
649649

650650
VersionState state = storage.getArtifactVersionState(gav.getRawGroupIdWithNull(),
651651
gav.getRawArtifactId(), gav.getRawVersionId());
@@ -667,7 +667,7 @@ public void updateArtifactVersionState(String groupId, String artifactId, String
667667
}
668668

669669
var gav = VersionExpressionParser.parse(new GA(groupId, artifactId), versionExpression,
670-
(ga, branchId) -> storage.getBranchTip(ga, branchId, RetrievalBehavior.DEFAULT));
670+
(ga, branchId) -> storage.getBranchTip(ga, branchId, RetrievalBehavior.ALL_STATES));
671671

672672
// Get current state.
673673
VersionState currentState = storage.getArtifactVersionState(gav.getRawGroupIdWithNull(),
@@ -680,7 +680,7 @@ public void updateArtifactVersionState(String groupId, String artifactId, String
680680

681681
// If the current state is DRAFT, apply rules.
682682
if (currentState == VersionState.DRAFT) {
683-
VersionMetaData vmd = getArtifactVersionMetaData(gav.getRawGroupIdWithNull(),
683+
VersionMetaData vmd = getArtifactVersionMetaData(gav.getRawGroupIdWithDefaultString(),
684684
gav.getRawArtifactId(), gav.getRawVersionId());
685685
StoredArtifactVersionDto artifact = storage.getArtifactVersionContent(gav.getRawGroupIdWithNull(),
686686
gav.getRawArtifactId(), gav.getRawVersionId());
@@ -714,7 +714,7 @@ public Comment addArtifactVersionComment(String groupId, String artifactId, Stri
714714
requireParameter("versionExpression", versionExpression);
715715

716716
var gav = VersionExpressionParser.parse(new GA(groupId, artifactId), versionExpression,
717-
(ga, branchId) -> storage.getBranchTip(ga, branchId, RetrievalBehavior.DEFAULT));
717+
(ga, branchId) -> storage.getBranchTip(ga, branchId, RetrievalBehavior.ALL_STATES));
718718

719719
CommentDto newComment = storage.createArtifactVersionComment(gav.getRawGroupIdWithNull(),
720720
gav.getRawArtifactId(), gav.getRawVersionId(), data.getValue());
@@ -737,7 +737,7 @@ public void deleteArtifactVersionComment(String groupId, String artifactId, Stri
737737
requireParameter("commentId", commentId);
738738

739739
var gav = VersionExpressionParser.parse(new GA(groupId, artifactId), versionExpression,
740-
(ga, branchId) -> storage.getBranchTip(ga, branchId, RetrievalBehavior.DEFAULT));
740+
(ga, branchId) -> storage.getBranchTip(ga, branchId, RetrievalBehavior.ALL_STATES));
741741

742742
storage.deleteArtifactVersionComment(gav.getRawGroupIdWithNull(), gav.getRawArtifactId(),
743743
gav.getRawVersionId(), commentId);
@@ -755,7 +755,7 @@ public List<Comment> getArtifactVersionComments(String groupId, String artifactI
755755
requireParameter("version", version);
756756

757757
var gav = VersionExpressionParser.parse(new GA(groupId, artifactId), version,
758-
(ga, branchId) -> storage.getBranchTip(ga, branchId, RetrievalBehavior.DEFAULT));
758+
(ga, branchId) -> storage.getBranchTip(ga, branchId, RetrievalBehavior.ALL_STATES));
759759

760760
return storage.getArtifactVersionComments(gav.getRawGroupIdWithNull(), gav.getRawArtifactId(),
761761
gav.getRawVersionId()).stream().map(V3ApiUtil::commentDtoToComment).collect(toList());
@@ -779,7 +779,7 @@ public void updateArtifactVersionComment(String groupId, String artifactId, Stri
779779
requireParameter("value", data.getValue());
780780

781781
var gav = VersionExpressionParser.parse(new GA(groupId, artifactId), versionExpression,
782-
(ga, branchId) -> storage.getBranchTip(ga, branchId, RetrievalBehavior.DEFAULT));
782+
(ga, branchId) -> storage.getBranchTip(ga, branchId, RetrievalBehavior.ALL_STATES));
783783

784784
storage.updateArtifactVersionComment(gav.getRawGroupIdWithNull(), gav.getRawArtifactId(),
785785
gav.getRawVersionId(), commentId, data.getValue());
@@ -1227,13 +1227,6 @@ private CreateArtifactResponse handleIfExists(String groupId, String artifactId,
12271227
switch (ifExists) {
12281228
case CREATE_VERSION:
12291229
return updateArtifactInternal(groupId, artifactId, theVersion);
1230-
// case RETURN:
1231-
// GAV latestGAV = storage.getBranchTip(new GA(groupId, artifactId), BranchId.LATEST,
1232-
// ArtifactRetrievalBehavior.DEFAULT);
1233-
// ArtifactVersionMetaDataDto latestVersionMD =
1234-
// storage.getArtifactVersionMetaData(latestGAV.getRawGroupIdWithNull(),
1235-
// latestGAV.getRawArtifactId(), latestGAV.getRawVersionId());
1236-
// return V3ApiUtil.dtoToVersionMetaData(latestVersionMD);
12371230
case FIND_OR_CREATE_VERSION:
12381231
return handleIfExistsReturnOrUpdate(groupId, artifactId, theVersion, canonical);
12391232
default:

0 commit comments

Comments
 (0)