Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import io.cdap.cdap.proto.id.ApplicationId;
import io.cdap.cdap.proto.id.DatasetId;
import io.cdap.cdap.proto.id.ProgramId;
import io.cdap.cdap.proto.security.StandardPermission;
import io.cdap.cdap.security.spi.authorization.ContextAccessEnforcer;
import io.cdap.http.AbstractHttpHandler;
import io.cdap.http.HttpResponder;
import io.netty.handler.codec.http.HttpRequest;
Expand All @@ -41,10 +43,12 @@ public class UsageHandler extends AbstractHttpHandler {

private static final Gson GSON = new Gson();
private final UsageRegistry registry;
private final ContextAccessEnforcer contextAccessEnforcer;

@Inject
public UsageHandler(UsageRegistry registry) {
public UsageHandler(UsageRegistry registry, ContextAccessEnforcer contextAccessEnforcer) {
this.registry = registry;
this.contextAccessEnforcer = contextAccessEnforcer;
}

@GET
Expand All @@ -53,6 +57,7 @@ public void getAppDatasetUsage(HttpRequest request, HttpResponder responder,
@PathParam("namespace-id") String namespaceId,
@PathParam("app-id") String appId) {
final ApplicationId id = new ApplicationId(namespaceId, appId);
contextAccessEnforcer.enforce(id, StandardPermission.GET);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The contextAccessEnforcer.enforce method throws AccessException, which is a checked exception. Since the getAppDatasetUsage method does not declare throws Exception (or throws AccessException) in its signature, this will result in a compilation error. Please update the method signature to declare throws Exception.

Set<DatasetId> ids = registry.getDatasets(id);
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(ids));
}
Expand All @@ -66,6 +71,7 @@ public void getProgramDatasetUsage(HttpRequest request, HttpResponder responder,
@PathParam("program-id") String programId) {
ProgramType type = ProgramType.valueOfCategoryName(programType);
final ProgramId id = new ProgramId(namespaceId, appId, type, programId);
contextAccessEnforcer.enforce(id, StandardPermission.GET);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The contextAccessEnforcer.enforce method throws AccessException, which is a checked exception. Since the getProgramDatasetUsage method does not declare throws Exception (or throws AccessException) in its signature, this will result in a compilation error. Please update the method signature to declare throws Exception.

Set<DatasetId> ids = registry.getDatasets(id);
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(ids));
}
Expand All @@ -77,6 +83,7 @@ public void getDatasetAppUsage(HttpRequest request, HttpResponder responder,
@PathParam("namespace-id") String namespaceId,
@PathParam("dataset-id") String datasetId) {
final DatasetId id = new DatasetId(namespaceId, datasetId);
contextAccessEnforcer.enforce(id, StandardPermission.GET);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The contextAccessEnforcer.enforce method throws AccessException, which is a checked exception. Since the getDatasetAppUsage method does not declare throws Exception (or throws AccessException) in its signature, this will result in a compilation error. Please update the method signature to declare throws Exception.

Set<ProgramId> ids = registry.getPrograms(id);
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(ids));
}
Expand Down