Skip to content

Commit

Permalink
feat(openapi): restore Timeline OpenAPIv1 and deprecations (#10768)
Browse files Browse the repository at this point in the history
  • Loading branch information
david-leifker committed Jun 24, 2024
1 parent 5678113 commit d494e35
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 3 deletions.
4 changes: 4 additions & 0 deletions docs/how/updating-datahub.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ This file documents any backwards-incompatible changes in DataHub and assists pe

### Deprecations

- OpenAPI v1: OpenAPI v1 is collectively defined as all endpoints which are not prefixed with `/v2` or `/v3`. The v1 endpoints
will be deprecated in no less than 6 months. Endpoints will be replaced with equivalents in the `/v2` or `/v3` APIs.
No loss of functionality expected unless explicitly mentioned in Breaking Changes.

### Other Notable Changes

## 0.13.3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import io.datahubproject.openapi.generated.EntityResponse;
import io.datahubproject.openapi.v1.entities.EntitiesController;
import io.datahubproject.openapi.v1.relationships.RelationshipsController;
import io.datahubproject.openapi.v2.controller.TimelineController;
import io.datahubproject.openapi.v2.controller.TimelineControllerV2;
import io.datahubproject.test.metadata.context.TestOperationContexts;
import java.util.Arrays;
import java.util.Map;
Expand Down Expand Up @@ -126,7 +126,7 @@ public EntitiesController entitiesController() {
return entitiesController;
}

@MockBean public TimelineController timelineController;
@MockBean public TimelineControllerV2 timelineControllerV2;

@MockBean public RelationshipsController relationshipsController;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/*
Use v2 or v3 controllers instead
*/
@Deprecated
@RestController
@RequestMapping("/entities/v1")
@Slf4j
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/*
Use v2 or v3 controllers instead
*/
@Deprecated
@RestController
@RequiredArgsConstructor
@RequestMapping("/relationships/v1")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package io.datahubproject.openapi.v1.timeline;

import com.datahub.authentication.Authentication;
import com.datahub.authentication.AuthenticationContext;
import com.datahub.authorization.AuthUtil;
import com.datahub.authorization.AuthorizerChain;
import com.datahub.authorization.ConjunctivePrivilegeGroup;
import com.datahub.authorization.DisjunctivePrivilegeGroup;
import com.datahub.authorization.EntitySpec;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.google.common.collect.ImmutableList;
import com.linkedin.common.urn.Urn;
import com.linkedin.metadata.authorization.PoliciesConfig;
import com.linkedin.metadata.timeline.TimelineService;
import com.linkedin.metadata.timeline.data.ChangeCategory;
import com.linkedin.metadata.timeline.data.ChangeTransaction;
import io.datahubproject.openapi.exception.UnauthorizedException;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.net.URISyntaxException;
import java.util.List;
import java.util.Set;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/*
Use v2 or v3 controllers instead
*/
@Deprecated
@RestController
@AllArgsConstructor
@RequestMapping("/timeline/v1")
@Tag(
name = "Timeline",
description =
"An API for retrieving historical updates to entities and their related documentation.")
public class TimelineControllerV1 {

private final TimelineService _timelineService;
private final AuthorizerChain _authorizerChain;

@Value("${authorization.restApiAuthorization:false}")
private Boolean restApiAuthorizationEnabled;

/**
* @param rawUrn
* @param startTime
* @param endTime
* @param raw
* @param categories
* @return
* @throws URISyntaxException
* @throws JsonProcessingException
*/
@GetMapping(path = "/{urn}", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<ChangeTransaction>> getTimeline(
@PathVariable("urn") String rawUrn,
@RequestParam(name = "startTime", defaultValue = "-1") long startTime,
@RequestParam(name = "endTime", defaultValue = "0") long endTime,
@RequestParam(name = "raw", defaultValue = "false") boolean raw,
@RequestParam(name = "categories") Set<ChangeCategory> categories)
throws URISyntaxException, JsonProcessingException {
// Make request params when implemented
String startVersionStamp = null;
String endVersionStamp = null;
Urn urn = Urn.createFromString(rawUrn);
Authentication authentication = AuthenticationContext.getAuthentication();
String actorUrnStr = authentication.getActor().toUrnStr();
EntitySpec resourceSpec = new EntitySpec(urn.getEntityType(), rawUrn);
DisjunctivePrivilegeGroup orGroup =
new DisjunctivePrivilegeGroup(
ImmutableList.of(
new ConjunctivePrivilegeGroup(
ImmutableList.of(PoliciesConfig.GET_TIMELINE_PRIVILEGE.getType()))));
if (restApiAuthorizationEnabled
&& !AuthUtil.isAuthorized(_authorizerChain, actorUrnStr, orGroup, resourceSpec)) {
throw new UnauthorizedException(actorUrnStr + " is unauthorized to edit entities.");
}
return ResponseEntity.ok(
_timelineService.getTimeline(
urn, categories, startTime, endTime, startVersionStamp, endVersionStamp, raw));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
name = "Timeline",
description =
"An API for retrieving historical updates to entities and their related documentation.")
public class TimelineController {
public class TimelineControllerV2 {

private final TimelineService _timelineService;
private final AuthorizerChain _authorizerChain;
Expand Down

0 comments on commit d494e35

Please sign in to comment.