Skip to content

Commit

Permalink
Add header for group customization in the ccompat api
Browse files Browse the repository at this point in the history
  • Loading branch information
carlesarnal committed Jul 18, 2023
1 parent 90804c1 commit 8ae2480
Show file tree
Hide file tree
Showing 15 changed files with 209 additions and 155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public List<String> listSubjects() {
@Override
@Authorized(style=AuthorizedStyle.ArtifactOnly, level=AuthorizedLevel.Read)
public Schema findSchemaByContent(String subject, SchemaInfo request) throws Exception {
return facade.getSchema(subject, request, false);
return facade.getSchemaNormalize(subject, request, false);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@

import io.apicurio.registry.ccompat.dto.CompatibilityCheckResponse;
import io.apicurio.registry.ccompat.dto.SchemaContent;
import io.apicurio.registry.rest.Headers;

import javax.validation.constraints.NotNull;
import javax.ws.rs.Consumes;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
Expand Down Expand Up @@ -70,7 +72,7 @@ public interface CompatibilityResource {
@Path("/subjects/{subject}/versions")
CompatibilityCheckResponse testCompatibilityBySubjectName(
@PathParam("subject") String subject,
@NotNull SchemaContent request, @QueryParam("verbose") Boolean verbose) throws Exception;
@NotNull SchemaContent request, @QueryParam("verbose") Boolean verbose, @HeaderParam(Headers.GROUP_ID) String groupId) throws Exception;

// ----- Path: /compatibility/subjects/{subject}/versions/{version} -----

Expand Down Expand Up @@ -102,6 +104,6 @@ CompatibilityCheckResponse testCompatibilityBySubjectName(
CompatibilityCheckResponse testCompatibilityByVersion(
@PathParam("subject") String subject,
@PathParam("version") String version,
@NotNull SchemaContent request, @QueryParam("verbose") Boolean verbose) throws Exception;
@NotNull SchemaContent request, @QueryParam("verbose") Boolean verbose, @HeaderParam(Headers.GROUP_ID) String groupId) throws Exception;

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@

import io.apicurio.registry.ccompat.dto.CompatibilityLevelDto;
import io.apicurio.registry.ccompat.dto.CompatibilityLevelParamDto;
import io.apicurio.registry.rest.Headers;

import javax.validation.constraints.NotNull;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
Expand Down Expand Up @@ -102,7 +104,7 @@ CompatibilityLevelDto updateGlobalCompatibilityLevel(
*/
@Path("/{subject}")
@GET
CompatibilityLevelParamDto getSubjectCompatibilityLevel(@PathParam("subject") String subject);
CompatibilityLevelParamDto getSubjectCompatibilityLevel(@PathParam("subject") String subject, @HeaderParam(Headers.GROUP_ID) String groupId);

/**
* Update compatibility level for the specified subject.
Expand All @@ -124,7 +126,7 @@ CompatibilityLevelDto updateGlobalCompatibilityLevel(
@PUT
CompatibilityLevelDto updateSubjectCompatibilityLevel(
@PathParam("subject") String subject,
@NotNull CompatibilityLevelDto request);
@NotNull CompatibilityLevelDto request, @HeaderParam(Headers.GROUP_ID) String groupId);

/**
* Deletes the specified subject-level compatibility level config and reverts to the global default.
Expand All @@ -141,5 +143,5 @@ CompatibilityLevelDto updateSubjectCompatibilityLevel(
@Path("/{subject}")
@DELETE
CompatibilityLevelParamDto deleteSubjectCompatibility(
@PathParam("subject") String subject);
@PathParam("subject") String subject, @HeaderParam(Headers.GROUP_ID) String groupId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@

import io.apicurio.registry.ccompat.dto.SchemaInfo;
import io.apicurio.registry.ccompat.dto.SubjectVersion;
import io.apicurio.registry.rest.Headers;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
Expand Down Expand Up @@ -68,7 +70,7 @@ public interface SchemasResource {
*/
@GET
@Path("/ids/{id}")
SchemaInfo getSchema(@PathParam("id") int id, @QueryParam("subject") String subject);
SchemaInfo getSchema(@PathParam("id") int id, @QueryParam("subject") String subject, @HeaderParam(Headers.GROUP_ID) String groupId);

// ----- Path: /schemas/types -----

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
import io.apicurio.registry.ccompat.dto.Schema;
import io.apicurio.registry.ccompat.dto.SchemaId;
import io.apicurio.registry.ccompat.dto.SchemaInfo;
import io.apicurio.registry.rest.Headers;

import javax.validation.constraints.NotNull;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
Expand Down Expand Up @@ -83,7 +85,7 @@ public interface SubjectVersionsResource {
* </ul>
*/
@GET
List<Integer> listVersions(@PathParam("subject") String subject) throws Exception;
List<Integer> listVersions(@PathParam("subject") String subject, @HeaderParam(Headers.GROUP_ID) String groupId) throws Exception;

/**
* Register a new schema under the specified subject. If successfully registered,
Expand Down Expand Up @@ -120,7 +122,7 @@ public interface SubjectVersionsResource {
@Authorized(style=AuthorizedStyle.ArtifactOnly)
SchemaId register(
@PathParam("subject") String subject,
@NotNull SchemaInfo request, @QueryParam("normalize") Boolean normalize) throws Exception;
@NotNull SchemaInfo request, @QueryParam("normalize") Boolean normalize, @HeaderParam(Headers.GROUP_ID) String groupId) throws Exception;


// ----- Path: /subjects/{subject}/versions/{version} -----
Expand Down Expand Up @@ -155,7 +157,7 @@ SchemaId register(
@Path("/{version}")
Schema getSchemaByVersion(
@PathParam("subject") String subject,
@PathParam("version") String version) throws Exception;
@PathParam("version") String version, @HeaderParam(Headers.GROUP_ID) String groupId) throws Exception;

/**
* Deletes a specific version of the schema registered under this subject.
Expand Down Expand Up @@ -193,7 +195,7 @@ Schema getSchemaByVersion(
@Authorized(style=AuthorizedStyle.ArtifactOnly)
int deleteSchemaVersion(
@PathParam("subject") String subject,
@PathParam("version") String version, @QueryParam("permanent") Boolean permanent) throws Exception;
@PathParam("version") String version, @QueryParam("permanent") Boolean permanent, @HeaderParam(Headers.GROUP_ID) String groupId) throws Exception;

// ----- Path: /subjects/{subject}/versions/{version}/schema -----

Expand Down Expand Up @@ -223,7 +225,7 @@ int deleteSchemaVersion(
@Path("/{version}/schema")
String getSchemaOnly(
@PathParam("subject") String subject,
@PathParam("version") String version) throws Exception;
@PathParam("version") String version, @HeaderParam(Headers.GROUP_ID) String groupId) throws Exception;

// ----- Path: /subjects/{subject}/versions/{version}/referencedby -----

Expand Down Expand Up @@ -253,7 +255,7 @@ String getSchemaOnly(
@GET
@Path("/{version}/referencedby")
List<Long> getSchemasReferencedBy(
@PathParam("subject") String subject, @PathParam("version") String version) throws Exception;
@PathParam("subject") String subject, @PathParam("version") String version, @HeaderParam(Headers.GROUP_ID) String groupId) throws Exception;


}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@

import io.apicurio.registry.ccompat.dto.Schema;
import io.apicurio.registry.ccompat.dto.SchemaInfo;
import io.apicurio.registry.rest.Headers;

import javax.validation.constraints.NotNull;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
Expand Down Expand Up @@ -65,7 +67,7 @@ public interface SubjectsResource {
* Error code 50001 – Error in the backend datastore
*/
@GET
List<String> listSubjects(@QueryParam("subjectPrefix") String subjectPrefix, @QueryParam("deleted") Boolean deleted);
List<String> listSubjects(@QueryParam("subjectPrefix") String subjectPrefix, @QueryParam("deleted") Boolean deleted, @HeaderParam(Headers.GROUP_ID) String groupId);

// ----- Path: /subjects/{subject} -----

Expand Down Expand Up @@ -97,7 +99,7 @@ public interface SubjectsResource {
@Path("/{subject}")
Schema findSchemaByContent(
@PathParam("subject") String subject,
@NotNull SchemaInfo request, @QueryParam("normalize") Boolean normalize) throws Exception;
@NotNull SchemaInfo request, @QueryParam("normalize") Boolean normalize, @HeaderParam(Headers.GROUP_ID) String groupId) throws Exception;

/**
* Deletes the specified subject and its associated compatibility level if registered.
Expand All @@ -123,5 +125,5 @@ Schema findSchemaByContent(
@DELETE
@Path("/{subject}")
List<Integer> deleteSubject(
@PathParam("subject") String subject, @QueryParam("permanent") Boolean permanent) throws Exception;
@PathParam("subject") String subject, @QueryParam("permanent") Boolean permanent, @HeaderParam(Headers.GROUP_ID) String groupId) throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ public class CompatibilityResourceImpl extends AbstractResource implements Compa

@Override
@Authorized(style = AuthorizedStyle.ArtifactOnly, level = AuthorizedLevel.Write)
public CompatibilityCheckResponse testCompatibilityBySubjectName(String subject, SchemaContent request, Boolean verbose) throws Exception {
public CompatibilityCheckResponse testCompatibilityBySubjectName(String subject, SchemaContent request, Boolean verbose, String groupId) throws Exception {
final boolean fverbose = verbose == null ? Boolean.FALSE : verbose;
return facade.testCompatibilityBySubjectName(subject, request, fverbose);
return facade.testCompatibilityBySubjectName(subject, request, fverbose, groupId);
}

@Override
@Authorized(style = AuthorizedStyle.ArtifactOnly, level = AuthorizedLevel.Write)
public CompatibilityCheckResponse testCompatibilityByVersion(String subject, String version, SchemaContent request, Boolean verbose) throws Exception {
public CompatibilityCheckResponse testCompatibilityByVersion(String subject, String version, SchemaContent request, Boolean verbose, String groupId) throws Exception {
final boolean fverbose = verbose == null ? Boolean.FALSE : verbose;
return facade.testCompatibilityByVersion(subject, version, request, fverbose);
return facade.testCompatibilityByVersion(subject, version, request, fverbose, groupId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,28 +96,28 @@ public CompatibilityLevelDto updateGlobalCompatibilityLevel(CompatibilityLevelDt
@Override
@Audited(extractParameters = {"0", AuditingConstants.KEY_ARTIFACT_ID, "1", AuditingConstants.KEY_RULE})
@Authorized(style = AuthorizedStyle.ArtifactOnly, level = AuthorizedLevel.Write)
public CompatibilityLevelDto updateSubjectCompatibilityLevel(String subject, CompatibilityLevelDto request) {
public CompatibilityLevelDto updateSubjectCompatibilityLevel(String subject, CompatibilityLevelDto request, String groupId) {
updateCompatibilityLevel(request.getCompatibility(),
dto -> facade.createOrUpdateArtifactRule(subject, RuleType.COMPATIBILITY, dto),
() -> facade.deleteArtifactRule(subject, RuleType.COMPATIBILITY));
dto -> facade.createOrUpdateArtifactRule(subject, RuleType.COMPATIBILITY, dto, groupId),
() -> facade.deleteArtifactRule(subject, RuleType.COMPATIBILITY, groupId));
return request;
}

@Override
@Authorized(style = AuthorizedStyle.ArtifactOnly, level = AuthorizedLevel.Read)
public CompatibilityLevelParamDto getSubjectCompatibilityLevel(String subject) {
public CompatibilityLevelParamDto getSubjectCompatibilityLevel(String subject, String groupId) {
return getCompatibilityLevel(() ->
facade.getArtifactRule(subject, RuleType.COMPATIBILITY).getConfiguration());
facade.getArtifactRule(subject, RuleType.COMPATIBILITY, groupId).getConfiguration());
}

@Override
@Audited(extractParameters = {"0", AuditingConstants.KEY_ARTIFACT_ID})
@Authorized(style = AuthorizedStyle.ArtifactOnly, level = AuthorizedLevel.Write)
public CompatibilityLevelParamDto deleteSubjectCompatibility(String subject) {
public CompatibilityLevelParamDto deleteSubjectCompatibility(String subject, String groupId) {
final CompatibilityLevelParamDto compatibilityLevel = getCompatibilityLevel(() ->
facade.getArtifactRule(subject, RuleType.COMPATIBILITY).getConfiguration());
facade.getArtifactRule(subject, RuleType.COMPATIBILITY, groupId).getConfiguration());
if (!CompatibilityLevel.NONE.name().equals(compatibilityLevel.getCompatibilityLevel())) {
facade.deleteArtifactRule(subject, RuleType.COMPATIBILITY);
facade.deleteArtifactRule(subject, RuleType.COMPATIBILITY, groupId);
}
return compatibilityLevel;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class SchemasResourceImpl extends AbstractResource implements SchemasReso

@Override
@Authorized(style = AuthorizedStyle.GlobalId, level = AuthorizedLevel.Read)
public SchemaInfo getSchema(int id, String subject) {
public SchemaInfo getSchema(int id, String subject, String groupId) {
//subject is not used since contexts are not supported
return facade.getSchemaById(id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,47 +49,47 @@ public class SubjectVersionsResourceImpl extends AbstractResource implements Sub

@Override
@Authorized(style = AuthorizedStyle.ArtifactOnly, level = AuthorizedLevel.Read)
public List<Integer> listVersions(String subject) throws Exception {
return facade.getVersions(subject);
public List<Integer> listVersions(String subject, String groupId) throws Exception {
return facade.getVersions(subject, groupId);
}

@Override
@Audited(extractParameters = {"0", KEY_ARTIFACT_ID})
@Authorized(style = AuthorizedStyle.ArtifactOnly, level = AuthorizedLevel.Write)
public SchemaId register(String subject, SchemaInfo request, Boolean normalize) throws Exception {
public SchemaId register(String subject, SchemaInfo request, Boolean normalize, String groupId) throws Exception {
final boolean fnormalize = normalize == null ? Boolean.FALSE : normalize;
Long id = facade.createSchema(subject, request.getSchema(), request.getSchemaType(), request.getReferences(), fnormalize);
Long id = facade.createSchema(subject, request.getSchema(), request.getSchemaType(), request.getReferences(), fnormalize, groupId);
int sid = converter.convertUnsigned(id);
return new SchemaId(sid);
}

@Override
@Authorized(style = AuthorizedStyle.ArtifactOnly, level = AuthorizedLevel.Read)
public Schema getSchemaByVersion(String subject, String version) throws Exception {
return facade.getSchema(subject, version);
public Schema getSchemaByVersion(String subject, String version, String groupId) throws Exception {
return facade.getSchema(subject, version, groupId);
}

@Override
@Audited(extractParameters = {"0", KEY_ARTIFACT_ID, "1", KEY_VERSION})
@Authorized(style = AuthorizedStyle.ArtifactOnly, level = AuthorizedLevel.Write)
public int deleteSchemaVersion(String subject, String version, Boolean permanent) throws Exception {
public int deleteSchemaVersion(String subject, String version, Boolean permanent, String groupId) throws Exception {
try {
final boolean fnormalize = permanent == null ? Boolean.FALSE : permanent;
return facade.deleteSchema(subject, version, fnormalize);
return facade.deleteSchema(subject, version, fnormalize, groupId);
} catch (IllegalArgumentException ex) {
throw new BadRequestException(ex); // TODO
}
}

@Override
@Authorized(style = AuthorizedStyle.ArtifactOnly, level = AuthorizedLevel.Read)
public String getSchemaOnly(String subject, String version) throws Exception {
return facade.getSchema(subject, version).getSchema();
public String getSchemaOnly(String subject, String version, String groupId) throws Exception {
return facade.getSchema(subject, version, groupId).getSchema();
}

@Override
@Authorized(style = AuthorizedStyle.ArtifactOnly, level = AuthorizedLevel.Read)
public List<Long> getSchemasReferencedBy(String subject, String version) throws Exception {
return facade.getContentIdsReferencingArtifact(subject, version);
public List<Long> getSchemasReferencedBy(String subject, String version, String groupId) throws Exception {
return facade.getContentIdsReferencingArtifact(subject, version, groupId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,24 @@ public class SubjectsResourceImpl extends AbstractResource implements SubjectsRe

@Override
@Authorized(style = AuthorizedStyle.None, level = AuthorizedLevel.Read)
public List<String> listSubjects(String subjectPrefix, Boolean deleted) {
public List<String> listSubjects(String subjectPrefix, Boolean deleted, String groupId) {
//Since contexts are not supported, subjectPrefix is not used
final boolean fdeleted = deleted == null ? Boolean.FALSE : deleted;
return facade.getSubjects(fdeleted);
return facade.getSubjects(fdeleted, groupId);
}

@Override
@Authorized(style = AuthorizedStyle.ArtifactOnly, level = AuthorizedLevel.Read)
public Schema findSchemaByContent(String subject, SchemaInfo request, Boolean normalize) throws Exception {
public Schema findSchemaByContent(String subject, SchemaInfo request, Boolean normalize, String groupId) throws Exception {
final boolean fnormalize = normalize == null ? Boolean.FALSE : normalize;
return facade.getSchema(subject, request, fnormalize);
return facade.getSchemaNormalize(subject, request, fnormalize, groupId);
}

@Override
@Audited(extractParameters = {"0", KEY_ARTIFACT_ID})
@Authorized(style = AuthorizedStyle.ArtifactOnly, level = AuthorizedLevel.Write)
public List<Integer> deleteSubject(String subject, Boolean permanent) throws Exception {
public List<Integer> deleteSubject(String subject, Boolean permanent, String groupId) throws Exception {
final boolean fpermanent = permanent == null ? Boolean.FALSE : permanent;
return facade.deleteSubject(subject, fpermanent);
return facade.deleteSubject(subject, fpermanent, groupId);
}
}
Loading

0 comments on commit 8ae2480

Please sign in to comment.