Skip to content

Commit

Permalink
Ensure that ccompat and v2 APIs do not return DRAFT content
Browse files Browse the repository at this point in the history
  • Loading branch information
EricWittmann committed Oct 15, 2024
1 parent db9adeb commit a8621ff
Show file tree
Hide file tree
Showing 19 changed files with 231 additions and 105 deletions.
8 changes: 4 additions & 4 deletions app/src/main/java/io/apicurio/registry/auth/AuthConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ public class AuthConfig {
Logger log;

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

@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")
@ConfigProperty(name = "apicurio.authn.basic-client-credentials.enabled", defaultValue = "false")
@Info(category = "auth", description = "Enable basic auth client credentials", availableSince = "0.1.18-SNAPSHOT", registryAvailableSince = "2.1.0.Final", studioAvailableSince = "1.0.0")
@Info(category = "auth", description = "Enable basic auth client credentials", availableSince = "0.1.18", registryAvailableSince = "2.1.0.Final", studioAvailableSince = "1.0.0")
Supplier<Boolean> basicClientCredentialsAuthEnabled;

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

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

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

@PostConstruct
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ protected boolean isArtifactActive(String artifactId, String groupId) {
protected String getLatestArtifactVersionForSubject(String artifactId, String groupId) {
try {
GAV latestGAV = storage.getBranchTip(new GA(groupId, artifactId), BranchId.LATEST,
RetrievalBehavior.SKIP_DISABLED_LATEST);
RetrievalBehavior.ACTIVE_STATES);
return latestGAV.getRawVersionId();
} catch (ArtifactNotFoundException ex) {
throw new VersionNotFoundException(groupId, artifactId, "latest");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.apicurio.registry.metrics.health.liveness.ResponseErrorLivenessCheck;
import io.apicurio.registry.metrics.health.readiness.ResponseTimeoutReadinessCheck;
import io.apicurio.registry.model.GA;
import io.apicurio.registry.storage.RegistryStorage.RetrievalBehavior;
import io.apicurio.registry.storage.dto.ArtifactVersionMetaDataDto;
import io.apicurio.registry.storage.dto.StoredArtifactVersionDto;
import io.apicurio.registry.storage.error.ArtifactNotFoundException;
Expand All @@ -37,8 +38,6 @@

import static io.apicurio.common.apps.logging.audit.AuditingConstants.KEY_ARTIFACT_ID;
import static io.apicurio.common.apps.logging.audit.AuditingConstants.KEY_VERSION;
import static io.apicurio.registry.storage.RegistryStorage.RetrievalBehavior.DEFAULT;
import static io.apicurio.registry.storage.RegistryStorage.RetrievalBehavior.SKIP_DISABLED_LATEST;

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

List<Integer> rval;
if (fdeleted) {
rval = storage.getArtifactVersions(ga.getRawGroupIdWithNull(), ga.getRawArtifactId(), DEFAULT)
rval = storage
.getArtifactVersions(ga.getRawGroupIdWithNull(), ga.getRawArtifactId(),
RetrievalBehavior.NON_DRAFT_STATES)
.stream().map(VersionUtil::toLong).map(converter::convertUnsigned).sorted()
.collect(Collectors.toList());
} else {
rval = storage
.getArtifactVersions(ga.getRawGroupIdWithNull(), ga.getRawArtifactId(),
SKIP_DISABLED_LATEST)
RetrievalBehavior.ACTIVE_STATES)
.stream().map(VersionUtil::toLong).map(converter::convertUnsigned).sorted()
.collect(Collectors.toList());
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/io/apicurio/registry/rest/RestConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
public class RestConfig {

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

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

@Dynamic(label = "Delete group", description = "When selected, users are permitted to delete groups.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import io.apicurio.registry.model.BranchId;
import io.apicurio.registry.model.GA;
import io.apicurio.registry.model.GAV;
import io.apicurio.registry.model.VersionExpressionParser;
import io.apicurio.registry.rest.HeadersHack;
import io.apicurio.registry.rest.MissingRequiredParameterException;
import io.apicurio.registry.rest.ParametersConflictException;
Expand Down Expand Up @@ -182,7 +183,7 @@ public Response getLatestArtifact(String groupId, String artifactId, Boolean der

try {
GAV latestGAV = storage.getBranchTip(new GA(groupId, artifactId), BranchId.LATEST,
RetrievalBehavior.SKIP_DISABLED_LATEST);
RetrievalBehavior.ACTIVE_STATES);
ArtifactVersionMetaDataDto metaData = storage.getArtifactVersionMetaData(
latestGAV.getRawGroupIdWithNull(), latestGAV.getRawArtifactId(),
latestGAV.getRawVersionId());
Expand Down Expand Up @@ -261,6 +262,13 @@ public ArtifactMetaData updateArtifact(String groupId, String artifactId, String
@Override
public List<ArtifactReference> getArtifactVersionReferences(String groupId, String artifactId,
String version, ReferenceType refType) {

if ("latest".equals(version)) {
var gav = VersionExpressionParser.parse(new GA(groupId, artifactId), "branch=latest",
(ga, branchId) -> storage.getBranchTip(ga, branchId, RetrievalBehavior.ALL_STATES));
version = gav.getRawVersionId();
}

if (refType == null || refType == ReferenceType.OUTBOUND) {
return storage.getArtifactVersionContent(defaultGroupIdToNull(groupId), artifactId, version)
.getReferences().stream().map(V2ApiUtil::referenceDtoToReference)
Expand Down Expand Up @@ -324,7 +332,7 @@ public ArtifactMetaData getArtifactMetaData(String groupId, String artifactId) {

ArtifactMetaDataDto dto = storage.getArtifactMetaData(defaultGroupIdToNull(groupId), artifactId);
GAV latestGAV = storage.getBranchTip(new GA(groupId, artifactId), BranchId.LATEST,
RetrievalBehavior.SKIP_DISABLED_LATEST);
RetrievalBehavior.ACTIVE_STATES);
ArtifactVersionMetaDataDto vdto = storage.getArtifactVersionMetaData(
latestGAV.getRawGroupIdWithNull(), latestGAV.getRawArtifactId(), latestGAV.getRawVersionId());

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

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

Expand Down Expand Up @@ -662,6 +670,12 @@ public Response getArtifactVersion(String groupId, String artifactId, String ver
dereference = Boolean.FALSE;
}

if ("latest".equals(version)) {
var gav = VersionExpressionParser.parse(new GA(groupId, artifactId), "branch=latest",
(ga, branchId) -> storage.getBranchTip(ga, branchId, RetrievalBehavior.ALL_STATES));
version = gav.getRawVersionId();
}

ArtifactVersionMetaDataDto metaData = storage
.getArtifactVersionMetaData(defaultGroupIdToNull(groupId), artifactId, version);
if (VersionState.DISABLED.equals(metaData.getState())) {
Expand Down Expand Up @@ -726,6 +740,12 @@ public VersionMetaData getArtifactVersionMetaData(String groupId, String artifac
requireParameter("artifactId", artifactId);
requireParameter("version", version);

if ("latest".equals(version)) {
var gav = VersionExpressionParser.parse(new GA(groupId, artifactId), "branch=latest",
(ga, branchId) -> storage.getBranchTip(ga, branchId, RetrievalBehavior.ALL_STATES));
version = gav.getRawVersionId();
}

ArtifactVersionMetaDataDto dto = storage.getArtifactVersionMetaData(defaultGroupIdToNull(groupId),
artifactId, version);
return V2ApiUtil.dtoToVersionMetaData(defaultGroupIdToNull(groupId), artifactId,
Expand Down Expand Up @@ -813,6 +833,12 @@ public List<Comment> getArtifactVersionComments(String groupId, String artifactI
requireParameter("artifactId", artifactId);
requireParameter("version", version);

if ("latest".equals(version)) {
var gav = VersionExpressionParser.parse(new GA(groupId, artifactId), "branch=latest",
(ga, branchId) -> storage.getBranchTip(ga, branchId, RetrievalBehavior.ALL_STATES));
version = gav.getRawVersionId();
}

return storage.getArtifactVersionComments(defaultGroupIdToNull(groupId), artifactId, version).stream()
.map(V2ApiUtil::commentDtoToComment).collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public List<ArtifactReference> getArtifactVersionReferences(String groupId, Stri
String versionExpression, ReferenceType refType) {

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

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

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

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

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

storage.deleteArtifactVersion(gav.getRawGroupIdWithNull(), gav.getRawArtifactId(),
gav.getRawVersionId());
Expand Down Expand Up @@ -626,7 +626,7 @@ public void updateArtifactVersionMetaData(String groupId, String artifactId, Str
requireParameter("versionExpression", versionExpression);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

storage.updateArtifactVersionComment(gav.getRawGroupIdWithNull(), gav.getRawArtifactId(),
gav.getRawVersionId(), commentId, data.getValue());
Expand Down Expand Up @@ -1227,13 +1227,6 @@ private CreateArtifactResponse handleIfExists(String groupId, String artifactId,
switch (ifExists) {
case CREATE_VERSION:
return updateArtifactInternal(groupId, artifactId, theVersion);
// case RETURN:
// GAV latestGAV = storage.getBranchTip(new GA(groupId, artifactId), BranchId.LATEST,
// ArtifactRetrievalBehavior.DEFAULT);
// ArtifactVersionMetaDataDto latestVersionMD =
// storage.getArtifactVersionMetaData(latestGAV.getRawGroupIdWithNull(),
// latestGAV.getRawArtifactId(), latestGAV.getRawVersionId());
// return V3ApiUtil.dtoToVersionMetaData(latestVersionMD);
case FIND_OR_CREATE_VERSION:
return handleIfExistsReturnOrUpdate(groupId, artifactId, theVersion, canonical);
default:
Expand Down
Loading

0 comments on commit a8621ff

Please sign in to comment.